[cfe-commits] r135134 - in /cfe/trunk: lib/Analysis/FormatString.cpp test/Sema/format-strings-fixit.c test/Sema/format-strings-i386.c test/Sema/format-strings.c

Ted Kremenek kremenek at apple.com
Wed Jul 13 23:49:52 PDT 2011


Author: kremenek
Date: Thu Jul 14 01:49:52 2011
New Revision: 135134

URL: http://llvm.org/viewvc/llvm-project?rev=135134&view=rev
Log:
Reapply r135075, but modify format-strings.c and format-strings-fixit.c test cases to be more portable with an explicit target triple.

Added:
    cfe/trunk/test/Sema/format-strings-i386.c
Modified:
    cfe/trunk/lib/Analysis/FormatString.cpp
    cfe/trunk/test/Sema/format-strings-fixit.c
    cfe/trunk/test/Sema/format-strings.c

Modified: cfe/trunk/lib/Analysis/FormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=135134&r1=135133&r2=135134&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/FormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/FormatString.cpp Thu Jul 14 01:49:52 2011
@@ -206,6 +206,10 @@
 // Methods on ArgTypeResult.
 //===----------------------------------------------------------------------===//
 
+static bool hasSameSize(ASTContext &astContext, QualType typeA, QualType typeB) {
+  return astContext.getTypeSize(typeA) == astContext.getTypeSize(typeB);
+}
+
 bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const {
   switch (K) {
     case InvalidTy:
@@ -226,26 +230,21 @@
             break;
           case BuiltinType::Char_S:
           case BuiltinType::SChar:
-            return T == C.UnsignedCharTy;
           case BuiltinType::Char_U:
           case BuiltinType::UChar:                    
-            return T == C.SignedCharTy;
+            return hasSameSize(C, T, C.UnsignedCharTy);            
           case BuiltinType::Short:
-            return T == C.UnsignedShortTy;
           case BuiltinType::UShort:
-            return T == C.ShortTy;
+            return hasSameSize(C, T, C.ShortTy);
           case BuiltinType::Int:
-            return T == C.UnsignedIntTy;
           case BuiltinType::UInt:
-            return T == C.IntTy;
+            return hasSameSize(C, T, C.IntTy);
           case BuiltinType::Long:
-            return T == C.UnsignedLongTy;
           case BuiltinType::ULong:
-            return T == C.LongTy;
+            return hasSameSize(C, T, C.LongTy);
           case BuiltinType::LongLong:
-            return T == C.UnsignedLongLongTy;
           case BuiltinType::ULongLong:
-            return T == C.LongLongTy;
+            return hasSameSize(C, T, C.LongLongTy);
         }
       return false;
     }

Modified: cfe/trunk/test/Sema/format-strings-fixit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-fixit.c?rev=135134&r1=135133&r2=135134&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-fixit.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit.c Thu Jul 14 01:49:52 2011
@@ -1,7 +1,7 @@
 // RUN: cp %s %t
-// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
-// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
-// RUN: %clang_cc1 -E -o - %t | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -pedantic -Wall -fixit %t || true
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -fsyntax-only -pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -E -o - %t | FileCheck %s
 
 /* This is a test of the various code modification hints that are
    provided as part of warning or extension diagnostics. All of the

Added: cfe/trunk/test/Sema/format-strings-i386.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-i386.c?rev=135134&view=auto
==============================================================================
--- cfe/trunk/test/Sema/format-strings-i386.c (added)
+++ cfe/trunk/test/Sema/format-strings-i386.c Thu Jul 14 01:49:52 2011
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple i386-apple-macosx10.7.0 -fsyntax-only -verify -Wformat-nonliteral %s
+
+int printf(const char *restrict, ...);
+
+// Test that 'long' is compatible with 'int' on 32-bit.
+typedef unsigned int UInt32;
+void test_rdar_9763999() {
+ UInt32 x = 7;
+ printf("x = %u\n", x); // no-warning
+}
+
+void test_positive() {
+  printf("%d", "hello"); // expected-warning {{conversion specifies type 'int' but the argument has type 'char *'}}
+}
+

Modified: cfe/trunk/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=135134&r1=135133&r2=135134&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Thu Jul 14 01:49:52 2011
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -fsyntax-only -verify -Wformat-nonliteral %s
 
 #include <stdarg.h>
 typedef __typeof(sizeof(int)) size_t;





More information about the cfe-commits mailing list