public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-coroutines] tree-cfg: Improve gimple switch verification
@ 2020-08-31 19:50 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2020-08-31 19:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:39f5b724844a28bea3dbb2a5c0b88bdce89ec4cb

commit 39f5b724844a28bea3dbb2a5c0b88bdce89ec4cb
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Aug 31 10:51:02 2020 +0200

    tree-cfg: Improve gimple switch verification
    
    When looking at the verification, I have noticed a bug in it.
    
    The verification that CASE_HIGH (if present) has the same type as CASE_LOW
    is only performed for the case label 2 and higher, case label 1 (the first
    one after the default label) isn't checked.
    
    The following patch fixes that, it will uselessly also compare
    TREE_TYPE (CASE_LOW (elt)) != elt_type for the case label 1, but I think
    that isn't that expensive and helps readability of the code.
    
    2020-08-31  Jakub Jelinek  <jakub@redhat.com>
    
            * tree-cfg.c (verify_gimple_switch): If the first non-default case
            label has CASE_HIGH, verify it has the same type as CASE_LOW.

Diff:
---
 gcc/tree-cfg.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 2bae2eeddba..2964209ccff 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4809,17 +4809,7 @@ verify_gimple_switch (gswitch *stmt)
 	  return true;
 	}
 
-      if (elt_type)
-	{
-	  if (TREE_TYPE (CASE_LOW (elt)) != elt_type
-	      || (CASE_HIGH (elt) && TREE_TYPE (CASE_HIGH (elt)) != elt_type))
-	    {
-	      error ("type mismatch for case label in switch statement");
-	      debug_generic_expr (elt);
-	      return true;
-	    }
-	}
-      else
+      if (! elt_type)
 	{
 	  elt_type = TREE_TYPE (CASE_LOW (elt));
 	  if (TYPE_PRECISION (index_type) < TYPE_PRECISION (elt_type))
@@ -4828,6 +4818,13 @@ verify_gimple_switch (gswitch *stmt)
 	      return true;
 	    }
 	}
+      if (TREE_TYPE (CASE_LOW (elt)) != elt_type
+          || (CASE_HIGH (elt) && TREE_TYPE (CASE_HIGH (elt)) != elt_type))
+	{
+	  error ("type mismatch for case label in switch statement");
+	  debug_generic_expr (elt);
+	  return true;
+	}
 
       if (prev_upper_bound)
 	{


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-31 19:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 19:50 [gcc/devel/c++-coroutines] tree-cfg: Improve gimple switch verification Iain D Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).