From fc02b568e2cd3f6a28d4b7c1063bbf8842c89aad Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 19 Aug 2020 09:27:16 -0400 Subject: [PATCH] analyzer: fix ICE on folding vector 0 [PR96705] gcc/analyzer/ChangeLog: * region-model-manager.cc PR analyzer/96705 (region_model_manager::maybe_fold_binop): Check that we have an integral type before calling build_int_cst. gcc/testsuite/ChangeLog: PR analyzer/96705 * gcc.dg/analyzer/pr96705.c: New test. --- gcc/analyzer/region-model-manager.cc | 4 ++-- gcc/testsuite/gcc.dg/analyzer/pr96705.c | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr96705.c diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index 07925743ab0..422c4a95e7b 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -445,7 +445,7 @@ region_model_manager::maybe_fold_binop (tree type, enum tree_code op, break; case MULT_EXPR: /* (VAL * 0). */ - if (cst1 && zerop (cst1)) + if (cst1 && zerop (cst1) && INTEGRAL_TYPE_P (type)) return get_or_create_constant_svalue (build_int_cst (type, 0)); /* (VAL * 1) -> VAL. */ if (cst1 && integer_onep (cst1)) @@ -455,7 +455,7 @@ region_model_manager::maybe_fold_binop (tree type, enum tree_code op, case TRUTH_AND_EXPR: if (cst1) { - if (zerop (cst1)) + if (zerop (cst1) && INTEGRAL_TYPE_P (type)) /* "(ARG0 && 0)" -> "0". */ return get_or_create_constant_svalue (build_int_cst (type, 0)); else diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96705.c b/gcc/testsuite/gcc.dg/analyzer/pr96705.c new file mode 100644 index 00000000000..d7856d20be5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr96705.c @@ -0,0 +1,9 @@ +int __attribute__ ((vector_size (8))) v; +int i; + +void +test (void) +{ + v &= 0; + v *= i; +} -- 2.30.2