From patchwork Thu Jul 30 21:46:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1339135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=pLYjedE4; dkim-atps=neutral Received: from sourceware.org (server2.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 ozlabs.org (Postfix) with ESMTPS id 4BHkWT0G71z9sT6 for ; Fri, 31 Jul 2020 07:46:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9CFC3857022; Thu, 30 Jul 2020 21:46:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9CFC3857022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596145586; bh=qG5RTM/cvUZDDRkzLdVF8eF2RcZUXovbwSTim6Ml7+A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pLYjedE4dWVU29Ok31e/3gOHWRyQU4lJgswH5LW6qixOMpa6qlRatdVXygCzT2k9P RmUg1s4BM+DSlv/Q1NmqioVnAvyFC1ZLCVtUT1LRt09yuEunjX0tq1TJ2r8dH8aRRK ymrW4ryveP2bCIXycMyvwYCV7/4Glkgnz69JwcUE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050::465:202]) by sourceware.org (Postfix) with ESMTPS id 0C9B43858D35 for ; Thu, 30 Jul 2020 21:46:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0C9B43858D35 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4BHkWM6KrSzQjll; Thu, 30 Jul 2020 23:46:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id 4L71uMkKjNNO; Thu, 30 Jul 2020 23:46:20 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Add -Wvarargs warning flag to the D front-end (PR96154) Date: Thu, 30 Jul 2020 23:46:18 +0200 Message-Id: <20200730214618.790033-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: 10 X-Rspamd-Score: 1.53 / 15.00 / 15.00 X-Rspamd-Queue-Id: A694F178C X-Rspamd-UID: 917640 X-Spam-Status: No, score=-16.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch adds the -Wvarargs warning flag to the D front-end. The language has C-style variadic functions and va_start/va_arg, so it is right to also have warnings for inproper use. Bootstrapped and regression tested on x86_64-linux-gnu, committed to mainline. Regards Iain --- gcc/d/ChangeLog: PR d/96154 * gdc.texi (Warnings): Document -Wvarargs. * lang.opt: Add -Wvarargs gcc/testsuite/ChangeLog: PR d/96154 * gdc.dg/pr96154a.d: New test. * gdc.dg/pr96154b.d: New test. --- gcc/d/gdc.texi | 6 ++++++ gcc/d/lang.opt | 4 ++++ gcc/testsuite/gdc.dg/pr96154a.d | 18 ++++++++++++++++++ gcc/testsuite/gdc.dg/pr96154b.d | 19 +++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/gdc.dg/pr96154a.d create mode 100644 gcc/testsuite/gdc.dg/pr96154b.d diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi index 2ce560f3cae..9bc1297cba4 100644 --- a/gcc/d/gdc.texi +++ b/gcc/d/gdc.texi @@ -600,6 +600,12 @@ Warn when a @code{pragma()} is encountered that is not understood by where a pragma that is part of the D language, but not implemented by the compiler, won't get reported. +@item -Wno-varargs +@cindex Wvarargs +@cindex Wno-varargs +Do not warn upon questionable usage of the macros used to handle variable +arguments like @code{va_start}. + @item -fignore-unknown-pragmas @cindex @option{-fignore-unknown-pragmas} @cindex @option{-fno-ignore-unknown-pragmas} diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt index e14c83d1adb..ade92d21cc6 100644 --- a/gcc/d/lang.opt +++ b/gcc/d/lang.opt @@ -146,6 +146,10 @@ Wunknown-pragmas D LangEnabledBy(D, Wall) ; Documented in C +Wvarargs +D +; Documented in C + X D Generate JSON file. diff --git a/gcc/testsuite/gdc.dg/pr96154a.d b/gcc/testsuite/gdc.dg/pr96154a.d new file mode 100644 index 00000000000..8c0ca658c55 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96154a.d @@ -0,0 +1,18 @@ +// { dg-do compile } + +import core.stdc.stdarg; + +void +error (int a) +{ + va_list vp; + va_start (vp, a); // { dg-error "used in function with fixed arguments" } +} + +void +warn (int a, int b, ...) +{ + va_list vp; + va_start (vp, a); // { dg-warning "second parameter" } + va_end (vp); +} diff --git a/gcc/testsuite/gdc.dg/pr96154b.d b/gcc/testsuite/gdc.dg/pr96154b.d new file mode 100644 index 00000000000..dec7f489308 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96154b.d @@ -0,0 +1,19 @@ +// { dg-options "-Wno-varargs" } +// { dg-do compile } + +import core.stdc.stdarg; + +void +error (int a) +{ + va_list vp; + va_start (vp, a); // { dg-error "used in function with fixed arguments" } +} + +void +warn (int a, int b, ...) +{ + va_list vp; + va_start (vp, a); // No warning because of -Wno-varargs in effect. + va_end (vp); +}