[cfe-commits] r119340 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/attr-format.cpp

Chandler Carruth chandlerc at gmail.com
Tue Nov 16 00:49:44 PST 2010


Author: chandlerc
Date: Tue Nov 16 02:49:43 2010
New Revision: 119340

URL: http://llvm.org/viewvc/llvm-project?rev=119340&view=rev
Log:
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/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/attr-format.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=119340&r1=119339&r2=119340&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Nov 16 02:49:43 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/trunk/test/SemaCXX/attr-format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-format.cpp?rev=119340&r1=119339&r2=119340&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-format.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-format.cpp Tue Nov 16 02:49:43 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 cfe-commits mailing list