diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2018-02-25 20:28:10 +0000 |
|---|---|---|
| committer | Aaron Ballman <aaron@aaronballman.com> | 2018-02-25 20:28:10 +0000 |
| commit | bd0f656631d12b8e65a7961e4c73371e2580ddb6 (patch) | |
| tree | 4ce5ba9bb5a5724d60440d62452914a52712c7ff | |
| parent | 46d02dee65d2ffa2682edb8abd929655b8412ace (diff) | |
| download | bcm5719-llvm-bd0f656631d12b8e65a7961e4c73371e2580ddb6.tar.gz bcm5719-llvm-bd0f656631d12b8e65a7961e4c73371e2580ddb6.zip | |
Fix a failing assertion with the pointer_with_type_tag attribute when the function the attribute appertains to is variadic.
Patch by Joel Denny.
llvm-svn: 326057
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Sema/warn-type-safety.c | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 4247b32a672..dea16f9f7c7 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -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( diff --git a/clang/test/Sema/warn-type-safety.c b/clang/test/Sema/warn-type-safety.c index 36fb47e254a..da914730d3a 100644 --- a/clang/test/Sema/warn-type-safety.c +++ b/clang/test/Sema/warn-type-safety.c @@ -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}} |

