]> granicus.if.org Git - clang/commitdiff
Don't warn about using PredefinedExprs as format string literals. These never can...
authorTed Kremenek <kremenek@apple.com>
Thu, 24 Feb 2011 23:03:04 +0000 (23:03 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 24 Feb 2011 23:03:04 +0000 (23:03 +0000)
Fixes PR 9314.

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

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

index 5c2356f54db98e62e52715fb04381d5391aabc6c..97cc44e7372f4411ccd28d00f1ad22fbb5c15306 100644 (file)
@@ -875,7 +875,7 @@ bool Sema::SemaBuiltinLongjmp(CallExpr *TheCall) {
   return false;
 }
 
-// Handle i > 1 ? "x" : "y", recursivelly
+// Handle i > 1 ? "x" : "y", recursively.
 bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
                                   bool HasVAListArg,
                                   unsigned format_idx, unsigned firstDataArg,
@@ -918,6 +918,12 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
     }
     return false;
 
+  case Stmt::PredefinedExprClass:
+    // While __func__, etc., are technically not string literals, they
+    // cannot contain format specifiers and thus are not a security
+    // liability.
+    return true;
+      
   case Stmt::DeclRefExprClass: {
     const DeclRefExpr *DR = cast<DeclRefExpr>(E);
 
index fe4f4567cbdb9a2b50e5c06f85f7448154fdf8c4..c78095a04d7b540dda8b8209a2a0bc1c41756547 100644 (file)
@@ -350,3 +350,11 @@ void posix_extensions() {
 void pr8486() {
   printf("%s", 1); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}}
 }
+
+// PR9314
+// Don't warn about string literals that are PreDefinedExprs, e.g. __func__.
+void pr9314() {
+  printf(__PRETTY_FUNCTION__); // no-warning
+  printf(__func__); // no-warning
+}
+