[committed] d: Add -Wvarargs warning flag to the D front-end (PR96154)

Message ID 20200730214618.790033-1-ibuclaw@gdcproject.org
State New
Headers show
Series
  • [committed] d: Add -Wvarargs warning flag to the D front-end (PR96154)
Related show

Commit Message

Ian Lance Taylor via Gcc-patches July 30, 2020, 9:46 p.m.
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

-- 
2.25.1

Patch

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);
+}