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

Wael Yehia via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jun 15 10:48:12 PDT 2026


w2yehia wrote:

I don't like that we have two user interfaces of specifying a copyright string (a pragma and a flag), but I can live with that for user's convenience and given the two interfaces converge as early as possible (i.e. in clang). However having seen this PR now, I see that we have two IRs:
1) pragma  => generates an MD in clang => LowerCommentStringPass lowers to a global variable that is referenced by every function with `!implicit.ref`
2) -mloadtime-comments-vars=foo,bar   =>  generate a different MD in clang `!loadtime_comment.vars = !{!{!"foo"}, !{!"bar"}}`  => LowerCommentStringPass processes the list of names on the MD and generates `!implicit.ref` to each named global.

I think it's better to have a single representation in IR for the two FE interfaces, and have the lowering pass handle one representation. Since we don't want to mutate existing variables referenced via the flag, annotating the variables (to be later consumed by the lowering pass) is fine. But we don't just list their names on an MD, instead you can list the variables directly on the MD (`!loadtime_comment.vars = !{ptr @sccsid, ptr @version}`) or better, decorate the variables themselves with an MD:
```
@sccsid = internal global ptr @.str, align 8, !loadtime_comment
@version = internal global [27 x i8] c"@(#) Copyright Version 2.0\00", align 1, !loadtime_comment
```
Then, for the pragma comment, you can generate a variable per comment (or concatenate them into one, if that works for you) in clang and decorate the variable(s) with `!loadtime_comment`. 

Adding the variables to `@llvm.compiler.used` will be done in clang.

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


More information about the llvm-branch-commits mailing list