diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index d50da69529c..de566b6cdfc 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2270,13 +2270,13 @@ bool LLParser::PerFunctionState::SetInstName(int NameID, /// forward reference record if needed. BasicBlock *LLParser::PerFunctionState::GetBB(const std::string &Name, LocTy Loc) { - return cast_or_null(GetVal(Name, - Type::getLabelTy(F.getContext()), Loc)); + return dyn_cast_or_null(GetVal(Name, + Type::getLabelTy(F.getContext()), Loc)); } BasicBlock *LLParser::PerFunctionState::GetBB(unsigned ID, LocTy Loc) { - return cast_or_null(GetVal(ID, - Type::getLabelTy(F.getContext()), Loc)); + return dyn_cast_or_null(GetVal(ID, + Type::getLabelTy(F.getContext()), Loc)); } /// DefineBB - Define the specified basic block, which is either named or @@ -4299,7 +4299,9 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) { } BasicBlock *BB = PFS.DefineBB(Name, NameLoc); - if (!BB) return true; + if (!BB) + return Error(NameLoc, + "unable to create block named '" + Name + "'"); std::string NameStr; diff --git a/test/Assembler/invalid-label.ll b/test/Assembler/invalid-label.ll new file mode 100644 index 00000000000..33dc63610aa --- /dev/null +++ b/test/Assembler/invalid-label.ll @@ -0,0 +1,11 @@ +; RUN: not llvm-as < %s >/dev/null 2> %t +; RUN: FileCheck %s < %t +; Test the case where an invalid label name is used + +; CHECK: unable to create block named 'bb' + +define void @test(label %bb) { +bb: + ret void +} +