From patchwork Mon Aug 29 16:12:11 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: 663720 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 3sNGrq3Tjrz9sBM for ; Tue, 30 Aug 2016 02:12:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=eDir3Nh3; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=XE7Z4qF5e2wLLGSEc RVcMcHdrrdULEiGbDS2gCN3rzw3GIjyAklIfaVRbFS/g0HWes/V9f3+PE6gDx5px 8iqGFIMCSXdRYGTr+9sgAh2r/v+BAPWfKA2H//9ijap3XOHYQ0Ii8/ALeQ1FMIBe HsKwLR9crOBQbnxjjX3ncZIaao= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=F5KmNN4qO6QLbznADaSma5n qemA=; b=eDir3Nh3joE59T7NS7SsKEsBtVZ9rjscJ2VuI5aVpt5xAsZi9hxlTyy FhhJUgYAOYsz3J5/oHZodUMCGJriCTMUtr4PvHWy1hehalBQ1W2JqNpvQVeIU/QS LKWMNQBDeS3xC3HmfrNmClqJIXLJTbgCdgENZbVhFnxtkkemgOtg= Received: (qmail 61835 invoked by alias); 29 Aug 2016 16:12:33 -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 61822 invoked by uid 89); 29 Aug 2016 16:12:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_RED autolearn=ham version=3.3.2 spammy=Treat, non-null, addr_expr, MEM_REF 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; Mon, 29 Aug 2016 16:12:22 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1bePAZ-00030a-EK from Tom_deVries@mentor.com ; Mon, 29 Aug 2016 09:12:19 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Mon, 29 Aug 2016 17:12:17 +0100 Subject: Re: [PATCH, PR71602, 4/4] Make canonical_va_list_type more strict To: Joseph Myers References: <576BB984.1040401@mentor.com> CC: Jason Merrill , GCC Patches From: Tom de Vries Message-ID: <61d0854f-16be-8bd6-a776-e9d51dd00739@mentor.com> Date: Mon, 29 Aug 2016 18:12:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: On 29/08/16 17:51, Joseph Myers wrote: > On Wed, 24 Aug 2016, Tom de Vries wrote: > >> This patch fixes PR71602 by making canonical_va_list_type more strict. >> >> Bootstrapped and reg-tested on x86_64. >> >> OK for trunk, 6-branch? > > ENOPATCH > Patch attached this time. Thanks, - Tom Make canonical_va_list_type more strict 2016-08-22 Tom de Vries PR C/71602 * builtins.c (std_canonical_va_list_type): Strictly return non-null for va_list type only. * config/i386/i386.c (ix86_canonical_va_list_type): Same. * gimplify.c (gimplify_va_arg_expr): Handle &va_list. * c-common.c (build_va_arg): Handle more strict targetm.canonical_va_list_type. * c-c++-common/va-arg-va-list-type.c: New test. --- gcc/builtins.c | 4 ---- gcc/c-family/c-common.c | 8 ++------ gcc/config/i386/i386.c | 8 -------- gcc/gimplify.c | 5 +++++ gcc/testsuite/c-c++-common/va-arg-va-list-type.c | 9 +++++++++ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index abc934b..101b1e3 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4089,10 +4089,6 @@ std_canonical_va_list_type (tree type) { tree wtype, htype; - if (INDIRECT_REF_P (type)) - type = TREE_TYPE (type); - else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE (type))) - type = TREE_TYPE (type); wtype = va_list_type_node; htype = type; /* Treat structure va_list types. */ diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 3b61e64..6cf2ffc 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5813,15 +5813,11 @@ build_va_arg (location_t loc, tree expr, tree type) { /* Case 1: Not an array type. */ - /* Take the address, to get '&ap'. */ + /* Take the address, to get '&ap'. Note that &ap is not a va_list + type. */ mark_addressable (expr); expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr); - /* Verify that &ap is still recognized as having va_list type. */ - tree canon_expr_type - = targetm.canonical_va_list_type (TREE_TYPE (expr)); - gcc_assert (canon_expr_type != NULL_TREE); - return build_va_arg_1 (loc, type, expr); } diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 2639c8c..343efa0 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -48565,14 +48565,6 @@ 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); - else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type))) - type = TREE_TYPE (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) { wtype = va_list_type_node; diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 288b472..6ce516a 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11959,6 +11959,11 @@ gimplify_va_arg_expr (tree *expr_p, gimple_seq *pre_p, if (have_va_type == error_mark_node) return GS_ERROR; have_va_type = targetm.canonical_va_list_type (have_va_type); + if (have_va_type == NULL_TREE + && TREE_CODE (valist) == ADDR_EXPR) + /* Handle 'Case 1: Not an array type' from c-common.c/build_va_arg. */ + have_va_type + = targetm.canonical_va_list_type (TREE_TYPE (TREE_TYPE (valist))); gcc_assert (have_va_type != NULL_TREE); /* Generate a diagnostic for requesting data of a type that cannot diff --git a/gcc/testsuite/c-c++-common/va-arg-va-list-type.c b/gcc/testsuite/c-c++-common/va-arg-va-list-type.c new file mode 100644 index 0000000..cdd97cf --- /dev/null +++ b/gcc/testsuite/c-c++-common/va-arg-va-list-type.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ + +__builtin_va_list *pap; + +void +fn1 (void) +{ + __builtin_va_arg (pap, double); /* { dg-error "first argument to 'va_arg' not of type 'va_list'" } */ +}