Skip to content

Commit 29e5998

Browse files
authored
[CIR][CIRGen] Enable comdat for static variables (#1015)
1 parent d6db31d commit 29e5998

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ CIRGenModule::getOrCreateStaticVarDecl(const VarDecl &D,
492492
GV.setAlignment(getASTContext().getDeclAlign(&D).getAsAlign().value());
493493

494494
if (supportsCOMDAT() && GV.isWeakForLinker())
495-
llvm_unreachable("COMDAT globals are NYI");
495+
GV.setComdat(true);
496496

497497
if (D.getTLSKind())
498498
llvm_unreachable("TLS mode is NYI");

clang/test/CIR/CodeGen/static-vars.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t1.ll
4+
// RUN: FileCheck --check-prefix=LLVM --input-file=%t1.ll %s
35

46
void func1(void) {
57
// Should lower default-initialized static vars.
@@ -35,3 +37,13 @@ void func2(void) {
3537
static float j;
3638
// CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func2vE1j = #cir.fp<0.000000e+00> : !cir.float
3739
}
40+
41+
// CHECK-DAG: cir.global linkonce_odr comdat @_ZZ4testvE1c = #cir.int<0> : !s32i
42+
43+
// LLVM-DAG: $_ZZ4testvE1c = comdat any
44+
// LLVM-DAG: @_ZZ4testvE1c = linkonce_odr global i32 0, comdat, align 4
45+
46+
inline void test() { static int c; }
47+
// CHECK-LABEL: @_Z4testv
48+
// CHECK: {{%.*}} = cir.get_global @_ZZ4testvE1c : !cir.ptr<!s32i>
49+
void foo() { test(); }

0 commit comments

Comments
 (0)