================
@@ -3514,6 +3520,31 @@ void CodeGenModule::AddDependentLib(StringRef Lib) {
   LinkerOptionsMetadata.push_back(llvm::MDNode::get(C, MDOpts));
 }
 
+/// Process copyright pragma and create LLVM metadata.
+/// #pragma comment(copyright, "string") embed copyright
+/// information into the object file's loader section.
+///
+/// Example: #pragma comment(copyright, "Copyright IBM Corp. 2024")
+///
+/// This should only be called once per translation unit.
+void CodeGenModule::ProcessPragmaComment(PragmaMSCommentKind Kind,
+                                         StringRef Comment) {
+  // Ensure we are only processing Copyright Pragmas
+  assert(Kind == PCK_Copyright &&
+         "Unexpected pragma comment kind, ProcessPragmaComment should only be "
+         "called for PCK_Copyright");
+
+  // Only one copyright pragma allowed per translation unit
+  if (LoadTimeComment) {
----------------
tonykuttai wrote:

The current behaviour is consistent with the Legacy XLC. XL also emitted a 
warning and continued with the compilation as shown below.

Example `tt.c`
```
#pragma comment(copyright,"My copyright")
#pragma comment(copyright,"My copyright 2")
int main() { return 0; }
```

```
$ $xlc_latest -c tt.c -o tt.o
"tt.c", line 6.1: 1506-264 (W) pragma comment(copyright) directive can be 
specified only once per source file.
[~/llvm/issues/pragmacomment/xlc] $ strings -a tt.o 
.text
 .data
@.bss
main
My copyright
.file
tt.c
.text
.data
.bss
.main
_$STATIC
_$STATIC
main
main
BMon Feb  9 01:37:11 2026 
IBM XL C for AIX, Version 16.1.0.21
[~/llvm/issues/pragmacomment/xlc] $
```

Bevaiour of OpenXL with our current changes
```
[~/llvm/issues/pragmacomment/xlc] $ $LLVM_BUILD/bin/clang -c tt.c -o tt_openxl.o
tt.c:6:17: warning: '#pragma comment copyright' can be specified only once per 
translation unit - ignored [-Wignored-pragmas]
    6 | #pragma comment(copyright,"My copyright 2")
      |                 ^
1 warning generated.
[~/llvm/issues/pragmacomment/xlc] $ strings -a tt_openxl.o 
.text
 .data
main
My copyright
.file
tt.c
.main
main
E__loadtime_comment
LLVM version 23.0.0git
__loadtime_comment_str
[~/llvm/issues/pragmacomment/xlc] $ 
```

https://github.com/llvm/llvm-project/pull/178184
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to