From d06fa8f87ae3bd4d01e4e3e8495c29e71c824a03 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 21 Apr 2020 13:15:47 -0400 Subject: [PATCH 067/179] WIP on selftest::test_POINTER_PLUS_EXPR_then_MEM_REF --- gcc/analyzer/region-model2.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index 0c84cb3d780..b5da026ecaa 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -8414,6 +8414,39 @@ test_mem_ref () ASSERT_EQ (sval->maybe_get_constant (), int_17); } +/* Test for a POINTER_PLUS_EXPR followed by a MEM_REF. + Analogous to this code: + void test_6 (int a[10]) + { + __analyzer_eval (a[3] == 42); [should be UNKNOWN] + a[3] = 42; + __analyzer_eval (a[3] == 42); [should be TRUE] + } + from data-model-1.c, which looks like this at the gimple level: + # __analyzer_eval (a[3] == 42); [should be UNKNOWN] + int *_1 = a_10(D) + 12; # POINTER_PLUS_EXPR + int _2 = *_1; # MEM_REF + _Bool _3 = _2 == 42; + int _4 = (int) _3; + __analyzer_eval (_4); + + # a[3] = 42; + int *_5 = a_10(D) + 12; # POINTER_PLUS_EXPR + *_5 = 42; # MEM_REF + + # __analyzer_eval (a[3] == 42); [should be TRUE] + int *_6 = a_10(D) + 12; # POINTER_PLUS_EXPR + int _7 = *_6; # MEM_REF + _Bool _8 = _7 == 42; + int _9 = (int) _8; + __analyzer_eval (_9); */ + +static void +test_POINTER_PLUS_EXPR_then_MEM_REF () +{ + // TODO: gimple dump +} + /* Run all of the selftests within this file. */ void @@ -8453,6 +8486,7 @@ analyzer_region_model2_cc_tests () test_var (); test_array (); test_mem_ref (); + test_POINTER_PLUS_EXPR_then_MEM_REF (); } } // namespace selftest -- 2.21.0