diff options
author | David Malcolm <dmalcolm@redhat.com> | 2022-11-29 19:56:27 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2022-11-29 19:56:27 -0500 |
commit | 3a32fb2eaa761aac13ffe5424748d5839038ef66 (patch) | |
tree | e5df88b6099b404c5fdd1c1d99f065ab976cafc7 /gcc/analyzer | |
parent | 000e9863120cbc75a0f8d497264519974c97669f (diff) | |
download | gcc-3a32fb2eaa761aac13ffe5424748d5839038ef66.zip gcc-3a32fb2eaa761aac13ffe5424748d5839038ef66.tar.gz gcc-3a32fb2eaa761aac13ffe5424748d5839038ef66.tar.bz2 |
analyzer: fix folding of '(PTR + 0) => PTR' [PR105784]
gcc/analyzer/ChangeLog:
PR analyzer/105784
* region-model-manager.cc
(region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
type matches that of arg0 in favor of a cast.
gcc/testsuite/ChangeLog:
PR analyzer/105784
* gcc.dg/analyzer/torture/fold-ptr-arith-pr105784.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer')
-rw-r--r-- | gcc/analyzer/region-model-manager.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index d9a7ae9..ae63c66 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -613,13 +613,13 @@ region_model_manager::maybe_fold_binop (tree type, enum tree_code op, case POINTER_PLUS_EXPR: case PLUS_EXPR: /* (VAL + 0) -> VAL. */ - if (cst1 && zerop (cst1) && type == arg0->get_type ()) - return arg0; + if (cst1 && zerop (cst1)) + return get_or_create_cast (type, arg0); break; case MINUS_EXPR: /* (VAL - 0) -> VAL. */ - if (cst1 && zerop (cst1) && type == arg0->get_type ()) - return arg0; + if (cst1 && zerop (cst1)) + return get_or_create_cast (type, arg0); break; case MULT_EXPR: /* (VAL * 0). */ |