From e99495409435826c17a0e58fa3caedf3e350489b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 29 Apr 2016 01:23:20 +0000 Subject: [PATCH] PR27549: fix bug that resulted in us giving a translation-unit-scope variable a mangled name if it happened to be declared in an 'extern "C++"' context. This also causes us to use the '_ZL' mangling rather than the '_Z' mangling for internal-linkage entities that are wrapped in a language linkage construct. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267969 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ItaniumMangle.cpp | 2 +- test/CodeGenCXX/c-linkage.cpp | 4 ++-- test/CodeGenCXX/extern-c.cpp | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 7ad464e1d9..62b60d7b89 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -79,7 +79,7 @@ static const DeclContext *getEffectiveDeclContext(const Decl *D) { if (FD->isExternC()) return FD->getASTContext().getTranslationUnitDecl(); - return DC; + return DC->getRedeclContext(); } static const DeclContext *getEffectiveParentContext(const DeclContext *DC) { diff --git a/test/CodeGenCXX/c-linkage.cpp b/test/CodeGenCXX/c-linkage.cpp index a70a22ef08..0f4c327725 100644 --- a/test/CodeGenCXX/c-linkage.cpp +++ b/test/CodeGenCXX/c-linkage.cpp @@ -15,10 +15,10 @@ extern "C" { extern "C" { static void test2_f() { } - // CHECK-LABEL: define internal {{.*}}void @_Z7test2_fv + // CHECK-LABEL: define internal {{.*}}void @_ZL7test2_fv static void test2_f(int x) { } - // CHECK-LABEL: define internal {{.*}}void @_Z7test2_fi + // CHECK-LABEL: define internal {{.*}}void @_ZL7test2_fi void test2_use() { test2_f(); test2_f(42); diff --git a/test/CodeGenCXX/extern-c.cpp b/test/CodeGenCXX/extern-c.cpp index 5b59a38ba0..1046915fca 100644 --- a/test/CodeGenCXX/extern-c.cpp +++ b/test/CodeGenCXX/extern-c.cpp @@ -16,8 +16,23 @@ extern "C" struct d; // CHECK-NOT: should_not_appear extern "C++" int should_not_appear; +// CHECK: @_ZN3foo10extern_cxxE = global +extern "C++" int extern_cxx = 0; + } +// CHECK-NOT: @global_a = global +extern "C" int global_a; + +// CHECK: @global_b = global +extern "C" int global_b = 0; + +// CHECK-NOT: should_not_appear +extern "C++" int should_not_appear; + +// CHECK: @extern_cxx = global +extern "C++" int extern_cxx = 0; + namespace test1 { namespace { struct X {}; @@ -59,10 +74,10 @@ extern "C" { // CHECK-NOT: @unused // CHECK-NOT: @duplicate_internal - // CHECK: @internal_var = internal alias i32, i32* @_Z12internal_var + // CHECK: @internal_var = internal alias i32, i32* @_ZL12internal_var // CHECK-NOT: @unused // CHECK-NOT: @duplicate_internal - // CHECK: @internal_fn = internal alias i32 (), i32 ()* @_Z11internal_fnv + // CHECK: @internal_fn = internal alias i32 (), i32 ()* @_ZL11internal_fnv // CHECK-NOT: @unused // CHECK-NOT: @duplicate_internal } -- 2.40.0