Author: ahatanak Date: Thu Jan 10 12:12:16 2019 New Revision: 350887 URL: http://llvm.org/viewvc/llvm-project?rev=350887&view=rev Log: [Sema] Call CheckPlaceholderExpr to resolve typeof or decltype placeholder expressions while an unevaluated context is still on the expression evaluation context stack.
This prevents recordUseOfWeek from being called when a weak variable is used as an operand of a decltype or a typeof expression and fixes spurious -Warc-repeated-use-of-weak warnings. rdar://problem/45742525 Differential Revision: https://reviews.llvm.org/D55662 Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaExprObjC.cpp cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/SemaObjC/arc-repeated-weak.mm Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=350887&r1=350886&r2=350887&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jan 10 12:12:16 2019 @@ -14557,6 +14557,10 @@ void Sema::DiscardCleanupsInEvaluationCo } ExprResult Sema::HandleExprEvaluationContextForTypeof(Expr *E) { + ExprResult Result = CheckPlaceholderExpr(E); + if (Result.isInvalid()) + return ExprError(); + E = Result.get(); if (!E->getType()->isVariablyModifiedType()) return E; return TransformToPotentiallyEvaluated(E); Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=350887&r1=350886&r2=350887&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Jan 10 12:12:16 2019 @@ -6543,6 +6543,11 @@ ExprResult Sema::ActOnDecltypeExpression ExpressionEvaluationContextRecord::EK_Decltype && "not in a decltype expression"); + ExprResult Result = CheckPlaceholderExpr(E); + if (Result.isInvalid()) + return ExprError(); + E = Result.get(); + // C++11 [expr.call]p11: // If a function call is a prvalue of object type, // -- if the function call is either Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=350887&r1=350886&r2=350887&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Jan 10 12:12:16 2019 @@ -3161,7 +3161,7 @@ ExprResult Sema::BuildInstanceMessage(Ex Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak; if (!IsWeak && Sel.isUnarySelector()) IsWeak = ReturnType.getObjCLifetime() & Qualifiers::OCL_Weak; - if (IsWeak && + if (IsWeak && !isUnevaluatedContext() && !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc)) getCurFunction()->recordUseOfWeak(Result, Prop); } Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=350887&r1=350886&r2=350887&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Jan 10 12:12:16 2019 @@ -4429,6 +4429,10 @@ Sema::DeduceAutoType(TypeLoc Type, Expr return DAR_FailedAlreadyDiagnosed; } + ExprResult ER = CheckPlaceholderExpr(Init); + if (ER.isInvalid()) + return DAR_FailedAlreadyDiagnosed; + Init = ER.get(); QualType Deduced = BuildDecltypeType(Init, Init->getBeginLoc(), false); if (Deduced.isNull()) return DAR_FailedAlreadyDiagnosed; Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=350887&r1=350886&r2=350887&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jan 10 12:12:16 2019 @@ -8055,9 +8055,7 @@ QualType Sema::getElaboratedType(Elabora } QualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) { - ExprResult ER = CheckPlaceholderExpr(E); - if (ER.isInvalid()) return QualType(); - E = ER.get(); + assert(!E->hasPlaceholderType() && "unexpected placeholder"); if (!getLangOpts().CPlusPlus && E->refersToBitField()) Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 2; @@ -8142,9 +8140,7 @@ static QualType getDecltypeForExpr(Sema QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc, bool AsUnevaluated) { - ExprResult ER = CheckPlaceholderExpr(E); - if (ER.isInvalid()) return QualType(); - E = ER.get(); + assert(!E->hasPlaceholderType() && "unexpected placeholder"); if (AsUnevaluated && CodeSynthesisContexts.empty() && E->HasSideEffects(Context, false)) { Modified: cfe/trunk/test/SemaObjC/arc-repeated-weak.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-repeated-weak.mm?rev=350887&r1=350886&r2=350887&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/arc-repeated-weak.mm (original) +++ cfe/trunk/test/SemaObjC/arc-repeated-weak.mm Thu Jan 10 12:12:16 2019 @@ -462,6 +462,9 @@ void foo() { NSString * t2 = NSBundle.foo2.prop; use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}} use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}} + decltype([NSBundle2.foo2 weakProp]) t3; + decltype(NSBundle2.foo2.weakProp) t4; + __typeof__(NSBundle2.foo2.weakProp) t5; } // This used to crash in the constructor of WeakObjectProfileTy when a _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits