File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
lib/Analysis/FlowSensitive
unittests/Analysis/FlowSensitive Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -382,6 +382,20 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
382
382
Env.setValue (*S, Env.makeNot (*SubExprVal));
383
383
break ;
384
384
}
385
+ case UO_PreInc:
386
+ case UO_PreDec:
387
+ // Propagate the storage location, but don't create a new value; to
388
+ // avoid generating unnecessary values, we leave it to the specific
389
+ // analysis to do this if desired.
390
+ propagateStorageLocation (*S->getSubExpr (), *S, Env);
391
+ break ;
392
+ case UO_PostInc:
393
+ case UO_PostDec:
394
+ // Propagate the old value, but don't create a new value; to avoid
395
+ // generating unnecessary values, we leave it to the specific analysis
396
+ // to do this if desired.
397
+ propagateValue (*S->getSubExpr (), *S, Env);
398
+ break ;
385
399
default :
386
400
break ;
387
401
}
Original file line number Diff line number Diff line change @@ -3760,6 +3760,42 @@ TEST(TransferTest, AddrOfReference) {
3760
3760
});
3761
3761
}
3762
3762
3763
+ TEST (TransferTest, Preincrement) {
3764
+ std::string Code = R"(
3765
+ void target(int I) {
3766
+ int &IRef = ++I;
3767
+ // [[p]]
3768
+ }
3769
+ )" ;
3770
+ runDataflow (
3771
+ Code,
3772
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3773
+ ASTContext &ASTCtx) {
3774
+ const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3775
+
3776
+ EXPECT_EQ (&getLocForDecl (ASTCtx, Env, " IRef" ),
3777
+ &getLocForDecl (ASTCtx, Env, " I" ));
3778
+ });
3779
+ }
3780
+
3781
+ TEST (TransferTest, Postincrement) {
3782
+ std::string Code = R"(
3783
+ void target(int I) {
3784
+ int OldVal = I++;
3785
+ // [[p]]
3786
+ }
3787
+ )" ;
3788
+ runDataflow (
3789
+ Code,
3790
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3791
+ ASTContext &ASTCtx) {
3792
+ const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3793
+
3794
+ EXPECT_EQ (&getValueForDecl (ASTCtx, Env, " OldVal" ),
3795
+ &getValueForDecl (ASTCtx, Env, " I" ));
3796
+ });
3797
+ }
3798
+
3763
3799
TEST (TransferTest, CannotAnalyzeFunctionTemplate) {
3764
3800
std::string Code = R"(
3765
3801
template <typename T>
You can’t perform that action at this time.
0 commit comments