From 11f2b46bb882c427f45f194196d89b22ec470240 Mon Sep 17 00:00:00 2001
From: Waffl3x <waff...@baylibre.com>
Date: Tue, 8 Jul 2025 19:52:05 -0600
Subject: [PATCH 3/3] middle-end/121005 Add checks for TREE_LANG_FLAG_*

TREE_LANG_FLAG_* is only valid for tree codes that do not use other union
fields in tree_base, previously it only checked for TREE_VEC and SSA_NAME.
This adds checks for INTEGER_CST, VECTOR_CST, POLYNOMIA_CHREC, MEM_REF,
TARGET_MEM_REF and everything between OMP_ATOMIC to OMP_ATOMIC_CAPTURE_NEW
inclusive.

This check is also added to TREE_UNAVAILABLE because it didn't have any
kind of checks.  The accessors for the other flags in tree_base::u::bits
are already constrained appropriately and not modified.

	PR middle-end/121005

gcc/ChangeLog:

	PR middle-end/121005
	* tree.h (TREE_CHECK_BITS_AVAILABLE): Define.
	(TREE_UNAVAILABLE): Use TREE_CHECK_BITS_AVAILABLE.
	(TREE_LANG_FLAG_0): Use TREE_CHECK_BITS_AVAILABLE.
	(TREE_LANG_FLAG_1): Likewise.
	(TREE_LANG_FLAG_2): Likewise.
	(TREE_LANG_FLAG_3): Likewise.
	(TREE_LANG_FLAG_4): Likewise.
	(TREE_LANG_FLAG_5): Likewise.
	(TREE_LANG_FLAG_6): Likewise.

Signed-off-by: Waffl3x <waff...@baylibre.com>
---
 gcc/tree.h | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/gcc/tree.h b/gcc/tree.h
index 6c0ce8e0908..90ac3d47861 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -571,6 +571,15 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
   TREE_CHECK6 (T, INTEGER_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, REAL_TYPE,	\
 	       FIXED_POINT_TYPE, BITINT_TYPE)
 
+/* Check if the bits field of tree_base is available for NODE.
+   Note, CALL_EXPR also sometimes makes use of the ifn union member, it would
+   be invalid to use TREE_LANG_FLAG_* when this is the case but it can't be
+   checked for here.  */
+#define TREE_CHECK_BITS_AVAILABLE(NODE) \
+  ((TREE_NOT_CHECK8 (NODE, INTEGER_CST, TREE_VEC, VECTOR_CST, SSA_NAME, \
+		     POLYNOMIAL_CHREC, MEM_REF, TARGET_MEM_REF), void), \
+   TREE_NOT_RANGE_CHECK (NODE, OMP_ATOMIC, OMP_ATOMIC_CAPTURE_NEW))
+
 /* Here is how primitive or already-canonicalized types' hash codes
    are made.  */
 #define TYPE_HASH(TYPE) (TYPE_UID (TYPE))
@@ -1101,7 +1110,7 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
 /* Nonzero in a _DECL if the use of the name is defined as an
    unavailable feature by __attribute__((unavailable)).  */
 #define TREE_UNAVAILABLE(NODE) \
-  ((NODE)->base.u.bits.unavailable_flag)
+  ((TREE_CHECK_BITS_AVAILABLE (NODE))->base.u.bits.unavailable_flag)
 
 /* Nonzero indicates an IDENTIFIER_NODE that names an anonymous
    aggregate, (as created by anon_aggr_name_format).  */
@@ -1154,19 +1163,19 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
 
 /* These flags are available for each language front end to use internally.  */
 #define TREE_LANG_FLAG_0(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_0)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_0)
 #define TREE_LANG_FLAG_1(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_1)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_1)
 #define TREE_LANG_FLAG_2(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_2)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_2)
 #define TREE_LANG_FLAG_3(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_3)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_3)
 #define TREE_LANG_FLAG_4(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_4)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_4)
 #define TREE_LANG_FLAG_5(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_5)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_5)
 #define TREE_LANG_FLAG_6(NODE) \
-  (TREE_NOT_CHECK2 (NODE, TREE_VEC, SSA_NAME)->base.u.bits.lang_flag_6)
+  (TREE_CHECK_BITS_AVAILABLE (NODE)->base.u.bits.lang_flag_6)
 
 /* Define additional fields and accessors for nodes representing constants.  */
 
-- 
2.49.0

Reply via email to