Skip to content

gdb/testsuite: strip ANSI escapes before pruning omp-rocm ld.lld warning - #242

Merged
spatrang merged 1 commit into
amd-stagingfrom
users/spatrang/omp-rocm-strip-ansi-lld-warning
Aug 6, 2026
Merged

gdb/testsuite: strip ANSI escapes before pruning omp-rocm ld.lld warning#242
spatrang merged 1 commit into
amd-stagingfrom
users/spatrang/omp-rocm-strip-ansi-lld-warning

Conversation

@spatrang

@spatrang spatrang commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

The OpenMP-offload ROCm tests (gdb.rocm/omp-target-*.exp) compile device code with amdclang. The device linker ld.lld emits a benign warning:

ld.lld: warning: <unknown>:0:0: in function __keep_alive void (): local memory global used by non-kernel function

gdb_compile treats leftover compiler/linker output as a build failure, so an existing regsub already prunes this warning. That prune is anchored on the literal ld.lld: warning:.

With newer toolchains (LLVM 23), ld.lld colorizes its own diagnostics: --color-diagnostics defaults to auto and turns on whenever stderr is a tty, which is the case when the compiler is spawned under a pty (as DejaGnu does), regardless of clang's -fdiagnostics-color=never. The warning then carries ANSI SGR escapes (e.g. ESC[0;35m) between ld.lld: and warning:, defeating the anchored regexp. The warning survives, the build is treated as failed, and the testcase is skipped (UNSUPPORTED/UNTESTED).

This strips ANSI SGR escapes from the captured compiler output before the existing omp-rocm prunes run. Only escape bytes are removed (never diagnostic text), so genuine error: diagnostics are still detected and real build failures still fail.

JIRA

AIROCGDB-642

@spatrang
spatrang requested a review from a team as a code owner August 3, 2026 08:39
Comment thread gdb/testsuite/lib/gdb.exp Outdated
The omp-rocm build path in gdb_compile prunes a benign ROCm device
linker warning (ld.lld: warning: ... __keep_alive ... local memory
global used by non-kernel function) so the OpenMP offload testcases
are not wrongly marked UNTESTED.  The prune is anchored on the literal
"ld.lld: warning:".

With newer toolchains (e.g. LLVM 23), ld.lld's --color-diagnostics
defaults to "auto" and colorizes when spawned under a pty (as DejaGnu
does), inserting ANSI escapes between "ld.lld:" and "warning:" that
stop the anchored regexp from matching.  The warning then survives,
gdb_compile treats it as a build failure, and the testcase is skipped.

Pass -Xoffload-linker --no-color-diagnostics on the link step so the
device (offload) linker never colorizes its diagnostics.  It is added
only when linking, so the compile step does not warn about an unused
argument; -Wl, would only reach the host linker, not the device ld.lld
that emits this warning.

Co-authored-by: Cursor <cursoragent@cursor.com>
@spatrang
spatrang force-pushed the users/spatrang/omp-rocm-strip-ansi-lld-warning branch from ae933f6 to 2daadd7 Compare August 3, 2026 13:52
@spatrang

spatrang commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Updated per review: switched from stripping the ANSI escapes to suppressing device-linker coloring at the source.

The omp-rocm build now passes -Xoffload-linker --no-color-diagnostics (added only on the link step, $type eq "executable"), so the device ld.lld never colorizes the benign __keep_alive warning and the existing anchored prune matches. As discussed, -Wl, only reaches the host linker, not the device ld.lld that emits this warning.

Adding it link-only avoids an unused-argument warning on the Fortran -c step (amdflang doesn't take -Wno-unused-command-line-argument), so no new warnings are introduced on any language path.

Verified with LLVM 22/23: C/C++/Fortran compile+link succeed and the warning is no longer colorized.

@spatrang
spatrang requested a review from lancesix August 4, 2026 07:23

@lancesix lancesix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks. Maybe, please wait for #244 to land before merging to difficulties merging the merge from upstream.

@spatrang

spatrang commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

LGTM, thanks. Maybe, please wait for #244 to land before merging to difficulties merging the merge from upstream.

Sure, @lancesix

@spatrang
spatrang merged commit ff03066 into amd-staging Aug 6, 2026
7 checks passed
@lumachad

lumachad commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Should we cherry-pick this to amd-staging-rocgdb-16?

@lancesix

lancesix commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Should we cherry-pick this to amd-staging-rocgdb-16?

Most probably, yes.

@lumachad

lumachad commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Should we cherry-pick this to amd-staging-rocgdb-16?

Most probably, yes.

Done in #252.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants