]> granicus.if.org Git - clang/commitdiff
Making type_tag_for_datatype consistent with its declared subject from Attr.td. Also...
authorAaron Ballman <aaron@aaronballman.com>
Mon, 25 Nov 2013 18:50:49 +0000 (18:50 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 25 Nov 2013 18:50:49 +0000 (18:50 +0000)
Reviewed by Dmitri Gribenko.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195675 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/warn-type-safety.c

index 15ec5857a956e673a33b2f9d2355620571a560cf..75674b08ef5886af3af1afb057a7a531d5834a6f 100644 (file)
@@ -4089,6 +4089,12 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D,
   if (!checkAttributeNumArgs(S, Attr, 1))
     return;
 
+  if (!isa<VarDecl>(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);
index dfab8f8c818b778d7f661ba7af9faafd36fe245e..04313865a8b853689f0e633645145e55ebbb9ef8 100644 (file)
@@ -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);
 }
-
-