[PATCH] D153722: [LLParser] Friendly error out if a non global value's name exceeds max name size
Han Yulong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 21:44:50 PDT 2023
wheatfox updated this revision to Diff 535230.
wheatfox added a comment.
cleanup the comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153722/new/
https://reviews.llvm.org/D153722
Files:
llvm/include/llvm/IR/ValueSymbolTable.h
llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/non-global-value-max-name-size-1.ll
llvm/test/Assembler/non-global-value-max-name-size-2.ll
llvm/test/Assembler/non-global-value-max-name-size.ll
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=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
+}
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ 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;
}
Index: llvm/include/llvm/IR/ValueSymbolTable.h
===================================================================
--- llvm/include/llvm/IR/ValueSymbolTable.h
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153722.535230.patch
Type: text/x-patch
Size: 2631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230628/a35075b7/attachment.bin>
More information about the llvm-commits
mailing list