[llvm] 24a0859 - [LLParser] Error out if a name is too long and gets renamed

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 15:44:01 PST 2023


Author: Arthur Eubanks
Date: 2023-03-06T15:43:34-08:00
New Revision: 24a08593b946ac78c54c57dc52ec005bd7c44aaa

URL: https://github.com/llvm/llvm-project/commit/24a08593b946ac78c54c57dc52ec005bd7c44aaa
DIFF: https://github.com/llvm/llvm-project/commit/24a08593b946ac78c54c57dc52ec005bd7c44aaa.diff

LOG: [LLParser] Error out if a name is too long and gets renamed

Typically names longer than -non-global-value-max-name-size will just get renamed if there is a collision after truncating. This is fine since we typically don't reference Values by name.

However LLParser does reference Values by name, so report an error when that happens, otherwise weird issues can crop up if there are name collisions (e.g. verifier issues with the changed test case because we end up reusing the same block for `testz` and `testa`).

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D145282

Added: 
    

Modified: 
    llvm/lib/AsmParser/LLParser.cpp
    llvm/test/Assembler/non-global-value-max-name-size.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 673a34ef7f181..8b8ba4107e717 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3330,6 +3330,12 @@ Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty,
   } else {
     FwdVal = new Argument(Ty, Name);
   }
+  if (FwdVal->getName() != Name) {
+    P.error(Loc, "name is too long which can result in name collisions, "
+                 "consider making the name shorter or "
+                 "increasing -non-global-value-max-name-size");
+    return nullptr;
+  }
 
   ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
   return FwdVal;

diff  --git a/llvm/test/Assembler/non-global-value-max-name-size.ll b/llvm/test/Assembler/non-global-value-max-name-size.ll
index 4536ce2056862..dd56286baa973 100644
--- a/llvm/test/Assembler/non-global-value-max-name-size.ll
+++ b/llvm/test/Assembler/non-global-value-max-name-size.ll
@@ -1,10 +1,15 @@
-; RUN: opt < %s -S -non-global-value-max-name-size=4
-; Test that local value name lookup works if the name is capped
+; RUN: opt < %s -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:
   br label %testz
 
 testz:
+  br label %testa
+
+testa:
   br label %testz
 }


        


More information about the llvm-commits mailing list