r179155 - Handle "typeof" in Objective-C format string checking. This previously crashed.

Jordan Rose jordan_rose at apple.com
Wed Apr 10 09:12:31 PDT 2013


Should this apply to C++11 decltype too?

(To anyone watching: we can't just get the canonical type because format string checking checks typedefs as well.)

Jordan


On Apr 9, 2013, at 23:26 , Ted Kremenek <kremenek at apple.com> wrote:

> Author: kremenek
> Date: Wed Apr 10 01:26:26 2013
> New Revision: 179155
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=179155&view=rev
> Log:
> Handle "typeof" in Objective-C format string checking.  This previously crashed.
> 
> Yes, this came from actual code.
> 
> Fixes <rdar://problem/13557053>.
> 
> Modified:
>    cfe/trunk/lib/Sema/SemaChecking.cpp
>    cfe/trunk/test/SemaObjC/format-strings-objc.m
> 
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=179155&r1=179154&r2=179155&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Apr 10 01:26:26 2013
> @@ -2744,6 +2744,10 @@ CheckPrintfHandler::checkFormatExpr(cons
>     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;
> 
> 
> Modified: cfe/trunk/test/SemaObjC/format-strings-objc.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/format-strings-objc.m?rev=179155&r1=179154&r2=179155&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/format-strings-objc.m (original)
> +++ cfe/trunk/test/SemaObjC/format-strings-objc.m Wed Apr 10 01:26:26 2013
> @@ -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}}
> +}
> +
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list