[cfe-commits] r114049 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/if-empty-body.c

Ted Kremenek kremenek at apple.com
Wed Sep 15 17:37:05 PDT 2010


Author: kremenek
Date: Wed Sep 15 19:37:05 2010
New Revision: 114049

URL: http://llvm.org/viewvc/llvm-project?rev=114049&view=rev
Log:
Do not warn about empty bodies for 'if' statements if the body is expanded from a macro.

Fixes <rdar://problem/8436021>.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/if-empty-body.c

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=114049&r1=114048&r2=114049&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Sep 15 19:37:05 2010
@@ -272,9 +272,12 @@
   // this helps prevent bugs due to typos, such as
   // if (condition);
   //   do_stuff();
+  //
+  // NOTE: Do not emit this warning if the body is expanded from a macro.
   if (!elseStmt) {
     if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt))
-      Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
+      if (!stmt->getLocStart().isMacroID())
+        Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
   }
 
   DiagnoseUnusedExprResult(elseStmt);

Modified: cfe/trunk/test/Sema/if-empty-body.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/if-empty-body.c?rev=114049&r1=114048&r2=114049&view=diff
==============================================================================
--- cfe/trunk/test/Sema/if-empty-body.c (original)
+++ cfe/trunk/test/Sema/if-empty-body.c Wed Sep 15 19:37:05 2010
@@ -14,3 +14,11 @@
   return;    // no empty body warning.
 }
 
+// Don't warn about an empty body if is expanded from a macro.
+void f4(int i) {
+  #define BODY ;
+  if (i == i) // expected-warning{{self-comparison always evaluates to true}}
+    BODY
+  #undef BODY
+}
+





More information about the cfe-commits mailing list