From: Fariborz Jahanian Date: Fri, 1 Nov 2013 21:58:17 +0000 (+0000) Subject: ObjectiveC. Define a new cc1 flag X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9553e35e1e3af6fc4ca817b169dc796a5b54bcd;p=clang ObjectiveC. Define a new cc1 flag -fobjc-subscripting-legacy-runtime which is off by default and on only when using ObjectiveC legacy runtime. Use this flag to allow array and dictionary subscripting and disallow objectiveC pointer arithmatic in ObjectiveC legacy runtime. // rdar://15363492 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193889 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index b637ec2c54..72b563dfe3 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -143,6 +143,7 @@ LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment") LANGOPT(HexagonQdsp6Compat , 1, 0, "hexagon-qdsp6 backward compatibility") LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated reference counting") LANGOPT(ObjCARCWeak , 1, 0, "__weak support in the ARC runtime") +LANGOPT(ObjCSubscriptingLegacyRuntime , 1, 0, "Subscripting support in legacy ObjectiveC runtime") LANGOPT(FakeAddressSpaceMap , 1, 0, "OpenCL fake address space map") ENUM_LANGOPT(AddressSpaceMapMangling , AddrSpaceMapMangling, 2, ASMM_Target, "OpenCL address space map mangling mode") diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index 45320542ab..d4e8b4eb5b 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -97,6 +97,11 @@ public: bool isSignedOverflowDefined() const { return getSignedOverflowBehavior() == SOB_Defined; } + + bool isSubscriptPointerArithmetic() const { + return ObjCRuntime.isSubscriptPointerArithmetic() && + !ObjCSubscriptingLegacyRuntime; + } /// \brief Reset all of the options that are not considered when building a /// module. diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 743e3a2e61..6b7dac8e44 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -472,6 +472,8 @@ def fno_deprecated_macro : Flag<["-"], "fno-deprecated-macro">, HelpText<"Undefines the __DEPRECATED macro">; def fsized_deallocation : Flag<["-"], "fsized-deallocation">, HelpText<"Enable C++1y sized global deallocation functions">; +def fobjc_subscripting_legacy_runtime : Flag<["-"], "fobjc-subscripting-legacy-runtime">, + HelpText<"Allow Objective-C array and dictionary subscripting in legacy runtime">; //===----------------------------------------------------------------------===// // Header Search Options diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 2f6407109d..3da8ba7309 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1218,6 +1218,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, if (Args.hasArg(OPT_fno_objc_infer_related_result_type)) Opts.ObjCInferRelatedResultType = 0; + + if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime)) + Opts.ObjCSubscriptingLegacyRuntime = + (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX); } if (Args.hasArg(OPT_fgnu89_inline)) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 158cf01502..77cf986351 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3639,7 +3639,8 @@ static bool checkArithmeticOnObjCPointer(Sema &S, SourceLocation opLoc, Expr *op) { assert(op->getType()->isObjCObjectPointerType()); - if (S.LangOpts.ObjCRuntime.allowsPointerArithmetic()) + if (S.LangOpts.ObjCRuntime.allowsPointerArithmetic() && + !S.LangOpts.ObjCSubscriptingLegacyRuntime) return false; S.Diag(opLoc, diag::err_arithmetic_nonfragile_interface) @@ -3744,15 +3745,10 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, // Use custom logic if this should be the pseudo-object subscript // expression. - if (!LangOpts.ObjCRuntime.isSubscriptPointerArithmetic()) + if (!LangOpts.isSubscriptPointerArithmetic()) return BuildObjCSubscriptExpression(RLoc, BaseExpr, IndexExpr, 0, 0); ResultType = PTy->getPointeeType(); - if (!LangOpts.ObjCRuntime.allowsPointerArithmetic()) { - Diag(LLoc, diag::err_subscript_nonfragile_interface) - << ResultType << BaseExpr->getSourceRange(); - return ExprError(); - } } else if (const PointerType *PTy = RHSTy->getAs()) { // Handle the uncommon case of "123[Ptr]". BaseExpr = RHSExp; @@ -3764,7 +3760,7 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, BaseExpr = RHSExp; IndexExpr = LHSExp; ResultType = PTy->getPointeeType(); - if (!LangOpts.ObjCRuntime.allowsPointerArithmetic()) { + if (!LangOpts.isSubscriptPointerArithmetic()) { Diag(LLoc, diag::err_subscript_nonfragile_interface) << ResultType << BaseExpr->getSourceRange(); return ExprError(); diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 7efa08b45c..fc2a6c736f 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -602,7 +602,7 @@ ExprResult Sema::BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, Expr *IndexExpr, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod) { - assert(!LangOpts.ObjCRuntime.isSubscriptPointerArithmetic()); + assert(!LangOpts.isSubscriptPointerArithmetic()); // We can't get dependent types here; our callers should have // filtered them out. diff --git a/test/SemaObjC/objc-array-literal.m b/test/SemaObjC/objc-array-literal.m index a3e29bf122..706207df74 100644 --- a/test/SemaObjC/objc-array-literal.m +++ b/test/SemaObjC/objc-array-literal.m @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // rdar://10111397 +// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-macosx10.9.0 -fobjc-runtime=macosx-fragile-10.9.0 -fobjc-subscripting-legacy-runtime -verify %s +// rdar://15363492 #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 typedef unsigned long NSUInteger; diff --git a/test/SemaObjC/objc-dictionary-literal.m b/test/SemaObjC/objc-dictionary-literal.m index 0b6da4a77b..9d86d88bcb 100644 --- a/test/SemaObjC/objc-dictionary-literal.m +++ b/test/SemaObjC/objc-dictionary-literal.m @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // rdar://11062080 +// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-macosx10.9.0 -fobjc-runtime=macosx-fragile-10.9.0 -fobjc-subscripting-legacy-runtime -verify %s +// rdar://15363492 @interface NSNumber + (NSNumber *)numberWithChar:(char)value;