From: Aaron Ballman Date: Mon, 25 Nov 2013 18:50:49 +0000 (+0000) Subject: Making type_tag_for_datatype consistent with its declared subject from Attr.td. Also... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6199e12689fef80658602ca0e6e704b8115a8d26;p=clang Making type_tag_for_datatype consistent with its declared subject from Attr.td. Also updated the related testcase. Reviewed by Dmitri Gribenko. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195675 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 15ec5857a9..75674b08ef 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4089,6 +4089,12 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, if (!checkAttributeNumArgs(S, Attr, 1)) return; + if (!isa(D)) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) + << Attr.getName() << ExpectedVariable; + return; + } + IdentifierInfo *PointerKind = Attr.getArgAsIdent(0)->Ident; TypeSourceInfo *MatchingCTypeLoc = 0; S.GetTypeFromParser(Attr.getMatchingCType(), &MatchingCTypeLoc); diff --git a/test/Sema/warn-type-safety.c b/test/Sema/warn-type-safety.c index dfab8f8c81..04313865a8 100644 --- a/test/Sema/warn-type-safety.c +++ b/test/Sema/warn-type-safety.c @@ -57,6 +57,8 @@ extern struct A datatype_wrong6 __attribute__(( type_tag_for_datatype(mpi,int,layout_compatible,not_a_flag) )); // expected-error {{invalid comparison flag 'not_a_flag'}} +void datatype_wrong7(void) __attribute__((type_tag_for_datatype(datatype_wrong7, int))); // expected-error {{'type_tag_for_datatype' attribute only applies to variables}} + // Using a tag with kind A in a place where the function requires kind B should // warn. @@ -156,5 +158,3 @@ void test_64bit_magic(int *int_ptr, float *float_ptr) F_func(float_ptr, 0xFFFFFFFFFFFFFFFFULL); // expected-warning {{argument type 'float *' doesn't match specified 'f' type tag that requires 'int *'}} F_func(float_ptr, 0xFFFFFFFFULL); } - -