From 6a142f828f15ee4e57e09040934aa778c794ae5a Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 14 Mar 2019 17:07:38 -0400 Subject: [PATCH 112/169] FIXME: add params.c --- .../gcc.dg/TODO-analyzer/facts/params/input.c | 53 --------------------- .../gcc.dg/TODO-analyzer/facts/params/script.py | 54 ---------------------- gcc/testsuite/gcc.dg/analyzer/params.c | 34 ++++++++++++++ 3 files changed, 34 insertions(+), 107 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/input.c delete mode 100644 gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/script.py create mode 100644 gcc/testsuite/gcc.dg/analyzer/params.c diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/input.c b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/input.c deleted file mode 100644 index e63270c..0000000 --- a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/input.c +++ /dev/null @@ -1,53 +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); - -static int called_function(int j) -{ - int k; - - marker_C(); - - k = j - 1; - - marker_D(); - - return k; -} - -void test(int i) -{ - marker_A(); - - if (i > 4) { - - marker_B(); - - i = called_function(i); - - marker_E(); - } - - marker_F(); -} diff --git a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/script.py b/gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/script.py deleted file mode 100644 index da8ac34..0000000 --- a/gcc/testsuite/gcc.dg/TODO-analyzer/facts/params/script.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# 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 -# . - -from sm import main, Options -from sm.parser import parse_file - -def selftest(ctxt, solution): - if 0: - import sys - solution.dump(sys.stderr) - - node = ctxt.find_call_of('marker_A') - - node = ctxt.find_call_of('marker_B') - ctxt.assert_fact(node, 'i', '>', 4) - - # Within called_function(), - # arg i was passed to param j: - node = ctxt.find_call_of('marker_C') - #ctxt.assert_fact(node, 'i', '>', 4) - ctxt.assert_fact(node, 'j', '>', 4) - - node = ctxt.find_call_of('marker_D') - #ctxt.assert_fact(node, 'i', '>', 4) - ctxt.assert_fact(node, 'j', '>', 4) - ctxt.assert_fact(node, 'k', '>', 3) - - # Back to test: - # return value k was returned to i: - node = ctxt.find_call_of('marker_E') - ctxt.assert_fact(node, 'i', '>', 3) - - # After control merges, we have no information: - node = ctxt.find_call_of('marker_F') - ctxt.assert_no_facts(node) - - -checker = parse_file('sm/checkers/malloc_checker.sm') -main([checker], selftest=selftest) diff --git a/gcc/testsuite/gcc.dg/analyzer/params.c b/gcc/testsuite/gcc.dg/analyzer/params.c new file mode 100644 index 0000000..2ef0bac --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/params.c @@ -0,0 +1,34 @@ +static int called_function(int j) +{ + int k; + + __analyzer_eval (j > 4); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): we're not passing on the knowledge from the callsite in test. */ + + k = j - 1; + + __analyzer_eval (k > 3); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): we're not then updating based on the assignment. */ + + return k; +} + +void test(int i) +{ + __analyzer_eval (i > 4); /* { dg-warning "UNKNOWN" } */ + + if (i > 4) { + + __analyzer_eval (i > 4); /* { dg-warning "TRUE" } */ + + i = called_function(i); + + __analyzer_eval (i > 3); /* { dg-warning "TRUE" "" { xfail *-*-* } } */ + /* { dg-warning "UNKNOWN" "" { target *-*-* } .-1 } */ + /* TODO(xfail): we're not updating from the returned value. */ + } + + __analyzer_eval (i > 3); /* { dg-warning "UNKNOWN" } */ +} -- 1.8.5.3