From: Martin Liska Date: Tue, 1 Dec 2020 16:25:36 +0000 (+0100) Subject: if-to-switch: consider only integral types X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e4c02ce4ab6fce1148f4025360096f18764deadf;p=gcc.git if-to-switch: consider only integral types gcc/ChangeLog: PR tree-optimization/98084 * gimple-if-to-switch.cc (find_conditions): Consider only integral types. gcc/testsuite/ChangeLog: PR tree-optimization/98084 * gcc.dg/tree-ssa/pr98084.c: New test. --- diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc index d132064fb9b..0aa1b0e4e7e 100644 --- a/gcc/gimple-if-to-switch.cc +++ b/gcc/gimple-if-to-switch.cc @@ -429,6 +429,7 @@ find_conditions (basic_block bb, for (unsigned i = 0; i < info.m_ranges.length (); ++i) if (info.m_ranges[i].exp == NULL_TREE + || !INTEGRAL_TYPE_P (TREE_TYPE (info.m_ranges[i].exp)) || info.m_ranges[i].low == NULL_TREE || info.m_ranges[i].high == NULL_TREE) return; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr98084.c b/gcc/testsuite/gcc.dg/tree-ssa/pr98084.c new file mode 100644 index 00000000000..637962481d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr98084.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/98084 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +enum { + JSON_VARIANT_STRING, + JSON_VARIANT_UNSIGNED, + JSON_VARIANT_REAL, + JSON_VARIANT_ARRAY, + _JSON_VARIANT_TYPE_INVALID, + _JSON_VARIANT_MAGIC_ZERO_UNSIGNED, + _JSON_VARIANT_MAGIC_ZERO_REAL, + _JSON_VARIANT_MAGIC_EMPTY_STRING, + _JSON_VARIANT_MAGIC_EMPTY_ARRAY +} json_variant_type(int *v) { + if (!v) + return _JSON_VARIANT_TYPE_INVALID; + if (v == (int *)_JSON_VARIANT_MAGIC_ZERO_UNSIGNED) + return JSON_VARIANT_UNSIGNED; + if (v == (int *)_JSON_VARIANT_MAGIC_ZERO_REAL) + return JSON_VARIANT_REAL; + if (v == (int *)_JSON_VARIANT_MAGIC_EMPTY_STRING) + return JSON_VARIANT_STRING; + if (v == (int *)_JSON_VARIANT_MAGIC_EMPTY_ARRAY) + return JSON_VARIANT_ARRAY; +}