From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2209) id 4FBA1385B833; Tue, 18 Jan 2022 20:57:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FBA1385B833 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: David Malcolm To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6700] analyzer: fix ICE on unary ops folding to casts of constants [PR104089] X-Act-Checkin: gcc X-Git-Author: David Malcolm X-Git-Refname: refs/heads/master X-Git-Oldrev: 79e746bb05e432dcd1c18161469272d67c33d79d X-Git-Newrev: 2aefe248aa4160205c44808166393a42031d2dea Message-Id: <20220118205714.4FBA1385B833@sourceware.org> Date: Tue, 18 Jan 2022 20:57:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 20:57:14 -0000 https://gcc.gnu.org/g:2aefe248aa4160205c44808166393a42031d2dea commit r12-6700-g2aefe248aa4160205c44808166393a42031d2dea Author: David Malcolm Date: Tue Jan 18 11:41:19 2022 -0500 analyzer: fix ICE on unary ops folding to casts of constants [PR104089] gcc/analyzer/ChangeLog: PR analyzer/104089 * region-model-manager.cc (region_model_manager::get_or_create_constant_svalue): Assert that we have a CONSTANT_CLASS_P. (region_model_manager::maybe_fold_unaryop): Only fold a constant when fold_unary's result is a constant or a cast of a constant. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/pr104089.c: New test. PR analyzer/104089 Signed-off-by: David Malcolm Diff: --- gcc/analyzer/region-model-manager.cc | 19 ++++++++++++++++++- gcc/testsuite/gcc.dg/analyzer/pr104089.c | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index 9d4f5952ef3..bb93526807f 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -209,6 +209,7 @@ const svalue * region_model_manager::get_or_create_constant_svalue (tree cst_expr) { gcc_assert (cst_expr); + gcc_assert (CONSTANT_CLASS_P (cst_expr)); constant_svalue **slot = m_constants_map.get (cst_expr); if (slot) @@ -426,7 +427,23 @@ region_model_manager::maybe_fold_unaryop (tree type, enum tree_code op, /* Constants. */ if (tree cst = arg->maybe_get_constant ()) if (tree result = fold_unary (op, type, cst)) - return get_or_create_constant_svalue (result); + { + if (CONSTANT_CLASS_P (result)) + return get_or_create_constant_svalue (result); + + /* fold_unary can return casts of constants; try to handle them. */ + if (op != NOP_EXPR + && type + && TREE_CODE (result) == NOP_EXPR + && CONSTANT_CLASS_P (TREE_OPERAND (result, 0))) + { + const svalue *inner_cst + = get_or_create_constant_svalue (TREE_OPERAND (result, 0)); + return get_or_create_cast (type, + get_or_create_cast (TREE_TYPE (result), + inner_cst)); + } + } return NULL; } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104089.c b/gcc/testsuite/gcc.dg/analyzer/pr104089.c new file mode 100644 index 00000000000..c51770411f1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr104089.c @@ -0,0 +1,9 @@ +/* { dg-additional-options "-frounding-math" } */ + +volatile _Float16 true_min = 5.96046447753906250000000000000000000e-8F16; + +int +main (void) +{ + return __builtin_fpclassify (0, 1, 4, 3, 2, true_min); +}