AsmParser: Reject alloca with function type
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 16 Feb 2015 08:38:03 +0000 (08:38 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 16 Feb 2015 08:38:03 +0000 (08:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229363 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
test/Assembler/alloca-invalid-type-2.ll [new file with mode: 0644]
test/Assembler/alloca-invalid-type.ll
test/Verifier/2008-03-01-AllocaSized.ll

index fc829166abfb396f9079d2ae324f3001e0c8276a..159bbccc87db9a56036de73c5eabb589f3b2a5e9 100644 (file)
@@ -5109,16 +5109,16 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
 ///   ::= 'alloca' 'inalloca'? Type (',' TypeAndValue)? (',' 'align' i32)?
 int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
   Value *Size = nullptr;
-  LocTy SizeLoc;
+  LocTy SizeLoc, TyLoc;
   unsigned Alignment = 0;
   Type *Ty = nullptr;
 
   bool IsInAlloca = EatIfPresent(lltok::kw_inalloca);
 
-  if (ParseType(Ty)) return true;
+  if (ParseType(Ty, TyLoc)) return true;
 
-  if (!PointerType::isValidElementType(Ty))
-    return TokError("pointer to this type is invalid");
+  if (Ty->isFunctionTy() || !PointerType::isValidElementType(Ty))
+    return Error(TyLoc, "invalid type for alloca");
 
   bool AteExtraComma = false;
   if (EatIfPresent(lltok::comma)) {
diff --git a/test/Assembler/alloca-invalid-type-2.ll b/test/Assembler/alloca-invalid-type-2.ll
new file mode 100644 (file)
index 0000000..7b1cc62
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: invalid type for alloca
+
+define void @test() {
+entry:
+  alloca i32 (i32)
+  ret void
+}
index fb2c05cc35af2ac3cedd6b9c50fa6bc945ee29ce..413bcbd76ba0b4daea614510ab2a9ad3b2db335c 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 
-; CHECK: pointer to this type is invalid
+; CHECK: invalid type for alloca
 
 define void @test() {
 entry:
index fc12a96e4f9f7f5a431169a6af2aee8e4db9ce46..7478334959fef02c91ea9f03384a577ce8c95c53 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
-; CHECK: Cannot allocate unsized type
+; CHECK: invalid type for alloca
 ; PR2113
 
 define void @test() {