[cfe-commits] r103216 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/attr-sentinel.c
John McCall
rjmccall at apple.com
Thu May 6 16:53:00 PDT 2010
Author: rjmccall
Date: Thu May 6 18:53:00 2010
New Revision: 103216
URL: http://llvm.org/viewvc/llvm-project?rev=103216&view=rev
Log:
After some discussion, conservatively extend our sentinel check to discard
casts, but still require the (casted) type to be a pointer. Fixes PR5685.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/attr-sentinel.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=103216&r1=103215&r2=103216&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 6 18:53:00 2010
@@ -160,16 +160,19 @@
++sentinel;
}
Expr *sentinelExpr = Args[sentinel];
- if (sentinelExpr && (!isa<GNUNullExpr>(sentinelExpr) &&
- !sentinelExpr->isTypeDependent() &&
- !sentinelExpr->isValueDependent() &&
- (!sentinelExpr->getType()->isPointerType() ||
- !sentinelExpr->isNullPointerConstant(Context,
- Expr::NPC_ValueDependentIsNull)))) {
- Diag(Loc, diag::warn_missing_sentinel) << isMethod;
- Diag(D->getLocation(), diag::note_sentinel_here) << isMethod;
- }
- return;
+ if (!sentinelExpr) return;
+ if (sentinelExpr->isTypeDependent()) return;
+ if (sentinelExpr->isValueDependent()) return;
+ if (sentinelExpr->getType()->isPointerType() &&
+ sentinelExpr->IgnoreParenCasts()->isNullPointerConstant(Context,
+ Expr::NPC_ValueDependentIsNull))
+ return;
+
+ // Unfortunately, __null has type 'int'.
+ if (isa<GNUNullExpr>(sentinelExpr)) return;
+
+ Diag(Loc, diag::warn_missing_sentinel) << isMethod;
+ Diag(D->getLocation(), diag::note_sentinel_here) << isMethod;
}
SourceRange Sema::getExprRange(ExprTy *E) const {
Modified: cfe/trunk/test/Sema/attr-sentinel.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-sentinel.c?rev=103216&r1=103215&r2=103216&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-sentinel.c (original)
+++ cfe/trunk/test/Sema/attr-sentinel.c Thu May 6 18:53:00 2010
@@ -4,7 +4,7 @@
#define ATTR __attribute__ ((__sentinel__))
-void foo1 (int x, ...) ATTR; // expected-note {{function has been explicitly marked sentinel here}}
+void foo1 (int x, ...) ATTR; // expected-note 2 {{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}}
@@ -24,6 +24,12 @@
foo7(1, NULL); // OK
foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}}
+
+ // PR 5685
+ struct A {};
+ 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);
}
More information about the cfe-commits
mailing list