http://reviews.llvm.org/D8405

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/duplicate-mangled-name2.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1370,6 +1370,15 @@
                               /*DontDefer=*/false);
       return;
     }
+
+    if (llvm::GlobalValue *GV = GetGlobalValue(getMangledName(GD)))
+      if (!GV->isDeclaration()) {
+        getDiags().Report(FD->getLocation(), diag::err_duplicate_mangled_name);
+        GlobalDecl OldGD = Manglings.lookup(GV->getName());
+        if (auto *Prev = OldGD.getDecl())
+          getDiags().Report(Prev->getLocation(), 
diag::note_previous_definition);
+        return;
+      }
   } else {
     const auto *VD = cast<VarDecl>(Global);
     assert(VD->isFileVarDecl() && "Cannot emit local var decl as global.");
@@ -2412,14 +2421,6 @@
     }
   }
 
-  if (!GV->isDeclaration()) {
-    getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name);
-    GlobalDecl OldGD = Manglings.lookup(GV->getName());
-    if (auto *Prev = OldGD.getDecl())
-      getDiags().Report(Prev->getLocation(), diag::note_previous_definition);
-    return;
-  }
-
   if (GV->getType()->getElementType() != Ty) {
     // If the types mismatch then we have to rewrite the definition.
     assert(GV->isDeclaration() && "Shouldn't replace non-declaration");
Index: test/CodeGenCXX/duplicate-mangled-name2.cpp
===================================================================
--- test/CodeGenCXX/duplicate-mangled-name2.cpp
+++ test/CodeGenCXX/duplicate-mangled-name2.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify
+// RUN: %clang_cc1 -triple %itanium_abi_triple -femit-all-decls 
-emit-llvm-only %s -verify
+
+void foo(void *p) __asm("_ZN1SC2Ev");
+void foo(void *p) { } // expected-note {{previous}}
+
+struct S {
+  S() {} // expected-error {{definition with same mangled name as another 
definition}}
+} s;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1370,6 +1370,15 @@
                               /*DontDefer=*/false);
       return;
     }
+
+    if (llvm::GlobalValue *GV = GetGlobalValue(getMangledName(GD)))
+      if (!GV->isDeclaration()) {
+        getDiags().Report(FD->getLocation(), diag::err_duplicate_mangled_name);
+        GlobalDecl OldGD = Manglings.lookup(GV->getName());
+        if (auto *Prev = OldGD.getDecl())
+          getDiags().Report(Prev->getLocation(), diag::note_previous_definition);
+        return;
+      }
   } else {
     const auto *VD = cast<VarDecl>(Global);
     assert(VD->isFileVarDecl() && "Cannot emit local var decl as global.");
@@ -2412,14 +2421,6 @@
     }
   }
 
-  if (!GV->isDeclaration()) {
-    getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name);
-    GlobalDecl OldGD = Manglings.lookup(GV->getName());
-    if (auto *Prev = OldGD.getDecl())
-      getDiags().Report(Prev->getLocation(), diag::note_previous_definition);
-    return;
-  }
-
   if (GV->getType()->getElementType() != Ty) {
     // If the types mismatch then we have to rewrite the definition.
     assert(GV->isDeclaration() && "Shouldn't replace non-declaration");
Index: test/CodeGenCXX/duplicate-mangled-name2.cpp
===================================================================
--- test/CodeGenCXX/duplicate-mangled-name2.cpp
+++ test/CodeGenCXX/duplicate-mangled-name2.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify
+// RUN: %clang_cc1 -triple %itanium_abi_triple -femit-all-decls -emit-llvm-only %s -verify
+
+void foo(void *p) __asm("_ZN1SC2Ev");
+void foo(void *p) { } // expected-note {{previous}}
+
+struct S {
+  S() {} // expected-error {{definition with same mangled name as another definition}}
+} s;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to