@@ -513,70 +513,25 @@ ProgramStateRef ExprEngine::updateObjectsUnderConstruction(
513
513
static ProgramStateRef
514
514
bindRequiredArrayElementToEnvironment (ProgramStateRef State,
515
515
const ArrayInitLoopExpr *AILE,
516
- const LocationContext *LCtx, SVal Idx) {
517
- // The ctor in this case is guaranteed to be a copy ctor, otherwise we hit a
518
- // compile time error.
519
- //
520
- // -ArrayInitLoopExpr <-- we're here
521
- // |-OpaqueValueExpr
522
- // | `-DeclRefExpr <-- match this
523
- // `-CXXConstructExpr
524
- // `-ImplicitCastExpr
525
- // `-ArraySubscriptExpr
526
- // |-ImplicitCastExpr
527
- // | `-OpaqueValueExpr
528
- // | `-DeclRefExpr
529
- // `-ArrayInitIndexExpr
530
- //
531
- // The resulting expression might look like the one below in an implicit
532
- // copy/move ctor.
533
- //
534
- // ArrayInitLoopExpr <-- we're here
535
- // |-OpaqueValueExpr
536
- // | `-MemberExpr <-- match this
537
- // | (`-CXXStaticCastExpr) <-- move ctor only
538
- // | `-DeclRefExpr
539
- // `-CXXConstructExpr
540
- // `-ArraySubscriptExpr
541
- // |-ImplicitCastExpr
542
- // | `-OpaqueValueExpr
543
- // | `-MemberExpr
544
- // | `-DeclRefExpr
545
- // `-ArrayInitIndexExpr
546
- //
547
- // The resulting expression for a multidimensional array.
548
- // ArrayInitLoopExpr <-- we're here
549
- // |-OpaqueValueExpr
550
- // | `-DeclRefExpr <-- match this
551
- // `-ArrayInitLoopExpr
552
- // |-OpaqueValueExpr
553
- // | `-ArraySubscriptExpr
554
- // | |-ImplicitCastExpr
555
- // | | `-OpaqueValueExpr
556
- // | | `-DeclRefExpr
557
- // | `-ArrayInitIndexExpr
558
- // `-CXXConstructExpr <-- extract this
559
- // ` ...
560
-
561
- const auto *OVESrc = AILE->getCommonExpr ()->getSourceExpr ();
516
+ const LocationContext *LCtx, NonLoc Idx) {
517
+ SValBuilder &SVB = State->getStateManager ().getSValBuilder ();
518
+ MemRegionManager &MRMgr = SVB.getRegionManager ();
519
+ ASTContext &Ctx = SVB.getContext ();
562
520
563
521
// HACK: There is no way we can put the index of the array element into the
564
522
// CFG unless we unroll the loop, so we manually select and bind the required
565
523
// parameter to the environment.
566
- const auto *CE =
524
+ const Expr *SourceArray = AILE->getCommonExpr ()->getSourceExpr ();
525
+ const auto *Ctor =
567
526
cast<CXXConstructExpr>(extractElementInitializerFromNestedAILE (AILE));
568
527
569
- SVal Base = UnknownVal ();
570
- if (const auto *ME = dyn_cast<MemberExpr>(OVESrc))
571
- Base = State->getSVal (ME, LCtx);
572
- else if (const auto *DRE = dyn_cast<DeclRefExpr>(OVESrc))
573
- Base = State->getLValue (cast<VarDecl>(DRE->getDecl ()), LCtx);
574
- else
575
- llvm_unreachable (" ArrayInitLoopExpr contains unexpected source expression" );
576
-
577
- SVal NthElem = State->getLValue (CE->getType (), Idx, Base);
528
+ const SubRegion *SourceArrayRegion =
529
+ cast<SubRegion>(State->getSVal (SourceArray, LCtx).getAsRegion ());
530
+ const ElementRegion *ElementRegion =
531
+ MRMgr.getElementRegion (Ctor->getType (), Idx, SourceArrayRegion, Ctx);
578
532
579
- return State->BindExpr (CE->getArg (0 ), LCtx, NthElem);
533
+ return State->BindExpr (Ctor->getArg (0 ), LCtx,
534
+ loc::MemRegionVal (ElementRegion));
580
535
}
581
536
582
537
void ExprEngine::handleConstructor (const Expr *E,
0 commit comments