summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-04-16 21:03:30 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-04-16 21:03:30 +0000
commit29898f45657314c7fa7f61e8157a36c832015fcc (patch)
tree17d058d7bb5bc90342c1906e0dc6f01ffd7ff5c0 /clang
parent1e8ac36b605e90c46b8d445dc300456978f75e4d (diff)
downloadbcm5719-llvm-29898f45657314c7fa7f61e8157a36c832015fcc.tar.gz
bcm5719-llvm-29898f45657314c7fa7f61e8157a36c832015fcc.zip
objective-c modern translator: buildit objc bool
type for rewriter project will be BoolTy. // rdar://11231426. llvm-svn: 154861
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/include/clang/Basic/TargetInfo.h15
-rw-r--r--clang/lib/AST/ASTContext.cpp3
-rw-r--r--clang/lib/Basic/TargetInfo.cpp1
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp4
-rw-r--r--clang/lib/Sema/SemaExpr.cpp18
-rw-r--r--clang/test/Rewriter/objc-bool-literal-check-modern.mm12
-rw-r--r--clang/test/Rewriter/objc-bool-literal-modern.mm2
-rw-r--r--clang/test/Rewriter/objc-modern-numeric-literal.mm10
-rw-r--r--clang/test/Rewriter/rewrite-modern-container-literal.mm2
-rw-r--r--clang/test/SemaObjC/objc-literal-nsnumber.m4
-rw-r--r--clang/test/SemaObjCXX/literals.mm2
12 files changed, 39 insertions, 37 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 48c48722f3b..baaddcfeb2d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1547,9 +1547,6 @@ def warn_objc_redundant_literal_use : Warning<
"using %0 with a literal is redundant">, InGroup<ObjCRedundantLiteralUse>;
}
-def warn_bool_for_boolean_literal : Warning<
- "BOOL of type %0 is non-intergal and unsuitable for a "
- "boolean literal - ignored">, InGroup<DiagGroup<"numeric-literals">>;
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/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index bbd376a8241..a03cf83ff7d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/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/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index acf5e0bbc9a..887beac4b0b 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/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/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index f938b5a6045..8c49486b0dc 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/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/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index cab6b90d0cd..803e418e241 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/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/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0d0f2f5b99a..3e368a3b100 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/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<TypedefDecl>(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/clang/test/Rewriter/objc-bool-literal-check-modern.mm b/clang/test/Rewriter/objc-bool-literal-check-modern.mm
index b28e594d72a..338619715e1 100644
--- a/clang/test/Rewriter/objc-bool-literal-check-modern.mm
+++ b/clang/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/clang/test/Rewriter/objc-bool-literal-modern.mm b/clang/test/Rewriter/objc-bool-literal-modern.mm
index 6bbbb449c90..328ee6bf46f 100644
--- a/clang/test/Rewriter/objc-bool-literal-modern.mm
+++ b/clang/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/clang/test/Rewriter/objc-modern-numeric-literal.mm b/clang/test/Rewriter/objc-modern-numeric-literal.mm
index d27d03d54e2..5f0b1fc3b1e 100644
--- a/clang/test/Rewriter/objc-modern-numeric-literal.mm
+++ b/clang/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/clang/test/Rewriter/rewrite-modern-container-literal.mm b/clang/test/Rewriter/rewrite-modern-container-literal.mm
index 87b9b892813..2c2f61df1d4 100644
--- a/clang/test/Rewriter/rewrite-modern-container-literal.mm
+++ b/clang/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/clang/test/SemaObjC/objc-literal-nsnumber.m b/clang/test/SemaObjC/objc-literal-nsnumber.m
index 449bfff4d96..6635bea72e7 100644
--- a/clang/test/SemaObjC/objc-literal-nsnumber.m
+++ b/clang/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/clang/test/SemaObjCXX/literals.mm b/clang/test/SemaObjCXX/literals.mm
index eed67652d2a..6cdd207d57d 100644
--- a/clang/test/SemaObjCXX/literals.mm
+++ b/clang/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)());
OpenPOWER on IntegriCloud