From 7f40c08dcab7b9623e7067dfb5a32f188173f832 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 16 Feb 2015 08:41:08 +0000 Subject: [PATCH] AsmParser: Make sure GlobalVariables have sane types llvm-svn: 229364 --- lib/AsmParser/LLParser.cpp | 2 +- test/Assembler/gv-invalid-type.ll | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/Assembler/gv-invalid-type.ll diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 159bbccc87d..7818586dfa4 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -749,7 +749,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, return true; } - if (Ty->isFunctionTy() || Ty->isLabelTy()) + if (Ty->isFunctionTy() || !PointerType::isValidElementType(Ty)) return Error(TyLoc, "invalid type for global variable"); GlobalValue *GVal = nullptr; diff --git a/test/Assembler/gv-invalid-type.ll b/test/Assembler/gv-invalid-type.ll new file mode 100644 index 00000000000..bde04dab7a2 --- /dev/null +++ b/test/Assembler/gv-invalid-type.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +@gv = global metadata undef +; CHECK: invalid type for global variable