diff --git a/llvm/include/llvm/IR/ValueSymbolTable.h b/llvm/include/llvm/IR/ValueSymbolTable.h --- a/llvm/include/llvm/IR/ValueSymbolTable.h +++ b/llvm/include/llvm/IR/ValueSymbolTable.h @@ -85,6 +85,9 @@ /// The number of name/type pairs is returned. inline unsigned size() const { return unsigned(vmap.size()); } + /// @returns the maximum size of a name in the symbol table + inline int getMaxNameSize() const { return MaxNameSize; } + /// This function can be used from the debugger to display the /// content of the symbol table while debugging. /// Print out symbol table on stderr 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 @@ -3439,9 +3439,31 @@ // Set the name on the instruction. Inst->setName(NameStr); - if (Inst->getName() != NameStr) + size_t NameStrSize = NameStr.size(); + + if (Inst->getName() != NameStr) { + if (Inst->getName().size() != NameStrSize + 1) { + // The name is too long. + 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 + "'"); + } else if (NameStr[NameStrSize - 1] == '1') { + // Check potential name size exceeding. + Function *F = Inst->getParent()->getParent(); + if (NameStrSize > F->getValueSymbolTable()->getMaxNameSize()) { + 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 false; } diff --git a/llvm/test/Assembler/non-global-value-max-name-size.ll b/llvm/test/Assembler/non-global-value-max-name-size-1.ll rename from llvm/test/Assembler/non-global-value-max-name-size.ll rename to llvm/test/Assembler/non-global-value-max-name-size-1.ll diff --git a/llvm/test/Assembler/non-global-value-max-name-size-2.ll b/llvm/test/Assembler/non-global-value-max-name-size-2.ll new file mode 100644 --- /dev/null +++ b/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=8 +; RUN: not llvm-as %s -non-global-value-max-name-size=7 2>&1 | FileCheck %s + +; CHECK: error: name is too long and exceeds non global max name size +; CHECK: 'varname1' + + +define void @f() { +entry: + %varname = alloca i32, align 4 + br label %bb.rt + +bb.rt: + %varname1 = add i32 0, 5 + ret void +}