aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-07-14 06:49:52 +0000
committerTed Kremenek <kremenek@apple.com>2011-07-14 06:49:52 +0000
commit826d5b4782d5c4c38c30eaae70a243c33a76edad (patch)
tree9364786ae201738f29741ed672473f15fe18703c
parent13d99bf2e9e13820d74ecc6a28630721736c1f10 (diff)
Reapply r135075, but modify format-strings.c and format-strings-fixit.c test cases to be more portable with an explicit target triple.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135134 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/FormatString.cpp19
-rw-r--r--test/Sema/format-strings-fixit.c6
-rw-r--r--test/Sema/format-strings-i386.c15
-rw-r--r--test/Sema/format-strings.c2
4 files changed, 28 insertions, 14 deletions
diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp
index 5f3cd4c615..74f1e92794 100644
--- a/lib/Analysis/FormatString.cpp
+++ b/lib/Analysis/FormatString.cpp
@@ -206,6 +206,10 @@ clang::analyze_format_string::ParseLengthModifier(FormatSpecifier &FS,
// 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 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const {
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;
}
diff --git a/test/Sema/format-strings-fixit.c b/test/Sema/format-strings-fixit.c
index c2fa2f7707..b4ab2306aa 100644
--- a/test/Sema/format-strings-fixit.c
+++ b/test/Sema/format-strings-fixit.c
@@ -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
diff --git a/test/Sema/format-strings-i386.c b/test/Sema/format-strings-i386.c
new file mode 100644
index 0000000000..45d10a763a
--- /dev/null
+++ b/test/Sema/format-strings-i386.c
@@ -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 *'}}
+}
+
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index b47d3ca261..d128d8ccc0 100644
--- a/test/Sema/format-strings.c
+++ b/test/Sema/format-strings.c
@@ -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;