From 39834ba5a9a9e998cc542f683d0e6327b406f088 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 27 Sep 2011 23:46:37 +0000 Subject: [PATCH] PR11002: Make sure we emit sentinel warnings with a valid source location. (Ideally, we want to use the location returned by getLocForEndOfToken, but that is not always successful.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140658 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 11 +++++++---- test/Sema/attr-sentinel.c | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 25f1342aeb..2b67b4dc48 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -252,10 +252,13 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, NullValue = "NULL"; else NullValue = "(void*) 0"; - - Diag(MissingNilLoc, diag::warn_missing_sentinel) - << calleeType - << FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue); + + if (MissingNilLoc.isInvalid()) + Diag(Loc, diag::warn_missing_sentinel) << calleeType; + else + Diag(MissingNilLoc, diag::warn_missing_sentinel) + << calleeType + << FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue); Diag(D->getLocation(), diag::note_sentinel_here) << calleeType; } diff --git a/test/Sema/attr-sentinel.c b/test/Sema/attr-sentinel.c index 5ca6a8d001..abc108fdc7 100644 --- a/test/Sema/attr-sentinel.c +++ b/test/Sema/attr-sentinel.c @@ -4,13 +4,15 @@ #define ATTR __attribute__ ((__sentinel__)) -void foo1 (int x, ...) ATTR; // expected-note 2 {{function has been explicitly marked sentinel here}} +void foo1 (int x, ...) ATTR; // expected-note 3 {{function has been explicitly marked sentinel here}} void foo5 (int x, ...) __attribute__ ((__sentinel__(1))); // expected-note {{function has been explicitly marked sentinel here}} void foo6 (int x, ...) __attribute__ ((__sentinel__(5))); // expected-note {{function has been explicitly marked sentinel here}} void foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{function has been explicitly marked sentinel here}} void foo10 (int x, ...) __attribute__ ((__sentinel__(1,1))); void foo12 (int x, ... ) ATTR; // expected-note {{function has been explicitly marked sentinel here}} +#define FOOMACRO(...) foo1(__VA_ARGS__) + void test1() { foo1(1, NULL); // OK foo1(1, 0) ; // expected-warning {{missing sentinel in function call}} @@ -30,6 +32,9 @@ void test1() { struct A a, b, c; foo1(3, &a, &b, &c); // expected-warning {{missing sentinel in function call}} foo1(3, &a, &b, &c, (struct A*) 0); + + // PR11002 + FOOMACRO(1, 2); // expected-warning {{missing sentinel in function call}} } -- 2.40.0