From: Peter Collingbourne Date: Sun, 4 Jun 2017 22:12:03 +0000 (+0000) Subject: IR: When creating a global variable, assert that its type is valid. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f38a0160b9067c9f8b677ca5df5c898c9808495d;p=llvm IR: When creating a global variable, assert that its type is valid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304690 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 17d27b016cf..2ddd78db631 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -293,6 +293,8 @@ GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link, InitVal != nullptr, Link, Name, AddressSpace), isConstantGlobal(constant), isExternallyInitializedConstant(isExternallyInitialized) { + assert(!Ty->isFunctionTy() && PointerType::isValidElementType(Ty) && + "invalid type for global variable"); setThreadLocalMode(TLMode); if (InitVal) { assert(InitVal->getType() == Ty && @@ -311,6 +313,8 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant, InitVal != nullptr, Link, Name, AddressSpace), isConstantGlobal(constant), isExternallyInitializedConstant(isExternallyInitialized) { + assert(!Ty->isFunctionTy() && PointerType::isValidElementType(Ty) && + "invalid type for global variable"); setThreadLocalMode(TLMode); if (InitVal) { assert(InitVal->getType() == Ty &&