[llvm] [IR] Fix string overlap issue in `Value::setNameImpl` (PR #158288)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 01:28:08 PDT 2025
================
@@ -356,6 +356,16 @@ void Value::setNameImpl(const Twine &NewName) {
if (getSymTab(this, ST))
return; // Cannot set a name on this value (e.g. constant).
+ // Copy NewName forcely if the memory overlaps.
+ if (!NameRef.empty()) {
+ StringRef OldNameRef = getName();
+ if ((OldNameRef.bytes_begin() < NameRef.bytes_end()) &&
+ (NameRef.bytes_begin() < OldNameRef.bytes_end())) {
----------------
nikic wrote:
I believe this is technically UB in the case where it doesn't overlap. One has to use std::less in this case.
https://github.com/llvm/llvm-project/pull/158288
More information about the llvm-commits
mailing list