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

2026-06-15 Thread Wael Yehia via llvm-branch-commits

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
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-06-02 Thread Tony Varghese via llvm-branch-commits

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

>From e8f38666590a715ed3533ddca5f512a808659b5c Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  66 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 +
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 271 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 421 insertions(+), 87 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 992c6f2927be8..e6da6bd88108b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6844,6 +6844,72 @@ When ``#pragma comment(copyright, ...)`` appears in a 
C++20 module interface
 unit, the copyright string is embedded only in the object file compiled from
 that interface unit. Importing TUs do not re-emit the string.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables rather than via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 5dab4af7618fc..dea04b41b51f9 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4765,6 +4765,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJ

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

2026-06-02 Thread via llvm-branch-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang-codegen

Author: Tony Varghese (tonykuttai)


Changes

This patch introduces a new Clang command-line option, 
`-mloadtime-comment-vars=`, which accepts a comma-separated list of variable 
names to preserve as loadtime identifying strings in the final binary object 
file. 
It ensures that these specific string variables (such as strings that embed 
'sccsid' or 'version' info in source variables) are preserved in the object 
file and not stripped during aggressive garbage collection. This complements 
the `#pragma comment(copyright, ...)` feature by supporting codebases that use 
this older pattern.

This is a stacked pr on top of [[Analysis][AIX] Add !implicit.ref globals as 
ThinLTO summary ref edges to support pragma comment(copyright) LTO 
interaction](https://github.com/llvm/llvm-project/pull/199358#top) which in 
turn depends on [[PowerPC][AIX] Support #pragma comment copyright for 
AIX](https://github.com/llvm/llvm-project/pull/178184#top).

---

Patch is 26.50 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/187986.diff


9 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+66) 
- (modified) clang/include/clang/Basic/CodeGenOptions.h (+3) 
- (modified) clang/include/clang/Options/Options.td (+7) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+77) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+8) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+5) 
- (added) clang/test/CodeGen/loadtime-comment-vars.c (+37) 
- (modified) llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp (+184-87) 
- (added) llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll 
(+34) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 992c6f2927be8..e6da6bd88108b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6844,6 +6844,72 @@ When ``#pragma comment(copyright, ...)`` appears in a 
C++20 module interface
 unit, the copyright string is embedded only in the object file compiled from
 that interface unit. Importing TUs do not re-emit the string.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables rather than via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, an

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

2026-06-02 Thread Tony Varghese via llvm-branch-commits

https://github.com/tonykuttai ready_for_review 
https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-06-02 Thread Tony Varghese via llvm-branch-commits

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

>From 66110fe109a470a7964e16c1373acc41bab79e91 Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  66 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 +
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 271 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 421 insertions(+), 87 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 992c6f2927be8..e6da6bd88108b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6844,6 +6844,72 @@ When ``#pragma comment(copyright, ...)`` appears in a 
C++20 module interface
 unit, the copyright string is embedded only in the object file compiled from
 that interface unit. Importing TUs do not re-emit the string.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables rather than via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 5dab4af7618fc..dea04b41b51f9 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4765,6 +4765,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJ

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

2026-06-02 Thread Tony Varghese via llvm-branch-commits

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

>From 481457d1e7398fcf8f2954ce3060d64a3f153b63 Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  67 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 +
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 271 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 422 insertions(+), 87 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 992c6f2927be8..11307dcb7ce7d 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6844,6 +6844,73 @@ When ``#pragma comment(copyright, ...)`` appears in a 
C++20 module interface
 unit, the copyright string is embedded only in the object file compiled from
 that interface unit. Importing TUs do not re-emit the string.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables, such as ``sccsid`` or ``version``, rather than
+via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 5dab4af7618fc..dea04b41b51f9 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4765,6 +4765,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def ml

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

2026-05-27 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :window: Windows x64 Test Results

* 135168 tests passed
* 3328 tests skipped
* 5 tests failed

## Failed Tests
(click on a test name to see its output)

### LLVM

LLVM.LTO/PowerPC/pragma-comment-copyright-thinlto.ll

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 7
rm -rf 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp
 && mkdir 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp
# executed command: rm -rf 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp'
# note: command had no output on stdout or stderr
# executed command: mkdir 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp'
# note: command had no output on stdout or stderr
# RUN: at line 8
split-file 
C:\_work\llvm-project\llvm-project\llvm\test\LTO\PowerPC\pragma-comment-copyright-thinlto.ll
 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp
# executed command: split-file 
'C:\_work\llvm-project\llvm-project\llvm\test\LTO\PowerPC\pragma-comment-copyright-thinlto.ll'
 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp'
# note: command had no output on stdout or stderr
# RUN: at line 9
c:\_work\llvm-project\llvm-project\build\bin\opt.exe 
-passes='thinlto-pre-link' 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu1.ll
 -o - |c:\_work\llvm-project\llvm-project\build\bin\opt.exe -module-summary 
-o 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu1.bc
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' 
'-passes=thinlto-pre-link' 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu1.ll'
 -o -
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' 
-module-summary -o 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu1.bc'
# note: command had no output on stdout or stderr
# RUN: at line 11
c:\_work\llvm-project\llvm-project\build\bin\opt.exe 
-passes='thinlto-pre-link' 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.ll
 -o - |c:\_work\llvm-project\llvm-project\build\bin\opt.exe -module-summary 
-o 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.bc
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' 
'-passes=thinlto-pre-link' 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.ll'
 -o -
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' 
-module-summary -o 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.bc'
# note: command had no output on stdout or stderr
# RUN: at line 13
c:\_work\llvm-project\llvm-project\build\bin\llvm-lto.exe 
--thinlto-action=thinlink -o combined 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu1.bc
 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.bc
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\llvm-lto.exe' 
--thinlto-action=thinlink -o combined 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu1.bc'
 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.bc'
# note: command had no output on stdout or stderr
# RUN: at line 14
c:\_work\llvm-project\llvm-project\build\bin\llvm-lto.exe 
--thinlto-action=import   --thinlto-index=combined   
--exported-symbol=main --exported-symbol=f_add
--exported-symbol=my_function 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.bc
 -o 
C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.imported.bc
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\llvm-lto.exe' 
--thinlto-action=import --thinlto-index=combined --exported-symbol=main 
--exported-symbol=f_add --exported-symbol=my_function 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.bc'
 -o 
'C:\_work\llvm-project\llvm-project\build\test\LTO\PowerPC\Output\pragma-comment-copyright-thinlto.ll.tmp/tu2.imported.bc'

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

2026-05-27 Thread Tony Varghese via llvm-branch-commits

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

>From 38146ce0b16e9fd7417c3ae67d3fe3e22478f1f7 Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  67 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 +
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 262 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 416 insertions(+), 84 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bab0c299a85ee..bb97f32f54975 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6874,6 +6874,73 @@ local ``internal`` global cannot be imported into 
another module without
 bringing that global along, which ThinLTO cannot do for ``internal``
 globals.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables, such as ``sccsid`` or ``version``, rather than
+via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 753e3ac1b74a5..ae800711a2612 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4758,6 +4758,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-comm

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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

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

>From aaf3e32ad107731f28260d0709f86887246f7cae Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH 1/2] [PowerPC][AIX] Add -mloadtime-comment-vars support

---
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  78 ++
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  28 
 .../Utils/LowerCommentStringPass.cpp  | 146 +++---
 .../loadtime-comment-vars.ll  |  26 
 8 files changed, 245 insertions(+), 56 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 753e3ac1b74a5..ae800711a2612 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4758,6 +4758,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-comment-vars=">,
+  Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Comma-separated list of global variable names to treat as "
+   "loadtime variables">,
+  MarshallingInfoStringVector>;
 def mdefault_visibility_export_mapping_EQ : Joined<["-"], 
"mdefault-visibility-export-mapping=">,
   Values<"none,explicit,all">,
   NormalizedValuesScope<"LangOptions::DefaultVisiblityExportMapping">,
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8630e000c59d0..2866abe8077cc 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1738,6 +1738,9 @@ void CodeGenModule::Release() {
 
   EmitLoadTimeComment();
 
+  // Emit loadtime comment variables specified via -mloadtime-comment-vars.
+  EmitLoadTimeCommentVars();
+
   // If there is device offloading code embed it in the host now.
   EmbedObject(&getModule(), CodeGenOpts, *getFileSystem(), getDiags());
 
@@ -4237,6 +4240,81 @@ void CodeGenModule::EmitLoadTimeComment() {
   }
 }
 
+/// Check if a variable declaration is suitable to be treated as a loadtime
+/// comment variable. Valid variables must be character pointers or character
+/// arrays with an initializer.
+bool CodeGenModule::isValidLoadTimeCommentVariable(const VarDecl *D) const {
+  // Must be a valid declaration and must have an initializer (the string)
+  if (!D || !D->hasInit())
+return false;
+
+  QualType Ty = D->getType();
+
+  // 1. Handle Pointers (e.g., char *sccsid, const char *copyright)
+  if (const PointerType *PT = Ty->getAs()) {
+if (PT->getPointeeType()->isAnyCharacterType())
+  return true;
+  }
+
+  // 2. Handle Arrays (e.g., char version[])
+  // We use ASTContext::getAsArrayType to safely unwrap constant arrays
+  if (const ArrayType *AT = getContext().getAsArrayType(Ty)) {
+if (AT->getElementType()->isAnyCharacterType())
+  return true;
+  }
+
+  return false; // Reject ints, structs, etc.
+}
+
+/// Emit global variables specified via -mloadtime-comment-vars as loadtime
+/// comment variables. These variables are tagged with metadata and marked as
+/// used to prevent garbage collection. Only valid on AIX.
+void CodeGenModule::EmitLoadTimeCommentVars() {
+  // Only supported on AIX
+  if (!getTriple().isOSAIX())
+return;
+
+  const auto &LoadTimeCommentVars = getCodeGenOpts().LoadTimeCommentVars;
+  if (LoadTimeCommentVars.empty())
+return;
+
+  TranslationUnitDecl *TU = getContext().getTranslationUnitDecl();
+  // Iterate through all top-level declarations
+  for (auto *D : TU->decls()) {
+if (VarDecl *VD = dyn_cast(D)) {
+
+  // Check if the variable name is 

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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

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

>From 268182a9ac6096ef9d382a83f63311621b16229b Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  67 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 ++
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 249 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 403 insertions(+), 84 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bab0c299a85ee..bb97f32f54975 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6874,6 +6874,73 @@ local ``internal`` global cannot be imported into 
another module without
 bringing that global along, which ThinLTO cannot do for ``internal``
 globals.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables, such as ``sccsid`` or ``version``, rather than
+via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 753e3ac1b74a5..ae800711a2612 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4758,6 +4758,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-com

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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

https://github.com/tonykuttai edited 
https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

https://github.com/tonykuttai edited 
https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-05-25 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 171625 tests passed
* 3065 tests skipped
* 2 tests failed

## Failed Tests
(click on a test name to see its output)

### lldb-api

lldb-api.functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py

```
Script:
--
/usr/bin/python3 
/home/gha/actions-runner/_work/llvm-project/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib
 --env 
LLVM_INCLUDE_DIR=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include
 --env 
LLVM_TOOLS_DIR=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin
 --libcxx-include-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include/c++/v1 
--libcxx-include-target-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include/x86_64-unknown-linux-gnu/c++/v1
 --libcxx-library-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib/x86_64-unknown-linux-gnu
 --arch x86_64 --build-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex
 --lldb-module-cache-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/lldb 
--compiler 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/clang 
--dsymutil 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin 
--lldb-obj-root 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/lldb 
--lldb-libs-dir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib 
--cmake-build-type Release 
/home/gha/actions-runner/_work/llvm-project/llvm-project/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list
 -p TestDataFormatterGenericList.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 23.0.0git (https://github.com/llvm/llvm-project revision 
c7f6d722b2d5a8ff8bf992f99203800bc0b49259)
  clang revision c7f6d722b2d5a8ff8bf992f99203800bc0b49259
  llvm revision c7f6d722b2d5a8ff8bf992f99203800bc0b49259
Skipping the following test categories: msvcstl, dsym, pdb, gmodules, 
debugserver, objc

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libcpp_dsym 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libcpp_dsym)
 (test case does not fall in any category of interest for this run) 
PASS: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libcpp_dwarf 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libcpp_dwarf)
PASS: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libcpp_dwo 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libcpp_dwo)
UNSUPPORTED: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libcpp_pdb 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libcpp_pdb)
 (test case does not fall in any category of interest for this run) 
UNSUPPORTED: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libstdcpp_dsym 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libstdcpp_dsym)
 (test case does not fall in any category of interest for this run) 
PASS: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libstdcpp_dwarf 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libstdcpp_dwarf)
PASS: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libstdcpp_dwo 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libstdcpp_dwo)
UNSUPPORTED: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_libstdcpp_pdb 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_libstdcpp_pdb)
 (test case does not fall in any category of interest for this run) 
UNSUPPORTED: LLDB 
(/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64)
 :: test_ptr_and_ref_msvcstl_dsym 
(TestDataFormatterGenericList.GenericListDataFormatterTestCase.test_ptr_and_ref_msvcstl_dsym)
 (test case does not fall in any category of interest for th

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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

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

>From a31b969a27f3c1ef0724ea1812c9ec8d622c445d Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  67 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 ++
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 248 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 402 insertions(+), 84 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bab0c299a85ee..bb97f32f54975 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6874,6 +6874,73 @@ local ``internal`` global cannot be imported into 
another module without
 bringing that global along, which ThinLTO cannot do for ``internal``
 globals.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables, such as ``sccsid`` or ``version``, rather than
+via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 753e3ac1b74a5..ae800711a2612 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4758,6 +4758,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-com

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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

https://github.com/tonykuttai edited 
https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

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

>From 38146ce0b16e9fd7417c3ae67d3fe3e22478f1f7 Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  67 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 +
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 262 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 416 insertions(+), 84 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bab0c299a85ee..bb97f32f54975 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6874,6 +6874,73 @@ local ``internal`` global cannot be imported into 
another module without
 bringing that global along, which ThinLTO cannot do for ``internal``
 globals.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables, such as ``sccsid`` or ``version``, rather than
+via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 753e3ac1b74a5..ae800711a2612 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4758,6 +4758,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-comm

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

2026-05-25 Thread Tony Varghese via llvm-branch-commits

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

>From 7bf2d97109b21eed0bce6b0fd22a961dc62905aa Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Sat, 23 May 2026 14:54:05 -0400
Subject: [PATCH] [PowerPC][AIX] Add -mloadtime-comment-vars support to
 preserve variables in the final object file.

---
 clang/docs/LanguageExtensions.rst |  67 +
 clang/include/clang/Basic/CodeGenOptions.h|   3 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  77 ++
 clang/lib/CodeGen/CodeGenModule.h |   8 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  37 +++
 .../Utils/LowerCommentStringPass.cpp  | 248 --
 .../loadtime-comment-vars.ll  |  34 +++
 9 files changed, 402 insertions(+), 84 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bab0c299a85ee..0ee9b447b2b55 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6874,6 +6874,73 @@ local ``internal`` global cannot be imported into 
another module without
 bringing that global along, which ThinLTO cannot do for ``internal``
 globals.
 
+Preserving Identifying Variables with -mloadtime-comment-vars
+--
+
+The ``-mloadtime-comment-vars=`` flag accepts a comma-separated list of
+global variable names that should be preserved in the final object file as
+loadtime identifying strings. This is an AIX-specific feature and is silently
+ignored on other targets.
+
+This flag complements ``#pragma comment(copyright, ...)`` for codebases that
+already use the traditional UNIX convention of embedding identifying strings
+directly in source variables, such as ``sccsid`` or ``version``, rather than
+via a pragma.
+
+**Syntax**
+
+.. code-block:: console
+
+  -mloadtime-comment-vars=[,,...]
+
+**Valid variable types**
+
+A variable named in the list must meet both of these conditions to be
+preserved:
+
+- Its type must be a character pointer (``char *``, ``const char *``) or a
+  character array (``char[]``).
+- It must have an initializer.
+
+Variables that fail either check -- for example, an ``int`` or a ``struct`` --
+are silently skipped. Variables that appear in the list but are not defined in
+the translation unit are also ignored.
+
+**Example**
+
+.. code-block:: c
+
+  static char *sccsid = "@(#) MyApp Version 1.0";
+  static char  version[] = "@(#) Built 2026-05-24";
+
+  void foo() {}
+
+Compiled with:
+
+.. code-block:: console
+
+  clang -target powerpc64-ibm-aix \
+-mloadtime-comment-vars=sccsid,version \
+-c source.c -o source.o
+
+Both ``sccsid`` and ``version`` survive optimization and garbage collection and
+are visible in the object file via standard AIX inspection tools:
+
+.. code-block:: console
+
+  $ what source.o
+  source.o:
+   MyApp Version 1.0
+   Built 2026-05-24
+
+**Interaction with** ``#pragma comment(copyright, ...)``
+
+The two mechanisms can be used together in the same translation unit. The
+pragma produces a dedicated ``__loadtime_comment_str`` symbol placed in the
+``__loadtime_comment`` section, while ``-mloadtime-comment-vars`` preserves
+the named source variables in place using ``.ref`` directives. Both sets of
+strings appear in the final object file independently.
+
 Evaluating Object Size
 ==
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e43112b4bb98b..54b2fd2077d7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -334,6 +334,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  /// List of global variable names to preserve as loadtime comment variables.
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 753e3ac1b74a5..ae800711a2612 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4758,6 +4758,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+:

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

2026-05-23 Thread Tony Varghese via llvm-branch-commits

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

>From 9fa76d028cc835c1aa1ab55544a6e42d8523e8b3 Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Wed, 18 Mar 2026 10:48:36 -0400
Subject: [PATCH 1/3] [Clang][AIX] Add -mloadtime-comment-vars flag to preserve
 identifying variables

---
 clang/include/clang/Basic/CodeGenOptions.h|   2 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  73 +++
 clang/lib/CodeGen/CodeGenModule.h |   6 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  28 
 .../Utils/LowerCommentStringPass.cpp  | 120 ++
 .../loadtime-comment-vars.ll  |  26 
 8 files changed, 212 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9454f7672b7e1..062a7a4dff73e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -323,6 +323,8 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 8b0c701521728..92d86bc3d06f1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4698,6 +4698,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-comment-vars=">,
+  Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Comma-separated list of global variable names to treat as "
+   "loadtime variables">,
+  MarshallingInfoStringVector>;
 def mdefault_visibility_export_mapping_EQ : Joined<["-"], 
"mdefault-visibility-export-mapping=">,
   Values<"none,explicit,all">,
   NormalizedValuesScope<"LangOptions::DefaultVisiblityExportMapping">,
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index eaa64b10e2368..a2432a80e71a9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -69,6 +69,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Hash.h"
 #include "llvm/Support/TimeProfiler.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
@@ -1633,6 +1634,9 @@ void CodeGenModule::Release() {
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
   EmitLoadTimeComment();
+  
+  // Handle CLI load-time string variables
+  EmitLoadTimeCommentVars();
 
   // If there is device offloading code embed it in the host now.
   EmbedObject(&getModule(), CodeGenOpts, *getFileSystem(), getDiags());
@@ -4106,6 +4110,75 @@ void CodeGenModule::EmitLoadTimeComment() {
   }
 }
 
+bool CodeGenModule::isValidLoadTimeCommentVariable(const VarDecl *D) const {
+  // Must be a valid declaration and must have an initializer (the string)
+  if (!D || !D->hasInit())
+return false;
+
+  QualType Ty = D->getType();
+
+  // 1. Handle Pointers (e.g., char *sccsid, const char *copyright)
+  if (const PointerType *PT = Ty->getAs()) {
+if (PT->getPointeeType()->isAnyCharacterType())
+  return true;
+  }
+
+  // 2. Handle Arrays (e.g., char version[])
+  // We use ASTContext::getAsArrayType to safely unwrap constant arrays
+  if (const ArrayType *AT = getContext().getAsArrayType(Ty)) {
+if (AT->getElementType()->isAnyCharacterType())
+  return true;
+  }
+
+  return false; // Reject ints, structs, etc.
+}
+
+void CodeGenModule::EmitLoadTimeCommentVars() {
+  // Handle CLI loadtime comment variables
+  if (!getTriple().isOSAIX())
+return;
+
+  const auto &LoadTimeCommentVars = getCodeGenOpts().LoadTimeCommentVars;
+  if (LoadTimeCommentVars.empty())
+return;
+
+  TranslationUnitDecl *TU = getContext().getTranslationUnitDecl();
+  // Iterate through ALL top-level declarations
+  for (auto *D : TU->decls()) {
+if (VarDecl *VD = dyn_cast(D)) {
+
+  // Check if the variable name is in our parsed list
+  if (!llvm::is_contained(LoadTimeCommentVars, VD->getName()))
+continue;
+
+  i

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

2026-03-23 Thread Tony Varghese via llvm-branch-commits

https://github.com/tonykuttai edited 
https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-03-23 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff origin/main HEAD --extensions c,h,cpp -- 
clang/test/CodeGen/loadtime-comment-vars.c 
clang/include/clang/Basic/CodeGenOptions.h clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/CodeGen/CodeGenModule.h clang/lib/Driver/ToolChains/Clang.cpp 
llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp --diff_from_common_commit
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index a2432a80e..739e0c1bc 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1634,7 +1634,7 @@ void CodeGenModule::Release() {
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
   EmitLoadTimeComment();
-  
+
   // Handle CLI load-time string variables
   EmitLoadTimeCommentVars();
 
diff --git a/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp 
b/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp
index 3a20694a6..5b0cfa582 100644
--- a/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp
+++ b/llvm/lib/Transforms/Utils/LowerCommentStringPass.cpp
@@ -115,7 +115,7 @@ PreservedAnalyses LowerCommentStringPass::run(Module &M,
   }
 }
 MD->eraseFromParent();
-  }  
+  }
 
   // 2. Process copyright variables - multiple allowed per TU
   for (GlobalVariable &GV : M.globals()) {

``




https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-03-23 Thread Tony Varghese via llvm-branch-commits

tonykuttai wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.com/github/pr/llvm/llvm-project/187986?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#187986** https://app.graphite.com/github/pr/llvm/llvm-project/187986?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.com/github/pr/llvm/llvm-project/187986?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#187985** https://app.graphite.com/github/pr/llvm/llvm-project/187985?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/187986
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


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

2026-03-23 Thread Tony Varghese via llvm-branch-commits

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

None

>From 9fa76d028cc835c1aa1ab55544a6e42d8523e8b3 Mon Sep 17 00:00:00 2001
From: Tony Varghese 
Date: Wed, 18 Mar 2026 10:48:36 -0400
Subject: [PATCH] [Clang][AIX] Add -mloadtime-comment-vars flag to preserve
 identifying variables

---
 clang/include/clang/Basic/CodeGenOptions.h|   2 +
 clang/include/clang/Options/Options.td|   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  73 +++
 clang/lib/CodeGen/CodeGenModule.h |   6 +
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +
 clang/test/CodeGen/loadtime-comment-vars.c|  28 
 .../Utils/LowerCommentStringPass.cpp  | 120 ++
 .../loadtime-comment-vars.ll  |  26 
 8 files changed, 212 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/CodeGen/loadtime-comment-vars.c
 create mode 100644 
llvm/test/Transforms/LowerCommentString/loadtime-comment-vars.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9454f7672b7e1..062a7a4dff73e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -323,6 +323,8 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
+  std::vector LoadTimeCommentVars;
+
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 8b0c701521728..92d86bc3d06f1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4698,6 +4698,13 @@ def fvisibility_global_new_delete_EQ : Joined<["-"], 
"fvisibility-global-new-del
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"The visibility for global C++ operator new and delete 
declarations. If 'source' is specified the visibility is not adjusted">,
   
MarshallingInfoVisibilityGlobalNewDelete,
 "ForceDefault">;
+def mloadtime_comment_vars_EQ
+: CommaJoined<["-"], "mloadtime-comment-vars=">,
+  Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Comma-separated list of global variable names to treat as "
+   "loadtime variables">,
+  MarshallingInfoStringVector>;
 def mdefault_visibility_export_mapping_EQ : Joined<["-"], 
"mdefault-visibility-export-mapping=">,
   Values<"none,explicit,all">,
   NormalizedValuesScope<"LangOptions::DefaultVisiblityExportMapping">,
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index eaa64b10e2368..a2432a80e71a9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -69,6 +69,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Hash.h"
 #include "llvm/Support/TimeProfiler.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
@@ -1633,6 +1634,9 @@ void CodeGenModule::Release() {
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
   EmitLoadTimeComment();
+  
+  // Handle CLI load-time string variables
+  EmitLoadTimeCommentVars();
 
   // If there is device offloading code embed it in the host now.
   EmbedObject(&getModule(), CodeGenOpts, *getFileSystem(), getDiags());
@@ -4106,6 +4110,75 @@ void CodeGenModule::EmitLoadTimeComment() {
   }
 }
 
+bool CodeGenModule::isValidLoadTimeCommentVariable(const VarDecl *D) const {
+  // Must be a valid declaration and must have an initializer (the string)
+  if (!D || !D->hasInit())
+return false;
+
+  QualType Ty = D->getType();
+
+  // 1. Handle Pointers (e.g., char *sccsid, const char *copyright)
+  if (const PointerType *PT = Ty->getAs()) {
+if (PT->getPointeeType()->isAnyCharacterType())
+  return true;
+  }
+
+  // 2. Handle Arrays (e.g., char version[])
+  // We use ASTContext::getAsArrayType to safely unwrap constant arrays
+  if (const ArrayType *AT = getContext().getAsArrayType(Ty)) {
+if (AT->getElementType()->isAnyCharacterType())
+  return true;
+  }
+
+  return false; // Reject ints, structs, etc.
+}
+
+void CodeGenModule::EmitLoadTimeCommentVars() {
+  // Handle CLI loadtime comment variables
+  if (!getTriple().isOSAIX())
+return;
+
+  const auto &LoadTimeCommentVars = getCodeGenOpts().LoadTimeCommentVars;
+  if (LoadTimeCommentVars.empty())
+return;
+
+  TranslationUnitDecl *TU = getContext().getTranslationUnitDecl();
+  // Iterate through ALL top-level declarations
+  for (auto *D : TU->decls()) {
+if (VarDecl *VD = dyn_cast(D)) {
+
+  // Check if the variable name is in our parsed list
+  if (!llvm::is_contained(LoadTimeCommentVars, VD->getName()))
+continue;
+
+