diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-10-28 20:10:39 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2020-10-28 20:10:39 -0400 |
commit | 1a9af271275f4893e28c789c8f1964025694eda1 (patch) | |
tree | 6f4b335ee28124f590e65d2ea4888bf93bc5919c /gcc/analyzer/region-model-reachability.cc | |
parent | e9751143e237b507a81234a573a200ea45e7111a (diff) | |
download | gcc-1a9af271275f4893e28c789c8f1964025694eda1.zip gcc-1a9af271275f4893e28c789c8f1964025694eda1.tar.gz gcc-1a9af271275f4893e28c789c8f1964025694eda1.tar.bz2 |
analyzer: fix false leak diagnostic on offsets from malloc [PR97608]
gcc/analyzer/ChangeLog:
PR analyzer/97608
* region-model-reachability.cc (reachable_regions::handle_sval):
Operands of reachable reversible operations are reachable.
gcc/testsuite/ChangeLog:
PR analyzer/97608
* gcc.dg/analyzer/malloc-1.c (test_42d): New.
* gcc.dg/analyzer/pr97608.c: New test.
Diffstat (limited to 'gcc/analyzer/region-model-reachability.cc')
-rw-r--r-- | gcc/analyzer/region-model-reachability.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/analyzer/region-model-reachability.cc b/gcc/analyzer/region-model-reachability.cc index 52525e1..f6f25cc 100644 --- a/gcc/analyzer/region-model-reachability.cc +++ b/gcc/analyzer/region-model-reachability.cc @@ -181,6 +181,40 @@ reachable_regions::handle_sval (const svalue *sval) } if (const svalue *cast = sval->maybe_undo_cast ()) handle_sval (cast); + + /* If SVAL is the result of a reversible operation, then the operands + are reachable. */ + switch (sval->get_kind ()) + { + default: + break; + case SK_UNARYOP: + { + const unaryop_svalue *unaryop_sval = (const unaryop_svalue *)sval; + switch (unaryop_sval->get_op ()) + { + default: + break; + case NEGATE_EXPR: + handle_sval (unaryop_sval->get_arg ()); + break; + } + } + break; + case SK_BINOP: + { + const binop_svalue *binop_sval = (const binop_svalue *)sval; + switch (binop_sval->get_op ()) + { + default: + break; + case POINTER_PLUS_EXPR: + handle_sval (binop_sval->get_arg0 ()); + handle_sval (binop_sval->get_arg1 ()); + break; + } + } + } } /* Add SVAL. If it is a pointer, add the pointed-to region. |