From a678ce4b50759d5896bb8ed9438d7672e01961dc Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 14 Mar 2019 17:18:32 -0400 Subject: [PATCH 113/169] FIXME: add operations.c --- .../gcc.dg/TODO-analyzer/facts/operations/input.c | 69 ---------------------- .../TODO-analyzer/facts/operations/script.py | 51 ---------------- .../TODO-analyzer/facts/operations/stdout.txt | 0 gcc/testsuite/gcc.dg/analyzer/operations.c | 42 +++++++++++++ 4 files changed, 42 insertions(+), 120 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/input.c delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/script.py delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/stdout.txt create mode 100644 gcc/testsuite/gcc.dg/analyzer/operations.c diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/input.c b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/input.c deleted file mode 100644 index b326aff..0000000 --- a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/input.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright 2012 David Malcolm - Copyright 2012 Red Hat, Inc. - - This is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - . -*/ - -extern void marker_A(void); -extern void marker_B(void); -extern void marker_C(void); -extern void marker_D(void); -extern void marker_E(void); -extern void marker_F(void); - -/* - Ensure that the fact-finder can sanely propagate information about - arithmetic operations -*/ - -void test(int i, int j) -{ - int k, m; - - if (i > 42) { - marker_A(); - - i += 3; - - /* (we should now know that i > 45) */ - marker_B(); - - i -= 1; - - /* (and now have i > 44) */ - marker_C(); - - i = 3 * i; - - /* (likewise now i > 132) */ - marker_D(); - - i /= 2; - - /* (should now have i > 66: */ - marker_E(); - - /* We don't know anything about j, so we don't know anything about k: */ - k = i + j; - - /* However, we should now know that m > 67: */ - m = i + 1; - - marker_F(); - - } - -} diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/script.py b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/script.py deleted file mode 100644 index bb020af..0000000 --- a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/script.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2012, 2013 David Malcolm -# Copyright 2012, 2013 Red Hat, Inc. -# -# This is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -from sm import main -from sm.parser import parse_file - -def selftest(ctxt, solution): - if 0: - import sys - solution.dump(sys.stderr) - - # Verify that we know i > 42 at marker_A: - node = ctxt.find_call_of('marker_A') - ctxt.assert_fact(node, 'i', '>', 42) - - # Verify the effect of the various arithmetic operations on the - # factfinder: - node = ctxt.find_call_of('marker_B') - ctxt.assert_fact(node, 'i', '>', 45) - - node = ctxt.find_call_of('marker_C') - ctxt.assert_fact(node, 'i', '>', 44) - - node = ctxt.find_call_of('marker_D') - ctxt.assert_fact(node, 'i', '>', 132) - - node = ctxt.find_call_of('marker_E') - ctxt.assert_fact(node, 'i', '>', 66) - - node = ctxt.find_call_of('marker_F') - ctxt.assert_fact(node, 'i', '>', 66) - ctxt.assert_fact(node, 'm', '>', 67) - # though we don't know anything about the relationship of i and m - -checker = parse_file('sm/checkers/malloc_checker.sm') -main([checker], selftest=selftest) diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/stdout.txt b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/operations/stdout.txt deleted file mode 100644 index e69de29..0000000 diff --git a/gcc/testsuite/gcc.dg/analyzer/operations.c b/gcc/testsuite/gcc.dg/analyzer/operations.c new file mode 100644 index 0000000..9ea2327 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/operations.c @@ -0,0 +1,42 @@ +void test (int i, int j) +{ + int k, m; + + if (i > 42) { + __analyzer_eval (i > 42); /* { dg-warning "TRUE" } */ + + i += 3; + + __analyzer_eval (i > 45); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): do we really know this? what about overflow? */ + + i -= 1; + + __analyzer_eval (i > 44); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): do we really know this? what about overflow? */ + + i = 3 * i; + + __analyzer_eval (i > 132); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): do we really know this? what about overflow? */ + + i /= 2; + + __analyzer_eval (i > 66); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): do we really know this? what about overflow? */ + + /* We don't know anything about j, so we don't know anything about k: */ + k = i + j; + __analyzer_eval (k == 0); /* { dg-warning "UNKNOWN" } */ + + /* However, we should now know that m > 67: */ + m = i + 1; + __analyzer_eval (m > 67); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): do we really know this? what about overflow? */ + } +} -- 1.8.5.3