Don't crash if a .ll file contains a forward-reference that looks like a global
authorNick Lewycky <nicholas@mxc.ca>
Thu, 11 Oct 2012 00:38:25 +0000 (00:38 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 11 Oct 2012 00:38:25 +0000 (00:38 +0000)
value but later turns out to be a function.

Unfortunately, we can't fold tests into a single file because we only get one
error out of llvm-as.

llvm-svn: 165680

llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/invalid-fwdref1.ll [new file with mode: 0644]

index 86bc7ac..349dd0d 100644 (file)
@@ -2795,6 +2795,9 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
       ForwardRefVals.find(FunctionName);
     if (FRVI != ForwardRefVals.end()) {
       Fn = M->getFunction(FunctionName);
+      if (!Fn)
+        return Error(FRVI->second.second, "invalid forward reference to "
+                     "function as global value!");
       if (Fn->getType() != PFT)
         return Error(FRVI->second.second, "invalid forward reference to "
                      "function '" + FunctionName + "' with wrong type!");
diff --git a/llvm/test/Assembler/invalid-fwdref1.ll b/llvm/test/Assembler/invalid-fwdref1.ll
new file mode 100644 (file)
index 0000000..ef8b16c
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: not llvm-as %s -disable-output 2>&1 | grep "invalid forward reference to function as global value!"
+
+define i8* @test1() { ret i8* @test1a }
+define void @test1a() { }