]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tighten type verification for CONJ_EXPR
authorAlexander Monakov <amonakov@ispras.ru>
Mon, 12 May 2025 20:23:31 +0000 (23:23 +0300)
committerAlexander Monakov <amonakov@ispras.ru>
Thu, 15 May 2025 11:07:52 +0000 (14:07 +0300)
As a followup to PAREN_EXPR verification, let's ensure that CONJ_EXPR is
only used with COMPLEX_TYPE.  While at it, move the whole block towards
the end of the switch, because unlike the other entries it needs to
break out of the switch, not immediately return from the function,
as after the switch we check that types of LHS and RHS match.

Refactor a bit to avoid repeated blocks with debug_generic_expr.

gcc/ChangeLog:

* tree-cfg.cc (verify_gimple_assign_unary): Accept only
COMPLEX_TYPE for CONJ_EXPR.

gcc/tree-cfg.cc

index 928459a38b2a7c5e569c5ce768bf3b6470eda7b1..b342b147716a83b3a60229fbae6c0dafb0d41a4e 100644 (file)
@@ -3867,32 +3867,6 @@ verify_gimple_assign_unary (gassign *stmt)
 
       return false;
 
-    case NEGATE_EXPR:
-    case ABS_EXPR:
-    case BIT_NOT_EXPR:
-    case CONJ_EXPR:
-      /* Disallow pointer and offset types for many of the unary gimple. */
-      if (POINTER_TYPE_P (lhs_type)
-         || TREE_CODE (lhs_type) == OFFSET_TYPE)
-       {
-         error ("invalid types for %qs", code_name);
-         debug_generic_expr (lhs_type);
-         debug_generic_expr (rhs1_type);
-         return true;
-       }
-      break;
-
-    case PAREN_EXPR:
-      /* Disallow non arthmetic types on PAREN_EXPR. */
-      if (AGGREGATE_TYPE_P (lhs_type))
-       {
-         error ("invalid types for %qs", code_name);
-         debug_generic_expr (lhs_type);
-         debug_generic_expr (rhs1_type);
-         return true;
-       }
-      break;
-
     case ABSU_EXPR:
       if (!ANY_INTEGRAL_TYPE_P (lhs_type)
          || !TYPE_UNSIGNED (lhs_type)
@@ -3918,6 +3892,27 @@ verify_gimple_assign_unary (gassign *stmt)
        }
       return false;
 
+    case CONJ_EXPR:
+      if (TREE_CODE (lhs_type) != COMPLEX_TYPE)
+       {
+diagnose_unary_lhs:
+         error ("invalid type for %qs", code_name);
+         debug_generic_expr (lhs_type);
+         return true;
+       }
+      break;
+
+    case NEGATE_EXPR:
+    case ABS_EXPR:
+    case BIT_NOT_EXPR:
+      if (POINTER_TYPE_P (lhs_type) || TREE_CODE (lhs_type) == OFFSET_TYPE)
+       goto diagnose_unary_lhs;
+      /* FALLTHRU */
+    case PAREN_EXPR:
+      if (AGGREGATE_TYPE_P (lhs_type))
+       goto diagnose_unary_lhs;
+      break;
+
     default:
       gcc_unreachable ();
     }