[clang] [llvm] [Clang][AIX] Add -mloadtime-comment-vars flag to preserve identifying variables (PR #187986)

Tony Varghese via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 17 07:38:25 PDT 2026


================
@@ -0,0 +1,228 @@
+// C/C++ behavior of -mloadtime-comment-vars= :
+//   codegen.cpp - mangled-name matching and what gets preserved
+//   storage.cpp - storage-duration and scope diagnostics
+//   diag.c      - volatile / non-string-literal diagnostics (C)
+//   init.cpp    - constant-initialization / string-literal diagnostics (C++)
+
+// RUN: rm -rf %t && split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++17 -O2 -triple powerpc64-ibm-aix \
+// RUN:   -mloadtime-comment-vars=x,_ZN1N1xE,_ZN1N1qE,_ZN1NL3ptrE,_ZN1A1xE,_ZN1B3verE,_ZN1C4infoE \
----------------
tonykuttai wrote:

To clarify:
Clang never allows the following:
```
❯ $LLVM_BUILD/bin/clang --target=powerpc64-ibm-aix -mloadtime-comment-vars=foo, bar -c list.c  
clang: error: no such file or directory: 'bar'
```

But we can use double quotes to allow space before ` bar`.
```
 ❯ cat list.c          
char foo[] = "@(#) foo";
char bar[] = "@(#) bar";

void f() {}

❯ $LLVM_BUILD/bin/clang --target=powerpc64-ibm-aix "-mloadtime-comment-vars=foo, bar" list.c -S -emit-llvm -o - 
; ModuleID = 'list.c'
source_filename = "list.c"
target datalayout = "E-m:a-Fi64-i64:64-i128:128-n32:64-f64:32:64-S128-v256:256:256-v512:512:512"
target triple = "powerpc64-ibm-aix"

@foo = global [9 x i8] c"@(#) foo\00", align 1, !loadtime_comment !0
@llvm.compiler.used = appending global [1 x ptr] [ptr @foo], section "llvm.metadata"
@bar = global [9 x i8] c"@(#) bar\00", align 1

; Function Attrs: noinline nounwind optnone
define void @f() #0 !implicit.ref !4 {
entry:
  ret void
}

attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="pwr7" "target-features"="+64bit-support,+allow-unaligned-fp-access,+altivec,+bpermd,+cmpb,+extdiv,+fcpsgn,+fpcvt,+fprnd,+fpu,+fre,+fres,+frsqrte,+frsqrtes,+fsqrt,+hard-float,+isa-v206-instructions,+isel,+ldbrx,+lfiwax,+mfocrf,+modern-aix-as,+popcntd,+recipprec,+stfiwx,+two-const-nr,+vsx" }

!llvm.module.flags = !{!1, !2}
!llvm.ident = !{!3}

!0 = !{}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{!"clang version 24.0.0git (git at github.com:llvm/llvm-project.git 8c0bbf4dad7888005471c32042c7fbc4a4cc8f34)"}
!4 = !{ptr @foo}
```

You can see that only `foo` gets added to `llvm.compiler.used` as ` bar` matched nothing.


https://github.com/llvm/llvm-project/pull/187986


More information about the cfe-commits mailing list