Verifier: Forbid comdats on linker declarations.
authorPeter Collingbourne <peter@pcc.me.uk>
Sun, 5 Jul 2015 20:52:40 +0000 (20:52 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sun, 5 Jul 2015 20:52:40 +0000 (20:52 +0000)
Differential Revision: http://reviews.llvm.org/D10945

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241414 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Verifier.cpp
test/Verifier/comdat-decl1.ll [new file with mode: 0644]
test/Verifier/comdat-decl2.ll [new file with mode: 0644]

index 3c61165768f8a92c55e0b8b36d46518ed24cef3f..cf88e644cea7ffa57ba9dd7271e62487e732f9a9 100644 (file)
@@ -438,6 +438,9 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
     Assert(GVar && GVar->getValueType()->isArrayTy(),
            "Only global arrays can have appending linkage!", GVar);
   }
+
+  if (GV.isDeclarationForLinker())
+    Assert(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV);
 }
 
 void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
diff --git a/test/Verifier/comdat-decl1.ll b/test/Verifier/comdat-decl1.ll
new file mode 100644 (file)
index 0000000..aee56b6
--- /dev/null
@@ -0,0 +1,5 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+$v = comdat any
+@v = available_externally global i32 0, comdat
+; CHECK: Declaration may not be in a Comdat!
diff --git a/test/Verifier/comdat-decl2.ll b/test/Verifier/comdat-decl2.ll
new file mode 100644 (file)
index 0000000..fcd3d5d
--- /dev/null
@@ -0,0 +1,5 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+$v = comdat any
+@v = external global i32, comdat
+; CHECK: Declaration may not be in a Comdat!