]> granicus.if.org Git - clang/commitdiff
[Sema] Fix PR30481: crash on checking printf args.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 22 Sep 2016 00:00:26 +0000 (00:00 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 22 Sep 2016 00:00:26 +0000 (00:00 +0000)
We were falling through from one case to another in a switch statement.
Oops.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282124 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/format-strings.c

index 1e17afc06bfa73e89c81688e681558fc0435e69b..0604c5aeac4453d78a5af26d183f5da612a8d07f 100644 (file)
@@ -4194,9 +4194,9 @@ checkFormatStringExpr(Sema &S, const Expr *E, ArrayRef<const Expr *> Args,
           goto tryAgain;
         }
       }
-
-      return SLCT_NotALiteral;
     }
+
+    return SLCT_NotALiteral;
   }
   case Stmt::UnaryOperatorClass: {
     const UnaryOperator *UnaOp = cast<UnaryOperator>(E);
index a6b3a699364434d99dc6b0d560716f8c06d785e9..5c332bd37a0c81d52ca4965702e7e59ec13d5c5b 100644 (file)
@@ -687,3 +687,8 @@ void test_char_pointer_arithmetic(int b) {
   printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
   // expected-note@-2{{format string is defined here}}
 }
+
+void PR30481() {
+  // This caused crashes due to invalid casts.
+  printf(1 > 0); // expected-warning{{format string is not a string literal}} expected-warning{{incompatible integer to pointer conversion}} expected-note@format-strings.c:*{{passing argument to parameter here}} expected-note{{to avoid this}}
+}