if-to-switch: consider only integral types
authorMartin Liska <mliska@suse.cz>
Tue, 1 Dec 2020 16:25:36 +0000 (17:25 +0100)
committerMartin Liska <mliska@suse.cz>
Wed, 2 Dec 2020 07:17:25 +0000 (08:17 +0100)
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.

gcc/gimple-if-to-switch.cc
gcc/testsuite/gcc.dg/tree-ssa/pr98084.c [new file with mode: 0644]

index d132064fb9b823623dd78d4350d019010f37655a..0aa1b0e4e7e8cccbe7ab4c946559091c3120caae 100644 (file)
@@ -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 (file)
index 0000000..6379624
--- /dev/null
@@ -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;
+}