Index: llvm/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/lib/AsmParser/LLParser.cpp +++ llvm/lib/AsmParser/LLParser.cpp @@ -3439,9 +3439,24 @@ // Set the name on the instruction. Inst->setName(NameStr); - if (Inst->getName() != NameStr) + if (Inst->getName() != NameStr) { + + size_t InstNameSize = Inst->getName().size(); + size_t NameStrSize = NameStr.size(); + + if (InstNameSize != NameStrSize + 1) { + // The name is too long and was trimmed when stored in SmallString with + // NonGlobalValueMaxNameSize + return P.error(NameLoc, + "name is too long and exceeds non global max name size, " + "consider making the name shorter or " + "increasing -non-global-value-max-name-size: '" + + NameStr + "'"); + } + return P.error(NameLoc, "multiple definition of local value named '" + NameStr + "'"); + } return false; } Index: llvm/test/Assembler/non-global-value-max-name-size-2.ll =================================================================== --- /dev/null +++ llvm/test/Assembler/non-global-value-max-name-size-2.ll @@ -0,0 +1,16 @@ +; RUN: llvm-as %s -non-global-value-max-name-size=18 +; RUN: not llvm-as %s -non-global-value-max-name-size=5 2>&1 | FileCheck %s + +; CHECK: error: name is too long and exceeds non global max name size +; CHECK: 'varname.too.long.1' + + +define void @f() { +entry: + %var.1 = alloca i32, align 4 + br label %bb.rt + +bb.rt: + %varname.too.long.1 = add i32 0, 5 + ret void +}