Skip to content

Commit

Permalink
[NFC] [clang] Use std::string instead of StringRef to reduce stack usage
Browse files Browse the repository at this point in the history
Comparisons between StringRef and string literals are lowered by MSVC to happen on the stack.
All string literals are allocated unique stack slots increasing the overall stack usage of
calculateAttributeSpellingListIndex. Use of std::string forces allocation of a string type per
literal, reducing the overall stack usage of the function.

Change-Id: I7ac39fc96ab2e559318413fa26ef304c3fb0bd6e
  • Loading branch information
chinmaydd committed Oct 30, 2024
1 parent b94762d commit e075173
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/Basic/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
// Both variables will be used in tablegen generated
// attribute spell list index matching code.
auto Syntax = static_cast<AttributeCommonInfo::Syntax>(getSyntax());
StringRef Scope = normalizeAttrScopeName(getScopeName(), Syntax);
StringRef Name = normalizeAttrName(getAttrName(), Scope, Syntax);
// We use std::string instead of StringRef to prevent local stack
// allocation of literal strings for comparison.
const std::string Scope = normalizeAttrScopeName(getScopeName(), Syntax);
const std::string Name = normalizeAttrName(getAttrName(), Scope, Syntax);

#include "clang/Sema/AttrSpellingListIndex.inc"
}

0 comments on commit e075173

Please sign in to comment.