AsmParser: Validate alloca's type
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 11 Feb 2015 09:13:11 +0000 (09:13 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 11 Feb 2015 09:13:11 +0000 (09:13 +0000)
An alloca's type should be weird things like metadata.

llvm-svn: 228820

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

index adf4c90..7af85b5 100644 (file)
@@ -4633,6 +4633,9 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
 
   if (ParseType(Ty)) return true;
 
+  if (!PointerType::isValidElementType(Ty))
+    return TokError("pointer to this type is invalid");
+
   bool AteExtraComma = false;
   if (EatIfPresent(lltok::comma)) {
     if (Lex.getKind() == lltok::kw_align) {
diff --git a/llvm/test/Assembler/alloca-invalid-type.ll b/llvm/test/Assembler/alloca-invalid-type.ll
new file mode 100644 (file)
index 0000000..fb2c05c
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: pointer to this type is invalid
+
+define void @test() {
+entry:
+  alloca metadata !{null}
+  ret void
+}