From patchwork Wed Dec 4 04:49:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 102349 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 686883858C53 for ; Wed, 4 Dec 2024 05:14:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 686883858C53 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VkSC7uEL X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id 9794E3858D38 for ; Wed, 4 Dec 2024 05:08:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9794E3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9794E3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::82d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733288891; cv=none; b=k3Ij0O2LqkICGcUo6IXBuf3LrrkXhDWOvkkDH023COeCzeYKenf2Z67T8aWqxNmj/SWdzzYu4HaMnNAwd3IOOWLRuT1TNRoHm8bMkwv66Dtl6xVRASXhSVa1TSgnUvBknvqGFoX8uiIlqOplHJPg3pENskbxSeiXLNxCJOdqyyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733288891; c=relaxed/simple; bh=UtgTvLgmGbwhjXgzMHc+TX5da1AxhkJa4IAHQaLexFI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BdsfGQHMeSvtuQ3x4NJBGMyHSq8Xr8K3jUGxd8nslutw3MFD/SkrpejSvP9e/3nhhZDHMyqtZvqG1+VsZXb7N3JG28wzWxjuEVnOo9ZYAUDaXOAuM0sINcus12+lAHGqAkJMtnckJZh6CyLgKTz1Wi2XvW8tJjp0Y+I4E+1lJRU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9794E3858D38 Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-46101120e70so53483411cf.1 for ; Tue, 03 Dec 2024 21:08:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733288890; x=1733893690; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PSzMbwKM+AfcwVND8wAq3BotYmCjKGu2z5mJxfnC7eU=; b=VkSC7uEL20hnEEEkuU3yWYEW5yAZ87OWYI8VvYRDhd4//ehcC/a7M3NiRO1xSiVR79 Xd4LNeCPDNvUE6Lad8+gwhyfpKsiBPBbmmkh4ol4ZpgpMwLuSrhVSrxJ9JRudMldBoXM h+FS7wecwIqF99vRLNYDBxHzagJjU5u1LXqDMfB4u9MPVts0MhNKNlS/OeIuRDfLbQeb tOYMGGsr30I7fp4KCRB0krv7IMiM7MNu3qKydjp43NU/rimBBWZ/y7o1EJJl2o9HRtaP qpVKHG34RYba+QlCH1h1C3dCzusYY9V2+A75X/q8w84DPfYpwvtCjdo2t92sgOAPPbIl lmhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288890; x=1733893690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PSzMbwKM+AfcwVND8wAq3BotYmCjKGu2z5mJxfnC7eU=; b=Po5xJ6ujUJJOfhmw3qlA/geWos4jxOG098KJ59TIP+xn9u+526u8LFcSYqj+i7Wq/t EYcBngq2Va3ivZie6wf+XfIfRcR5g4WIbdE5GYDFQDwNb+w8ej1AMljhLjlxG7DWPEiN BsZXyotHhatQWl4JqYN8b/9oMpoAA/Fk3xpkmJPvcAELmAb889Oi3SUxHFtNo3alZXFp kuOTiF+YuQpw8EDgP+TyAHmXEIEigtyUUfL6fx/DSCe2aD2wnOX7hxsdtlo/a36pBHQq Kst21tz8m/oEcvAP5xG2QYeP153efKDv5hY2MUZhWkVdUPPPjeF4O/0xUuDXuznaX51s iG9w== X-Gm-Message-State: AOJu0YzJaxJoPpaDOzsSMSUrJZ6n/b4O26+njkSbSKAJ32xuHR647XWM C7J70aIU6aTfAABcAL4MGiMhfO0D6hOQ7KG+NG7g59U6aZaa9D4a X-Gm-Gg: ASbGncvecbQLArTU6Us+wBP6G/lDwdCeJPPATWc+5c2Vz3n2zn7tMZ5J7C2gU37CWtA 5m6SRoTgdnOU7yks/XfW5H1jYU5Ix1hD5IXh1a7e7Qgy0Ie6P3mLCsgLU2+56SNvof966w5Zow7 jB3M4nUSzF5fxOIQEjlBxoU+qcN1rWQpHbYHxQXgsWib7r8k8u4Q9yoXoRZtLlvUBIPX4BvTNxJ wD88CX1V8YjyRrZ4tzjQeCYWlZ11PPYShQMqvm9RsTCssm84Lp/UyR1XioH9NtPg3edvgb/OIGf 5Dpg8rYM9aaZ+zwruj2VRNt/dkNYuhp3CcxrMA== X-Google-Smtp-Source: AGHT+IFc2RSrTCdmeAIYLT5r0uR80VaJFYb3fMa8Y5Jir4tsSGgiGI7lzv3apZ/YIuX6lsA2nLg4aw== X-Received: by 2002:a05:622a:548:b0:466:ab8f:8978 with SMTP id d75a77b69052e-46717c97ed7mr56788431cf.37.1733288890126; Tue, 03 Dec 2024 21:08:10 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.160.52]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-466c421f825sm69777531cf.64.2024.12.03.21.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:09 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id A9518C058F; Wed, 04 Dec 2024 12:49:51 +0800 (CST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, jeffreyalaw@gmail.com, jakub@redhat.com, richard.sandiford@arm.com, matz@suse.de Subject: [PATCH v5 2/7] Drop targetm.promote_prototypes from C, C++ and Ada frontends Date: Wed, 4 Dec 2024 12:49:46 +0800 Message-ID: <20241204044951.509713-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204044951.509713-1-hjl.tools@gmail.com> References: <20241204044951.509713-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3019.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Remove the targetm.calls.promote_prototypes call from C, C++ and Ada frontends. gcc/ PR c/48274 PR middle-end/14907 PR middle-end/112877 * gimple.cc (gimple_builtin_call_types_compatible_p): Remove the targetm.calls.promote_prototypes call. * tree.cc (tree_builtin_call_types_compatible_p): Likewise. gcc/ada/ PR middle-end/14907 PR middle-end/112877 * gcc-interface/utils.cc (create_param_decl): Remove the targetm.calls.promote_prototypes call. gcc/c/ PR c/48274 PR middle-end/14907 PR middle-end/112877 * c-decl.cc (start_decl): Remove the targetm.calls.promote_prototypes call. (store_parm_decls_oldstyle): Likewise. (finish_function): Likewise. * c-typeck.cc (convert_argument): Likewise. (c_safe_arg_type_equiv_p): Likewise. gcc/cp/ PR middle-end/14907 PR middle-end/112877 * call.cc (type_passed_as): Remove the targetm.calls.promote_prototypes call. (convert_for_arg_passing): Likewise. * typeck.cc (cxx_safe_arg_type_equiv_p): Likewise. Signed-off-by: H.J. Lu --- gcc/ada/gcc-interface/utils.cc | 24 -------------------- gcc/c/c-decl.cc | 40 ---------------------------------- gcc/c/c-typeck.cc | 19 ++++------------ gcc/cp/call.cc | 10 --------- gcc/cp/typeck.cc | 13 ++++------- gcc/gimple.cc | 10 +-------- gcc/tree.cc | 14 ------------ 7 files changed, 9 insertions(+), 121 deletions(-) diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index 8e8cf55ae12..cbbac5160d2 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -3282,30 +3282,6 @@ tree create_param_decl (tree name, tree type) { tree param_decl = build_decl (input_location, PARM_DECL, name, type); - - /* Honor TARGET_PROMOTE_PROTOTYPES like the C compiler, as not doing so - can lead to various ABI violations. */ - if (targetm.calls.promote_prototypes (NULL_TREE) - && INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) - { - /* We have to be careful about biased types here. Make a subtype - of integer_type_node with the proper biasing. */ - if (TREE_CODE (type) == INTEGER_TYPE - && TYPE_BIASED_REPRESENTATION_P (type)) - { - tree subtype - = make_unsigned_type (TYPE_PRECISION (integer_type_node)); - TREE_TYPE (subtype) = integer_type_node; - TYPE_BIASED_REPRESENTATION_P (subtype) = 1; - SET_TYPE_RM_MIN_VALUE (subtype, TYPE_MIN_VALUE (type)); - SET_TYPE_RM_MAX_VALUE (subtype, TYPE_MAX_VALUE (type)); - type = subtype; - } - else - type = integer_type_node; - } - DECL_ARG_TYPE (param_decl) = type; return param_decl; } diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 1c11c216bd6..9642257c961 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5719,26 +5719,6 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl); } - if (TREE_CODE (decl) == FUNCTION_DECL - && targetm.calls.promote_prototypes (TREE_TYPE (decl))) - { - struct c_declarator *ce = declarator; - - if (ce->kind == cdk_pointer) - ce = declarator->declarator; - if (ce->kind == cdk_function) - { - tree args = ce->u.arg_info->parms; - for (; args; args = DECL_CHAIN (args)) - { - tree type = TREE_TYPE (args); - if (type && INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (args) = c_type_promotes_to (type); - } - } - } - if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl) && DECL_UNINLINABLE (decl) @@ -11172,13 +11152,6 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) useful for argument types like uid_t. */ DECL_ARG_TYPE (parm) = TREE_TYPE (parm); - if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl)) - && INTEGRAL_TYPE_P (TREE_TYPE (parm)) - && (TYPE_PRECISION (TREE_TYPE (parm)) - < TYPE_PRECISION (integer_type_node))) - DECL_ARG_TYPE (parm) - = c_type_promotes_to (TREE_TYPE (parm)); - /* ??? Is it possible to get here with a built-in prototype or will it always have been diagnosed as conflicting with an @@ -11406,19 +11379,6 @@ finish_function (location_t end_loc) if (c_dialect_objc ()) objc_finish_function (); - if (TREE_CODE (fndecl) == FUNCTION_DECL - && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) - { - tree args = DECL_ARGUMENTS (fndecl); - for (; args; args = DECL_CHAIN (args)) - { - tree type = TREE_TYPE (args); - if (INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (args) = c_type_promotes_to (type); - } - } - if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node) BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index e60f89a21d9..d5f947132ad 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -4124,12 +4124,6 @@ convert_argument (location_t ploc, tree function, tree fundecl, val, origtype, ic_argpass, npc, fundecl, function, parmnum + 1, warnopt); - - if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0) - && INTEGRAL_TYPE_P (type) - && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) - parmval = default_conversion (parmval); - return parmval; } @@ -6665,17 +6659,12 @@ c_safe_arg_type_equiv_p (tree t1, tree t2) && TREE_CODE (t2) == POINTER_TYPE) return true; - /* The signedness of the parameter matters only when an integral - type smaller than int is promoted to int, otherwise only the - precision of the parameter matters. - This check should make sure that the callee does not see - undefined values in argument registers. */ + /* Only the precision of the parameter matters. This check should + make sure that the callee does not see undefined values in argument + registers. */ if (INTEGRAL_TYPE_P (t1) && INTEGRAL_TYPE_P (t2) - && TYPE_PRECISION (t1) == TYPE_PRECISION (t2) - && (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2) - || !targetm.calls.promote_prototypes (NULL_TREE) - || TYPE_PRECISION (t1) >= TYPE_PRECISION (integer_type_node))) + && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)) return true; return comptypes (t1, t2); diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 9fbc1602b0d..02946b80434 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -9437,11 +9437,6 @@ type_passed_as (tree type) /* Pass classes with copy ctors by invisible reference. */ if (TREE_ADDRESSABLE (type)) type = build_reference_type (type); - else if (targetm.calls.promote_prototypes (NULL_TREE) - && INTEGRAL_TYPE_P (type) - && COMPLETE_TYPE_P (type) - && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node))) - type = integer_type_node; return type; } @@ -9477,11 +9472,6 @@ convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain) /* Pass classes with copy ctors by invisible reference. */ else if (TREE_ADDRESSABLE (type)) val = build1 (ADDR_EXPR, build_reference_type (type), val); - else if (targetm.calls.promote_prototypes (NULL_TREE) - && INTEGRAL_TYPE_P (type) - && COMPLETE_TYPE_P (type) - && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node))) - val = cp_perform_integral_promotions (val, complain); if (complain & tf_warning) { if (warn_suggest_attribute_format) diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index adc71132721..dc3c817374d 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -1372,17 +1372,12 @@ cxx_safe_arg_type_equiv_p (tree t1, tree t2) && TYPE_PTR_P (t2)) return true; - /* The signedness of the parameter matters only when an integral - type smaller than int is promoted to int, otherwise only the - precision of the parameter matters. - This check should make sure that the callee does not see - undefined values in argument registers. */ + /* Only the precision of the parameter matters. This check should + make sure that the callee does not see undefined values in argument + registers. */ if (INTEGRAL_TYPE_P (t1) && INTEGRAL_TYPE_P (t2) - && TYPE_PRECISION (t1) == TYPE_PRECISION (t2) - && (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2) - || !targetm.calls.promote_prototypes (NULL_TREE) - || TYPE_PRECISION (t1) >= TYPE_PRECISION (integer_type_node))) + && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)) return true; return same_type_p (t1, t2); diff --git a/gcc/gimple.cc b/gcc/gimple.cc index 477315cb1b8..2ddbe1dfc34 100644 --- a/gcc/gimple.cc +++ b/gcc/gimple.cc @@ -2896,15 +2896,7 @@ gimple_builtin_call_types_compatible_p (const gimple *stmt, tree fndecl) return true; tree arg = gimple_call_arg (stmt, i); tree type = TREE_VALUE (targs); - if (!useless_type_conversion_p (type, TREE_TYPE (arg)) - /* char/short integral arguments are promoted to int - by several frontends if targetm.calls.promote_prototypes - is true. Allow such promotion too. */ - && !(INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node) - && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)) - && useless_type_conversion_p (integer_type_node, - TREE_TYPE (arg)))) + if (!useless_type_conversion_p (type, TREE_TYPE (arg))) return false; targs = TREE_CHAIN (targs); } diff --git a/gcc/tree.cc b/gcc/tree.cc index 83a03374a32..c510bcc65dd 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -8694,20 +8694,6 @@ tree_builtin_call_types_compatible_p (const_tree call, tree fndecl) && POINTER_TYPE_P (TREE_TYPE (arg)) && tree_nop_conversion_p (type, TREE_TYPE (arg))) continue; - /* char/short integral arguments are promoted to int - by several frontends if targetm.calls.promote_prototypes - is true. Allow such promotion too. */ - if (INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node) - && INTEGRAL_TYPE_P (TREE_TYPE (arg)) - && !TYPE_UNSIGNED (TREE_TYPE (arg)) - && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)) - && (gimple_form - ? useless_type_conversion_p (integer_type_node, - TREE_TYPE (arg)) - : tree_nop_conversion_p (integer_type_node, - TREE_TYPE (arg)))) - continue; return false; } }