aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2015-04-13 17:40:46 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2015-04-13 17:40:46 +0000
commit6f1fadf989a2ecff98521895b2540140f1aeaada (patch)
tree684a2671cb0aa4dece5b285fd0df5fa6f27f7716 /clang/lib/CodeGen/CodeGenModule.cpp
parent9a2e01d90875a08ce1bfcd8eeeda305195b3c85e (diff)
downloadllvm-6f1fadf989a2ecff98521895b2540140f1aeaada.zip
llvm-6f1fadf989a2ecff98521895b2540140f1aeaada.tar.gz
llvm-6f1fadf989a2ecff98521895b2540140f1aeaada.tar.bz2
[CodeGen] Fix crash with duplicated mangled name.
Patch by Yunzhong Gao! llvm-svn: 234767
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index dd9d630..8175347 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1372,6 +1372,15 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
/*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.");
@@ -2405,14 +2414,6 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
}
}
- 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");