From 1a38b46ae2f818592577546c8c800ada8de7962b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 4 Aug 2011 23:58:03 +0000 Subject: [PATCH] objc rewriter: Fixes a rewriting of implicit casting of an integral argument to bool. // rdar://9899834 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136946 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Rewrite/RewriteObjC.cpp | 6 +++++- test/Rewriter/rewrite-cast-to-bool.mm | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/Rewriter/rewrite-cast-to-bool.mm diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index 63e2084686..3ba7e90dac 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -3008,7 +3008,11 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, type = Context->getObjCIdType(); // Make sure we convert "type (^)(...)" to "type (*)(...)". (void)convertBlockPointerToFunctionPointer(type); - userExpr = NoTypeInfoCStyleCastExpr(Context, type, CK_BitCast, + const Expr *SubExpr = ICE->IgnoreParenImpCasts(); + bool integral = SubExpr->getType()->isIntegralType(*Context); + userExpr = NoTypeInfoCStyleCastExpr(Context, type, + (integral && type->isBooleanType()) + ? CK_IntegralToBoolean : CK_BitCast, userExpr); } // Make id cast into an 'id' cast. diff --git a/test/Rewriter/rewrite-cast-to-bool.mm b/test/Rewriter/rewrite-cast-to-bool.mm new file mode 100644 index 0000000000..0e9f3640fb --- /dev/null +++ b/test/Rewriter/rewrite-cast-to-bool.mm @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 9899834 + +void *sel_registerName(const char *); + +@interface NSURLDownload +-(void)setBool:(bool)Arg; +@end + +@implementation NSURLDownload +- (void) Meth +{ + [self setBool:(signed char)1]; +} +@end + -- 2.40.0