[llvm-branch-commits] [cfe-branch] r71673 - in /cfe/branches/Apple/Dib: lib/Sema/SemaChecking.cpp test/Sema/format-strings.c

Mike Stump mrs at apple.com
Wed May 13 09:09:32 PDT 2009


Author: mrs
Date: Wed May 13 11:09:32 2009
New Revision: 71673

URL: http://llvm.org/viewvc/llvm-project?rev=71673&view=rev
Log:
Merge in 71672:

Fix <rdar://problem/6880975> [format string] Assertion failed: (Arg < NumArgs && "Arg access out of range!").

For format string checking, only check the type of the format
specifier for non-vararg functions.

Modified:
    cfe/branches/Apple/Dib/lib/Sema/SemaChecking.cpp
    cfe/branches/Apple/Dib/test/Sema/format-strings.c

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaChecking.cpp?rev=71673&r1=71672&r2=71673&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaChecking.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaChecking.cpp Wed May 13 11:09:32 2009
@@ -917,36 +917,38 @@
     case '*': {
       ++numConversions;
       
-      if (!HasVAListArg && numConversions > numDataArgs) {
+      if (!HasVAListArg) {
+        if (numConversions > numDataArgs) {
+          SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);
+
+          if (Str[StrIdx-1] == '.')
+            Diag(Loc, diag::warn_printf_asterisk_precision_missing_arg)
+              << OrigFormatExpr->getSourceRange();
+          else
+            Diag(Loc, diag::warn_printf_asterisk_width_missing_arg)
+              << OrigFormatExpr->getSourceRange();
+          
+          // Don't do any more checking.  We'll just emit spurious errors.
+          return;
+        }
+      
+        // Perform type checking on width/precision specifier.
+        const Expr *E = TheCall->getArg(format_idx+numConversions);
+        if (const BuiltinType *BT = E->getType()->getAsBuiltinType())
+          if (BT->getKind() == BuiltinType::Int)
+            break;
+        
         SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);
-
+        
         if (Str[StrIdx-1] == '.')
-          Diag(Loc, diag::warn_printf_asterisk_precision_missing_arg)
-            << OrigFormatExpr->getSourceRange();
+          Diag(Loc, diag::warn_printf_asterisk_precision_wrong_type)
+          << E->getType() << E->getSourceRange();
         else
-          Diag(Loc, diag::warn_printf_asterisk_width_missing_arg)
-            << OrigFormatExpr->getSourceRange();
+          Diag(Loc, diag::warn_printf_asterisk_width_wrong_type)
+          << E->getType() << E->getSourceRange();
         
-        // Don't do any more checking.  We'll just emit spurious errors.
-        return;
+        break;        
       }
-      
-      // Perform type checking on width/precision specifier.
-      const Expr *E = TheCall->getArg(format_idx+numConversions);
-      if (const BuiltinType *BT = E->getType()->getAsBuiltinType())
-        if (BT->getKind() == BuiltinType::Int)
-          break;
-
-      SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);
-      
-      if (Str[StrIdx-1] == '.')
-        Diag(Loc, diag::warn_printf_asterisk_precision_wrong_type)
-          << E->getType() << E->getSourceRange();
-      else
-        Diag(Loc, diag::warn_printf_asterisk_width_wrong_type)
-          << E->getType() << E->getSourceRange();
-      
-      break;
     }
       
     // Characters which can terminate a format conversion

Modified: cfe/branches/Apple/Dib/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Sema/format-strings.c?rev=71673&r1=71672&r2=71673&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/Sema/format-strings.c (original)
+++ cfe/branches/Apple/Dib/test/Sema/format-strings.c Wed May 13 11:09:32 2009
@@ -125,3 +125,8 @@
   printf(P, 42);
   printf("%n", &x); // expected-warning {{use of '%n' in format string discouraged }}
 }
+
+void torture(va_list v8) {
+  vprintf ("%*.*d", v8);  // no-warning
+}
+





More information about the llvm-branch-commits mailing list