diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3330,6 +3330,12 @@ } else { FwdVal = new Argument(Ty, Name); } + if (FwdVal->getName() != Name) { + P.error(Loc, "name is too long which can result in name collisions, " + "consider making the name shorter or " + "increasing -non-global-value-max-name-size"); + return nullptr; + } ForwardRefVals[Name] = std::make_pair(FwdVal, Loc); return FwdVal; diff --git a/llvm/test/Assembler/non-global-value-max-name-size.ll b/llvm/test/Assembler/non-global-value-max-name-size.ll --- a/llvm/test/Assembler/non-global-value-max-name-size.ll +++ b/llvm/test/Assembler/non-global-value-max-name-size.ll @@ -1,10 +1,15 @@ -; RUN: opt < %s -S -non-global-value-max-name-size=4 -; Test that local value name lookup works if the name is capped +; RUN: opt < %s -S -non-global-value-max-name-size=5 +; RUN: not opt < %s -S -non-global-value-max-name-size=4 2>&1 | FileCheck %s + +; CHECK: name is too long define void @f() { bb0: br label %testz testz: + br label %testa + +testa: br label %testz }