aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorWei Yi Tee <wyt@google.com>2022-06-27 20:53:07 +0200
committerDmitri Gribenko <gribozavr@gmail.com>2022-06-27 21:04:52 +0200
commitfa34210fa69f64a96dc64983b3de00ddd21e55e1 (patch)
tree30de6545e680578a2dba5a5aec702735c67e139a /clang/unittests
parent4db52450c1a444ccb5c0c27b631e06b4902c0300 (diff)
[clang][dataflow] Do not allow substitution of true/false boolean literals in `buildAndSubstituteFlowCondition`
Reviewed By: gribozavr2, xazax.hun Differential Revision: https://reviews.llvm.org/D128658
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp b/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
index 26bc37bda617..758b1a8b21a2 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -276,6 +276,34 @@ TEST_F(DataflowAnalysisContextTest, EquivBoolVals) {
Context.getOrCreateConjunction(X, Context.getOrCreateConjunction(Y, Z))));
}
+#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsTrueUnchanged) {
+ auto &True = Context.getBoolLiteralValue(true);
+ auto &Other = Context.createAtomicBoolValue();
+
+ // FC = True
+ auto &FC = Context.makeFlowConditionToken();
+ Context.addFlowConditionConstraint(FC, True);
+
+ // `True` should never be substituted
+ EXPECT_DEATH(Context.buildAndSubstituteFlowCondition(FC, {{&True, &Other}}),
+ "Do not substitute true/false boolean literals");
+}
+
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsFalseUnchanged) {
+ auto &False = Context.getBoolLiteralValue(false);
+ auto &Other = Context.createAtomicBoolValue();
+
+ // FC = False
+ auto &FC = Context.makeFlowConditionToken();
+ Context.addFlowConditionConstraint(FC, False);
+
+ // `False` should never be substituted
+ EXPECT_DEATH(Context.buildAndSubstituteFlowCondition(FC, {{&False, &Other}}),
+ "Do not substitute true/false boolean literals");
+}
+#endif
+
TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsAtomicFC) {
auto &X = Context.createAtomicBoolValue();
auto &True = Context.getBoolLiteralValue(true);