[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
Sun Jun 25 19:01:33 PDT 2023
wheatfox updated this revision to Diff 534405.
wheatfox added a comment.
designed a new test in `\llvm\test\Assembler\non-global-value-max-name-size-2.ll`, and used `llvm-lit` to run the new test locally to make sure that things work fine.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153722/new/
https://reviews.llvm.org/D153722
Files:
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=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
+}
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153722.534405.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230626/96d84c01/attachment.bin>
More information about the llvm-commits
mailing list