xref: /llvm-project/clang/test/CodeGenCXX/duplicate-mangled-name.cpp (revision 7c1d9b15eee3a34678addab2bab66f3020ac0753)
1 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -DTEST1
2 // RUN: %clang_cc1 -triple %itanium_abi_triple-only %s -verify -DTEST2 -emit-llvm -o - | FileCheck %s
3 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -DTEST3
4 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -DTEST4
5 
6 #ifdef TEST1
7 
8 class MyClass {
9  static void meth();
10 };
meth()11 void MyClass::meth() { } // expected-note {{previous}}
12 extern "C" {
_ZN7MyClass4methEv()13   void _ZN7MyClass4methEv() { } // expected-error {{definition with same mangled name '_ZN7MyClass4methEv' as another definition}}
14 }
15 
16 #elif TEST2
17 
18 // expected-no-diagnostics
19 
20 // We expect no warnings here, as there is only declaration of _ZN1TD1Ev
21 // function, no definitions.
22 extern "C" void _ZN1TD1Ev();
23 struct T {
~TT24   ~T() {}
25 };
26 
27 // We expect no warnings here, as there is only declaration of _ZN2nm3abcE
28 // global, no definitions.
29 extern "C" {
30   int _ZN2nm3abcE;
31 }
32 
33 namespace nm {
34   float abc = 2;
35 }
36 // CHECK: @_ZN2nm3abcE = {{(dso_local )?}}global float
37 
foo()38 float foo() {
39   _ZN1TD1Ev();
40 // CHECK: call void @_ZN1TD1Ev()
41   T t;
42 // CHECK: call {{.*}} @_ZN1TD1Ev(ptr {{[^,]*}} %t)
43   return _ZN2nm3abcE + nm::abc;
44 }
45 
46 #elif TEST3
47 
_ZN2T2D2Ev()48 extern "C" void _ZN2T2D2Ev() {}; // expected-note {{previous definition is here}}
49 
50 struct T2 {
~T2T251   ~T2() {} // expected-error {{definition with same mangled name '_ZN2T2D2Ev' as another definition}}
52 };
53 
foo()54 void foo() {
55   _ZN2T2D2Ev();
56   T2 t;
57 }
58 
59 #elif TEST4
60 
61 extern "C" {
62   int _ZN2nm3abcE = 1; // expected-note {{previous definition is here}}
63 }
64 
65 namespace nm {
66   float abc = 2; // expected-error {{definition with same mangled name '_ZN2nm3abcE' as another definition}}
67 }
68 
foo()69 float foo() {
70   return _ZN2nm3abcE + nm::abc;
71 }
72 
73 #else
74 
75 #error Unknown test
76 
77 #endif
78 
79