lebedev.ri updated this revision to Diff 156235. lebedev.ri retitled this revision from "[CodeGen] VisitMaterializeTemporaryExpr(): don't skip NoOp Casts." to "[Sema] Expr::skipRValueSubobjectAdjustments(): record skipped NoOp casts.". lebedev.ri edited the summary of this revision. lebedev.ri added a comment.
In https://reviews.llvm.org/D49508#1167177, @efriedma wrote: > Would it be enough to accumulate the skipped casts into a SmallVector, like > we do for the skipped comma operators? Duuuh, why did i not try this in the first place?! That works, thanks! Repository: rC Clang https://reviews.llvm.org/D49508 Files: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/AST/ExprConstant.cpp lib/Analysis/CFG.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprConstant.cpp lib/Sema/JumpDiagnostics.cpp lib/StaticAnalyzer/Core/ExprEngine.cpp
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -358,9 +358,10 @@ SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; + SmallVector<const CastExpr *, 2> SkippedCasts; const Expr *Init = InitWithAdjustments->skipRValueSubobjectAdjustments( - CommaLHSs, Adjustments); + CommaLHSs, Adjustments, SkippedCasts); // Take the region for Init, i.e. for the whole object. If we do not remember // the region in which the object originally was constructed, come up with Index: lib/Sema/JumpDiagnostics.cpp =================================================================== --- lib/Sema/JumpDiagnostics.cpp +++ lib/Sema/JumpDiagnostics.cpp @@ -531,9 +531,10 @@ if (MTE->getStorageDuration() == SD_Automatic) { SmallVector<const Expr *, 4> CommaLHS; SmallVector<SubobjectAdjustment, 4> Adjustments; + SmallVector<const CastExpr *, 2> SkippedCasts; const Expr *ExtendedObject = MTE->GetTemporaryExpr()->skipRValueSubobjectAdjustments( - CommaLHS, Adjustments); + CommaLHS, Adjustments, SkippedCasts); if (ExtendedObject->getType().isDestructedType()) { Scopes.push_back(GotoScope(ParentScope, 0, diag::note_exits_temporary_dtor, Index: lib/CodeGen/CGExprConstant.cpp =================================================================== --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -1829,14 +1829,14 @@ return CGM.GetAddrOfUuidDescriptor(E); } -ConstantLValue -ConstantLValueEmitter::VisitMaterializeTemporaryExpr( - const MaterializeTemporaryExpr *E) { +ConstantLValue ConstantLValueEmitter::VisitMaterializeTemporaryExpr( + const MaterializeTemporaryExpr *E) { assert(E->getStorageDuration() == SD_Static); SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; - const Expr *Inner = E->GetTemporaryExpr() - ->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); + SmallVector<const CastExpr *, 2> SkippedCasts; + const Expr *Inner = E->GetTemporaryExpr()->skipRValueSubobjectAdjustments( + CommaLHSs, Adjustments, SkippedCasts); return CGM.GetAddrOfGlobalTemporary(E, Inner); } Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -467,7 +467,8 @@ SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; - E = E->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); + SmallVector<const CastExpr *, 2> SkippedCasts; + E = E->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments, SkippedCasts); for (const auto &Ignored : CommaLHSs) EmitIgnoredExpr(Ignored); Index: lib/Analysis/CFG.cpp =================================================================== --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -1539,8 +1539,9 @@ // Skip sub-object accesses into rvalues. SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; - const Expr *SkippedInit = - Init->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); + SmallVector<const CastExpr *, 2> SkippedCasts; + const Expr *SkippedInit = Init->skipRValueSubobjectAdjustments( + CommaLHSs, Adjustments, SkippedCasts); if (SkippedInit != Init) { Init = SkippedInit; continue; @@ -4384,11 +4385,12 @@ BindToTemporary = (MTE->getStorageDuration() != SD_FullExpression); SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; + SmallVector<const CastExpr *, 2> SkippedCasts; // Find the expression whose lifetime needs to be extended. - E = const_cast<Expr *>( - cast<MaterializeTemporaryExpr>(E) - ->GetTemporaryExpr() - ->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments)); + E = const_cast<Expr *>(cast<MaterializeTemporaryExpr>(E) + ->GetTemporaryExpr() + ->skipRValueSubobjectAdjustments( + CommaLHSs, Adjustments, SkippedCasts)); // Visit the skipped comma operator left-hand sides for other temporaries. for (const Expr *CommaLHS : CommaLHSs) { VisitForTemporaryDtors(const_cast<Expr *>(CommaLHS), Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -88,9 +88,10 @@ dyn_cast<MaterializeTemporaryExpr>(Base)) { SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; + SmallVector<const CastExpr *, 2> SkippedCasts; const Expr *Temp = MTE->GetTemporaryExpr(); - const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHSs, - Adjustments); + const Expr *Inner = Temp->skipRValueSubobjectAdjustments( + CommaLHSs, Adjustments, SkippedCasts); // Keep any cv-qualifiers from the reference if we generated a temporary // for it directly. Otherwise use the type after adjustment. if (!Adjustments.empty()) @@ -5358,8 +5359,9 @@ // Walk through the expression to find the materialized temporary itself. SmallVector<const Expr *, 2> CommaLHSs; SmallVector<SubobjectAdjustment, 2> Adjustments; - const Expr *Inner = E->GetTemporaryExpr()-> - skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); + SmallVector<const CastExpr *, 2> SkippedCasts; + const Expr *Inner = E->GetTemporaryExpr()->skipRValueSubobjectAdjustments( + CommaLHSs, Adjustments, SkippedCasts); // If we passed any comma operators, evaluate their LHSs. for (unsigned I = 0, N = CommaLHSs.size(); I != N; ++I) Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -76,7 +76,8 @@ const Expr *Expr::skipRValueSubobjectAdjustments( SmallVectorImpl<const Expr *> &CommaLHSs, - SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { + SmallVectorImpl<SubobjectAdjustment> &Adjustments, + SmallVectorImpl<const CastExpr *> &SkippedCasts) const { const Expr *E = this; while (true) { E = E->IgnoreParens(); @@ -93,6 +94,7 @@ } if (CE->getCastKind() == CK_NoOp) { + SkippedCasts.emplace_back(CE); E = CE->getSubExpr(); continue; } Index: include/clang/AST/Expr.h =================================================================== --- include/clang/AST/Expr.h +++ include/clang/AST/Expr.h @@ -850,11 +850,13 @@ /// the LHSs of comma expressions and adjustments needed along the path. const Expr *skipRValueSubobjectAdjustments( SmallVectorImpl<const Expr *> &CommaLHS, - SmallVectorImpl<SubobjectAdjustment> &Adjustments) const; + SmallVectorImpl<SubobjectAdjustment> &Adjustments, + SmallVectorImpl<const CastExpr *> &SkippedCasts) const; const Expr *skipRValueSubobjectAdjustments() const { SmallVector<const Expr *, 8> CommaLHSs; SmallVector<SubobjectAdjustment, 8> Adjustments; - return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); + SmallVector<const CastExpr *, 2> SkippedCasts; + return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments, SkippedCasts); } static bool classof(const Stmt *T) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits