[PATCH] D102707: Fix non-global-value-max-name-size not considered by LLParser
Hasyimi Bahrudin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 18 11:39:50 PDT 2021
hasyimibhar updated this revision to Diff 346232.
hasyimibhar added a comment.
Add description to test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102707/new/
https://reviews.llvm.org/D102707
Files:
llvm/include/llvm/IR/Value.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Value.cpp
llvm/test/Assembler/non-global-value-max-name-size.ll
Index: llvm/test/Assembler/non-global-value-max-name-size.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/non-global-value-max-name-size.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -S -non-global-value-max-name-size=1024
+; Test that local value name lookup works if the name is capped
+
+define void @func_two_branches_to_the_same_bb_with_a_long_name() {
+bb0:
+ br label %for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit7
+
+for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit7:
+ br label %for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit_edge.i.split.split.split_crit_edge.i.split.split.for.body4.lr.ph.split.split.split.us18.split.split.for.body4.lr.ph.split.split.split.us18.split.split.split_crit7
+}
Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -55,6 +55,12 @@
return Ty;
}
+inline std::string llvm::capLocalValueName(const std::string &name) {
+ if (name.size() > NonGlobalValueMaxNameSize)
+ return name.substr(0, std::max(1u, (unsigned)NonGlobalValueMaxNameSize));
+ return name;
+}
+
Value::Value(Type *ty, unsigned scid)
: VTy(checkType(ty)), UseList(nullptr), SubclassID(scid), HasValueHandle(0),
SubclassOptionalData(0), SubclassData(0), NumUserOperands(0),
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -3116,7 +3116,10 @@
Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty,
LocTy Loc, bool IsCall) {
// Look this name up in the normal function symbol table.
- Value *Val = F.getValueSymbolTable()->lookup(Name);
+ // Ensure that the name is capped according to the value of
+ // non-global-value-max-name-size, otherwise symbol table
+ // lookup will fail if Name exceeds the size cap.
+ Value *Val = F.getValueSymbolTable()->lookup(capLocalValueName(Name));
// If this is a forward reference for the value, see if we already created a
// forward ref record.
Index: llvm/include/llvm/IR/Value.h
===================================================================
--- llvm/include/llvm/IR/Value.h
+++ llvm/include/llvm/IR/Value.h
@@ -854,6 +854,10 @@
void setValueSubclassData(unsigned short D) { SubclassData = D; }
};
+// Use this to cap local value name according to the value of
+// non-global-value-max-name-size.
+std::string capLocalValueName(const std::string &name);
+
struct ValueDeleter { void operator()(Value *V) { V->deleteValue(); } };
/// Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102707.346232.patch
Type: text/x-patch
Size: 5528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/114b7d62/attachment.bin>
More information about the llvm-commits
mailing list