[cfe-commits] r157962 - in /cfe/trunk: lib/Analysis/PrintfFormatString.cpp lib/Analysis/ScanfFormatString.cpp test/FixIt/format.m
Jordan Rose
jordan_rose at apple.com
Mon Jun 4 15:49:02 PDT 2012
Author: jrose
Date: Mon Jun 4 17:49:02 2012
New Revision: 157962
URL: http://llvm.org/viewvc/llvm-project?rev=157962&view=rev
Log:
Make suggestions for mismatched enum arguments to printf/scanf.
Modified:
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/lib/Analysis/ScanfFormatString.cpp
cfe/trunk/test/FixIt/format.m
Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=157962&r1=157961&r2=157962&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Mon Jun 4 17:49:02 2012
@@ -381,6 +381,10 @@
return true;
}
+ // If it's an enum, get its underlying type.
+ if (const EnumType *ETy = QT->getAs<EnumType>())
+ QT = ETy->getDecl()->getIntegerType();
+
// We can only work with builtin types.
const BuiltinType *BT = QT->getAs<BuiltinType>();
if (!BT)
Modified: cfe/trunk/lib/Analysis/ScanfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ScanfFormatString.cpp?rev=157962&r1=157961&r2=157962&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ScanfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/ScanfFormatString.cpp Mon Jun 4 17:49:02 2012
@@ -316,6 +316,11 @@
return false;
QualType PT = QT->getPointeeType();
+
+ // If it's an enum, get its underlying type.
+ if (const EnumType *ETy = QT->getAs<EnumType>())
+ QT = ETy->getDecl()->getIntegerType();
+
const BuiltinType *BT = PT->getAs<BuiltinType>();
if (!BT)
return false;
Modified: cfe/trunk/test/FixIt/format.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/format.m?rev=157962&r1=157961&r2=157962&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/format.m (original)
+++ cfe/trunk/test/FixIt/format.m Mon Jun 4 17:49:02 2012
@@ -79,3 +79,17 @@
// CHECK: fix-it:"{{.*}}":{75:11-75:14}:"%@"
}
+
+typedef enum : int { NSUTF8StringEncoding = 8 } NSStringEncoding;
+void test_fixed_enum_correction(NSStringEncoding x) {
+ NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'NSStringEncoding'}}
+ // CHECK: fix-it:"{{.*}}":{85:11-85:13}:"%d"
+}
+
+typedef __SIZE_TYPE__ size_t;
+enum SomeSize : size_t { IntegerSize = sizeof(int) };
+void test_named_fixed_enum_correction(enum SomeSize x) {
+ NSLog(@"%@", x); // expected-warning{{format specifies type 'id' but the argument has type 'enum SomeSize'}}
+ // CHECK: fix-it:"{{.*}}":{92:11-92:13}:"%zu"
+}
+
More information about the cfe-commits
mailing list