[llvm-branch-commits] [cfe-branch] r119422 - in /cfe/branches/Apple/whitney: lib/Sema/SemaChecking.cpp test/SemaCXX/attr-format.cpp
Daniel Dunbar
daniel at zuster.org
Tue Nov 16 16:23:52 PST 2010
Author: ddunbar
Date: Tue Nov 16 18:23:52 2010
New Revision: 119422
URL: http://llvm.org/viewvc/llvm-project?rev=119422&view=rev
Log:
Merge r119340:
--
Author: Chandler Carruth <chandlerc at gmail.com>
Date: Tue Nov 16 08:49:43 2010 +0000
Fix PR8625 and correctly interpret member-calls to static members when
producing warnings.
This feels really fragile, and I've not audited all other argument index-based
warnings. I suspect we'll grow this bug on another warning eventually. It might
be nice to adjust the argument indices when building up the attribute AST node,
as we already have to remember about the 'this' argument within that code to
produce correct errors.
Modified:
cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp
cfe/branches/Apple/whitney/test/SemaCXX/attr-format.cpp
Modified: cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp?rev=119422&r1=119421&r2=119422&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaChecking.cpp Tue Nov 16 18:23:52 2010
@@ -1090,12 +1090,16 @@
// of member functions is counted. However, it doesn't appear in our own
// lists, so decrement format_idx in that case.
if (isa<CXXMemberCallExpr>(TheCall)) {
- // Catch a format attribute mistakenly referring to the object argument.
- if (format_idx == 0)
- return;
- --format_idx;
- if(firstDataArg != 0)
- --firstDataArg;
+ const CXXMethodDecl *method_decl =
+ dyn_cast<CXXMethodDecl>(TheCall->getCalleeDecl());
+ if (method_decl && method_decl->isInstance()) {
+ // Catch a format attribute mistakenly referring to the object argument.
+ if (format_idx == 0)
+ return;
+ --format_idx;
+ if(firstDataArg != 0)
+ --firstDataArg;
+ }
}
// CHECK: printf/scanf-like function is called with no format string.
Modified: cfe/branches/Apple/whitney/test/SemaCXX/attr-format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/SemaCXX/attr-format.cpp?rev=119422&r1=119421&r2=119422&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/SemaCXX/attr-format.cpp (original)
+++ cfe/branches/Apple/whitney/test/SemaCXX/attr-format.cpp Tue Nov 16 18:23:52 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s
struct S {
static void f(const char*, ...) __attribute__((format(printf, 1, 2)));
static const char* f2(const char*) __attribute__((format_arg(1)));
@@ -21,3 +21,15 @@
void b(A x) {
x.a("%d", 3);
}
+
+// PR8625: correctly interpret static member calls as not having an implicit
+// 'this' argument.
+namespace PR8625 {
+ struct S {
+ static void f(const char*, const char*, ...)
+ __attribute__((format(printf, 2, 3)));
+ };
+ void test(S s, const char* str) {
+ s.f(str, "%s", str);
+ }
+}
More information about the llvm-branch-commits
mailing list