From patchwork Thu Apr 7 15:52:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1614563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=r7J1fNRt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZ5Xp3t3wz9sGS for ; Fri, 8 Apr 2022 01:54:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EC2D385780D for ; Thu, 7 Apr 2022 15:54:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EC2D385780D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649346855; bh=CP0hNbhd2CVzTel48pSx7fBJE8W4H5zpgSGRU+hkafg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=r7J1fNRtJpyhG07myx4amss1xSCBRe1wENVYGPbG+7M/bRs+ABo/Dh40gIdczO/6K x5SN8++T/opDgptYgMd33cPWtrqo3fEaDHYlWeTbNHrMISxk1HbeVhHx97uYDs4mVe R/VvkO/30dVOiaYpsLDGjigBGvsCf2Vu3N/q1ZU0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C94B03840C26 for ; Thu, 7 Apr 2022 15:53:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C94B03840C26 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-248-xnlQMVPUMauTxxWzsOSh4g-1; Thu, 07 Apr 2022 11:53:19 -0400 X-MC-Unique: xnlQMVPUMauTxxWzsOSh4g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 971563C13A22; Thu, 7 Apr 2022 15:53:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D70DC27E91; Thu, 7 Apr 2022 15:53:18 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 237Fr0xf1100026 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Apr 2022 17:53:05 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 237FqrRr1100025; Thu, 7 Apr 2022 17:52:53 +0200 Date: Thu, 7 Apr 2022 17:52:53 +0200 To: "Joseph S. Myers" , Marek Polacek Subject: [PATCH] c: Error on va_arg with function type [PR105149] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! In the PR Joseph said that the C standard for va_arg talks about pointers to object type and as a function type is not object type, it is invalid. The following patch diagnoses it in the FE, instead of ICEing later on when optimizations are turned on (and with -O0 doing something weird at runtime). Bootstrapped/regtested on powerpc64le-linux, ok for trunk? 2022-04-07 Jakub Jelinek PR c/105149 * c-typeck.cc (c_build_va_arg): Reject function types. * gcc.dg/pr105149.c: New test. Jakub --- gcc/c/c-typeck.cc.jj 2022-03-23 10:29:20.172967605 +0100 +++ gcc/c/c-typeck.cc 2022-04-07 12:26:17.236469809 +0200 @@ -15896,6 +15896,12 @@ c_build_va_arg (location_t loc1, tree ex "type %qT", type); return error_mark_node; } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + error_at (loc2, "second argument to % is a function type %qT", + type); + return error_mark_node; + } else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE) warning_at (loc2, OPT_Wc___compat, "C++ requires promoted type, not enum type, in %"); --- gcc/testsuite/gcc.dg/pr105149.c.jj 2022-04-07 12:39:08.202711511 +0200 +++ gcc/testsuite/gcc.dg/pr105149.c 2022-04-07 12:38:21.418364583 +0200 @@ -0,0 +1,16 @@ +/* PR c/105149 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include + +void +foo (int s, ...) +{ + int e; + va_list ap; + + va_start (ap, s); + e = va_arg (ap, int (void)) (); /* { dg-error "second argument to 'va_arg' is a function type" } */ + va_end (ap); +}