From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109802 invoked by alias); 24 Aug 2016 06:22:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 109788 invoked by uid 89); 24 Aug 2016 06:22:33 -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=merrill, Merrill, Hx-languages-length:2456, Hook 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 06:22:22 +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 1bcRZs-0001Wl-Im from Tom_deVries@mentor.com ; Tue, 23 Aug 2016 23:22:20 -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 07:22:19 +0100 Subject: [PATCH, PR71602, 4/4] Make canonical_va_list_type more strict To: Jason Merrill References: <576BB984.1040401@mentor.com> CC: GCC Patches From: Tom de Vries Message-ID: Date: Wed, 24 Aug 2016 06:22:00 -0000 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: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2016-08/txt/msg01691.txt.bz2 [ was: Re: [PATCH, PR71602] Give error for invalid va_list argument to va_arg ] On 23/06/16 23:21, Jason Merrill wrote: > On Thu, Jun 23, 2016 at 1:27 PM, Tom de Vries wrote: >> Hi, >> >> this patch fixes PR71602, a 6/7 regression. >> >> Consider this test-case:>> The patch fixes the ICE by making the valid va_list check in build_va_arg >> more precise, by taking into account the non-strict behavior of >> canonical_va_list_type. > > If you do need to check this here, is there a reason you need to pass > in a callback rather than use lang_hooks.types_compatible_p? > > Jason > >> ... >> __builtin_va_list *pap; >> >> void >> fn1 (void) >> { >> __builtin_va_arg(pap, double); >> } >> ... >> >> The testcase is invalid, because we're not passing a va_list as first >> argument of va_arg, but a va_list*. >> >> When compiling for x86_64 -m64, we run into the second assert in this >> snippet from build_va_arg: >> ... >> { >> /* Case 2b: va_list is pointer to array elem type. */ >> gcc_assert (POINTER_TYPE_P (va_type)); >> gcc_assert (TREE_TYPE (va_type) == TREE_TYPE (canon_va_type)); >> >> /* Don't take the address. We've already got '&ap'. */ >> ; >> } >> ... >> >> At that point, va_type and canon_va_type are: >> ... >> (gdb) call debug_generic_expr (va_type) >> struct [1] * >> (gdb) call debug_generic_expr (canon_va_type) >> struct [1] >> ... >> >> so TREE_TYPE (va_type) and TREE_TYPE (canon_va_type) are not equal: >> ... >> (gdb) call debug_generic_expr (va_type.typed.type) >> struct [1] >> (gdb) call debug_generic_expr (canon_va_type.typed.type) >> struct >> ... >> >> Given the semantics of the target hook: >> ... >> Target Hook: tree TARGET_CANONICAL_VA_LIST_TYPE (tree type) >> >> This hook returns the va_list type of the calling convention specified >> by the type of type. If type is not a valid va_list type, it returns >> NULL_TREE. >> ... >> one could argue that canonical_va_list_type should return NULL_TREE for a >> va_list*, which would fix the ICE. But the current implementation seems to >> rely on canonical_va_list_type to return va_list for a va_list* argument. > > It does seem like it's the job of canonical_va_list_type to detect an > invalid argument. Why not fix that? > This patch fixes PR71602 by making canonical_va_list_type more strict. Bootstrapped and reg-tested on x86_64. OK for trunk, 6-branch? Thanks, - Tom