From bc94613edd48e37e2e6ca3a6768cc608c8c4796e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 7 Jan 2026 10:50:39 +0100 Subject: [PATCH] Assorted tweaks to eval_alignment_of. --- gcc/cp/reflect.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 79369c19527..daf20caf837 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -3265,32 +3265,32 @@ eval_alignment_of (location_t loc, const constexpr_ctx *ctx, tree r, else if (TREE_CODE (r) == FIELD_DECL || eval_is_variable (r, kind) == boolean_true_node || (eval_is_object (kind) == boolean_true_node - && DECL_P (r) - && TREE_CODE (r) != FUNCTION_DECL)) - return build_int_cst (ret_type, MAX (DECL_ALIGN (r) / BITS_PER_UNIT, 1)); + && ((DECL_P (r) && TREE_CODE (r) != FUNCTION_DECL) + || TREE_CODE (r) == COMPONENT_REF))) + { + if (TREE_CODE (r) == COMPONENT_REF) + r = TREE_OPERAND (r, 1); + return build_int_cst (ret_type, MAX (DECL_ALIGN_UNIT (r), 1)); + } else if (TYPE_P (r)) type = r; else if (eval_is_object (kind) == boolean_true_node) - { - if (TREE_CODE (r) == COMPONENT_REF) - return build_int_cst (ret_type, MAX (DECL_ALIGN (TREE_OPERAND (r, 1)) - / BITS_PER_UNIT, 1)); - else - type = TREE_TYPE (r); - } + type = TREE_TYPE (r); else gcc_unreachable (); if (TYPE_REF_P (type)) type = ptr_type_node; - if (!complete_type_or_maybe_complain (type, NULL_TREE, tf_none)) - return throw_exception (loc, ctx, "reflection with incomplete type", - fun, non_constant_p, jump_target); if (FUNC_OR_METHOD_TYPE_P (type)) return throw_exception (loc, ctx, "alignment_of on function type", fun, non_constant_p, jump_target); - tree ret = c_sizeof_or_alignof_type (loc, type, false, true, 0); - if (ret == error_mark_node) - return throw_exception (loc, ctx, "reflection with incomplete type", + tree ret; + if (!complete_type_or_maybe_complain (type, NULL_TREE, tf_none) + /* No special casing of references needed, c_sizeof_or_alignof_type + returns the same alignment for POINTER_TYPE and REFERENCE_TYPE. */ + || ((ret = c_sizeof_or_alignof_type (loc, type, false, true, 0)) + == error_mark_node)) + return throw_exception (loc, ctx, + "reflection with incomplete type in alignment_of", fun, non_constant_p, jump_target); return fold_convert (ret_type, ret); }