diff options
author | Ted Kremenek <kremenek@apple.com> | 2013-04-10 06:26:26 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2013-04-10 06:26:26 +0000 |
commit | 02be968a08184acd42aaefa6f9a7dc883a4d1937 (patch) | |
tree | 10734a8b0fda147173a039835744bfdb83ff5863 | |
parent | 0b0ca4724d1c05dc0dd1d6e5aff4c8a439cbb1a2 (diff) |
Handle "typeof" in Objective-C format string checking. This previously crashed.
Yes, this came from actual code.
Fixes <rdar://problem/13557053>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179155 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 4 | ||||
-rw-r--r-- | test/SemaObjC/format-strings-objc.m | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 4e11b3aa79..8adfbd598f 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2744,6 +2744,10 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS, return true; QualType ExprTy = E->getType(); + while (const TypeOfExprType *TET = dyn_cast<TypeOfExprType>(ExprTy)) { + ExprTy = TET->getUnderlyingExpr()->getType(); + } + if (AT.matchesType(S.Context, ExprTy)) return true; diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index bd33ad41a5..8490130224 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -13,6 +13,7 @@ typedef signed char BOOL; typedef unsigned int NSUInteger; +typedef long NSInteger; @class NSString, Protocol; extern void NSLog(NSString *format, ...); extern void NSLogv(NSString *format, va_list args); @@ -235,3 +236,8 @@ void testByValueObjectInFormat(Foo *obj) { [Bar log2:@"%d", *obj]; // expected-error {{cannot pass object with interface type 'Foo' by value to variadic method; expected type from format string was 'int'}} } +// <rdar://problem/13557053> +void testTypeOf(NSInteger dW, NSInteger dH) { + NSLog(@"dW %d dH %d",({ __typeof__(dW) __a = (dW); __a < 0 ? -__a : __a; }),({ __typeof__(dH) __a = (dH); __a < 0 ? -__a : __a; })); // expected-warning 2 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}} +} + |