Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions clang/include/clang/Basic/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ int hasAttribute(AttributeCommonInfo::Syntax Syntax,
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
const TargetInfo &Target, const LangOptions &LangOpts);

inline const char* deuglifyAttrScope(StringRef Scope) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a huge fan of ugly here as it isn't particularly descriptive, but mostly just on the name of it.

if (Scope == "_Clang")
return "clang";
if (Scope == "__gnu__")
return "gnu";
if (Scope == "__msvc__")
return "msvc";
return nullptr;
}

inline const char* uglifyAttrScope(StringRef Scope) {
if (Scope == "clang")
return "_Clang";
if (Scope == "gnu")
return "__gnu__";
if (Scope == "msvc")
return "__msvc__";
return nullptr;
}

inline bool isPotentiallyUglyScope(StringRef Scope) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the inverse? These are the not-ugly ones, right?

return Scope == "gnu" || Scope == "clang" || Scope == "msvc";
}

} // end namespace clang

#endif // LLVM_CLANG_BASIC_ATTRIBUTES_H
23 changes: 9 additions & 14 deletions clang/lib/Basic/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,

// Normalize the scope name, but only for gnu and clang attributes.
StringRef ScopeName = Scope ? Scope->getName() : "";
if (ScopeName == "__gnu__")
ScopeName = "gnu";
else if (ScopeName == "_Clang")
ScopeName = "clang";
if (const char *prettyName = deuglifyAttrScope(ScopeName))
ScopeName = prettyName;

// As a special case, look for the omp::sequence and omp::directive
// attributes. We support those, but not through the typical attribute
Expand Down Expand Up @@ -87,10 +85,8 @@ normalizeAttrScopeName(const IdentifierInfo *Scope,
StringRef ScopeName = Scope->getName();
if (SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
SyntaxUsed == AttributeCommonInfo::AS_C23) {
if (ScopeName == "__gnu__")
ScopeName = "gnu";
else if (ScopeName == "_Clang")
ScopeName = "clang";
if (const char *prettySpelling = deuglifyAttrScope(ScopeName))
return prettySpelling;
}
return ScopeName;
}
Expand All @@ -100,12 +96,11 @@ static StringRef normalizeAttrName(const IdentifierInfo *Name,
AttributeCommonInfo::Syntax SyntaxUsed) {
// Normalize the attribute name, __foo__ becomes foo. This is only allowable
// for GNU attributes, and attributes using the double square bracket syntax.
bool ShouldNormalize =
SyntaxUsed == AttributeCommonInfo::AS_GNU ||
((SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
SyntaxUsed == AttributeCommonInfo::AS_C23) &&
(NormalizedScopeName.empty() || NormalizedScopeName == "gnu" ||
NormalizedScopeName == "clang"));
bool ShouldNormalize = SyntaxUsed == AttributeCommonInfo::AS_GNU ||
((SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
SyntaxUsed == AttributeCommonInfo::AS_C23) &&
(NormalizedScopeName.empty() ||
isPotentiallyUglyScope(NormalizedScopeName)));
StringRef AttrName = Name->getName();
if (ShouldNormalize && AttrName.size() >= 4 && AttrName.starts_with("__") &&
AttrName.ends_with("__"))
Expand Down
23 changes: 4 additions & 19 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Basic/Attributes.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/Specifiers.h"
Expand Down Expand Up @@ -4579,22 +4580,6 @@ void SemaCodeCompletion::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
Results.size());
}

static const char *underscoreAttrScope(llvm::StringRef Scope) {
if (Scope == "clang")
return "_Clang";
if (Scope == "gnu")
return "__gnu__";
return nullptr;
}

static const char *noUnderscoreAttrScope(llvm::StringRef Scope) {
if (Scope == "_Clang")
return "clang";
if (Scope == "__gnu__")
return "gnu";
return nullptr;
}

void SemaCodeCompletion::CodeCompleteAttribute(
AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion,
const IdentifierInfo *InScope) {
Expand All @@ -4618,7 +4603,7 @@ void SemaCodeCompletion::CodeCompleteAttribute(
bool InScopeUnderscore = false;
if (InScope) {
InScopeName = InScope->getName();
if (const char *NoUnderscore = noUnderscoreAttrScope(InScopeName)) {
if (const char *NoUnderscore = deuglifyAttrScope(InScopeName)) {
InScopeName = NoUnderscore;
InScopeUnderscore = true;
}
Expand Down Expand Up @@ -4653,7 +4638,7 @@ void SemaCodeCompletion::CodeCompleteAttribute(
Results.AddResult(
CodeCompletionResult(Results.getAllocator().CopyString(Scope)));
// Include alternate form (__gnu__ instead of gnu).
if (const char *Scope2 = underscoreAttrScope(Scope))
if (const char *Scope2 = uglifyAttrScope(Scope))
Results.AddResult(CodeCompletionResult(Scope2));
}
continue;
Expand Down Expand Up @@ -4712,7 +4697,7 @@ void SemaCodeCompletion::CodeCompleteAttribute(
if (Scope.empty()) {
Add(Scope, Name, /*Underscores=*/true);
} else {
const char *GuardedScope = underscoreAttrScope(Scope);
const char *GuardedScope = uglifyAttrScope(Scope);
if (!GuardedScope)
continue;
Add(GuardedScope, Name, /*Underscores=*/true);
Expand Down
3 changes: 3 additions & 0 deletions clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct [[msvc::no_unique_address]] S { // expected-error {{only applies to non-b
[[msvc::no_unique_address()]] int arglist; // expected-error {{cannot have an argument list}} unsupported-warning {{unknown}}

int [[msvc::no_unique_address]] c; // expected-error {{cannot be applied to types}} unsupported-error {{cannot be applied to types}}
[[__msvc__::__no_unique_address__]] int d; // unsupported-warning {{unknown}}
[[__msvc__::no_unique_address]] int e; // unsupported-warning {{unknown}}
[[msvc::__no_unique_address__]] int g; // unsupported-warning {{unknown}}
};

struct CStructNoUniqueAddress {
Expand Down
Loading