]> granicus.if.org Git - clang/commitdiff
Fix a failing assertion with the pointer_with_type_tag attribute when the function...
authorAaron Ballman <aaron@aaronballman.com>
Sun, 25 Feb 2018 20:28:10 +0000 (20:28 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Sun, 25 Feb 2018 20:28:10 +0000 (20:28 +0000)
Patch by Joel Denny.

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

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

index 4247b32a672c176af72f64ff5883b6ad8a53676a..dea16f9f7c7cde7d58db48c446c196c4d52420ae 100644 (file)
@@ -4567,11 +4567,10 @@ static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D,
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
     // Ensure that buffer has a pointer type.
-    QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-    if (!BufferTy->isPointerType()) {
+    if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+        !getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
       S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-        << AL.getName() << 0;
-    }
+          << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
index 36fb47e254a51a55736ca6900689161bd19ed024..da914730d3aad85e6aa079335d86fc3535fedd61 100644 (file)
@@ -37,6 +37,10 @@ int wrong9 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error
 int wrong10(double buf, MPI_Datatype type)
     __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error {{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+    __attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+    __attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error {{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
     __attribute__(( type_tag_for_datatype )); // expected-error {{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}