Fix small regression in Ada
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 14 Feb 2023 12:27:18 +0000 (13:27 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 14 Feb 2023 12:27:18 +0000 (13:27 +0100)
gcc/
* gimplify.cc (gimplify_save_expr): Add missing guard.
gcc/ada/
* gcc-interface/trans.cc (gnat_gimplify_expr): Add missing guard.
gcc/testsuite/
* gnat.dg/shift2.adb: New test.

gcc/ada/gcc-interface/trans.cc
gcc/gimplify.cc
gcc/testsuite/gnat.dg/shift2.adb [new file with mode: 0644]

index 28e3867..5fc1a26 100644 (file)
@@ -9049,7 +9049,9 @@ gnat_gimplify_expr (tree *expr_p, gimple_seq *pre_p,
 
       /* Propagate TREE_NO_WARNING from expression to temporary by using the
         SAVE_EXPR itself as an intermediate step.  See gimplify_save_expr.  */
-      if (SAVE_EXPR_RESOLVED_P (expr))
+      if (type == void_type_node)
+       ;
+      else if (SAVE_EXPR_RESOLVED_P (expr))
        TREE_NO_WARNING (op) = TREE_NO_WARNING (expr);
       else
        TREE_NO_WARNING (expr) = TREE_NO_WARNING (op);
index 1b362dd..9684515 100644 (file)
@@ -6441,7 +6441,7 @@ gimplify_save_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
   gcc_assert (TREE_CODE (*expr_p) == SAVE_EXPR);
   val = TREE_OPERAND (*expr_p, 0);
 
-  if (TREE_TYPE (val) == error_mark_node)
+  if (val && TREE_TYPE (val) == error_mark_node)
     return GS_ERROR;
 
   /* If the SAVE_EXPR has not been resolved, then evaluate it once.  */
diff --git a/gcc/testsuite/gnat.dg/shift2.adb b/gcc/testsuite/gnat.dg/shift2.adb
new file mode 100644 (file)
index 0000000..b45e440
--- /dev/null
@@ -0,0 +1,8 @@
+-- { dg-do compile }
+
+with Interfaces; use Interfaces;
+
+function Shift2 (V : Unsigned_32) return Unsigned_32 is
+begin
+  return Shift_Left (V, (case V is when 0 => 1, when others => 0));
+end;