[llvm] [IR] Fix ignoring `non-global-value-max-name-size` in `ValueSymbolTable::makeUniqueName()`. (PR #89057)
Daniil Fukalov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 10:28:05 PDT 2024
================
@@ -43,23 +43,34 @@ ValueSymbolTable::~ValueSymbolTable() {
ValueName *ValueSymbolTable::makeUniqueName(Value *V,
SmallString<256> &UniqueName) {
unsigned BaseSize = UniqueName.size();
+ bool AppenDot = false;
+ if (auto *GV = dyn_cast<GlobalValue>(V)) {
+ // A dot is appended to mark it as clone during ABI demangling so that
+ // for example "_Z1fv" and "_Z1fv.1" both demangle to "f()", the second
+ // one being a clone.
+ // On NVPTX we cannot use a dot because PTX only allows [A-Za-z0-9_$] for
+ // identifiers. This breaks ABI demangling but at least ptxas accepts and
+ // compiles the program.
+ const Module *M = GV->getParent();
+ if (!(M && Triple(M->getTargetTriple()).isNVPTX()))
+ AppenDot = true;
+ }
+
while (true) {
// Trim any suffix off and append the next number.
UniqueName.resize(BaseSize);
raw_svector_ostream S(UniqueName);
- if (auto *GV = dyn_cast<GlobalValue>(V)) {
- // A dot is appended to mark it as clone during ABI demangling so that
- // for example "_Z1fv" and "_Z1fv.1" both demangle to "f()", the second
- // one being a clone.
- // On NVPTX we cannot use a dot because PTX only allows [A-Za-z0-9_$] for
- // identifiers. This breaks ABI demangling but at least ptxas accepts and
- // compiles the program.
- const Module *M = GV->getParent();
- if (!(M && Triple(M->getTargetTriple()).isNVPTX()))
- S << ".";
- }
+ if (AppenDot)
+ S << ".";
S << ++LastUnique;
+ // Retry if MaxNameSize has been exceeded.
+ if (MaxNameSize > -1 && UniqueName.size() > (size_t)MaxNameSize) {
+ assert(BaseSize >= UniqueName.size() - (size_t)MaxNameSize &&
----------------
dfukalov wrote:
This part of the function is actually for resolving conflicts, i.e. generate an unique name. Firstly, `UniqueName` resized (trimmed) in line 61. Then it adds an unique suffix with `S << ++LastUnique;` in few lines above. Here in case it (with suffix) exceeded `MaxNameSize`, we truncate it more and go to one more try in the loop.
https://github.com/llvm/llvm-project/pull/89057
More information about the llvm-commits
mailing list