From 366bd1ac01a5249a463e64234674ad2d174faa9a Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 19 Aug 2020 05:00:52 -0400 Subject: [PATCH] analyzer: fix ICE converting float to int [PR96699] gcc/analyzer/ChangeLog: PR analyzer/96699 * region-model-manager.cc (region_model_manager::get_or_create_cast): Use FIX_TRUNC_EXPR for casting from REAL_TYPE to INTEGER_TYPE. gcc/testsuite/ChangeLog: PR analyzer/96699 * gcc.dg/analyzer/pr96699.c: New test. --- gcc/analyzer/region-model-manager.cc | 5 +++++ gcc/testsuite/gcc.dg/analyzer/pr96699.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr96699.c diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index 4faeaa52a63..07925743ab0 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -396,6 +396,11 @@ region_model_manager::get_or_create_unaryop (tree type, enum tree_code op, const svalue * region_model_manager::get_or_create_cast (tree type, const svalue *arg) { + gcc_assert (type); + if (arg->get_type ()) + if (TREE_CODE (type) == INTEGER_TYPE + && TREE_CODE (arg->get_type ()) == REAL_TYPE) + return get_or_create_unaryop (type, FIX_TRUNC_EXPR, arg); return get_or_create_unaryop (type, NOP_EXPR, arg); } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96699.c b/gcc/testsuite/gcc.dg/analyzer/pr96699.c new file mode 100644 index 00000000000..c68e45a9401 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr96699.c @@ -0,0 +1,13 @@ +struct qi { + union { + int hj; + float sl; + }; +}; + +void +i2 (struct qi *la) +{ + if (la->hj == 0) + la->sl = 0.0f; +} -- 2.30.2