Skip to content

Commit 252f063

Browse files
author
Tony Varghese
committed
Pragmas from imported C++20 modules are ignored in the importing translation unit, add backend tests
1 parent cfa6019 commit 252f063

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7474,7 +7474,10 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
74747474
case PCK_Lib:
74757475
AddDependentLib(PCD->getArg());
74767476
break;
7477-
case PCK_Copyright:
7477+
case PCK_Copyright:
7478+
// Skip pragmas deserialized from modules/PCHs
7479+
if (PCD->isFromASTFile())
7480+
break;
74787481
ProcessPragmaCommentCopyright(PCD->getArg());
74797482
break;
74807483
case PCK_Compiler:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: split-file %s %t
2+
3+
// Build the module interface to a PCM
4+
// RUN: %clang_cc1 -std=c++20 -triple powerpc-ibm-aix \
5+
// RUN: -emit-module-interface %t/copymod.cppm -o %t/copymod.pcm
6+
7+
// verify that module interface emit copyright string when compiled to assembly
8+
// RUN: %clang_cc1 -std=c++20 -triple powerpc-ibm-aix -S %t/copymod.cppm -o - \
9+
// RUN: | FileCheck %s --check-prefix=CHECK-MOD
10+
// CHECK-MOD: .string "module me"
11+
12+
// Compile an importing TU that uses the prebuilt module and verify that it
13+
// does NOT re-emit the module's copyright string.
14+
// RUN: %clang_cc1 -std=c++20 -triple powerpc-ibm-aix \
15+
// RUN: -fprebuilt-module-path=%t -S %t/importmod.cc -o - \
16+
// RUN: | FileCheck %s
17+
// CHECK-NOT: .string "module me"
18+
19+
//--- copymod.cppm
20+
export module copymod;
21+
#pragma comment(copyright, "module me")
22+
export inline void f() {}
23+
24+
//--- importmod.cc
25+
import copymod;
26+
void g() { f(); }
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; REQUIRES: powerpc-registered-target, system-aix
2+
3+
; This test verify that the CopyrightMetadataPass and the PowerPC AIX backend
4+
; correctly lower and preserve copyright metadata emitted by Clang
5+
; from `#pragma comment(copyright, "...")`.
6+
7+
; Build IR with the pass:
8+
; RUN: opt -passes=copyright-metadata %s -o %t.bc
9+
10+
; ---------------- 32-bit AIX ----------------
11+
; RUN: llc -mtriple=powerpc-ibm-aix -filetype=obj -o %t32.o %t.bc
12+
; RUN: llc -mtriple=powerpc-ibm-aix -filetype=asm %t.bc -o - | FileCheck %s --check-prefix=CHECK-ASM
13+
14+
; Verify that TU-local symbols and relocations reference the string.
15+
; RUN: llvm-objdump -t %t32.o | FileCheck %s --check-prefix=CHECK-SYMS
16+
; RUN: llvm-objdump -r %t32.o | FileCheck %s --check-prefix=CHECK-REL
17+
18+
; ---------------- 64-bit AIX ----------------
19+
; RUN: llc -mtriple=powerpc64-ibm-aix -filetype=obj -o %t64.o %t.bc
20+
; RUN: llc -mtriple=powerpc-ibm-aix -filetype=asm %t.bc -o - | FileCheck %s --check-prefix=CHECK-ASM
21+
; RUN: llvm-objdump -t %t64.o | FileCheck %s --check-prefix=CHECK-SYMS
22+
; RUN: llvm-objdump -r %t64.o | FileCheck %s --check-prefix=CHECK-REL
23+
24+
target triple = "powerpc-ibm-aix"
25+
26+
define void @f0() {
27+
entry:
28+
ret void
29+
}
30+
31+
define i32 @main() {
32+
entry:
33+
ret i32 0
34+
}
35+
36+
!llvm.module.flags = !{!0}
37+
!0 = !{i32 1, !"wchar_size", i32 2}
38+
39+
!aix.copyright.comment = !{!1}
40+
!1 = !{!"Copyright IBM"}
41+
42+
; ---------------- Assembly checks ----------------
43+
; Verify that the backend:
44+
; - Emits a `.ref` directive to tie the string to the TU
45+
; - Emits the string in a dedicated read-only csect
46+
;
47+
; CHECK-ASM: .ref __aix_copyright_str
48+
; CHECK-ASM: .csect __aix_copyright[RO],2
49+
; CHECK-ASM-NEXT: .lglobl __aix_copyright_str
50+
; CHECK-ASM: __aix_copyright_str
51+
; CHECK-ASM: .string "Copyright IBM"
52+
53+
; ---------------- Symbol table checks ----------------
54+
; TU-local globals/functions should be present in the symbol table
55+
; CHECK-SYMS: __aix_copyright_str
56+
57+
; ---------------- Relocation checks ----------------
58+
; The object should contain a relocation in the text section
59+
; that references the copyright string.
60+
; CHECK-LABEL: RELOCATION RECORDS FOR [.text]
61+
; CHECK-REL: __aix_copyright_str

llvm/test/Transforms/CopyrightMetadata/copyright-metadata.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
; defined function in the module. The PowerPC AIX backend recognizes
2222
; this metadata and emits a `.ref` directive from the function to the
2323
; string, creating a concrete relocation that prevents the linker from
24-
; discarding it.
24+
; discarding it (as long as the referencing symbol is kept).
2525

2626
target triple = "powerpc-ibm-aix"
2727

0 commit comments

Comments
 (0)