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.

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

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

index adf4c9073ab87ade648eb62a775b77661e3937c7..7af85b5846cddc11dbeb7f2d6d2e040fbf8ee595 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/test/Assembler/alloca-invalid-type.ll b/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
+}