https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/145551
The CIR handling of `dso_local` for globals was upstreamed without the underscore, making it inconsistent with the incubator and LLVM IR. This change restores the underscore. >From f3927e3fd07cad46f183e434129f6dc91cb89e3e Mon Sep 17 00:00:00 2001 From: Andy Kaylor <akay...@nvidia.com> Date: Tue, 24 Jun 2025 09:53:54 -0700 Subject: [PATCH] [CIR] Restore the underscore in dso_local The CIR handling of `dso_local` for globals was upstreamed without the underscore, making it inconsistent with the incubator and LLVM IR. This change restores the underscore. --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 4 ++-- .../include/clang/CIR/Interfaces/CIROpInterfaces.td | 4 ++-- clang/include/clang/CIR/MissingFeatures.h | 2 +- clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 6 +++--- clang/test/CIR/CodeGen/builtin_printf.cpp | 4 ++-- clang/test/CIR/CodeGen/deferred-defs.cpp | 2 +- clang/test/CIR/CodeGen/namespace.cpp | 2 +- clang/test/CIR/CodeGen/static-vars.c | 12 ++++++------ clang/test/CIR/CodeGen/static-vars.cpp | 12 ++++++------ clang/test/CIR/CodeGen/string-literals.c | 6 +++--- clang/test/CIR/CodeGen/string-literals.cpp | 2 +- clang/test/CIR/global-var-linkage.cpp | 2 +- 12 files changed, 29 insertions(+), 29 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index d2eeeafc60ba3..372e117981ea6 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -1610,7 +1610,7 @@ def GlobalOp : CIR_Op<"global", CIR_GlobalLinkageKind:$linkage, OptionalAttr<AnyAttr>:$initial_value, UnitAttr:$comdat, - UnitAttr:$dsolocal, + UnitAttr:$dso_local, OptionalAttr<I64Attr>:$alignment); let assemblyFormat = [{ @@ -1618,7 +1618,7 @@ def GlobalOp : CIR_Op<"global", (`` $global_visibility^)? $linkage (`comdat` $comdat^)? - (`dsolocal` $dsolocal^)? + (`dso_local` $dso_local^)? $sym_name custom<GlobalOpTypeAndInitialValue>($sym_type, $initial_value) attr-dict diff --git a/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td b/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td index 203e42f7c575e..5817b91b49e31 100644 --- a/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td +++ b/clang/include/clang/CIR/Interfaces/CIROpInterfaces.td @@ -138,13 +138,13 @@ let cppNamespace = "::cir" in { InterfaceMethod<"", "void", "setDSOLocal", (ins "bool":$val), [{}], /*defaultImplementation=*/[{ - $_op.setDsolocal(val); + $_op.setDsoLocal(val); }] >, InterfaceMethod<"", "bool", "isDSOLocal", (ins), [{}], /*defaultImplementation=*/[{ - return $_op.getDsolocal(); + return $_op.getDsoLocal(); }] >, InterfaceMethod<"", diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h index 3ba363772316c..752d4165c8664 100644 --- a/clang/include/clang/CIR/MissingFeatures.h +++ b/clang/include/clang/CIR/MissingFeatures.h @@ -74,7 +74,7 @@ struct MissingFeatures { static bool opFuncOpenCLKernelMetadata() { return false; } static bool opFuncCallingConv() { return false; } static bool opFuncExtraAttrs() { return false; } - static bool opFuncDsolocal() { return false; } + static bool opFuncDsoLocal() { return false; } static bool opFuncLinkage() { return false; } static bool opFuncVisibility() { return false; } static bool opFuncNoProto() { return false; } diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 5f41e340e2474..106ec38105a9a 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -1016,7 +1016,7 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite( mlir::ConversionPatternRewriter &rewriter) const { cir::FuncType fnType = op.getFunctionType(); - assert(!cir::MissingFeatures::opFuncDsolocal()); + assert(!cir::MissingFeatures::opFuncDsoLocal()); bool isDsoLocal = false; mlir::TypeConverter::SignatureConversion signatureConversion( fnType.getNumInputs()); @@ -1103,7 +1103,7 @@ void CIRToLLVMGlobalOpLowering::setupRegionInitializedLLVMGlobalOp( const bool isConst = false; assert(!cir::MissingFeatures::addressSpace()); const unsigned addrSpace = 0; - const bool isDsoLocal = op.getDsolocal(); + const bool isDsoLocal = op.getDsoLocal(); assert(!cir::MissingFeatures::opGlobalThreadLocal()); const bool isThreadLocal = false; const uint64_t alignment = op.getAlignment().value_or(0); @@ -1157,7 +1157,7 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( const bool isConst = false; assert(!cir::MissingFeatures::addressSpace()); const unsigned addrSpace = 0; - const bool isDsoLocal = op.getDsolocal(); + const bool isDsoLocal = op.getDsoLocal(); assert(!cir::MissingFeatures::opGlobalThreadLocal()); const bool isThreadLocal = false; const uint64_t alignment = op.getAlignment().value_or(0); diff --git a/clang/test/CIR/CodeGen/builtin_printf.cpp b/clang/test/CIR/CodeGen/builtin_printf.cpp index 366e474c2b09a..35c71eba86874 100644 --- a/clang/test/CIR/CodeGen/builtin_printf.cpp +++ b/clang/test/CIR/CodeGen/builtin_printf.cpp @@ -5,8 +5,8 @@ // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG -// CIR: cir.global "private" cir_private dsolocal @".str" = #cir.const_array<"%s\00" : !cir.array<!s8i x 3>> : !cir.array<!s8i x 3> -// CIR: cir.global "private" cir_private dsolocal @".str.1" = #cir.const_array<"%s %d\0A\00" : !cir.array<!s8i x 7>> : !cir.array<!s8i x 7> +// CIR: cir.global "private" cir_private dso_local @".str" = #cir.const_array<"%s\00" : !cir.array<!s8i x 3>> : !cir.array<!s8i x 3> +// CIR: cir.global "private" cir_private dso_local @".str.1" = #cir.const_array<"%s %d\0A\00" : !cir.array<!s8i x 7>> : !cir.array<!s8i x 7> // LLVM: @.str = private global [3 x i8] c"%s\00" // LLVM: @.str.1 = private global [7 x i8] c"%s %d\0A\00" // OGCG: @.str = private unnamed_addr constant [3 x i8] c"%s\00" diff --git a/clang/test/CIR/CodeGen/deferred-defs.cpp b/clang/test/CIR/CodeGen/deferred-defs.cpp index 4230a4ed3e24e..0b9ff92fa2f4c 100644 --- a/clang/test/CIR/CodeGen/deferred-defs.cpp +++ b/clang/test/CIR/CodeGen/deferred-defs.cpp @@ -18,5 +18,5 @@ void use() { } // CIR: cir.global external @locallyDefined = #cir.int<0> : !s32i -// CIR: cir.global "private" internal dsolocal @_ZN12_GLOBAL__N_112usedInternalE = #cir.int<0> : !s32i +// CIR: cir.global "private" internal dso_local @_ZN12_GLOBAL__N_112usedInternalE = #cir.int<0> : !s32i // CIR: cir.global "private" external @usedExternal : !s32i diff --git a/clang/test/CIR/CodeGen/namespace.cpp b/clang/test/CIR/CodeGen/namespace.cpp index 14490d505140c..cf02673c07787 100644 --- a/clang/test/CIR/CodeGen/namespace.cpp +++ b/clang/test/CIR/CodeGen/namespace.cpp @@ -20,7 +20,7 @@ namespace test { } } -// CHECK-DAG: cir.global "private" internal dsolocal @_ZN12_GLOBAL__N_12g1E = #cir.int<1> : !s32i +// CHECK-DAG: cir.global "private" internal dso_local @_ZN12_GLOBAL__N_12g1E = #cir.int<1> : !s32i // CHECK-DAG: cir.global external @_ZN4test2g2E = #cir.int<2> : !s32i // CHECK-DAG: cir.global external @_ZN4test5test22g3E = #cir.int<3> : !s32i // CHECK-DAG: cir.func @_ZN12_GLOBAL__N_12f1Ev() diff --git a/clang/test/CIR/CodeGen/static-vars.c b/clang/test/CIR/CodeGen/static-vars.c index f45a41d9a00fc..ee4db82c40ade 100644 --- a/clang/test/CIR/CodeGen/static-vars.c +++ b/clang/test/CIR/CodeGen/static-vars.c @@ -4,20 +4,20 @@ void func1(void) { // Should lower default-initialized static vars. static int i; - // CHECK-DAG: cir.global "private" internal dsolocal @func1.i = #cir.int<0> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @func1.i = #cir.int<0> : !s32i // Should lower constant-initialized static vars. static int j = 1; - // CHECK-DAG: cir.global "private" internal dsolocal @func1.j = #cir.int<1> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @func1.j = #cir.int<1> : !s32i // Should properly shadow static vars in nested scopes. { static int j = 2; - // CHECK-DAG: cir.global "private" internal dsolocal @func1.j.1 = #cir.int<2> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @func1.j.1 = #cir.int<2> : !s32i } { static int j = 3; - // CHECK-DAG: cir.global "private" internal dsolocal @func1.j.2 = #cir.int<3> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @func1.j.2 = #cir.int<3> : !s32i } // Should lower basic static vars arithmetics. @@ -31,7 +31,7 @@ void func1(void) { // Should shadow static vars on different functions. void func2(void) { static char i; - // CHECK-DAG: cir.global "private" internal dsolocal @func2.i = #cir.int<0> : !s8i + // CHECK-DAG: cir.global "private" internal dso_local @func2.i = #cir.int<0> : !s8i static float j; - // CHECK-DAG: cir.global "private" internal dsolocal @func2.j = #cir.fp<0.000000e+00> : !cir.float + // CHECK-DAG: cir.global "private" internal dso_local @func2.j = #cir.fp<0.000000e+00> : !cir.float } diff --git a/clang/test/CIR/CodeGen/static-vars.cpp b/clang/test/CIR/CodeGen/static-vars.cpp index 9b892c69a6fed..d949936f6bff9 100644 --- a/clang/test/CIR/CodeGen/static-vars.cpp +++ b/clang/test/CIR/CodeGen/static-vars.cpp @@ -6,20 +6,20 @@ void func1(void) { // Should lower default-initialized static vars. static int i; - // CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func1vE1i = #cir.int<0> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @_ZZ5func1vE1i = #cir.int<0> : !s32i // Should lower constant-initialized static vars. static int j = 1; - // CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func1vE1j = #cir.int<1> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @_ZZ5func1vE1j = #cir.int<1> : !s32i // Should properly shadow static vars in nested scopes. { static int j = 2; - // CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func1vE1j_0 = #cir.int<2> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @_ZZ5func1vE1j_0 = #cir.int<2> : !s32i } { static int j = 3; - // CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func1vE1j_1 = #cir.int<3> : !s32i + // CHECK-DAG: cir.global "private" internal dso_local @_ZZ5func1vE1j_1 = #cir.int<3> : !s32i } // Should lower basic static vars arithmetics. @@ -33,9 +33,9 @@ void func1(void) { // Should shadow static vars on different functions. void func2(void) { static char i; - // CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func2vE1i = #cir.int<0> : !s8i + // CHECK-DAG: cir.global "private" internal dso_local @_ZZ5func2vE1i = #cir.int<0> : !s8i static float j; - // CHECK-DAG: cir.global "private" internal dsolocal @_ZZ5func2vE1j = #cir.fp<0.000000e+00> : !cir.float + // CHECK-DAG: cir.global "private" internal dso_local @_ZZ5func2vE1j = #cir.fp<0.000000e+00> : !cir.float } // CHECK-DAG: cir.global linkonce_odr comdat @_ZZ4testvE1c = #cir.int<0> : !s32i diff --git a/clang/test/CIR/CodeGen/string-literals.c b/clang/test/CIR/CodeGen/string-literals.c index 90ea21906f363..be9622f9abe27 100644 --- a/clang/test/CIR/CodeGen/string-literals.c +++ b/clang/test/CIR/CodeGen/string-literals.c @@ -17,9 +17,9 @@ char g_exact[4] = "123"; // CIR: cir.global external @g_exact = #cir.const_array<"123\00" : !cir.array<!s8i x 4>> : !cir.array<!s8i x 4> -// CIR: cir.global "private" cir_private dsolocal @[[STR1_GLOBAL:.*]] = #cir.const_array<"1\00" : !cir.array<!s8i x 2>> : !cir.array<!s8i x 2> -// CIR: cir.global "private" cir_private dsolocal @[[STR2_GLOBAL:.*]] = #cir.zero : !cir.array<!s8i x 1> -// CIR: cir.global "private" cir_private dsolocal @[[STR3_GLOBAL:.*]] = #cir.zero : !cir.array<!s8i x 2> +// CIR: cir.global "private" cir_private dso_local @[[STR1_GLOBAL:.*]] = #cir.const_array<"1\00" : !cir.array<!s8i x 2>> : !cir.array<!s8i x 2> +// CIR: cir.global "private" cir_private dso_local @[[STR2_GLOBAL:.*]] = #cir.zero : !cir.array<!s8i x 1> +// CIR: cir.global "private" cir_private dso_local @[[STR3_GLOBAL:.*]] = #cir.zero : !cir.array<!s8i x 2> // LLVM: @[[STR1_GLOBAL:.*]] = private global [2 x i8] c"1\00" // LLVM: @[[STR2_GLOBAL:.*]] = private global [1 x i8] zeroinitializer diff --git a/clang/test/CIR/CodeGen/string-literals.cpp b/clang/test/CIR/CodeGen/string-literals.cpp index c56eb74387329..081c4c2c5a4a2 100644 --- a/clang/test/CIR/CodeGen/string-literals.cpp +++ b/clang/test/CIR/CodeGen/string-literals.cpp @@ -5,7 +5,7 @@ // RUN: %clang_cc1 -triple aarch64-none-linux-android21 -emit-llvm %s -o %t.ll // RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s -// CIR: cir.global "private" cir_private dsolocal @[[STR1_GLOBAL:.*]] = #cir.const_array<"abcd\00" : !cir.array<!s8i x 5>> : !cir.array<!s8i x 5> +// CIR: cir.global "private" cir_private dso_local @[[STR1_GLOBAL:.*]] = #cir.const_array<"abcd\00" : !cir.array<!s8i x 5>> : !cir.array<!s8i x 5> // LLVM: @[[STR1_GLOBAL:.*]] = private global [5 x i8] c"abcd\00" diff --git a/clang/test/CIR/global-var-linkage.cpp b/clang/test/CIR/global-var-linkage.cpp index 3a288b8990ad7..c9ee8fb6a502c 100644 --- a/clang/test/CIR/global-var-linkage.cpp +++ b/clang/test/CIR/global-var-linkage.cpp @@ -17,7 +17,7 @@ int aaaa; // OGCG: @dddd = weak_odr global i32 0, comdat static int bbbb; -// CIR: cir.global "private" internal dsolocal @_ZL4bbbb +// CIR: cir.global "private" internal dso_local @_ZL4bbbb // LLVM: @_ZL4bbbb = internal global i32 0 // OGCG: @_ZL4bbbb = internal global i32 0 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits