From patchwork Wed Aug 24 05:56:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 662141 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 3sJxRF4HS0z9sCp for ; Wed, 24 Aug 2016 15:57:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=gNIvLEw/; 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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=gQHtBdf+zWa0kQJup/t4oXM0z1uwBhJtFV8h2XiGRf8DxhAYeq oscTdI0lv9yuyinD04xKBm0JBAEWXKYJplVENd6PKKKXq4aZqDlnNvXKNGI+wrxE dW/Xx24/UQW7jGTsB+MMyKc9c8wH0pzFXcsrs47lG0ZsnFQ84wkPxJWXI= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=gEqdesSS/P45D24q6H9/M8y9s54=; b=gNIvLEw/YVtDFFUWxp3s FIC0fUfhoFeyTTwpp/XM9SdxYNpf9dqEZslSl0XHJhA3+islmsQTWoEpUN6TotcB 6xrN9tpKAGgTs/FBOnrbZ7MYSLWvFq//pTmU6pjyYzGBQ6UKlEqAQtRm6th8nztq 3Hjt7N2vmz7wcUQ9+FbnFbs= Received: (qmail 30267 invoked by alias); 24 Aug 2016 05:57:17 -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 30251 invoked by uid 89); 24 Aug 2016 05:57:16 -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=Lets, Let's, Hx-languages-length:3222, H*r:Wed 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 05:57:05 +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 1bcRBO-0004ZK-S3 from Tom_deVries@mentor.com for gcc-patches@gcc.gnu.org; Tue, 23 Aug 2016 22:57:03 -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 06:57:01 +0100 To: GCC Patches From: Tom de Vries Subject: [PATCH, 1/4] Handle errors in both args of va_arg Message-ID: <4828e445-76d1-7ae5-1a36-acc4e7073925@mentor.com> Date: Wed, 24 Aug 2016 07:56:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Hi, I. Consider test-case: ... struct A {}; void foo (void) { __builtin_va_arg (0, A); } ... Compiling this with g++ gives the error: ... error: first argument to ‘va_arg’ not of type ‘va_list’ ... II. Now we add ++ in front of the expression, and get: ... struct A {}; void foo (void) { ++__builtin_va_arg (0, A); } ... Compiling this with g++ gives this error: ... error: no match for ‘operator++’ (operand type is ‘A’) ... and the previous error disappears. III. This patch makes sure that both errors are given for the last example, by moving the error call from gimplify_va_arg_expr to build_va_arg. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom Handle errors in both args of va_arg 2016-08-22 Tom de Vries * c-common.c (build_va_arg): Add first argument error. Build va_arg with error_mark_node as va_list instead of with illegal va_list. * gimplify.c (gimplify_va_arg_expr): Replace first argument type error with assert. * g++.dg/ext/va-arg1.C: Add error check for illegal first argument. --- gcc/c-family/c-common.c | 7 +++++-- gcc/gimplify.c | 7 +------ gcc/testsuite/g++.dg/ext/va-arg1.C | 4 +++- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 32468ca..7ad1930 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5794,16 +5794,19 @@ build_va_arg (location_t loc, tree expr, tree type) { tree va_type = TREE_TYPE (expr); tree canon_va_type = (va_type == error_mark_node - ? NULL_TREE + ? error_mark_node : targetm.canonical_va_list_type (va_type)); if (va_type == error_mark_node || canon_va_type == NULL_TREE) { + if (canon_va_type == NULL_TREE) + error_at (loc, "first argument to % not of type %"); + /* Let's handle things neutrallly, if expr: - has undeclared type, or - is not an va_list type. */ - return build_va_arg_1 (loc, type, expr); + return build_va_arg_1 (loc, type, error_mark_node); } if (TREE_CODE (canon_va_type) != ARRAY_TYPE) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 4715332..288b472 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11959,12 +11959,7 @@ 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) - { - error_at (loc, "first argument to % not of type %"); - return GS_ERROR; - } + gcc_assert (have_va_type != NULL_TREE); /* Generate a diagnostic for requesting data of a type that cannot be passed through `...' due to type promotion at the call site. */ diff --git a/gcc/testsuite/g++.dg/ext/va-arg1.C b/gcc/testsuite/g++.dg/ext/va-arg1.C index 5606128..c0477ad 100644 --- a/gcc/testsuite/g++.dg/ext/va-arg1.C +++ b/gcc/testsuite/g++.dg/ext/va-arg1.C @@ -4,5 +4,7 @@ struct A {}; void foo() { - ++__builtin_va_arg(0, A); // { dg-error "operand type is 'A'" } + ++__builtin_va_arg (0, A); + // { dg-error "operand type is 'A'" "" {target *-*-*} "7" } + // { dg-error "first argument to 'va_arg' not of type 'va_list'" "" {target *-*-*} "7" } }