[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 08:26:37 PDT 2023


wheatfox updated this revision to Diff 534337.
wheatfox added a comment.

update `llvm\test\Assembler\non-global-value-max-name-size.ll` and add `llvm-as` test


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.ll


Index: llvm/test/Assembler/non-global-value-max-name-size.ll
===================================================================
--- llvm/test/Assembler/non-global-value-max-name-size.ll
+++ llvm/test/Assembler/non-global-value-max-name-size.ll
@@ -1,10 +1,12 @@
 ; RUN: opt < %s -S -non-global-value-max-name-size=5
+; RUN: llvm-as %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:
+  %var.1 = alloca i32, align 4
   br label %testz
 
 testz:
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -3439,9 +3439,23 @@
   // 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 length 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.534337.patch
Type: text/x-patch
Size: 1607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230625/019eb5b5/attachment-0001.bin>


More information about the llvm-commits mailing list