Skip to content

Commit b9f3a5a

Browse files
committed
simplify parsing by limiting to TypeAttr
Changing the attr base class from DeclOrTypeAttr to TypeAttr allows us to better isolate the attribute handling logic just in SemaType.cpp in the handleWrapsAttr() method. Furthermore, check for language compatibility at this step as well. Rely on `COnly` to provide the warnings to the user, then silently discard the attribute. | let LangOpts = [COnly]; Signed-off-by: Justin Stitt <[email protected]>
1 parent 0cb962f commit b9f3a5a

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,14 +4856,14 @@ def ClspvLibclcBuiltin: InheritableAttr {
48564856
let SimpleHandler = 1;
48574857
}
48584858

4859-
def Wraps : DeclOrTypeAttr {
4859+
def Wraps : TypeAttr {
48604860
let Spellings = [Clang<"wraps">];
48614861
let Subjects = SubjectList<[Var, TypedefName, Field]>;
48624862
let Documentation = [WrapsDocs];
48634863
let LangOpts = [COnly];
48644864
}
48654865

4866-
def NoWraps : DeclOrTypeAttr {
4866+
def NoWraps : TypeAttr {
48674867
let Spellings = [Clang<"no_wraps">];
48684868
let Subjects = SubjectList<[Var, TypedefName, Field]>;
48694869
let Documentation = [NoWrapsDocs];

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,14 +4009,6 @@ void Sema::AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E) {
40094009
D->addAttr(::new (Context) AlignValueAttr(Context, CI, E));
40104010
}
40114011

4012-
static void handleWrapsAttr(Sema &S, Decl *D, const ParsedAttr &AL,
4013-
bool NoWraps = false) {
4014-
if (NoWraps)
4015-
D->addAttr(::new (S.Context) NoWrapsAttr(S.Context, AL));
4016-
else
4017-
D->addAttr(::new (S.Context) WrapsAttr(S.Context, AL));
4018-
}
4019-
40204012
static void handleAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
40214013
if (AL.hasParsedType()) {
40224014
const ParsedType &TypeArg = AL.getTypeArg();
@@ -6970,12 +6962,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
69706962
case ParsedAttr::AT_SizedByOrNull:
69716963
handleCountedByAttrField(S, D, AL);
69726964
break;
6973-
case ParsedAttr::AT_Wraps:
6974-
handleWrapsAttr(S, D, AL);
6975-
break;
6976-
case ParsedAttr::AT_NoWraps:
6977-
handleWrapsAttr(S, D, AL, true);
6978-
break;
69796965

69806966
// Microsoft attributes:
69816967
case ParsedAttr::AT_LayoutVersion:

clang/lib/Sema/SemaType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6541,6 +6541,11 @@ static void handleWrapsAttr(QualType &Type, const ParsedAttr &Attr,
65416541
Sema &S = State.getSema();
65426542
ASTContext &Ctx = S.Context;
65436543

6544+
// wraps and no_wraps are most useful and consistent when used with C. Other
6545+
// languages have better alternatives within their type systems.
6546+
if (S.LangOpts.CPlusPlus || S.LangOpts.ObjC)
6547+
return;
6548+
65446549
if (!Type->isIntegerType()) {
65456550
S.Diag(Attr.getLoc(), diag::warn_wraps_attr_var_decl_type_not_integer)
65466551
<< (int)NoWraps << Type.getAsString();

0 commit comments

Comments
 (0)