diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index df4c13c9ad97aa..550454abdd1ef2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3911,9 +3911,20 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { assert(!MayBeEmittedEagerly(Global)); addDeferredDeclToEmit(GD); } else { - // Otherwise, remember that we saw a deferred decl with this name. The - // first use of the mangled name will cause it to move into - // DeferredDeclsToEmit. + // Otherwise, remember that we saw a deferred decl with this name. + auto DDI = DeferredDecls.find(MangledName); + const auto *FD = dyn_cast(Global); + if (FD && DDI != DeferredDecls.end()) { + bool IsDefinitionAvailableExternally = + getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally; + if (!IsDefinitionAvailableExternally && !FD->isMultiVersion() && + !FD->hasAttr()) + getDiags().Report(Global->getLocation(), + diag::err_duplicate_mangled_name) + << MangledName; + } + // The first use of the mangled name will cause it to move + // into DeferredDeclsToEmit. DeferredDecls[MangledName] = GD; } } diff --git a/clang/test/CodeGenCXX/duplicate-mangled-name.cpp b/clang/test/CodeGenCXX/duplicate-mangled-name.cpp index 04e6fee506ebd7..cfa70623de53cd 100644 --- a/clang/test/CodeGenCXX/duplicate-mangled-name.cpp +++ b/clang/test/CodeGenCXX/duplicate-mangled-name.cpp @@ -2,6 +2,7 @@ // RUN: %clang_cc1 -triple %itanium_abi_triple-only %s -verify -DTEST2 -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -DTEST3 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -DTEST4 +// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -DTEST5 #ifdef TEST1 @@ -70,6 +71,13 @@ float foo() { return _ZN2nm3abcE + nm::abc; } +#elif TEST5 + +inline void f(int) asm("foo"); +inline void f(int) {} +inline void f() asm("foo"); +inline void f(){} // expected-error {{definition with same mangled name 'foo' as another definition}} + #else #error Unknown test diff --git a/clang/test/CodeGenCXX/lambda-instantiation-mangling-conflicts.cpp b/clang/test/CodeGenCXX/lambda-instantiation-mangling-conflicts.cpp new file mode 100644 index 00000000000000..3a5adc5cb7c7d0 --- /dev/null +++ b/clang/test/CodeGenCXX/lambda-instantiation-mangling-conflicts.cpp @@ -0,0 +1,30 @@ +// REQUIRES: aarch64-registered-target + +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 -emit-llvm -o - %t/a.cpp -verify +// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 -emit-llvm -o - %t/b.cpp -verify + +;--- a.cpp + +int normal_fn(int); +int vector_pcs_fn(int) __attribute__((aarch64_vector_pcs)); + +// expected-error@+3 {{definition with same mangled name '_ZZ23function_pcs_attributesvENK3$_0clIFiiEEEDaRT_' as another definition}} +__attribute__((aarch64_vector_pcs)) +int function_pcs_attributes() { + auto a = [](auto &fn) { return fn(42); }; + return a(normal_fn) + a(vector_pcs_fn); +} + +;--- b.cpp + +int normal_fn(int); +int streaming_fn(int) __arm_streaming; + +// expected-error@+2 {{definition with same mangled name '_ZZ32function_params_normal_streamingvENK3$_0clIFiiEEEDaRT_' as another definition}} +int function_params_normal_streaming() { + auto a = [](auto &fn) { return fn(42); }; + return a(normal_fn) + a(streaming_fn); +} diff --git a/clang/test/CodeGenCXX/mangle-lambdas-gh88906.cpp b/clang/test/CodeGenCXX/mangle-lambdas-gh88906.cpp index e7592cec5da776..6130756af0e618 100644 --- a/clang/test/CodeGenCXX/mangle-lambdas-gh88906.cpp +++ b/clang/test/CodeGenCXX/mangle-lambdas-gh88906.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-linux-gnu %s -emit-llvm -mconstructor-aliases -o - | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-linux-gnu -fclang-abi-compat=18 %s -emit-llvm -mconstructor-aliases -o - | FileCheck --check-prefix=CLANG18 %s +// RUN: not %clang_cc1 -triple x86_64-linux-gnu -fclang-abi-compat=18 %s -emit-llvm -mconstructor-aliases 2>&1 | FileCheck --check-prefix=CLANG18 %s // RUN: %clang_cc1 -triple i386-pc-win32 %s -emit-llvm -mconstructor-aliases -o - | FileCheck --check-prefix=MSABI %s @@ -29,12 +29,7 @@ void GH88906(){ // CHECK-LABEL: define internal void @_ZN4funcC2IN7GH889064Test1bMUlvE_EEET_ // CHECK-LABEL: define internal void @_ZN4funcC2IN7GH889064Test1cMUlvE_EEET_ -// CLANG18-LABEL: define internal void @_ZZ7GH88906vEN4TestC2Ev -// CLANG18: call void @_ZN4funcC2IZ7GH88906vEN4TestUlvE_EZ7GH88906vENS1_UlvE0_EEET_T0_ -// CLANG18: call void @_ZN4funcC2IZ7GH88906vEN4TestUlvE_EEET_ -// CLANG18: call void @_ZN4funcC2IZ7GH88906vEN4TestUlvE_EEET_ - - +// CLANG18: error: definition with same mangled name '_ZN4funcC1IZ7GH88906vEN4TestUlvE_EEET_' as another definition // MSABI-LABEL: define internal x86_thiscallcc noundef ptr @"??0Test@?1??GH88906@@YAXXZ@QAE@XZ" // MSABI: call x86_thiscallcc noundef ptr @"??$?0V@a@Test@?1??GH88906@@YAXXZ@V@12?1??3@YAXXZ@@func@@QAE@V@a@Test@?1??GH88906@@YAXXZ@V@23?1??4@YAXXZ@@Z"