From patchwork Wed Aug 24 18:28:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 662452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sKG6r4Jfnz9sdm for ; Thu, 25 Aug 2016 04:29:23 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=YwlKLKuz; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=YlO6k1oNTwihdngjZOOpYpkjoUtxTED+hTxSSAQduqIgmNmgjF A8g2znHpFoNx4oMdA8iaBTsDl/bJWq+MkdhbUALpzSQDPunsjYnhMJwHNoTmR+uf VaELzEFF71NH3+0DdLtXBhR38GUxpWP+SK6ys/vzikoZsyJB4th0Sh7sE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=oSQF+7u62O00MwNwY9nENdOmq0Y=; b=YwlKLKuzumB629Ci+KbJ dNMbFgROvFGejRgWU0zHwvf084jSRAtKbKI1n0lIYONkgbMP9aANLc2wHsEA33Tj zU810oo0zm03iuTV2GNrodzpCfTCdTgbaE1kpgBre1xAkQlLFGJK0bOXW1P4Qofp spNQ/69z5Te28OjjMOtygnY= Received: (qmail 56686 invoked by alias); 24 Aug 2016 18:29:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56640 invoked by uid 89); 24 Aug 2016 18:29:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=type_fields, TYPE_FIELDS, fp_offset, field_decl X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 Aug 2016 18:29:04 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1bccv7-0004Q1-AR from Tom_deVries@mentor.com ; Wed, 24 Aug 2016 11:29:01 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Wed, 24 Aug 2016 19:28:59 +0100 To: Richard Biener CC: GCC Patches From: Tom de Vries Subject: [PATCH, PR70955] Tag {ms, sysv}_va_list_type_node with {ms, sysv}_abi attribute Message-ID: <0b95bce7-65c8-b122-9125-9e7a19041df3@mentor.com> Date: Wed, 24 Aug 2016 20:28:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Hi, in PR70955, ix86_canonical_va_list_type fails to recognize a __builtin_ms_va_list that was declared in a TU, because its type doesn't have the same main variant as the ms_va_list_type_node initialized in lto1. This patch fixes the PR by tagging ms_va_list_type_node and sysv_va_list_type_node with ms_abi/sysv_abi attributes. sysv_va_list_type_node is of type array of length one with elemtype record, and I ran into trouble with both adding the attribute to the array type and the record type, so I ended up adding it to the first field type. Bootstrapped and reg-tested on x86_64. OK for trunk, 6 branch? Thanks, - Tom Tag {ms,sysv}_va_list_type_node with {ms,sysv}_abi attribute 2016-08-24 Tom de Vries PR lto/70955 * config/i386/i386.c (ix86_build_builtin_va_list_64): Tag type with sysv_abi attribute. (ix86_build_builtin_va_list): Tag type with ms_abi attribute. (ix86_canonical_va_list_type): Handle sysv_abi and ms_abi attributes. * gcc.dg/pr70955.c: New test. --- gcc/config/i386/i386.c | 89 +++++++++++++----------------------------- gcc/testsuite/gcc.dg/pr70955.c | 33 ++++++++++++++++ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 2639c8c..b5a5bd1 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -10518,9 +10518,13 @@ ix86_build_builtin_va_list_64 (void) type_decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("__va_list_tag"), record); + tree attr = tree_cons (get_identifier ("sysv_abi"), NULL_TREE, NULL_TREE); + tree sysv_unsigned_type_node + = build_type_attribute_variant (unsigned_type_node, attr); + f_gpr = build_decl (BUILTINS_LOCATION, FIELD_DECL, get_identifier ("gp_offset"), - unsigned_type_node); + sysv_unsigned_type_node); f_fpr = build_decl (BUILTINS_LOCATION, FIELD_DECL, get_identifier ("fp_offset"), unsigned_type_node); @@ -10561,16 +10565,16 @@ ix86_build_builtin_va_list (void) if (TARGET_64BIT) { /* Initialize ABI specific va_list builtin types. */ - tree sysv_va_list, ms_va_list; - - sysv_va_list = ix86_build_builtin_va_list_64 (); - sysv_va_list_type_node = build_variant_type_copy (sysv_va_list); + sysv_va_list_type_node = ix86_build_builtin_va_list_64 (); /* For MS_ABI we use plain pointer to argument area. */ - ms_va_list = build_pointer_type (char_type_node); - ms_va_list_type_node = build_variant_type_copy (ms_va_list); + tree char_ptr_type = build_pointer_type (char_type_node); + tree attr = tree_cons (get_identifier ("ms_abi"), NULL_TREE, NULL_TREE); + ms_va_list_type_node = build_type_attribute_variant (char_ptr_type, attr); - return (ix86_abi == MS_ABI) ? ms_va_list : sysv_va_list; + return ((ix86_abi == MS_ABI) + ? ms_va_list_type_node + : sysv_va_list_type_node); } else { @@ -48563,8 +48567,6 @@ ix86_fn_abi_va_list (tree fndecl) static tree ix86_canonical_va_list_type (tree type) { - tree wtype, htype; - /* Resolve references and pointers to va_list type. */ if (TREE_CODE (type) == MEM_REF) type = TREE_TYPE (type); @@ -48573,64 +48575,29 @@ ix86_canonical_va_list_type (tree type) else if (POINTER_TYPE_P (type) && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE) type = TREE_TYPE (type); - if (TARGET_64BIT && va_list_type_node != NULL_TREE) + if (TARGET_64BIT) { - wtype = va_list_type_node; - gcc_assert (wtype != NULL_TREE); - htype = type; - if (TREE_CODE (wtype) == ARRAY_TYPE) - { - /* If va_list is an array type, the argument may have decayed - to a pointer type, e.g. by being passed to another function. - In that case, unwrap both types so that we can compare the - underlying records. */ - if (TREE_CODE (htype) == ARRAY_TYPE - || POINTER_TYPE_P (htype)) - { - wtype = TREE_TYPE (wtype); - htype = TREE_TYPE (htype); - } - } - if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype)) - return va_list_type_node; - wtype = sysv_va_list_type_node; - gcc_assert (wtype != NULL_TREE); - htype = type; - if (TREE_CODE (wtype) == ARRAY_TYPE) - { - /* If va_list is an array type, the argument may have decayed - to a pointer type, e.g. by being passed to another function. - In that case, unwrap both types so that we can compare the - underlying records. */ - if (TREE_CODE (htype) == ARRAY_TYPE - || POINTER_TYPE_P (htype)) - { - wtype = TREE_TYPE (wtype); - htype = TREE_TYPE (htype); - } - } - if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype)) - return sysv_va_list_type_node; - wtype = ms_va_list_type_node; - gcc_assert (wtype != NULL_TREE); - htype = type; - if (TREE_CODE (wtype) == ARRAY_TYPE) + if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (type))) + return ms_va_list_type_node; + + if ((TREE_CODE (type) == ARRAY_TYPE + && integer_zerop (array_type_nelts (type))) + || POINTER_TYPE_P (type)) { - /* If va_list is an array type, the argument may have decayed - to a pointer type, e.g. by being passed to another function. - In that case, unwrap both types so that we can compare the - underlying records. */ - if (TREE_CODE (htype) == ARRAY_TYPE - || POINTER_TYPE_P (htype)) + tree elem_type = TREE_TYPE (type); + tree first_field; + if (TREE_CODE (elem_type) == RECORD_TYPE + && (first_field = TYPE_FIELDS (elem_type))) { - wtype = TREE_TYPE (wtype); - htype = TREE_TYPE (htype); + tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (first_field)); + if (lookup_attribute ("sysv_abi", attrs)) + return sysv_va_list_type_node; } } - if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype)) - return ms_va_list_type_node; + return NULL_TREE; } + return std_canonical_va_list_type (type); } diff --git a/gcc/testsuite/gcc.dg/pr70955.c b/gcc/testsuite/gcc.dg/pr70955.c new file mode 100644 index 0000000..11685c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70955.c @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-require-effective-target lto } */ +/* { dg-options "-flto" } */ + +#include + +int __attribute__((ms_abi)) +foo (int n, ...) +{ + __builtin_ms_va_list ap; + int sum = 0; + + __builtin_ms_va_start (ap, n); + + while (n--) { + sum += __builtin_va_arg (ap, int); + printf("sum = %d\n", sum); + } + __builtin_ms_va_end (ap); + + return sum; +} + +int +main () +{ + int res = foo (10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + + if (res != 55) + __builtin_abort (); + + return 0; +}