[clang] [NFC] [clang] Use std::string instead of StringRef to reduce stack usage (PR #114285)

Krzysztof Parzyszek via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 11:50:49 PDT 2024


kparzysz wrote:

> Don't see how or why this would introduce stackusage. std::string temporaries should be avoided whenever possible

The code that's included afterwards contains a lot of comparisons with string literals:
```
if (Name == "aarch64_sve_pcs" && getSyntax() == AttributeCommonInfo::AS_GNU && Scope == "")
    return 0;
if (Name == "aarch64_sve_pcs" && getSyntax() == AttributeCommonInfo::AS_CXX11 && Scope == "clang")
    return 1;
if (Name == "aarch64_sve_pcs" && getSyntax() == AttributeCommonInfo::AS_C23 && Scope == "clang")
    return 2;
```

IIUC, @chinmaydd claims that MSVC allocates these literals on the stack, and they take up more space than a `std::string` would.

https://github.com/llvm/llvm-project/pull/114285


More information about the cfe-commits mailing list