From patchwork Mon Jan 29 23:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 1892557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FiBJdumD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TP4001zr1z23fD for ; Tue, 30 Jan 2024 10:15:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 340723857C41 for ; Mon, 29 Jan 2024 23:15:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 696723858298; Mon, 29 Jan 2024 23:14:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 696723858298 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 696723858298 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706570083; cv=none; b=XhOJnCuzpEbKVQc+41eLPEmaUawlSU7tjrP4TawOCgybepDshc+DSxPELfGsSZXccM3Jn+bAzuJHP1R17wPgFDWPKmNvCjLZhRD4+eJaKTfMn9E58ZXROrgWJ0PiwduFSWaMiANl/6rREp6o3aM1RPTOco0MxZ7EF2KikrqqSYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706570083; c=relaxed/simple; bh=sjlLSTWyPF0TnJRTYsL9JVUILmzAbSjxm2z5K1Ta/ek=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=hOsdRNBSNLgnVofIWRk7ub48WBlj9xnjfglINCTR2mgLWLqfBum6YGKYzjyoCCZsylN4E30Ga5Ptn/bBDcYPAPACumo8a4cNbNcj1oH0hWO0Cr7OsErzsTmESFiZOX1d86nubebN6bLnuZaRKLgrQS4EEw0CcbY/uzSyqMTHcR4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40ed3101ce3so47656945e9.2; Mon, 29 Jan 2024 15:14:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706570079; x=1707174879; darn=gcc.gnu.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=1//Cy70aAJHcNzClOC7vuC3TTCilJtVrHApTqDe/3es=; b=FiBJdumDQHk1YqkHtDWvMfHU9TXmRHAl7P2rk9HksrowHW0BVxhPhjqqx0Jgx2nN+3 1BE7AP8Fn9+wWPNNfERQNh7ljNfTrJB7HvFc7IuOp9XBLAonXYNr9ujm9YNFamc/ob3s huPj6nfzjdOXm/smik1dyXS5Ll/pP93sPpZagD8R+a3uTRCMgOxS4f8ULR2kvIu2x/3f U1yOuCEH0lMDyOjZsAVk+fD2abszfhYyhu3D/xIVOJSIEUZIEHj+nLEL1syRBrXJZFPp 9n1/9lOkdd5dewzg5qOlQfNG4XMxaMupwa2PIlUPKR4y7/2mJchFbKlKtXRlwWW6QiTL moBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706570079; x=1707174879; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1//Cy70aAJHcNzClOC7vuC3TTCilJtVrHApTqDe/3es=; b=UyCOjDU5MC0cSo9BeEz4EfPoh3qjwKkJWELzeXFhNIKJnnVpzM6Lc0etIA3sKDndq1 tKQ6Y+2KdzoZ/iWCFssPxEuEC+/uJqtCtgYa2B8D4F+RUhStUniNhsMRELeNs960a/vt o1zSZrwOu9KXVYt4tCe1H8Cvu1OsqMZp1LfGLWmDKNfr2N0e16TjRkFAVj5SavxnFNcw gc1D73eiQwcMuLyLkIBtJj1sFLckQuHAz3+WOehiO0LSfOlrwXxum/9BOQ7xXKn6ZArz j1WOVqatFzTpCKs9IvdT06TdeaEGs7UarlcEZoT05pLyj+JuBaQclcHiOwQRu5NwqHZ6 SXrQ== X-Gm-Message-State: AOJu0YwznwoJowput8X1Gk+eyr859hyU3bbQcYlhnnhrW8WlOnrKz8zD yxC7Cp2pfh/70YgM8R4P7TjwPhQ5m3pInIfhOzMQ7kr4zCSEEXiB X-Google-Smtp-Source: AGHT+IFPno8IWVyFSgwW8miqDCkpSuLGOGEEeNbHNzKfmcGlPQB3idJsBir130XZP2pxFHMHWZc91g== X-Received: by 2002:a05:600c:4e8c:b0:40e:66ba:7fff with SMTP id f12-20020a05600c4e8c00b0040e66ba7fffmr6999928wmq.19.1706570078775; Mon, 29 Jan 2024 15:14:38 -0800 (PST) Received: from nbbrfq.loc (80-110-214-113.static.upcbusiness.at. [80.110.214.113]) by smtp.gmail.com with ESMTPSA id h7-20020a05600c314700b0040efd216050sm686641wmo.35.2024.01.29.15.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 15:14:38 -0800 (PST) Date: Tue, 30 Jan 2024 00:14:34 +0100 From: Bernhard Reutner-Fischer To: gcc@gcc.gnu.org, ubizjak@gmail.com, hubicka@ucw.cz, hjl.tools@gmail.com, gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer Subject: [Patch, stage-1, RFC]: i386: attribute regparm/stdcall and vaargs Message-ID: <20240130001434.35b2b856@nbbrfq.loc> MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@gcc.gnu.org [I was torn towards asking gcc@ only, individual i386 maintainers in private or bluntly asking for help on gcc-patches or re-iterate through ABI, so in an attempt to cut off years of latency i hereby ask all and everybody for assistance. Stage4 means any chances are low, i know.. hence stage 1 material since it's not pressing in any foreseeable way] Hello i386 maintainers Recently, elsewhere, there was discussion about attribute regparm (and stdcall) on functions with variable number of arguments in C. Allegedly clang warns about these but GCC does not. I did not look at clang. gcc/doc/extend.texi currently states that: ---8<--- @cindex @code{regparm} function attribute, x86 [] Functions that take a variable number of arguments continue to be passed all of their arguments on the stack. [] @cindex @code{sseregparm} function attribute, x86 [] Functions that take a variable number of arguments continue to pass all of their floating-point arguments on the stack. [] @cindex @code{stdcall} function attribute, x86-32 [] On x86-32 targets, the @code{stdcall} attribute causes the compiler to assume that the called function pops off the stack space used to pass arguments, unless it takes a variable number of arguments. ---8<--- which seems to suggest that all of attribute regparm/sseregparm/stdcall are ignored on functions with variable number of arguments. I.e. the ABI mandates that everything is passed on the stack. [Right? ISTM that this is correct; Didn't follow ABI (tweaks) too closely in the last decade, admittedly.. But i think this still holds. Please correct me if i missed something?] If this is correct, then ISTM that attributes regparm/sseregparm/stdcall should be rejected on functions with variable number of arguments also in GCC. There seems to be (exact) struct function cfun->va_list_[fg]pr_size for the real fpr and gpr save area sizes. But (unfortunately / of course) they are layed out way later than parsing the attributes in both the C++ and C FEs, so using those in ix86_handle_cconv_attribute is not possible as there is no cfun readily available there yet. ²). Hence i would propose to ¹): gcc/ChangeLog: * builtin-attrs.def (ATTR_TM_NOTHROW_RT_LIST): Use ATTR_NOTHROW_LIST instead of ATTR_TM_NOTHROW_LIST, thus removing ATTR_TM_REGPARM. * config/i386/i386-options.cc (ix86_handle_cconv_attribute): Decline regparm, stdcall and regparm attribute on functions with variable number of arguments. libitm/ChangeLog: * libitm.h (_ITM_beginTransaction): Remove ITM_REGPARM. gcc/testsuite/ChangeLog: * gcc.dg/lto/trans-mem.h: Remove ITM_REGPARM. * gcc.target/i386/attributes-error.c: Extend to cover (regparm(3),stdcall) on vaargs functions. * gcc.target/i386/attributes-error-sse.c: New test. ¹) as per attached ²) Unfortunately, the C FE does not readily provide a sensible locus for the attributes in question but points input_location at that spot of the beginning of the declaration of such a function. The C++ FE is a little bit better in this regard: [here i meant to verbatim emphasis discrepancy of the C++ and C FE diagnostics for the abovementioned target tests, striking, isn't it, But see yourselves.] ³) unreferenced, hence implied, where would on do this instead, more helpful? diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def index 71f4db1f3da..4813509b9c3 100644 --- a/gcc/builtin-attrs.def +++ b/gcc/builtin-attrs.def @@ -400,7 +400,7 @@ DEF_ATTR_TREE_LIST (ATTR_TM_NORETURN_NOTHROW_LIST, DEF_ATTR_TREE_LIST (ATTR_TM_CONST_NOTHROW_LIST, ATTR_TM_REGPARM, ATTR_NULL, ATTR_CONST_NOTHROW_LIST) DEF_ATTR_TREE_LIST (ATTR_TM_NOTHROW_RT_LIST, - ATTR_RETURNS_TWICE, ATTR_NULL, ATTR_TM_NOTHROW_LIST) + ATTR_RETURNS_TWICE, ATTR_NULL, ATTR_NOTHROW_LIST) /* Same attributes used for BUILT_IN_MALLOC except with TM_PURE thrown in. */ DEF_ATTR_TREE_LIST (ATTR_TMPURE_MALLOC_NOTHROW_LIST, diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 3605c2c53fb..daea2394e1a 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3679,6 +3679,12 @@ ix86_handle_cconv_attribute (tree *node, tree name, tree args, int, name, REGPARM_MAX); *no_add_attrs = true; } + else if (FUNC_OR_METHOD_TYPE_P (*node) && stdarg_p (*node)) + { + warning (OPT_Wattributes, "%qE attribute ignored " + "on function with variable number of arguments", name); + *no_add_attrs = true; + } return NULL_TREE; } @@ -3732,6 +3738,12 @@ ix86_handle_cconv_attribute (tree *node, tree name, tree args, int, { error ("stdcall and thiscall attributes are not compatible"); } + if (FUNC_OR_METHOD_TYPE_P (*node) && stdarg_p (*node)) + { + warning (OPT_Wattributes, "%qE attribute ignored " + "on function with variable number of arguments", name); + *no_add_attrs = true; + } } /* Can combine cdecl with regparm and sseregparm. */ @@ -3768,6 +3780,15 @@ ix86_handle_cconv_attribute (tree *node, tree name, tree args, int, error ("cdecl and thiscall attributes are not compatible"); } } + else if (is_attribute_p ("sseregparm", name)) + { + if (FUNC_OR_METHOD_TYPE_P (*node) && stdarg_p (*node)) + { + warning (OPT_Wattributes, "%qE attribute ignored " + "on function with variable number of arguments", name); + *no_add_attrs = true; + } + } /* Can combine sseregparm with all attributes. */ diff --git a/gcc/testsuite/gcc.dg/lto/trans-mem.h b/gcc/testsuite/gcc.dg/lto/trans-mem.h index add5a297b51..a1c97cb28c1 100644 --- a/gcc/testsuite/gcc.dg/lto/trans-mem.h +++ b/gcc/testsuite/gcc.dg/lto/trans-mem.h @@ -14,7 +14,7 @@ # define ITM_REGPARM #endif -ITM_REGPARM noinline uint32_t _ITM_beginTransaction(uint32_t a, ...) { asm(""); } +noinline uint32_t _ITM_beginTransaction(uint32_t a, ...) { asm(""); } ITM_REGPARM noinline void _ITM_commitTransaction (void) { asm(""); } ITM_REGPARM noinline void _ITM_WU4 (void *a, uint32_t b) { asm(""); } ITM_REGPARM noinline void _ITM_WU8 (void *a, uint64_t b) { asm(""); } diff --git a/gcc/testsuite/gcc.target/i386/attributes-error-sse.c b/gcc/testsuite/gcc.target/i386/attributes-error-sse.c new file mode 100644 index 00000000000..dd5381b72c7 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/attributes-error-sse.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ia32 } */ +/* { dg-require-effective-target sse } */ + +char *foo1(int, ...) __attribute__((sseregparm)); /* { dg-warning "attribute ignored on function with variable number of arguments" } */ +char *foo2(float, ...) __attribute__((sseregparm)); /* { dg-warning "attribute ignored on function with variable number of arguments" } */ + diff --git a/gcc/testsuite/gcc.target/i386/attributes-error.c b/gcc/testsuite/gcc.target/i386/attributes-error.c index 405eda50105..54eaa688bc5 100644 --- a/gcc/testsuite/gcc.target/i386/attributes-error.c +++ b/gcc/testsuite/gcc.target/i386/attributes-error.c @@ -9,4 +9,7 @@ void foo5(int i, int j) __attribute__((stdcall, fastcall)); /* { dg-error "not c void foo6(int i, int j) __attribute__((cdecl, fastcall)); /* { dg-error "not compatible" } */ void foo7(int i, int j) __attribute__((cdecl, stdcall)); /* { dg-error "not compatible" } */ void foo8(int i, int j) __attribute__((regparm(2), fastcall)); /* { dg-error "not compatible" } */ +char *foo9(const char *format, ...) __attribute__((regparm(3),stdcall)); /* { dg-warning "attribute ignored on function with variable number of arguments" } */ +char *foo10(int, ...) __attribute__((regparm(2))); /* { dg-warning "attribute ignored on function with variable number of arguments" } */ +char *foo11(int, ...) __attribute__((stdcall)); /* { dg-warning "attribute ignored on function with variable number of arguments" } */ diff --git a/libitm/libitm.h b/libitm/libitm.h index a361be7df24..a3357f13796 100644 --- a/libitm/libitm.h +++ b/libitm/libitm.h @@ -154,7 +154,7 @@ typedef uint64_t _ITM_transactionId_t; /* Transaction identifier */ extern _ITM_transactionId_t _ITM_getTransactionId(void) ITM_REGPARM; -extern uint32_t _ITM_beginTransaction(uint32_t, ...) ITM_REGPARM; +extern uint32_t _ITM_beginTransaction(uint32_t, ...); extern void _ITM_abortTransaction(_ITM_abortReason) ITM_REGPARM ITM_NORETURN;