From 93a49944e0e68e32bc22d45d44ee136b34beffb3 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 16 Apr 2012 21:03:30 +0000 Subject: [PATCH] objective-c modern translator: buildit objc bool type for rewriter project will be BoolTy. // rdar://11231426. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154861 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 --- include/clang/Basic/TargetInfo.h | 15 +++++++++++++++ lib/AST/ASTContext.cpp | 3 ++- lib/Basic/TargetInfo.cpp | 1 + lib/Frontend/CompilerInstance.cpp | 4 ++++ lib/Sema/SemaExpr.cpp | 18 +----------------- .../Rewriter/objc-bool-literal-check-modern.mm | 12 ++++++------ test/Rewriter/objc-bool-literal-modern.mm | 2 +- test/Rewriter/objc-modern-numeric-literal.mm | 10 +++++----- .../rewrite-modern-container-literal.mm | 2 +- test/SemaObjC/objc-literal-nsnumber.m | 4 ++-- test/SemaObjCXX/literals.mm | 2 +- 12 files changed, 39 insertions(+), 37 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 48c48722f3..baaddcfeb2 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1547,9 +1547,6 @@ def warn_objc_redundant_literal_use : Warning< "using %0 with a literal is redundant">, InGroup; } -def warn_bool_for_boolean_literal : Warning< - "BOOL of type %0 is non-intergal and unsuitable for a " - "boolean literal - ignored">, InGroup>; def err_only_annotate_after_access_spec : Error< "access specifier can only have annotation attributes">; def err_attribute_section_invalid_for_target : Error< diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index bbd376a824..a03cf83ff7 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -132,6 +132,11 @@ protected: IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType, WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType; + /// Flag whether the Objective-C built-in boolean type should be signed char. + /// Otherwise, when this flag is not set, the normal built-in boolean type is + /// used. + unsigned UseSignedCharForObjCBool : 1; + /// Control whether the alignment of bit-field types is respected when laying /// out structures. If true, then the alignment of the bit-field type will be /// used to (a) impact the alignment of the containing structure, and (b) @@ -299,6 +304,16 @@ public: return MCountName; } + /// useSignedCharForObjCBool - Check if the Objective-C built-in boolean + /// type should be signed char. Otherwise, if this returns false, the + /// normal built-in boolean type should also be used for Objective-C. + bool useSignedCharForObjCBool() const { + return UseSignedCharForObjCBool; + } + void noSignedCharForObjCBool() { + UseSignedCharForObjCBool = false; + } + /// useBitFieldTypeAlignment() - Check whether the alignment of bit-field /// types is respected when laying out structures. bool useBitFieldTypeAlignment() const { diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index acf5e0bbc9..887beac4b0 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -481,7 +481,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) { InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); // Builtin type for __objc_yes and __objc_no - ObjCBuiltinBoolTy = SignedCharTy; + ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? + SignedCharTy : BoolTy); ObjCConstantStringType = QualType(); diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index f938b5a604..8c49486b0d 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -58,6 +58,7 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) { Char32Type = UnsignedInt; Int64Type = SignedLongLong; SigAtomicType = SignedInt; + UseSignedCharForObjCBool = true; UseBitFieldTypeAlignment = true; UseZeroLengthBitfieldAlignment = false; ZeroLengthBitfieldBoundary = 0; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index cab6b90d0c..803e418e24 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -651,6 +651,10 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { // created. This complexity should be lifted elsewhere. getTarget().setForcedLangOptions(getLangOpts()); + // rewriter project will change target built-in bool type from its default. + if (getFrontendOpts().ProgramAction == frontend::RewriteObjC) + getTarget().noSignedCharForObjCBool(); + // Validate/process some options. if (getHeaderSearchOpts().Verbose) OS << "clang -cc1 version " CLANG_VERSION_STRING diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0d0f2f5b99..3e368a3b10 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11268,22 +11268,6 @@ ExprResult Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) { assert((Kind == tok::kw___objc_yes || Kind == tok::kw___objc_no) && "Unknown Objective-C Boolean value!"); - QualType ObjCBoolLiteralQT = Context.ObjCBuiltinBoolTy; - // signed char is the default type for boolean literals. Use 'BOOL' - // instead, if BOOL typedef is visible in its scope instead. - Decl *TD = - LookupSingleName(TUScope, &Context.Idents.get("BOOL"), - SourceLocation(), LookupOrdinaryName); - if (TypedefDecl *BoolTD = dyn_cast_or_null(TD)) { - QualType QT = BoolTD->getUnderlyingType(); - if (!QT->isIntegralOrUnscopedEnumerationType()) { - Diag(OpLoc, diag::warn_bool_for_boolean_literal) << QT; - Diag(BoolTD->getLocation(), diag::note_previous_declaration); - } - else - ObjCBoolLiteralQT = QT; - } - return Owned(new (Context) ObjCBoolLiteralExpr(Kind == tok::kw___objc_yes, - ObjCBoolLiteralQT, OpLoc)); + Context.ObjCBuiltinBoolTy, OpLoc)); } diff --git a/test/Rewriter/objc-bool-literal-check-modern.mm b/test/Rewriter/objc-bool-literal-check-modern.mm index b28e594d72..338619715e 100644 --- a/test/Rewriter/objc-bool-literal-check-modern.mm +++ b/test/Rewriter/objc-bool-literal-check-modern.mm @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s // rdar://11124775 -typedef signed char BOOL; +typedef bool BOOL; BOOL yes() { return __objc_yes; @@ -22,8 +22,8 @@ int main() { return __objc_yes; } -// CHECK: return ((signed char)1); -// CHECK: return ((signed char)0); -// CHECK: which (((signed char)1)); -// CHECK: which (((signed char)0)); -// CHECK: return ((signed char)1); +// CHECK: return ((bool)1); +// CHECK: return ((bool)0); +// CHECK: which (((bool)1)); +// CHECK: which (((bool)0)); +// CHECK: return ((bool)1); diff --git a/test/Rewriter/objc-bool-literal-modern.mm b/test/Rewriter/objc-bool-literal-modern.mm index 6bbbb449c9..328ee6bf46 100644 --- a/test/Rewriter/objc-bool-literal-modern.mm +++ b/test/Rewriter/objc-bool-literal-modern.mm @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -fsyntax-only -D"__declspec(X)=" %t-rw.cpp // rdar://11124775 -typedef signed char BOOL; +typedef bool BOOL; BOOL yes() { return __objc_yes; diff --git a/test/Rewriter/objc-modern-numeric-literal.mm b/test/Rewriter/objc-modern-numeric-literal.mm index d27d03d54e..5f0b1fc3b1 100644 --- a/test/Rewriter/objc-modern-numeric-literal.mm +++ b/test/Rewriter/objc-modern-numeric-literal.mm @@ -4,7 +4,7 @@ extern "C" void *sel_registerName(const char *); -typedef signed char BOOL; +typedef bool BOOL; typedef long NSInteger; typedef unsigned long NSUInteger; @@ -63,7 +63,7 @@ int main(int argc, const char *argv[]) { // CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), 42LL); // CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), 3.1415927); // CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), 3.1415926535); -// CHECK: NSNumber *yesNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)true); -// CHECK: NSNumber *noNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)false); -// CHECK: NSNumber *trueNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)true); -// CHECK: NSNumber *falseNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)false); +// CHECK: NSNumber *yesNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true); +// CHECK: NSNumber *noNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false); +// CHECK: NSNumber *trueNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true); +// CHECK: NSNumber *falseNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false); diff --git a/test/Rewriter/rewrite-modern-container-literal.mm b/test/Rewriter/rewrite-modern-container-literal.mm index 87b9b89281..2c2f61df1d 100644 --- a/test/Rewriter/rewrite-modern-container-literal.mm +++ b/test/Rewriter/rewrite-modern-container-literal.mm @@ -5,7 +5,7 @@ void *sel_registerName(const char *); typedef unsigned long NSUInteger; typedef long NSInteger; -typedef signed char BOOL; +typedef bool BOOL; @interface NSNumber + (NSNumber *)numberWithChar:(char)value; diff --git a/test/SemaObjC/objc-literal-nsnumber.m b/test/SemaObjC/objc-literal-nsnumber.m index 449bfff4d9..6635bea72e 100644 --- a/test/SemaObjC/objc-literal-nsnumber.m +++ b/test/SemaObjC/objc-literal-nsnumber.m @@ -78,8 +78,8 @@ NSDictionary * warn() { } // rdar:// 11231426 -typedef float BOOL; // expected-note {{previous declaration is here}} +typedef float BOOL; BOOL radar11231426() { - return __objc_yes; // expected-warning {{BOOL of type 'float' is non-intergal and unsuitable for a boolean literal - ignored}} + return __objc_yes; } diff --git a/test/SemaObjCXX/literals.mm b/test/SemaObjCXX/literals.mm index eed67652d2..6cdd207d57 100644 --- a/test/SemaObjCXX/literals.mm +++ b/test/SemaObjCXX/literals.mm @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s // rdar://11231426 -typedef bool BOOL; +typedef signed char BOOL; void y(BOOL (^foo)()); -- 2.40.0