summaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog153
-rw-r--r--gcc/testsuite/g++.dg/init/ref16.C23
-rw-r--r--gcc/testsuite/g++.dg/other/pr35504.C147
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/pr19637.C33
-rw-r--r--gcc/testsuite/gcc.dg/20050811-1.c4
-rw-r--r--gcc/testsuite/gcc.dg/20050811-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/cpp/cmdlne-dI-M.c2
-rw-r--r--gcc/testsuite/gcc.dg/cpp/cmdlne-dM-M.c2
-rw-r--r--gcc/testsuite/gcc.dg/format/attr-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/format/attr-2.c25
-rw-r--r--gcc/testsuite/gcc.dg/format/attr-3.c41
-rw-r--r--gcc/testsuite/gcc.dg/format/attr-4.c9
-rw-r--r--gcc/testsuite/gcc.dg/format/attr-7.c9
-rw-r--r--gcc/testsuite/gcc.dg/format/c90-printf-3.c2
-rw-r--r--gcc/testsuite/gcc.dg/format/c90-scanf-4.c2
-rw-r--r--gcc/testsuite/gcc.dg/format/c99-printf-3.c2
-rw-r--r--gcc/testsuite/gcc.dg/format/format.h120
-rw-r--r--gcc/testsuite/gcc.dg/format/miss-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/format/miss-3.c7
-rw-r--r--gcc/testsuite/gcc.dg/format/miss-4.c9
-rw-r--r--gcc/testsuite/gcc.dg/format/miss-5.c5
-rw-r--r--gcc/testsuite/gcc.dg/format/miss-6.c7
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_array-1.c42
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_attr-1.c10
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_attr-2.c68
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_attr-3.c71
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_attr-4.c26
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_attr-7.c35
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_bitfld-1.c52
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_branch-1.c28
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-printf-1.c184
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-printf-2.c25
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-printf-3.c43
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-scanf-1.c119
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-scanf-2.c26
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-scanf-3.c20
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-scanf-4.c31
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-scanf-5.c20
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-strftime-1.c20
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c90-strftime-2.c28
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c94-printf-1.c19
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c94-scanf-1.c18
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-printf-1.c109
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-printf-2.c32
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c40
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-scanf-1.c63
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-scanf-2.c27
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-scanf-3.c33
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-scanf-4.c20
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-strftime-1.c20
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_c99-strftime-2.c20
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_cast-1.c17
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_miss-1.c40
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_miss-2.c17
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_miss-3.c27
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_miss-4.c33
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_miss-5.c49
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_miss-6.c32
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_multattr-1.c51
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_multattr-2.c40
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_multattr-3.c29
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_no-exargs-1.c15
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_no-exargs-2.c28
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_no-y2k-1.c13
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_nonlit-1.c14
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_nonlit-2.c14
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_nonlit-3.c13
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_nul-1.c15
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_nul-2.c17
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_null-1.c28
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_plus-1.c21
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_sec-1.c13
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_unnamed-1.c24
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_va-1.c14
-rw-r--r--gcc/testsuite/gcc.dg/format/ms_zero-length-1.c16
-rw-r--r--gcc/testsuite/gcc.dg/format/multattr-1.c17
-rw-r--r--gcc/testsuite/gcc.dg/format/multattr-2.c13
-rw-r--r--gcc/testsuite/gcc.dg/format/null-1.c3
-rwxr-xr-xgcc/testsuite/gcc.dg/format/sys_format.c14
-rw-r--r--gcc/testsuite/gcc.dg/pr30957-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr35616.c43
-rw-r--r--gcc/testsuite/gcc.dg/sms-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/forwprop-4.c18
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/loop-19.c2
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-16.c18
-rw-r--r--gcc/testsuite/gcc.dg/uninit-15.c17
-rw-r--r--gcc/testsuite/gcc.dg/uninit-16.c22
-rw-r--r--gcc/testsuite/gcc.dg/var-expand1.c2
-rw-r--r--gcc/testsuite/gcc.dg/var-expand3.c2
-rw-r--r--gcc/testsuite/gcc.target/i386/pr14552.c16
-rw-r--r--gcc/testsuite/gcc.target/ia64/visibility-1.c6
-rw-r--r--gcc/testsuite/gfortran.dg/argument_checking_16.f909
-rw-r--r--gcc/testsuite/gfortran.dg/internal_pack_1.f9085
-rw-r--r--gcc/testsuite/gfortran.dg/internal_pack_2.f9025
-rw-r--r--gcc/testsuite/gfortran.dg/internal_pack_3.f9021
-rw-r--r--gcc/testsuite/gfortran.dg/namelist_45.f9018
-rw-r--r--gcc/testsuite/gfortran.dg/namelist_46.f9023
97 files changed, 2733 insertions, 85 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 10ead70ab01..cee836cc8a3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,156 @@
+2008-03-20 Kai Tietz <kai.tietz@onevision.com>
+
+ * gcc.dg/format/ms_array-1.c: New.
+ * gcc.dg/format/ms_c90-scanf-3.c: New.
+ * gcc.dg/format/ms_c99-strftime-1.c: New.
+ * gcc.dg/format/ms_no-y2k-1.c: New.
+ * gcc.dg/format/ms_attr-1.c: New.
+ * gcc.dg/format/ms_c90-scanf-4.c: New.
+ * gcc.dg/format/ms_c99-strftime-2.c: New.
+ * gcc.dg/format/ms_nonlit-1.c: New.
+ * gcc.dg/format/ms_c90-scanf-5.c: New.
+ * gcc.dg/format/ms_cast-1.c: New.
+ * gcc.dg/format/ms_nonlit-2.c: New.
+ * gcc.dg/format/ms_attr-2.c: New.
+ * gcc.dg/format/ms_c90-strftime-1.c: New.
+ * gcc.dg/format/ms_miss-1.c: New.
+ * gcc.dg/format/ms_nonlit-3.c: New.
+ * gcc.dg/format/ms_attr-3.c: New.
+ * gcc.dg/format/ms_c90-strftime-2.c: New.
+ * gcc.dg/format/ms_miss-2.c: New.
+ * gcc.dg/format/ms_nul-1.c: New.
+ * gcc.dg/format/ms_attr-4.c: New.
+ * gcc.dg/format/ms_c94-printf-1.c: New.
+ * gcc.dg/format/ms_miss-3.c: New.
+ * gcc.dg/format/ms_nul-2.c: New.
+ * gcc.dg/format/ms_attr-7.c: New.
+ * gcc.dg/format/ms_c94-scanf-1.c: New.
+ * gcc.dg/format/ms_miss-4.c: New.
+ * gcc.dg/format/ms_null-1.c: New.
+ * gcc.dg/format/ms_bitfld-1.c: New.
+ * gcc.dg/format/ms_c99-printf-1.c: New.
+ * gcc.dg/format/ms_miss-5.c: New.
+ * gcc.dg/format/ms_plus-1.c: New.
+ * gcc.dg/format/ms_branch-1.c: New.
+ * gcc.dg/format/ms_c99-printf-2.c: New.
+ * gcc.dg/format/ms_miss-6.c: New.
+ * gcc.dg/format/ms_sec-1.c: New.
+ * gcc.dg/format/ms_c90-printf-1.c: New.
+ * gcc.dg/format/ms_c99-printf-3.c: New.
+ * gcc.dg/format/ms_multattr-1.c: New.
+ * gcc.dg/format/ms_unnamed-1.c: New.
+ * gcc.dg/format/ms_c90-printf-2.c: New.
+ * gcc.dg/format/ms_c99-scanf-1.c: New.
+ * gcc.dg/format/ms_multattr-2.c: New.
+ * gcc.dg/format/ms_va-1.c: New.
+ * gcc.dg/format/ms_c90-printf-3.c: New.
+ * gcc.dg/format/ms_c99-scanf-2.c: New.
+ * gcc.dg/format/ms_multattr-3.c: New.
+ * gcc.dg/format/ms_c90-scanf-1.c: New.
+ * gcc.dg/format/ms_c99-scanf-3.c: New.
+ * gcc.dg/format/ms_no-exargs-1.c: New.
+ * gcc.dg/format/ms_zero-length-1.c: New.
+ * gcc.dg/format/ms_c90-scanf-2.c: New.
+ * gcc.dg/format/ms_c99-scanf-4.c: New.
+ * gcc.dg/format/ms_no-exargs-2.c: New.
+ * gcc.dg/format/null-1.c: Add gnu style usage for mingw.
+ * gcc.dg/format/miss-1.c: Likewise.
+ * gcc.dg/format/miss-3.c: Likewise.
+ * gcc.dg/format/multattr-2.c: Likewise.
+ * gcc.dg/format/miss-5.c: Likewise.
+ * gcc.dg/format/attr-2.c: Likewise.
+ * gcc.dg/format/attr-4.c: Likewise.
+ * gcc.dg/format/c90-scanf-4.c: Likewise.
+ * gcc.dg/format/c99-printf-3.c: Likewise.
+ * gcc.dg/format/multattr-1.c: Likewise.
+ * gcc.dg/format/miss-4.c: Likewise.
+ * gcc.dg/format/miss-6.c: Likewise.
+ * gcc.dg/format/c90-printf-3.c: Likewise.
+ * gcc.dg/format/attr-1.c: Likewise.
+ * gcc.dg/format/attr-3.c: Likewise.
+ * gcc.dg/format/attr-7.c: Likewise.
+ * gcc.dg/format/format.h: Treat mingw and gnu style.
+ * gcc.dg/format/sys_format.c: New.
+
+2008-03-19 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR libfortran/35627
+ * gfortran.dg/namelist_46.f90: New test.
+
+2008-03-20 Uros Bizjak <ubizjak@gmail.com>
+
+ PR target/14552
+ * gcc.target/i386/pr14552.c: New test.
+
+2008-03-19 Michael Matz <matz@suse.de>
+
+ PR middle-end/35616
+ * gcc.dg/pr35616.c: New test.
+
+2008-03-19 Daniel Franke <franke.daniel@gmail.com>
+
+ PR fortran/35152
+ * gfortran.dg/argument_checking_16.f90: New test.
+
+2008-03-19 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR libfortran/32972
+ * gfortran.dg/internal_pack_1.f90: New test case.
+ * gfortran.dg/internal_pack_2.f90: New test case.
+ * gfortran.dg/internal_pack_3.f90: New test case.
+
+2008-03-19 Jan Hubicka <jh@suse.cz>
+
+ * gcc.dg/20050811-2.c: Update dumping flags.
+ * gcc.dg/sms-2.c: Update dumping flags.
+ * gcc.dg/var-expand1.c: Update dumping flags.
+ * gcc.dg/var-expand3.c: Update dumping flags.
+ * gcc.dg/pr30957-1.c: Update dumping flags.
+ * gcc.dg/20050811-1.c: Update dumping flags.
+ * gcc.dg/cpp/cmdlne-dI-M.C: Do not xfail.
+ * gcc.dg/cpp/cmdlne-dM-M.C: Do not xfail.
+
+2008-03-19 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/35609
+ * gcc.dg/testsuite/uninit-15.c: New testcase.
+ * gcc.dg/testsuite/uninit-16.c: Likewise.
+
+2008-03-18 Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
+
+ PR target/35504
+ * g++.dg/other/pr35504.C: New test.
+
+2008-03-18 Richard Guenther <rguenther@suse.de>
+
+ * gcc.dg/tree-ssa/forwprop-4.c: New testcase.
+ * gcc.dg/tree-ssa/ssa-fre-16.c: Likewise.
+
+2008-03-18 Richard Guenther <rguenther@suse.de>
+
+ * gcc.dg/tree-ssa/loop-19.c: Revert previous change.
+
+2008-03-17 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR libfortran/35617
+ * gfortran.dg/namelist_45.f90: New test.
+
+2008-03-17 James E. Wilson <wilson@tuliptree.org>
+
+ PR testsuite/35512
+ * gcc.target/ia64/visibility-1.c (foo): Change return type to void.
+ Write variables instead of reading them.
+
+2008-03-17 Jason Merrill <jason@redhat.com>
+
+ PR c++/35548
+ * g++.dg/init/ref16.C: New testcase.
+
+2008-03-17 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/19637
+ * g++.dg/tree-ssa/pr19637.C: New testcase.
+
2008-03-16 Paul Thomas <pault@gcc.gnu.org>
PR fortran/35470
diff --git a/gcc/testsuite/g++.dg/init/ref16.C b/gcc/testsuite/g++.dg/init/ref16.C
new file mode 100644
index 00000000000..2d56395cb63
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/ref16.C
@@ -0,0 +1,23 @@
+// PR c++/35548
+// { dg-do run }
+
+int c;
+struct A
+{
+ A() { ++c; }
+ A(const A&) { ++c; }
+ ~A() { --c; }
+};
+
+A f()
+{
+ return A();
+}
+
+int i;
+const A* ap;
+int main()
+{
+ const A& ar = i ? *ap : f();
+ return (c == 0);
+}
diff --git a/gcc/testsuite/g++.dg/other/pr35504.C b/gcc/testsuite/g++.dg/other/pr35504.C
new file mode 100644
index 00000000000..09c13fd08a7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/pr35504.C
@@ -0,0 +1,147 @@
+// { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } }
+
+#define ATTR0 __attribute__((__regparm__(0)))
+#define ATTR1 __attribute__((__regparm__(1)))
+#define ATTR2 __attribute__((__regparm__(2)))
+#define ATTR3 __attribute__((__regparm__(3)))
+#define ATTR4 __attribute__((__fastcall__))
+#define ATTR5 __attribute__((__stdcall__))
+#define ATTR6 __attribute__((__cdecl__))
+#define ATTR7
+
+extern "C" void abort (void);
+
+struct long_struct
+{
+ int a[3];
+};
+
+struct long_struct ret;
+
+class c3 *this3;
+
+class c1
+{
+ int val1;
+public:
+ virtual void foo () { }
+};
+
+class c2
+{
+public:
+ virtual ATTR0 struct long_struct method0 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR1 struct long_struct method1 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR2 struct long_struct method2 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR3 struct long_struct method3 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR4 struct long_struct method4 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR5 struct long_struct method5 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR6 struct long_struct method6 ()
+ {
+ return ret;
+ }
+
+ virtual ATTR7 struct long_struct method7 ()
+ {
+ return ret;
+ }
+};
+
+class c3:c1, public c2
+{
+public:
+ c3 ()
+ {
+ this3 = this;
+ }
+
+ struct long_struct check_this (int a)
+ {
+ if (this3 != this)
+ abort ();
+
+ return ret;
+ }
+
+ virtual ATTR0 struct long_struct method0 ()
+ {
+ return check_this (0);
+ }
+
+ virtual ATTR1 struct long_struct method1 ()
+ {
+ return check_this (1);
+ }
+
+ virtual ATTR2 struct long_struct method2 ()
+ {
+ return check_this (2);
+ }
+
+ virtual ATTR3 struct long_struct method3 ()
+ {
+ return check_this (3);
+ }
+
+ virtual ATTR4 struct long_struct method4 ()
+ {
+ return check_this (4);
+ }
+
+ virtual ATTR5 struct long_struct method5 ()
+ {
+ return check_this (5);
+ }
+
+ virtual ATTR6 struct long_struct method6 ()
+ {
+ return check_this (6);
+ }
+
+ virtual ATTR7 struct long_struct method7 ()
+ {
+ return check_this (7);
+ }
+};
+
+class c3 c3_instance;
+class c2 *c2_ptr = &c3_instance;
+
+int
+main ()
+{
+ c2_ptr->method0 ();
+ c2_ptr->method1 ();
+ c2_ptr->method2 ();
+ c2_ptr->method3 ();
+ c2_ptr->method4 ();
+ c2_ptr->method5 ();
+ c2_ptr->method6 ();
+ c2_ptr->method7 ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr19637.C b/gcc/testsuite/g++.dg/tree-ssa/pr19637.C
new file mode 100644
index 00000000000..2d1dcceba42
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr19637.C
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dom1" } */
+
+#include <new>
+
+struct Foo {
+ Foo() { i[0] = 1; }
+ int i[2];
+};
+
+int foo_char(void)
+{
+ int i[2];
+ new (reinterpret_cast<char *>(i)) Foo();
+ return reinterpret_cast<Foo *>(i)->i[0];
+}
+
+int foo_void(void)
+{
+ int i[2];
+ new (reinterpret_cast<void *>(i)) Foo();
+ return reinterpret_cast<Foo *>(i)->i[0];
+}
+
+int foo_void_offset(void)
+{
+ int i[2];
+ new (reinterpret_cast<void *>(&i[0])) Foo();
+ return reinterpret_cast<Foo *>(&i[0])->i[0];
+}
+
+/* { dg-final { scan-tree-dump-times "return 1;" 3 "dom1" } } */
+/* { dg-final { cleanup-tree-dump "dom1" } } */
diff --git a/gcc/testsuite/gcc.dg/20050811-1.c b/gcc/testsuite/gcc.dg/20050811-1.c
index cfc181692c1..a9f860bb8bd 100644
--- a/gcc/testsuite/gcc.dg/20050811-1.c
+++ b/gcc/testsuite/gcc.dg/20050811-1.c
@@ -1,6 +1,6 @@
-/* Test whether -dav doesn't crash. */
+/* Test whether -dv -fdump-rtl-all doesn't crash. */
/* { dg-do compile } */
-/* { dg-options "-O2 -dav" } */
+/* { dg-options "-O2 -dv -fdump-rtl-all" } */
int foo (void)
{
diff --git a/gcc/testsuite/gcc.dg/20050811-2.c b/gcc/testsuite/gcc.dg/20050811-2.c
index 2f1d48b350e..ffd1f390498 100644
--- a/gcc/testsuite/gcc.dg/20050811-2.c
+++ b/gcc/testsuite/gcc.dg/20050811-2.c
@@ -1,6 +1,6 @@
/* Test whether -dov doesn't crash. */
/* { dg-do compile } */
-/* { dg-options "-O2 -dov" } */
+/* { dg-options "-O2 -dv -fdump-rtl-postreload" } */
int foo (void)
{
diff --git a/gcc/testsuite/gcc.dg/cpp/cmdlne-dI-M.c b/gcc/testsuite/gcc.dg/cpp/cmdlne-dI-M.c
index c003d5ade98..a30b4bc12db 100644
--- a/gcc/testsuite/gcc.dg/cpp/cmdlne-dI-M.c
+++ b/gcc/testsuite/gcc.dg/cpp/cmdlne-dI-M.c
@@ -13,4 +13,4 @@ int variable;
/* { dg-final { scan-file-not cmdlne-dI-M.i "(^|\\n)#define foo bar($|\\n)" } }
{ dg-final { scan-file-not cmdlne-dI-M.i "variable" } }
- { dg-final { scan-file cmdlne-dI-M.i "(^|\\n)cmdlne-dI-M.*:\[^\\n\]*cmdlne-dI-M.c" { xfail *-*-* } } } */
+ { dg-final { scan-file cmdlne-dI-M.i "(^|\\n)cmdlne-dI-M.*:\[^\\n\]*cmdlne-dI-M.c" } } */
diff --git a/gcc/testsuite/gcc.dg/cpp/cmdlne-dM-M.c b/gcc/testsuite/gcc.dg/cpp/cmdlne-dM-M.c
index fb21f40f408..193168e940f 100644
--- a/gcc/testsuite/gcc.dg/cpp/cmdlne-dM-M.c
+++ b/gcc/testsuite/gcc.dg/cpp/cmdlne-dM-M.c
@@ -12,4 +12,4 @@ int variable;
/* { dg-final { scan-file cmdlne-dM-M.i "(^|\\n)#define foo bar($|\\n)" } }
{ dg-final { scan-file-not cmdlne-dM-M.i "variable" } }
- { dg-final { scan-file cmdlne-dM-M.i "(^|\\n)cmdlne-dM-M\[^\\n\]*:\[^\\n\]*cmdlne-dM-M.c" { xfail *-*-* } } } */
+ { dg-final { scan-file cmdlne-dM-M.i "(^|\\n)cmdlne-dM-M\[^\\n\]*:\[^\\n\]*cmdlne-dM-M.c"} } */
diff --git a/gcc/testsuite/gcc.dg/format/attr-1.c b/gcc/testsuite/gcc.dg/format/attr-1.c
index b92c67a81e7..8b2f5b7a357 100644
--- a/gcc/testsuite/gcc.dg/format/attr-1.c
+++ b/gcc/testsuite/gcc.dg/format/attr-1.c
@@ -3,7 +3,8 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
-extern void foo0 (const char *) __attribute__((__format__(__strftime__, 1, 0)));
-extern void foo1 (const char *, ...) __attribute__((__format__(__strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
+extern void foo0 (const char *) __attribute__((__format__(gnu_attr___strftime__, 1, 0)));
+extern void foo1 (const char *, ...) __attribute__((__format__(gnu_attr___strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
diff --git a/gcc/testsuite/gcc.dg/format/attr-2.c b/gcc/testsuite/gcc.dg/format/attr-2.c
index 54d4655ef2c..f560ed06bb1 100644
--- a/gcc/testsuite/gcc.dg/format/attr-2.c
+++ b/gcc/testsuite/gcc.dg/format/attr-2.c
@@ -3,22 +3,23 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
-extern void tformatprintf (const char *, ...) __attribute__((format(printf, 1, 2)));
-extern void tformat__printf__ (const char *, ...) __attribute__((format(__printf__, 1, 2)));
-extern void tformatscanf (const char *, ...) __attribute__((format(scanf, 1, 2)));
-extern void tformat__scanf__ (const char *, ...) __attribute__((format(__scanf__, 1, 2)));
-extern void tformatstrftime (const char *) __attribute__((format(strftime, 1, 0)));
-extern void tformat__strftime__ (const char *) __attribute__((format(__strftime__, 1, 0)));
+extern void tformatprintf (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
+extern void tformat__printf__ (const char *, ...) __attribute__((format(gnu_attr___printf__, 1, 2)));
+extern void tformatscanf (const char *, ...) __attribute__((format(gnu_attr_scanf, 1, 2)));
+extern void tformat__scanf__ (const char *, ...) __attribute__((format(gnu_attr___scanf__, 1, 2)));
+extern void tformatstrftime (const char *) __attribute__((format(gnu_attr_strftime, 1, 0)));
+extern void tformat__strftime__ (const char *) __attribute__((format(gnu_attr___strftime__, 1, 0)));
extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2)));
extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2)));
-extern void t__format__printf (const char *, ...) __attribute__((__format__(printf, 1, 2)));
-extern void t__format____printf__ (const char *, ...) __attribute__((__format__(__printf__, 1, 2)));
-extern void t__format__scanf (const char *, ...) __attribute__((__format__(scanf, 1, 2)));
-extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(__scanf__, 1, 2)));
-extern void t__format__strftime (const char *) __attribute__((__format__(strftime, 1, 0)));
-extern void t__format____strftime__ (const char *) __attribute__((__format__(__strftime__, 1, 0)));
+extern void t__format__printf (const char *, ...) __attribute__((__format__(gnu_attr_printf, 1, 2)));
+extern void t__format____printf__ (const char *, ...) __attribute__((__format__(gnu_attr___printf__, 1, 2)));
+extern void t__format__scanf (const char *, ...) __attribute__((__format__(gnu_attr_scanf, 1, 2)));
+extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(gnu_attr___scanf__, 1, 2)));
+extern void t__format__strftime (const char *) __attribute__((__format__(gnu_attr_strftime, 1, 0)));
+extern void t__format____strftime__ (const char *) __attribute__((__format__(gnu_attr___strftime__, 1, 0)));
extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2)));
extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2)));
diff --git a/gcc/testsuite/gcc.dg/format/attr-3.c b/gcc/testsuite/gcc.dg/format/attr-3.c
index 8fc1faa6819..bee5ff4841b 100644
--- a/gcc/testsuite/gcc.dg/format/attr-3.c
+++ b/gcc/testsuite/gcc.dg/format/attr-3.c
@@ -3,20 +3,21 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
/* Proper uses of the attributes. */
-extern void fa0 (const char *, ...) __attribute__((format(printf, 1, 2)));
-extern void fa1 (char *, ...) __attribute__((format(printf, 1, 2)));
+extern void fa0 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
+extern void fa1 (char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
extern char *fa2 (const char *) __attribute__((format_arg(1)));
extern char *fa3 (char *) __attribute__((format_arg(1)));
/* Uses with too few or too many arguments. */
extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */
extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */
-extern void fb2 (const char *, ...) __attribute__((format(printf))); /* { dg-error "wrong number of arguments" "bad format" } */
-extern void fb3 (const char *, ...) __attribute__((format(printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
-extern void fb4 (const char *, ...) __attribute__((format(printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb2 (const char *, ...) __attribute__((format(gnu_attr_printf))); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb4 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */
extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */
@@ -25,9 +26,9 @@ extern void fc3 (const char *) __attribute__((format_arg(1, 2))); /* { dg-error
/* These attributes presently only apply to declarations, not to types.
Eventually, they should be usable with declarators for function types
anywhere, but still not with structure/union/enum types. */
-struct s0 { int i; } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
-union u0 { int i; } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
-enum e0 { E0V0 } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
+struct s0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
+union u0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
+enum e0 { E0V0 } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
struct s1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on struct" } */
union u1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on union" } */
@@ -38,28 +39,28 @@ extern void fe0 (const char *, ...) __attribute__((format(12345, 1, 2))); /* { d
extern void fe1 (const char *, ...) __attribute__((format(nosuch, 1, 2))); /* { dg-warning "format function type" "unknown format" } */
/* Both the numbers must be integer constant expressions. */
-extern void ff0 (const char *, ...) __attribute__((format(printf, 3-2, (long long)(10/5))));
+extern void ff0 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, (long long)(10/5))));
int foo;
-extern void ff1 (const char *, ...) __attribute__((format(printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
-extern void ff2 (const char *, ...) __attribute__((format(printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
+extern void ff1 (const char *, ...) __attribute__((format(gnu_attr_printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
+extern void ff2 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
extern char *ff3 (const char *) __attribute__((format_arg(3-2)));
extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */
/* The format string argument must precede the arguments to be formatted.
This includes if no parameter types are specified (which is not valid ISO
C for variadic functions). */
-extern void fg0 () __attribute__((format(printf, 1, 2)));
-extern void fg1 () __attribute__((format(printf, 1, 0)));
-extern void fg2 () __attribute__((format(printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
-extern void fg3 () __attribute__((format(printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
+extern void fg0 () __attribute__((format(gnu_attr_printf, 1, 2)));
+extern void fg1 () __attribute__((format(gnu_attr_printf, 1, 0)));
+extern void fg2 () __attribute__((format(gnu_attr_printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
+extern void fg3 () __attribute__((format(gnu_attr_printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
/* The format string argument must be a string type, and the arguments to
be formatted must be the "...". */
-extern void fh0 (int, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
-extern void fh1 (signed char *, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
-extern void fh2 (unsigned char *, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
-extern void fh3 (const char *, ...) __attribute__((format(printf, 1, 3))); /* { dg-error "is not" "not ..." } */
-extern void fh4 (const char *, int, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "is not" "not ..." } */
+extern void fh0 (int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
+extern void fh1 (signed char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
+extern void fh2 (unsigned char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
+extern void fh3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 3))); /* { dg-error "is not" "not ..." } */
+extern void fh4 (const char *, int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "is not" "not ..." } */
/* format_arg formats must take and return a string. */
extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */
diff --git a/gcc/testsuite/gcc.dg/format/attr-4.c b/gcc/testsuite/gcc.dg/format/attr-4.c
index ef50c494f35..caeed93a790 100644
--- a/gcc/testsuite/gcc.dg/format/attr-4.c
+++ b/gcc/testsuite/gcc.dg/format/attr-4.c
@@ -4,12 +4,13 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
-extern __attribute__((format(printf, 1, 2))) void tformatprintf0 (const char *, ...);
-extern void __attribute__((format(printf, 1, 2))) tformatprintf1 (const char *, ...);
-extern void foo (void), __attribute__((format(printf, 1, 2))) tformatprintf2 (const char *, ...);
-extern __attribute__((noreturn)) void bar (void), __attribute__((format(printf, 1, 2))) tformatprintf3 (const char *, ...);
+extern __attribute__((format(gnu_attr_printf, 1, 2))) void tformatprintf0 (const char *, ...);
+extern void __attribute__((format(gnu_attr_printf, 1, 2))) tformatprintf1 (const char *, ...);
+extern void foo (void), __attribute__((format(gnu_attr_printf, 1, 2))) tformatprintf2 (const char *, ...);
+extern __attribute__((noreturn)) void bar (void), __attribute__((format(gnu_attr_printf, 1, 2))) tformatprintf3 (const char *, ...);
void
baz (int i, int *ip, double d)
diff --git a/gcc/testsuite/gcc.dg/format/attr-7.c b/gcc/testsuite/gcc.dg/format/attr-7.c
index 78526a5e9bb..c370448193f 100644
--- a/gcc/testsuite/gcc.dg/format/attr-7.c
+++ b/gcc/testsuite/gcc.dg/format/attr-7.c
@@ -3,12 +3,13 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
-__attribute__((format(printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
-void (*tformatprintf1) (const char *, ...) __attribute__((format(printf, 1, 2)));
-void (__attribute__((format(printf, 1, 2))) *tformatprintf2) (const char *, ...);
-void (__attribute__((format(printf, 1, 2))) ****tformatprintf3) (const char *, ...);
+__attribute__((format(gnu_attr_printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
+void (*tformatprintf1) (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
+void (__attribute__((format(gnu_attr_printf, 1, 2))) *tformatprintf2) (const char *, ...);
+void (__attribute__((format(gnu_attr_printf, 1, 2))) ****tformatprintf3) (const char *, ...);
char * (__attribute__((format_arg(1))) *tformat_arg) (const char *);
diff --git a/gcc/testsuite/gcc.dg/format/c90-printf-3.c b/gcc/testsuite/gcc.dg/format/c90-printf-3.c
index 1d53de32f65..bf48f3114e0 100644
--- a/gcc/testsuite/gcc.dg/format/c90-printf-3.c
+++ b/gcc/testsuite/gcc.dg/format/c90-printf-3.c
@@ -3,7 +3,7 @@
do not.
*/
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
-/* { dg-do compile } */
+/* { dg-do compile { target { ! *-*-mingw* } } } */
/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
#include "format.h"
diff --git a/gcc/testsuite/gcc.dg/format/c90-scanf-4.c b/gcc/testsuite/gcc.dg/format/c90-scanf-4.c
index e15dbd22616..0a47f3f3500 100644
--- a/gcc/testsuite/gcc.dg/format/c90-scanf-4.c
+++ b/gcc/testsuite/gcc.dg/format/c90-scanf-4.c
@@ -3,7 +3,7 @@
do not.
*/
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
-/* { dg-do compile } */
+/* { dg-do compile { target { ! *-*-mingw* } } } */
/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
#include "format.h"
diff --git a/gcc/testsuite/gcc.dg/format/c99-printf-3.c b/gcc/testsuite/gcc.dg/format/c99-printf-3.c
index b8ae405b299..2407bb60391 100644
--- a/gcc/testsuite/gcc.dg/format/c99-printf-3.c
+++ b/gcc/testsuite/gcc.dg/format/c99-printf-3.c
@@ -2,7 +2,7 @@
attributes in strict C99 mode, but the gettext functions do not.
*/
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
-/* { dg-do compile } */
+/* { dg-do compile { target { ! *-*-mingw* } } } */
/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
#include "format.h"
diff --git a/gcc/testsuite/gcc.dg/format/format.h b/gcc/testsuite/gcc.dg/format/format.h
index e55d23cd4d3..a99927e3c64 100644
--- a/gcc/testsuite/gcc.dg/format/format.h
+++ b/gcc/testsuite/gcc.dg/format/format.h
@@ -1,6 +1,37 @@
/* Format checking tests: common header. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* DONT_GNU_PROTOTYPE */
+#if defined (_WIN32) && !defined (__CYGWIN__)
+#if !defined (USE_SYSTEM_FORMATS)
+#define gnu_attr_printf gnu_printf
+#define gnu_attr___printf__ __gnu_printf__
+#define gnu_attr_scanf gnu_scanf
+#define gnu_attr___scanf__ __gnu_scanf__
+#define gnu_attr_strftime gnu_strftime
+#define gnu_attr___strftime__ __gnu_strftime__
+#endif
+#endif
+
+#ifndef gnu_attr_printf
+#define gnu_attr_printf printf
+#define gnu_attr___printf__ __printf__
+#define gnu_attr_scanf scanf
+#define gnu_attr___scanf__ __scanf__
+#define gnu_attr_strftime strftime
+#define gnu_attr___strftime__ __strftime__
+#endif
+
+#if !defined (USE_SYSTEM_FORMATS)
+#define USE_PRINTF(FMTPOS, WILDARG) __attribute__((format(gnu_printf, FMTPOS, WILDARG))) __attribute__((nonnull (FMTPOS)))
+#define USE_SCANF(FMTPOS, WILDARG) __attribute__((format(gnu_scanf, FMTPOS, WILDARG))) __attribute__((nonnull (FMTPOS)))
+#define USE_STRFTIME(FMTPOS) __attribute__((__format__(gnu_strftime, FMTPOS, 0))) __attribute__((nonnull (FMTPOS)))
+#else
+#define USE_PRINTF(FMTPOS, WILDARG)
+#define USE_SCANF(FMTPOS, WILDARG)
+#define USE_STRFTIME(FMTPOS)
+#endif
+
#include <stdarg.h>
#include <stddef.h>
@@ -11,6 +42,20 @@
typedef __WINT_TYPE__ wint_t;
#endif
+#ifdef _WIN64
+/* Kludges to get types corresponding to size_t and ptrdiff_t. */
+#define unsigned signed
+typedef signed int signed_size_t __attribute__ ((mode (DI)));
+/* We also use this type to approximate ssize_t. */
+typedef signed int ssize_t __attribute__ ((mode (DI)));
+#undef unsigned
+#define signed /* Type might or might not have explicit 'signed'. */
+typedef unsigned int unsigned_ptrdiff_t __attribute__ ((mode (DI)));
+#undef signed
+
+__extension__ typedef int llong __attribute__ ((mode (DI)));
+__extension__ typedef unsigned int ullong __attribute__ ((mode (DI)));
+#else
/* Kludges to get types corresponding to size_t and ptrdiff_t. */
#define unsigned signed
typedef __SIZE_TYPE__ signed_size_t;
@@ -23,6 +68,7 @@ typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t;
__extension__ typedef long long int llong;
__extension__ typedef unsigned long long int ullong;
+#endif
/* %q formats want a "quad"; GCC considers this to be a long long. */
typedef llong quad_t;
@@ -70,3 +116,77 @@ extern size_t strftime (char *restrict, size_t, const char *restrict,
const struct tm *restrict);
extern ssize_t strfmon (char *restrict, size_t, const char *restrict, ...);
+
+/* Mingw specific part. */
+#if !defined (USE_SYSTEM_FORMATS) && defined(_WIN32) && !defined(DONT_GNU_PROTOTYPE)
+
+extern USE_PRINTF(2,3) int fprintf_gnu (FILE *restrict, const char *restrict, ...);
+#undef fprintf
+#define fprintf fprintf_gnu
+
+extern USE_PRINTF(1,2) int printf_gnu (const char *restrict, ...);
+#undef printf
+#define printf printf_gnu
+
+extern USE_PRINTF(2,3) int fprintf_unlocked_gnu (FILE *restrict, const char *restrict, ...);
+#undef fprintf_unlocked
+#define fprintf_unlocked fprintf_unlocked_gnu
+
+extern USE_PRINTF(1,2)int printf_unlocked_gnu (const char *restrict, ...);
+#undef printf_unlocked
+#define printf_unlocked printf_unlocked_gnu
+
+extern USE_PRINTF(2,3) int sprintf_gnu (char *restrict, const char *restrict, ...);
+#undef sprintf
+#define sprintf sprintf_gnu
+
+extern USE_PRINTF(2,0) int vfprintf_gnu (FILE *restrict, const char *restrict, va_list);
+#undef vsprintf
+#define vsprintf vsprintf_gnu
+
+extern USE_PRINTF(1,0) int vprintf_gnu (const char *restrict, va_list);
+#undef vprintf
+#define vprintf vprintf_gnu
+
+extern USE_PRINTF(2,0) int vsprintf_gnu (char *restrict, const char *restrict, va_list);
+#undef vsprintf
+#define vsprintf vsprintf_gnu
+
+extern USE_PRINTF(3,4) int snprintf_gnu (char *restrict, size_t, const char *restrict, ...);
+#undef snprintf
+#define snprintf snprintf_gnu
+
+extern USE_PRINTF(3,0) int vsnprintf_gnu (char *restrict, size_t, const char *restrict, va_list);
+#undef vsnprintf
+#define vsnprintf vsnprintf_gnu
+
+extern USE_SCANF(2,3) int fscanf_gnu (FILE *restrict, const char *restrict, ...);
+#undef fscanf
+#define fscanf fscanf_gnu
+
+extern USE_SCANF(1,2) int scanf_gnu (const char *restrict, ...);
+#undef scanf
+#define scanf scanf_gnu
+
+extern USE_SCANF(2,3) int sscanf_gnu (const char *restrict, const char *restrict, ...);
+#undef sscanf
+#define sscanf sscanf_gnu
+
+extern USE_SCANF(2,0) int vfscanf_gnu (FILE *restrict, const char *restrict, va_list);
+#undef vfscanf
+#define vfscanf vfscanf_gnu
+
+extern USE_SCANF(1,0) int vscanf_gnu (const char *restrict, va_list);
+#undef vscanf
+#define vscanf vscanf_gnu
+
+extern USE_SCANF(2,0) int vsscanf_gnu (const char *restrict, const char *restrict, va_list);
+#undef vsscanf
+#define vsscanf vsscanf_gnu
+
+extern USE_STRFTIME(3) size_t strftime_gnu (char *restrict, size_t, const char *restrict,
+ const struct tm *restrict);
+#undef strftime
+#define strftime strftime_gnu
+
+#endif
diff --git a/gcc/testsuite/gcc.dg/format/miss-1.c b/gcc/testsuite/gcc.dg/format/miss-1.c
index 839f2963ae7..3d4b99124ef 100644
--- a/gcc/testsuite/gcc.dg/format/miss-1.c
+++ b/gcc/testsuite/gcc.dg/format/miss-1.c
@@ -23,7 +23,7 @@ bar (const char *fmt, ...)
va_end (ap);
}
-__attribute__((__format__(__printf__, 1, 2))) void
+__attribute__((__format__(gnu_attr___printf__, 1, 2))) void
foo2 (const char *fmt, ...)
{
va_list ap;
diff --git a/gcc/testsuite/gcc.dg/format/miss-3.c b/gcc/testsuite/gcc.dg/format/miss-3.c
index c588bed3519..e9cf19d1f0a 100644
--- a/gcc/testsuite/gcc.dg/format/miss-3.c
+++ b/gcc/testsuite/gcc.dg/format/miss-3.c
@@ -3,13 +3,14 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
typedef void (*noattr_t) (const char *, ...);
-typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
+typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
typedef void (*vnoattr_t) (const char *, va_list);
-typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
+typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
void
foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
@@ -18,7 +19,7 @@ foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
noattr_t na2 = a; /* { dg-warning "candidate" "initialization warning" } */
attr_t a1 = na;
attr_t a2 = a;
-
+
vnoattr_t vna1 = vna;
vnoattr_t vna2 = va; /* { dg-warning "candidate" "initialization warning" } */
vattr_t va1 = vna;
diff --git a/gcc/testsuite/gcc.dg/format/miss-4.c b/gcc/testsuite/gcc.dg/format/miss-4.c
index 9be5e4df4e5..f6cfd64cdbf 100644
--- a/gcc/testsuite/gcc.dg/format/miss-4.c
+++ b/gcc/testsuite/gcc.dg/format/miss-4.c
@@ -3,20 +3,21 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
typedef void (*noattr_t) (const char *, ...);
-typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
+typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
typedef void (*vnoattr_t) (const char *, va_list);
-typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
+typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
void
foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
{
noattr_t na1, na2;
attr_t a1, a2;
-
+
vnoattr_t vna1, vna2;
vattr_t va1, va2;
@@ -24,7 +25,7 @@ foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
na2 = a; /* { dg-warning "candidate" "assignment warning" } */
a1 = na;
a2 = a;
-
+
vna1 = vna;
vna2 = va; /* { dg-warning "candidate" "assignment warning" } */
va1 = vna;
diff --git a/gcc/testsuite/gcc.dg/format/miss-5.c b/gcc/testsuite/gcc.dg/format/miss-5.c
index eaf1473ddc1..1706e369b02 100644
--- a/gcc/testsuite/gcc.dg/format/miss-5.c
+++ b/gcc/testsuite/gcc.dg/format/miss-5.c
@@ -3,13 +3,14 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
typedef void (*noattr_t) (const char *, ...);
-typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
+typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
typedef void (*vnoattr_t) (const char *, va_list);
-typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
+typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
noattr_t
foo1 (noattr_t na, attr_t a, int i)
diff --git a/gcc/testsuite/gcc.dg/format/miss-6.c b/gcc/testsuite/gcc.dg/format/miss-6.c
index abe221f917f..77e287465e8 100644
--- a/gcc/testsuite/gcc.dg/format/miss-6.c
+++ b/gcc/testsuite/gcc.dg/format/miss-6.c
@@ -3,13 +3,14 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
typedef void (*noattr_t) (const char *, ...);
-typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
+typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
typedef void (*vnoattr_t) (const char *, va_list);
-typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
+typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
extern void foo1 (noattr_t);
extern void foo2 (attr_t);
@@ -23,7 +24,7 @@ foo (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
foo1 (a); /* { dg-warning "candidate" "parameter passing warning" } */
foo2 (na);
foo2 (a);
-
+
foo3 (vna);
foo3 (va); /* { dg-warning "candidate" "parameter passing warning" } */
foo4 (vna);
diff --git a/gcc/testsuite/gcc.dg/format/ms_array-1.c b/gcc/testsuite/gcc.dg/format/ms_array-1.c
new file mode 100644
index 00000000000..b34506830bb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_array-1.c
@@ -0,0 +1,42 @@
+/* Test for format checking of constant arrays. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat=2" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+const char a1[] = "foo";
+const char a2[] = "foo%d";
+const char b1[3] = "foo";
+const char b2[1] = "1";
+static const char c1[] = "foo";
+static const char c2[] = "foo%d";
+char d[] = "foo";
+volatile const char e[] = "foo";
+
+void
+foo (int i, long l)
+{
+ const char p1[] = "bar";
+ const char p2[] = "bar%d";
+ static const char q1[] = "bar";
+ static const char q2[] = "bar%d";
+ printf (a1);
+ printf (a2, i);
+ printf (a2, l); /* { dg-warning "format" "wrong type with array" } */
+ printf (b1); /* { dg-warning "unterminated" "unterminated array" } */
+ printf (b2); /* { dg-warning "unterminated" "unterminated array" } */
+ printf (c1);
+ printf (c2, i);
+ printf (c2, l); /* { dg-warning "format" "wrong type with array" } */
+ printf (p1);
+ printf (p2, i);
+ printf (p2, l); /* { dg-warning "format" "wrong type with array" } */
+ printf (q1);
+ printf (q2, i);
+ printf (q2, l); /* { dg-warning "format" "wrong type with array" } */
+ /* Volatile or non-constant arrays must not be checked. */
+ printf (d); /* { dg-warning "not a string literal" "non-const" } */
+ printf ((const char *)e); /* { dg-warning "not a string literal" "volatile" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_attr-1.c b/gcc/testsuite/gcc.dg/format/ms_attr-1.c
new file mode 100644
index 00000000000..90709bb1fb0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_attr-1.c
@@ -0,0 +1,10 @@
+/* Test for strftime format attributes: can't have first_arg_num != 0. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define DONT_GNU_PROTOTYPE
+#include "format.h"
+
+extern void foo0 (const char *) __attribute__((__format__(__ms_strftime__, 1, 0)));
+extern void foo1 (const char *, ...) __attribute__((__format__(__ms_strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
diff --git a/gcc/testsuite/gcc.dg/format/ms_attr-2.c b/gcc/testsuite/gcc.dg/format/ms_attr-2.c
new file mode 100644
index 00000000000..9a9ce0fe355
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_attr-2.c
@@ -0,0 +1,68 @@
+/* Test for format attributes: test use of __attribute__. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define DONT_GNU_PROTOTYPE
+#include "format.h"
+
+extern void tformatprintf (const char *, ...) __attribute__((format(ms_printf, 1, 2)));
+extern void tformat__printf__ (const char *, ...) __attribute__((format(__ms_printf__, 1, 2)));
+extern void tformatscanf (const char *, ...) __attribute__((format(ms_scanf, 1, 2)));
+extern void tformat__scanf__ (const char *, ...) __attribute__((format(__ms_scanf__, 1, 2)));
+extern void tformatstrftime (const char *) __attribute__((format(ms_strftime, 1, 0)));
+extern void tformat__strftime__ (const char *) __attribute__((format(__ms_strftime__, 1, 0)));
+extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2)));
+extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2)));
+extern void t__format__printf (const char *, ...) __attribute__((__format__(ms_printf, 1, 2)));
+extern void t__format____printf__ (const char *, ...) __attribute__((__format__(__ms_printf__, 1, 2)));
+extern void t__format__scanf (const char *, ...) __attribute__((__format__(ms_scanf, 1, 2)));
+extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(__ms_scanf__, 1, 2)));
+extern void t__format__strftime (const char *) __attribute__((__format__(ms_strftime, 1, 0)));
+extern void t__format____strftime__ (const char *) __attribute__((__format__(__ms_strftime__, 1, 0)));
+extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2)));
+extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2)));
+
+extern char *tformat_arg (const char *) __attribute__((format_arg(1)));
+extern char *t__format_arg__ (const char *) __attribute__((__format_arg__(1)));
+
+void
+foo (int i, int *ip, double d)
+{
+ tformatprintf ("%d", i);
+ tformatprintf ("%"); /* { dg-warning "format" "attribute format printf" } */
+ tformat__printf__ ("%d", i);
+ tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */
+ tformatscanf ("%d", ip);
+ tformatscanf ("%"); /* { dg-warning "format" "attribute format scanf" } */
+ tformat__scanf__ ("%d", ip);
+ tformat__scanf__ ("%"); /* { dg-warning "format" "attribute format __scanf__" } */
+ tformatstrftime ("%a");
+ tformatstrftime ("%"); /* { dg-warning "format" "attribute format strftime" } */
+ tformat__strftime__ ("%a");
+ tformat__strftime__ ("%"); /* { dg-warning "format" "attribute format __strftime__" } */
+ tformatstrfmon ("%n", d);
+ tformatstrfmon ("%"); /* { dg-warning "format" "attribute format strfmon" } */
+ tformat__strfmon__ ("%n", d);
+ tformat__strfmon__ ("%"); /* { dg-warning "format" "attribute format __strfmon__" } */
+ t__format__printf ("%d", i);
+ t__format__printf ("%"); /* { dg-warning "format" "attribute __format__ printf" } */
+ t__format____printf__ ("%d", i);
+ t__format____printf__ ("%"); /* { dg-warning "format" "attribute __format__ __printf__" } */
+ t__format__scanf ("%d", ip);
+ t__format__scanf ("%"); /* { dg-warning "format" "attribute __format__ scanf" } */
+ t__format____scanf__ ("%d", ip);
+ t__format____scanf__ ("%"); /* { dg-warning "format" "attribute __format__ __scanf__" } */
+ t__format__strftime ("%a");
+ t__format__strftime ("%"); /* { dg-warning "format" "attribute __format__ strftime" } */
+ t__format____strftime__ ("%a");
+ t__format____strftime__ ("%"); /* { dg-warning "format" "attribute __format__ __strftime__" } */
+ t__format__strfmon ("%n", d);
+ t__format__strfmon ("%"); /* { dg-warning "format" "attribute __format__ strfmon" } */
+ t__format____strfmon__ ("%n", d);
+ t__format____strfmon__ ("%"); /* { dg-warning "format" "attribute __format__ __strfmon__" } */
+ tformatprintf (tformat_arg ("%d"), i);
+ tformatprintf (tformat_arg ("%")); /* { dg-warning "format" "attribute format_arg" } */
+ tformatprintf (t__format_arg__ ("%d"), i);
+ tformatprintf (t__format_arg__ ("%")); /* { dg-warning "format" "attribute __format_arg__" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_attr-3.c b/gcc/testsuite/gcc.dg/format/ms_attr-3.c
new file mode 100644
index 00000000000..5341dd8164b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_attr-3.c
@@ -0,0 +1,71 @@
+/* Test for format attributes: test bad uses of __attribute__. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+/* Proper uses of the attributes. */
+extern void fa0 (const char *, ...) __attribute__((format(ms_printf, 1, 2)));
+extern void fa1 (char *, ...) __attribute__((format(ms_printf, 1, 2)));
+extern char *fa2 (const char *) __attribute__((format_arg(1)));
+extern char *fa3 (char *) __attribute__((format_arg(1)));
+
+/* Uses with too few or too many arguments. */
+extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb2 (const char *, ...) __attribute__((format(ms_printf))); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb3 (const char *, ...) __attribute__((format(ms_printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
+extern void fb4 (const char *, ...) __attribute__((format(ms_printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
+
+extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */
+extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */
+extern void fc3 (const char *) __attribute__((format_arg(1, 2))); /* { dg-error "wrong number of arguments" "bad format_arg" } */
+
+/* These attributes presently only apply to declarations, not to types.
+ Eventually, they should be usable with declarators for function types
+ anywhere, but still not with structure/union/enum types. */
+struct s0 { int i; } __attribute__((format(ms_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
+union u0 { int i; } __attribute__((format(ms_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
+enum e0 { E0V0 } __attribute__((format(ms_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
+
+struct s1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on struct" } */
+union u1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on union" } */
+enum e1 { E1V0 } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on enum" } */
+
+/* The format type must be an identifier, one of those recognized. */
+extern void fe0 (const char *, ...) __attribute__((format(12345, 1, 2))); /* { dg-error "format specifier" "non-id format" } */
+extern void fe1 (const char *, ...) __attribute__((format(nosuch, 1, 2))); /* { dg-warning "format function type" "unknown format" } */
+
+/* Both the numbers must be integer constant expressions. */
+extern void ff0 (const char *, ...) __attribute__((format(ms_printf, 3-2, (long long)(10/5))));
+int foo;
+extern void ff1 (const char *, ...) __attribute__((format(ms_printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
+extern void ff2 (const char *, ...) __attribute__((format(ms_printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
+extern char *ff3 (const char *) __attribute__((format_arg(3-2)));
+extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */
+
+/* The format string argument must precede the arguments to be formatted.
+ This includes if no parameter types are specified (which is not valid ISO
+ C for variadic functions). */
+extern void fg0 () __attribute__((format(ms_printf, 1, 2)));
+extern void fg1 () __attribute__((format(ms_printf, 1, 0)));
+extern void fg2 () __attribute__((format(ms_printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
+extern void fg3 () __attribute__((format(ms_printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
+
+/* The format string argument must be a string type, and the arguments to
+ be formatted must be the "...". */
+extern void fh0 (int, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
+extern void fh1 (signed char *, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
+extern void fh2 (unsigned char *, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
+extern void fh3 (const char *, ...) __attribute__((format(ms_printf, 1, 3))); /* { dg-error "is not" "not ..." } */
+extern void fh4 (const char *, int, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "is not" "not ..." } */
+
+/* format_arg formats must take and return a string. */
+extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */
+extern char *fi1 (signed char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg signed char string" } */
+extern char *fi2 (unsigned char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg unsigned char string" } */
+extern int fi3 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret int string" } */
+extern signed char *fi4 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret signed char string" } */
+extern unsigned char *fi5 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret unsigned char string" } */
diff --git a/gcc/testsuite/gcc.dg/format/ms_attr-4.c b/gcc/testsuite/gcc.dg/format/ms_attr-4.c
new file mode 100644
index 00000000000..45f09ef2278
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_attr-4.c
@@ -0,0 +1,26 @@
+/* Test for format attributes: test use of __attribute__
+ in prefix attributes. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+extern __attribute__((format(ms_printf, 1, 2))) void tformatprintf0 (const char *, ...);
+extern void __attribute__((format(ms_printf, 1, 2))) tformatprintf1 (const char *, ...);
+extern void foo (void), __attribute__((format(ms_printf, 1, 2))) tformatprintf2 (const char *, ...);
+extern __attribute__((noreturn)) void bar (void), __attribute__((format(ms_printf, 1, 2))) tformatprintf3 (const char *, ...);
+
+void
+baz (int i, int *ip, double d)
+{
+ tformatprintf0 ("%d", i);
+ tformatprintf0 ("%"); /* { dg-warning "format" "attribute format printf case 0" } */
+ tformatprintf1 ("%d", i);
+ tformatprintf1 ("%"); /* { dg-warning "format" "attribute format printf case 1" } */
+ tformatprintf2 ("%d", i);
+ tformatprintf2 ("%"); /* { dg-warning "format" "attribute format printf case 2" } */
+ tformatprintf3 ("%d", i);
+ tformatprintf3 ("%"); /* { dg-warning "format" "attribute format printf case 3" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_attr-7.c b/gcc/testsuite/gcc.dg/format/ms_attr-7.c
new file mode 100644
index 00000000000..b169e2c3ab5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_attr-7.c
@@ -0,0 +1,35 @@
+/* Test for format attributes: test applying them to types. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define DONT_GNU_PROTOTYPE
+#include "format.h"
+
+__attribute__((format(ms_printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
+void (*tformatprintf1) (const char *, ...) __attribute__((format(ms_printf, 1, 2)));
+void (__attribute__((format(ms_printf, 1, 2))) *tformatprintf2) (const char *, ...);
+void (__attribute__((format(ms_printf, 1, 2))) ****tformatprintf3) (const char *, ...);
+
+char * (__attribute__((format_arg(1))) *tformat_arg) (const char *);
+
+void
+baz (int i)
+{
+ (*tformatprintf0) ("%d", i);
+ (*tformatprintf0) ((*tformat_arg) ("%d"), i);
+ (*tformatprintf0) ("%"); /* { dg-warning "format" "prefix" } */
+ (*tformatprintf0) ((*tformat_arg) ("%")); /* { dg-warning "format" "prefix" } */
+ (*tformatprintf1) ("%d", i);
+ (*tformatprintf1) ((*tformat_arg) ("%d"), i);
+ (*tformatprintf1) ("%"); /* { dg-warning "format" "postfix" } */
+ (*tformatprintf1) ((*tformat_arg) ("%")); /* { dg-warning "format" "postfix" } */
+ (*tformatprintf2) ("%d", i);
+ (*tformatprintf2) ((*tformat_arg) ("%d"), i);
+ (*tformatprintf2) ("%"); /* { dg-warning "format" "nested" } */
+ (*tformatprintf2) ((*tformat_arg) ("%")); /* { dg-warning "format" "nested" } */
+ (****tformatprintf3) ("%d", i);
+ (****tformatprintf3) ((*tformat_arg) ("%d"), i);
+ (****tformatprintf3) ("%"); /* { dg-warning "format" "nested 2" } */
+ (****tformatprintf3) ((*tformat_arg) ("%")); /* { dg-warning "format" "nested 2" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_bitfld-1.c b/gcc/testsuite/gcc.dg/format/ms_bitfld-1.c
new file mode 100644
index 00000000000..83eb2fec625
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_bitfld-1.c
@@ -0,0 +1,52 @@
+/* Test for printf formats and bit-fields: bug 22421. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+/* { dg-require-effective-target int32plus } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+struct s {
+ unsigned int u1 : 1;
+ signed int s1 : 1;
+ unsigned int u15 : 15;
+ signed int s15 : 15;
+ unsigned int u16 : 16;
+ signed int s16 : 16;
+ unsigned long u31 : 31;
+ signed long s31 : 31;
+ unsigned long u32 : 32;
+ signed long s32 : 32;
+ unsigned long long u48 : 48;
+} x;
+
+void
+foo (void)
+{
+ printf ("%d%u", x.u1, x.u1);
+ printf ("%d%u", x.s1, x.s1);
+ printf ("%d%u", x.u15, x.u15);
+ printf ("%d%u", x.s15, x.s15);
+ printf ("%d%u", x.u16, x.u16);
+ printf ("%d%u", x.s16, x.s16);
+#if __INT_MAX__ > 32767
+ /* If integers are 16 bits, there doesn't seem to be a way of
+ printing these without getting an error. */
+ printf ("%d%u", x.u31, x.u31);
+ printf ("%d%u", x.s31, x.s31);
+#endif
+#if __LONG_MAX__ > 2147483647 && __INT_MAX__ >= 2147483647
+ /* If long is wider than 32 bits, the 32-bit bit-fields are int or
+ unsigned int or promote to those types. Otherwise, long is 32
+ bits and the bit-fields are of type plain long or unsigned
+ long. */
+ printf ("%d%u", x.u32, x.u32);
+ printf ("%d%u", x.s32, x.s32);
+#else
+ printf ("%ld%lu", x.u32, x.u32);
+ printf ("%ld%lu", x.s32, x.s32);
+#endif
+ printf ("%I64u", x.u48); /* { dg-warning "has type '.*unsigned int:48'" } */
+ printf ("%I64u", (unsigned long long)x.u48);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_branch-1.c b/gcc/testsuite/gcc.dg/format/ms_branch-1.c
new file mode 100644
index 00000000000..fe3f80e57d5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_branch-1.c
@@ -0,0 +1,28 @@
+/* Test for format checking of conditional expressions. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (long l, int nfoo)
+{
+ printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
+ printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ /* Should allow one case to have extra arguments. */
+ printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
+ printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "too many" "too many args in all branches" } */
+ printf ((nfoo > 1) ? "%d foos" : "", nfoo);
+ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo);
+ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo);
+ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
+ /* Extra arguments to NULL should be complained about. */
+ printf (NULL, "foo"); /* { dg-warning "too many" "NULL extra args" } */
+ /* { dg-warning "null" "null format arg" { target *-*-* } 26 } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-printf-1.c b/gcc/testsuite/gcc.dg/format/ms_c90-printf-1.c
new file mode 100644
index 00000000000..f99d4c49db9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-printf-1.c
@@ -0,0 +1,184 @@
+/* Test for printf formats. Formats using C90 features, including cases
+ where C90 specifies some aspect of the format to be ignored or where
+ the behavior is undefined.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
+ int *n, short int *hn, long int l, unsigned long int ul,
+ long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll,
+ ullong ull, unsigned int *un, const int *cn, signed char *ss,
+ unsigned char *us, const signed char *css, unsigned int u1,
+ unsigned int u2)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134). */
+ /* Basic sanity checks for the different components of a format. */
+ printf ("%d\n", i);
+ printf ("%+d\n", i);
+ printf ("%3d\n", i);
+ printf ("%-3d\n", i);
+ printf ("%*d\n", i1, i);
+ printf ("%d %lu\n", i, ul);
+ /* Bogus use of width. */
+ printf ("%5n\n", n); /* { dg-warning "width" "width with %n" } */
+ /* Valid and invalid %% constructions. Some of the warning messages
+ are non-optimal, but they do detect the errorneous nature of the
+ format string.
+ */
+ printf ("%%");
+ printf ("%-%"); /* { dg-warning "format" "bogus %%" } */
+ printf ("%-%\n"); /* { dg-warning "format" "bogus %%" } */
+ printf ("%5%\n"); /* { dg-warning "format" "bogus %%" } */
+ printf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */
+ /* Valid and invalid %h, %l, %L constructions. */
+ printf ("%hd", i);
+ printf ("%hi", i);
+ /* Strictly, these parameters should be int or unsigned int according to
+ what unsigned short promotes to. However, GCC ignores sign
+ differences in format checking here, and this is relied on to get the
+ correct checking without print_char_table needing to know whether
+ int and short are the same size.
+ */
+ printf ("%ho%hu%hx%hX", u, u, u, u);
+ printf ("%hn", hn);
+ printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hc", i);
+ printf ("%hs", hn);
+ printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */
+ printf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul);
+ printf ("%ln", ln);
+ printf ("%lf", d); /* { dg-warning "length|C" "bad use of %l" } */
+ printf ("%le", d); /* { dg-warning "length|C" "bad use of %l" } */
+ printf ("%lE", d); /* { dg-warning "length|C" "bad use of %l" } */
+ printf ("%lg", d); /* { dg-warning "length|C" "bad use of %l" } */
+ printf ("%lG", d); /* { dg-warning "length|C" "bad use of %l" } */
+ printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */
+ /* These next two were added in C94, but should be objected to in C90.
+ For the first one, GCC has wanted wchar_t instead of the correct C94
+ and C99 wint_t.
+ */
+ printf ("%lc", lc); /* { dg-warning "length|C" "C90 bad use of %l" } */
+ printf ("%ls", ls); /* { dg-warning "length|C" "C90 bad use of %l" } */
+ /* Valid uses of each bare conversion. */
+ printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u, d, d, d, d, d,
+ i, s, p, n);
+ /* Uses of the - flag (valid on all non-%, non-n conversions). */
+ printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i, u, u, u, u,
+ d, d, d, d, d, i, s, p);
+ printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */
+ /* Uses of the + flag (valid on signed conversions only). */
+ printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d);
+ printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */
+ /* Uses of the space flag (valid on signed conversions only, and ignored
+ with +).
+ */
+ printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
+ printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
+ printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d);
+ printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */
+ /* Uses of the # flag. */
+ printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d, d, d);
+ printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */
+ /* Uses of the 0 flag. */
+ printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i, u, u, u, u,
+ d, d, d, d, d);
+ printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */
+ printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */
+ printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */
+ printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */
+ /* 0 flag ignored with - flag. */
+ printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ /* Various tests of bad argument types. */
+ printf ("%d", l); /* { dg-warning "format" "bad argument types" } */
+ printf ("%ld", i); /* { dg-warning "format" "bad argument types" } */
+ printf ("%s", n); /* { dg-warning "format" "bad argument types" } */
+ printf ("%p", i); /* { dg-warning "format" "bad argument types" } */
+ printf ("%n", p); /* { dg-warning "format" "bad argument types" } */
+ /* With -pedantic, we want some further checks for pointer targets:
+ %p should allow only pointers to void (possibly qualified) and
+ to character types (possibly qualified), but not function pointers
+ or pointers to other types. (Whether, in fact, character types are
+ allowed here is unclear; see thread on comp.std.c, July 2000 for
+ discussion of the requirements of rules on identical representation,
+ and of the application of the as if rule with the new va_arg
+ allowances in C99 to printf.) Likewise, we should warn if
+ pointer targets differ in signedness, except in some circumstances
+ for character pointers. (In C99 we should consider warning for
+ char * or unsigned char * being passed to %hhn, even if strictly
+ legitimate by the standard.)
+ */
+ printf ("%p", foo); /* { dg-warning "format" "bad argument types" } */
+ printf ("%n", un); /* { dg-warning "format" "bad argument types" } */
+ printf ("%p", n); /* { dg-warning "format" "bad argument types" } */
+ /* Allow character pointers with %p. */
+ printf ("%p%p%p%p", s, ss, us, css);
+ /* %s allows any character type. */
+ printf ("%s%s%s%s", s, ss, us, css);
+ /* Warning for void * arguments for %s is GCC's historical behavior,
+ and seems useful to keep, even if some standard versions might be
+ read to permit it.
+ */
+ printf ("%s", p); /* { dg-warning "format" "bad argument types" } */
+ /* The historical behavior is to allow signed / unsigned types
+ interchangably as arguments. For values representable in both types,
+ such usage may be correct. For now preserve the behavior of GCC
+ in such cases.
+ */
+ printf ("%d", u);
+ /* Wrong number of arguments. */
+ printf ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */
+ printf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */
+ /* Miscellaneous bogus constructions. */
+ printf (""); /* { dg-warning "zero-length" "warning for empty format" } */
+ printf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */
+ printf ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */
+ printf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
+ printf (NULL); /* { dg-warning "null" "null format string warning" } */
+ printf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
+ printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */
+ printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */
+ printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */
+ printf ("%n", (int *)0); /* { dg-warning "null" "%n with NULL" } */
+ printf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-printf-2.c b/gcc/testsuite/gcc.dg/format/ms_c90-printf-2.c
new file mode 100644
index 00000000000..b5395588120
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-printf-2.c
@@ -0,0 +1,25 @@
+/* Test for printf formats. Formats using C99 features should be rejected
+ outside of C99 mode.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, double d, llong ll, intmax_t j, size_t z, ptrdiff_t t)
+{
+ /* Some tests already in c90-printf-1.c, e.g. %lf. */
+ /* The widths hh, ll, j, z, t are new. */
+ printf ("%hhd", i); /* { dg-warning "unknown|format" "%hh is unsupported" } */
+ printf ("%I64d", ll); /* { dg-warning "length|C" "%I64 in C90" } */
+ printf ("%jd", j); /* { dg-warning "unknown|format" "%j is unsupported" } */
+ printf ("%zu", z); /* { dg-warning "unknown|format" "%z is unsupported" } */
+ printf ("%td", t); /* { dg-warning "unknown|format" "%t is unsupported" } */
+ /* The formats F, a, A are new. */
+ printf ("%F", d); /* { dg-warning "unknown|format" "%F is unsupported" } */
+ printf ("%a", d); /* { dg-warning "unknown|format" "%a is unsupported" } */
+ printf ("%A", d); /* { dg-warning "unknown|format" "%A is unsupported" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-printf-3.c b/gcc/testsuite/gcc.dg/format/ms_c90-printf-3.c
new file mode 100644
index 00000000000..8e4b19a774e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-printf-3.c
@@ -0,0 +1,43 @@
+/* Test for printf formats. Test that the C90 functions get their default
+ attributes in strict C90 mode, but the C99 and gettext functions
+ do not.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3,
+ va_list v4, va_list v5, va_list v6, va_list v7, va_list v8)
+{
+ fprintf (stdout, "%d", i);
+ fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */
+ printf ("%d", i);
+ printf ("%ld", i); /* { dg-warning "format" "printf" } */
+ /* The "unlocked" functions shouldn't warn in c90 mode. */
+ fprintf_unlocked (stdout, "%ld", i);
+ printf_unlocked ("%ld", i);
+ sprintf (s, "%d", i);
+ sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */
+ vfprintf (stdout, "%d", v0);
+ vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */
+ vprintf ("%d", v2);
+ vprintf ("%Y", v3); /* { dg-warning "format" "vprintf" } */
+ /* The following used to give a bogus warning. */
+ vprintf ("%*.*d", v8); /* { dg-bogus "format" "vprintf" } */
+ vsprintf (s, "%d", v4);
+ vsprintf (s, "%Y", v5); /* { dg-warning "format" "Y is invalid" } */
+ snprintf (s, n, "%d", i);
+ snprintf (s, n, "%ld", i);
+ vsnprintf (s, n, "%d", v6);
+ vsnprintf (s, n, "%Y", v7);
+ printf (gettext ("%d"), i);
+ printf (gettext ("%ld"), i);
+ printf (dgettext ("", "%d"), i);
+ printf (dgettext ("", "%ld"), i);
+ printf (dcgettext ("", "%d", 0), i);
+ printf (dcgettext ("", "%ld", 0), i);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-scanf-1.c b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-1.c
new file mode 100644
index 00000000000..6e2cb10063b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-1.c
@@ -0,0 +1,119 @@
+/* Test for scanf formats. Formats using C90 features, including cases
+ where C90 specifies some aspect of the format to be ignored or where
+ the behavior is undefined.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
+ long int *lp, unsigned long int *ulp, float *fp, double *dp,
+ long double *ldp, char *s, signed char *ss, unsigned char *us,
+ void **pp, int *n, llong *llp, ullong *ullp, wchar_t *ls,
+ const int *cip, const int *cn, const char *cs, const void **ppc,
+ void *const *pcp, short int *hn, long int *ln, void *p, char **sp,
+ volatile void *ppv)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138). */
+ /* Basic sanity checks for the different components of a format. */
+ scanf ("%d", ip);
+ scanf ("%*d");
+ scanf ("%3d", ip);
+ scanf ("%hd", hp);
+ scanf ("%3ld", lp);
+ scanf ("%*3d");
+ scanf ("%d %ld", ip, lp);
+ /* Valid and invalid %% constructions. */
+ scanf ("%%");
+ scanf ("%*%"); /* { dg-warning "format" "bogus %%" } */
+ scanf ("%*%\n"); /* { dg-warning "format" "bogus %%" } */
+ scanf ("%4%"); /* { dg-warning "format" "bogus %%" } */
+ scanf ("%4%\n"); /* { dg-warning "format" "bogus %%" } */
+ scanf ("%h%"); /* { dg-warning "format" "bogus %%" } */
+ scanf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */
+ /* Valid, invalid and silly assignment-suppression constructions. */
+ scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p");
+ scanf ("%*2d%*8s%*3c");
+ scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
+ scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
+ /* Valid, invalid and silly width constructions. */
+ scanf ("%2d%3i%4o%5u%6x%7X%8e%9E%10f%11g%12G%13s%14[abc]%15c%16p",
+ ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp, s, s, s, pp);
+ scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
+ scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
+ /* Valid and invalid %h, %l, %L constructions. */
+ scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
+ scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hs", hp);
+ scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hc", hp);
+ scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */
+ scanf ("%h."); /* { dg-warning "conversion" "bogus %h" } */
+ scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
+ scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp);
+ scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
+ /* These next three formats were added in C94. */
+ scanf ("%ls", ls); /* { dg-warning "length|C" "bad use of %l" } */
+ scanf ("%l[ac]", ls); /* { dg-warning "length|C" "bad use of %l" } */
+ scanf ("%lc", ls); /* { dg-warning "length|C" "bad use of %l" } */
+ scanf ("%Ld", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Li", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Lo", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Lu", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Lx", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%LX", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Ls", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%L[ac]", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Lc", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Lp", pp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ scanf ("%Ln", n); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ /* Valid uses of each bare conversion. */
+ scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
+ uip, fp, fp, fp, fp, fp, s, s, s, pp, n);
+ /* Allow other character pointers with %s, %c, %[]. */
+ scanf ("%2s%3s%4c%5c%6[abc]%7[abc]", ss, us, ss, us, ss, us);
+ /* Further tests for %[]. */
+ scanf ("%[%d]%d", s, ip);
+ scanf ("%[^%d]%d", s, ip);
+ scanf ("%[]%d]%d", s, ip);
+ scanf ("%[^]%d]%d", s, ip);
+ scanf ("%[%d]%d", s, ip);
+ scanf ("%[]abcd", s); /* { dg-warning "no closing" "incomplete scanset" } */
+ /* Various tests of bad argument types. Some of these are only pedantic
+ warnings.
+ */
+ scanf ("%d", lp); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%d", uip); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%d", pp); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%p", ppc); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%p", ppv); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%s", n); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%s", p); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%p", p); /* { dg-warning "format" "bad argument types" } */
+ scanf ("%p", sp); /* { dg-warning "format" "bad argument types" } */
+ /* Tests for writing into constant values. */
+ scanf ("%d", cip); /* { dg-warning "constant" "%d writing into const" } */
+ scanf ("%n", cn); /* { dg-warning "constant" "%n writing into const" } */
+ scanf ("%s", cs); /* { dg-warning "constant" "%s writing into const" } */
+ scanf ("%p", pcp); /* { dg-warning "constant" "%p writing into const" } */
+ /* Wrong number of arguments. */
+ scanf ("%d%d", ip); /* { dg-warning "arguments" "wrong number of args" } */
+ scanf ("%d", ip, ip); /* { dg-warning "arguments" "wrong number of args" } */
+ /* Miscellaneous bogus constructions. */
+ scanf (""); /* { dg-warning "zero-length" "warning for empty format" } */
+ scanf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */
+ scanf ("%d\0", ip); /* { dg-warning "embedded" "warning for embedded NUL" } */
+ scanf ("%d\0%d", ip, ip); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
+ scanf (NULL); /* { dg-warning "null" "null format string warning" } */
+ scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
+ scanf ("%d", (int *)0); /* { dg-warning "null" "writing into NULL" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-scanf-2.c b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-2.c
new file mode 100644
index 00000000000..b55122792ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-2.c
@@ -0,0 +1,26 @@
+/* Test for scanf formats. Formats using C99 features should be rejected
+ outside of C99 mode.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (signed char *hhp, float *fp, llong *llp, intmax_t *jp,
+ size_t *zp, ptrdiff_t *tp)
+{
+ /* Some tests already in c90-scanf-1.c. */
+ /* The widths hh, ll, j, z, t are new. */
+ scanf ("%hhd", hhp); /* { dg-warning "unknown|format" "%hh is unsupported" } */
+ scanf ("%I64d", llp); /* { dg-warning "length|C" "%I64 in C90" } */
+ scanf ("%jd", jp); /* { dg-warning "unknown|format" "%j is unsupported" } */
+ scanf ("%zu", zp); /* { dg-warning "unknown|format" "%z is unsupported" } */
+ scanf ("%td", tp); /* { dg-warning "unknown|format" "%t is unsupported" } */
+ /* The formats F, a, A are new. */
+ scanf ("%F", fp); /* { dg-warning "unknown|format" "%F is unsupported" } */
+ scanf ("%a", fp); /* { dg-warning "unknown|format" "%a is unsupported" } */
+ scanf ("%A", fp); /* { dg-warning "unknown|format" "%A is unsupported" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-scanf-3.c b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-3.c
new file mode 100644
index 00000000000..b9d3e38bc00
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-3.c
@@ -0,0 +1,20 @@
+/* Test for scanf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp)
+{
+ /* %a formats for allocation, only recognized in C90 mode, are a
+ GNU extension.
+ */
+ scanf ("%as", sp); /* { dg-warning "flag" "%as is unsupported" } */
+ scanf ("%aS", lsp); /* { dg-warning "format|flag" "%aS is unsupported" } */
+ scanf ("%a[bcd]", sp); /* { dg-warning "flag" "%a[] is unsupported" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-scanf-4.c b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-4.c
new file mode 100644
index 00000000000..4b1fda7cafb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-4.c
@@ -0,0 +1,31 @@
+/* Test for scanf formats. Test that the C90 functions get their default
+ attributes in strict C90 mode, but the C99 and gettext functions
+ do not.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int *ip, char *s, va_list v0, va_list v1, va_list v2, va_list v3,
+ va_list v4, va_list v5)
+{
+ fscanf (stdin, "%d", ip);
+ fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */
+ scanf ("%d", ip);
+ scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */
+ sscanf (s, "%d", ip);
+ sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */
+ vfscanf (stdin, "%d", v0);
+ vscanf ("%d", v2);
+ vsscanf (s, "%d", v4);
+ scanf (gettext ("%d"), ip);
+ scanf (gettext ("%ld"), ip);
+ scanf (dgettext ("", "%d"), ip);
+ scanf (dgettext ("", "%ld"), ip);
+ scanf (dcgettext ("", "%d", 0), ip);
+ scanf (dcgettext ("", "%ld", 0), ip);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-scanf-5.c b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-5.c
new file mode 100644
index 00000000000..c714689e06f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-5.c
@@ -0,0 +1,20 @@
+/* Test for scanf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp)
+{
+ /* m assignment-allocation modifier, recognized in both C90
+ and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension. */
+ scanf ("%ms", sp); /* { dg-warning "unknown|format" "%ms is unsupported" } */
+ scanf ("%mS", lsp); /* { dg-warning "unknown|format" "%mS is unsupported" } */
+ scanf ("%mls", lsp); /* { dg-warning "unknown|format" "%mls is unsupported" } */
+ scanf ("%m[bcd]", sp); /* { dg-warning "unknown|format" "%m[] is unsupported" } */
+ scanf ("%ml[bcd]", lsp); /* { dg-warning "unknown|format" "%ml[] is unsupported" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-strftime-1.c b/gcc/testsuite/gcc.dg/format/ms_c90-strftime-1.c
new file mode 100644
index 00000000000..34143c1b214
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-strftime-1.c
@@ -0,0 +1,20 @@
+/* Test for strftime formats. Formats using C90 features. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wformat-y2k" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175). */
+ /* Formats which are Y2K-compliant (no 2-digit years). */
+ strftime (s, m, "%a%A%b%B%d%H%I%j%m%M%p%S%U%w%W%X%Y%Z%%", tp);
+ /* Formats with 2-digit years. */
+ strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */
+ /* Formats with 2-digit years in some locales. */
+ strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */
+ strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c90-strftime-2.c b/gcc/testsuite/gcc.dg/format/ms_c90-strftime-2.c
new file mode 100644
index 00000000000..446f235336b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c90-strftime-2.c
@@ -0,0 +1,28 @@
+/* Test for strftime formats. Rejection of formats using C99 features in
+ pedantic C90 mode. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wformat-y2k" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp)
+{
+ strftime (s, m, "%C", tp); /* { dg-warning "format" "%C is unsupported" } */
+ strftime (s, m, "%D", tp); /* { dg-warning "format" "%D is unsupported" } */
+ strftime (s, m, "%e", tp); /* { dg-warning "format" "%e is unsupported" } */
+ strftime (s, m, "%F", tp); /* { dg-warning "format" "%F is unsupported" } */
+ strftime (s, m, "%g", tp); /* { dg-warning "format" "%g is unsupported" } */
+ strftime (s, m, "%G", tp); /* { dg-warning "format" "%G is unsupported" } */
+ strftime (s, m, "%h", tp); /* { dg-warning "format" "%h is unsupported" } */
+ strftime (s, m, "%n", tp); /* { dg-warning "format" "%n is unsupported" } */
+ strftime (s, m, "%r", tp); /* { dg-warning "format" "%r is unsupported" } */
+ strftime (s, m, "%R", tp); /* { dg-warning "format" "%R is unsupported" } */
+ strftime (s, m, "%t", tp); /* { dg-warning "format" "%t is unsupported" } */
+ strftime (s, m, "%T", tp); /* { dg-warning "format" "%T is unsupported" } */
+ strftime (s, m, "%u", tp); /* { dg-warning "format" "%u is unsupported" } */
+ strftime (s, m, "%V", tp); /* { dg-warning "format" "%V is unsupported" } */
+ strftime (s, m, "%z", tp); /* { dg-warning "C" "%z not in C90" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c94-printf-1.c b/gcc/testsuite/gcc.dg/format/ms_c94-printf-1.c
new file mode 100644
index 00000000000..8a7a12e3f06
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c94-printf-1.c
@@ -0,0 +1,19 @@
+/* Test for printf formats. Changes in C94 to C90. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:199409 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (wint_t lc, wchar_t *ls)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134),
+ as amended by ISO/IEC 9899:1990/Amd.1:1995 (E) (pages 4-5).
+ We do not repeat here all the C90 format checks, but just verify
+ that %ls and %lc are accepted without warning.
+ */
+ printf ("%lc", lc);
+ printf ("%ls", ls);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c94-scanf-1.c b/gcc/testsuite/gcc.dg/format/ms_c94-scanf-1.c
new file mode 100644
index 00000000000..85b300f4fc6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c94-scanf-1.c
@@ -0,0 +1,18 @@
+/* Test for scanf formats. Changes in C94 to C90. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:199409 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (wchar_t *ls)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138),
+ as amended by ISO/IEC 9899:1990/Amd.1:1995 (E) (pages 5-6).
+ We do not repeat here all the C90 format checks, but just verify
+ that %ls, %lc, %l[] are accepted without warning.
+ */
+ scanf ("%lc%ls%l[abc]", ls, ls, ls);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-printf-1.c b/gcc/testsuite/gcc.dg/format/ms_c99-printf-1.c
new file mode 100644
index 00000000000..ad5634ceb78
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-printf-1.c
@@ -0,0 +1,109 @@
+/* Test for printf formats. Formats using C99 features, including cases
+ where C99 specifies some aspect of the format to be ignored or where
+ the behavior is undefined.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, unsigned int u, double d, char *s, void *p, int *n,
+ long double ld, wint_t lc, wchar_t *ls, long long int ll,
+ unsigned long long int ull, signed char *ss, unsigned char *us,
+ long long int *lln, intmax_t j, uintmax_t uj, intmax_t *jn,
+ size_t z, signed_size_t sz, signed_size_t *zn,
+ ptrdiff_t t, ptrdiff_t *tn)
+{
+ /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.1 (pages 273-281).
+ We do not repeat here most of the checks for correct C90 formats
+ or completely broken formats.
+ */
+ /* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions. */
+ printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hF", d); /* { dg-warning "unknown|format" "bad use of %hF" } */
+ printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%ha", d); /* { dg-warning "unknown|format" "bad use of %ha" } */
+ printf ("%hA", d); /* { dg-warning "unknown|format" "bad use of %hA" } */
+ printf ("%hc", i);
+ printf ("%hs", (short *)s);
+ printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */
+ printf ("%lc", lc);
+ printf ("%ls", ls);
+ printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */
+ /* Valid uses of each bare conversion. */
+ printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u,
+ d, d, d, d, d, i, s, p, n);
+ /* Uses of the - flag (valid on all non-%, non-n conversions). */
+ printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i,
+ u, u, u, u, d, d, d, d, d, i, s, p);
+ printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */
+ /* Uses of the + flag (valid on signed conversions only). */
+ printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d);
+ printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */
+ printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */
+ /* Uses of the space flag (valid on signed conversions only, and ignored
+ with +).
+ */
+ printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
+ printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
+ printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d);
+ printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */
+ printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */
+ /* Uses of the # flag. */
+ printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d,
+ d, d);
+ printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */
+ printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */
+ /* Uses of the 0 flag. */
+ printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i,
+ u, u, u, u, d, d, d, d, d);
+ printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */
+ printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */
+ printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */
+ printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */
+ /* 0 flag ignored with - flag. */
+ printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08F", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
+ printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
+ printf ("%-08a", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
+ printf ("%-08A", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
+ /* Various tests of bad argument types. Mostly covered in c90-printf-1.c;
+ here just test for pointer target sign with %hhn. (Probably allowed
+ by the standard, but a bad idea, so GCC should diagnose if what
+ is used is not signed char *.)
+ */
+ printf ("%hhn", s); /* { dg-warning "unknown|format" "%hhn is unsupported" } */
+ printf ("%hhn", us); /* { dg-warning "unknown|format" "%hhn is unsupported" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-printf-2.c b/gcc/testsuite/gcc.dg/format/ms_c99-printf-2.c
new file mode 100644
index 00000000000..0a4d3160d30
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-printf-2.c
@@ -0,0 +1,32 @@
+/* Test for printf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, long long ll, size_t z, wint_t lc, wchar_t *ls)
+{
+ /* The length modifiers q, Z and L as applied to integer formats are
+ extensions.
+ */
+ printf ("%qd", ll); /* { dg-warning "unknown|format" "%q length is unsupported" } */
+ printf ("%Ld", ll); /* { dg-warning "unknown|format" "%L length is unsupported" } */
+ printf ("%Zd", z); /* { dg-warning "unknown|format" "%Z length is unsupported" } */
+ /* The conversion specifiers C and S are X/Open extensions; the
+ conversion specifier m is a GNU extension.
+ */
+ printf ("%m"); /* { dg-warning "unknown" "printf %m is unsupported" } */
+ printf ("%C", lc); /* { dg-warning "C" "printf %C" } */
+ printf ("%S", ls); /* { dg-warning "C" "printf %S" } */
+ /* The flag character ', and the use of operand number $ formats, are
+ X/Open extensions.
+ */
+ printf ("%'d", i); /* { dg-warning "C" "printf ' flag" } */
+ printf ("%1$d", i); /* { dg-warning "C" "printf $ format" } */
+ printf ("%Ix", z); /* { dg-warning "C" "printf I format" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c b/gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c
new file mode 100644
index 00000000000..d8c51eaa063
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c
@@ -0,0 +1,40 @@
+/* Test for printf formats. Test that the C99 functions get their default
+ attributes in strict C99 mode, but the gettext functions do not.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3,
+ va_list v4, va_list v5, va_list v6, va_list v7)
+{
+ fprintf (stdout, "%d", i);
+ fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */
+ printf ("%d", i);
+ printf ("%ld", i); /* { dg-warning "format" "printf" } */
+ /* The "unlocked" functions shouldn't warn in c99 mode. */
+ fprintf_unlocked (stdout, "%ld", i);
+ printf_unlocked ("%ld", i);
+ sprintf (s, "%d", i);
+ sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */
+ snprintf (s, n, "%d", i);
+ snprintf (s, n, "%ld", i); /* { dg-warning "format" "snprintf" } */
+ vfprintf (stdout, "%d", v0);
+ vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */
+ vprintf ("%d", v0);
+ vprintf ("%Y", v1); /* { dg-warning "format" "vprintf" } */
+ vsprintf (s, "%d", v0);
+ vsprintf (s, "%Y", v1); /* { dg-warning "format" "vsprintf" } */
+ vsnprintf (s, n, "%d", v0);
+ vsnprintf (s, n, "%Y", v1); /* { dg-warning "format" "vsnprintf" } */
+ printf (gettext ("%d"), i);
+ printf (gettext ("%ld"), (long) i);
+ printf (dgettext ("", "%d"), i);
+ printf (dgettext ("", "%ld"), (long) i);
+ printf (dcgettext ("", "%d", 0), i);
+ printf (dcgettext ("", "%ld", 0), (long) i);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-scanf-1.c b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-1.c
new file mode 100644
index 00000000000..f4ac706e7c4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-1.c
@@ -0,0 +1,63 @@
+/* Test for scanf formats. Formats using C99 features, including cases
+ where C99 specifies some aspect of the format to be ignored or where
+ the behavior is undefined.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
+ signed char *hhp, unsigned char *uhhp, long int *lp,
+ unsigned long int *ulp, float *fp, double *dp, long double *ldp, char *s,
+ void **pp, int *n, long long *llp, unsigned long long *ullp, wchar_t *ls,
+ short int *hn, signed char *hhn, long int *ln, long long int *lln,
+ intmax_t *jp, uintmax_t *ujp, intmax_t *jn, size_t *zp,
+ signed_size_t *szp, signed_size_t *zn, ptrdiff_t *tp,
+ unsigned_ptrdiff_t *utp, ptrdiff_t *tn)
+{
+ /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.2 (pages 281-288).
+ We do not repeat here most of the checks for correct C90 formats
+ or completely broken formats.
+ */
+ /* Valid, invalid and silly assignment-suppression
+ and width constructions.
+ */
+ scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p");
+ scanf ("%*2d%*8s%*3c");
+ scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
+ scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
+ scanf ("%2d%3i%4o%5u%6x%7X%10e%11E%12f%14g%15G%16s%3[abc]%4c%5p",
+ ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp,
+ s, s, s, pp);
+ scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
+ scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
+ /* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions. */
+ scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
+ scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hs", hp);
+ scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hc", (short *)s);
+ scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
+ scanf ("%hhd", hhp); /* { dg-warning "unknown|format" "%hh is unsupported" } */
+ scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
+ scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp);
+ scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
+ scanf ("%ls", ls);
+ scanf ("%l[ac]", ls);
+ scanf ("%lc", ls);
+ scanf ("%jd", jp); /* { dg-warning "unknown|format" "%j not supported" } */
+ scanf ("%zd", zp); /* { dg-warning "unknown|format" "%z not supported" } */
+ scanf ("%td", tp); /* { dg-warning "unknown|format" "%t not supported" } */
+ scanf ("%Lf", llp); /* { dg-warning "unknown|format" "bad use of %L is not supported" } */
+ /* Valid uses of each bare conversion. */
+ scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
+ uip, fp, fp, fp, fp, fp, s, s, s, pp, n);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-scanf-2.c b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-2.c
new file mode 100644
index 00000000000..e16f5bfc3ca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-2.c
@@ -0,0 +1,27 @@
+/* Test for scanf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int *ip, long long int *llp, wchar_t *ls)
+{
+ /* The length modifiers q and L as applied to integer formats are
+ extensions.
+ */
+ scanf ("%qd", llp); /* { dg-warning "unknown|format" "%q is unsupported" } */
+ scanf ("%Ld", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
+ /* The conversion specifiers C and S are X/Open extensions. */
+ scanf ("%C", ls); /* { dg-warning "C" "scanf %C" } */
+ scanf ("%S", ls); /* { dg-warning "C" "scanf %S" } */
+ /* The use of operand number $ formats is an X/Open extension. */
+ scanf ("%1$d", ip); /* { dg-warning "C" "scanf $ format" } */
+ /* glibc also supports flags ' and I on scanf formats as an extension. */
+ scanf ("%'d", ip); /* { dg-warning "C" "scanf ' flag" } */
+ scanf ("%Id", (ssize_t *)ip); /* { dg-warning "C" "scanf I flag" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-scanf-3.c b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-3.c
new file mode 100644
index 00000000000..cde2f3703d4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-3.c
@@ -0,0 +1,33 @@
+/* Test for scanf formats. Test that the C99 functions get their default
+ attributes in strict C99 mode, but the gettext functions do not.
+*/
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int *ip, char *s, va_list v0, va_list v1, va_list v2, va_list v3,
+ va_list v4, va_list v5)
+{
+ fscanf (stdin, "%d", ip);
+ fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */
+ scanf ("%d", ip);
+ scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */
+ sscanf (s, "%d", ip);
+ sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */
+ vfscanf (stdin, "%d", v0);
+ vfscanf (stdin, "%Y", v1); /* { dg-warning "format" "vfscanf" } */
+ vscanf ("%d", v2);
+ vscanf ("%Y", v3); /* { dg-warning "format" "vscanf" } */
+ vsscanf (s, "%d", v4);
+ vsscanf (s, "%Y", v5); /* { dg-warning "format" "vsscanf" } */
+ scanf (gettext ("%d"), ip);
+ scanf (gettext ("%ld"), ip);
+ scanf (dgettext ("", "%d"), ip);
+ scanf (dgettext ("", "%ld"), ip);
+ scanf (dcgettext ("", "%d", 0), ip);
+ scanf (dcgettext ("", "%ld", 0), ip);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-scanf-4.c b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-4.c
new file mode 100644
index 00000000000..bddc11dd1f4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-4.c
@@ -0,0 +1,20 @@
+/* Test for scanf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp)
+{
+ /* m assignment-allocation modifier, recognized in both C90
+ and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension. */
+ scanf ("%ms", sp); /* { dg-warning "unknown|format" "%ms is unsupported" } */
+ scanf ("%mS", lsp); /* { dg-warning "unknown|format" "%mS is unsupported" } */
+ scanf ("%mls", lsp); /* { dg-warning "unknown|format" "%mls is unsupported" } */
+ scanf ("%m[bcd]", sp); /* { dg-warning "unknown|format" "%m[] is unsupported" } */
+ scanf ("%ml[bcd]", lsp); /* { dg-warning "unknown|format" "%ml[] is unsupported" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-strftime-1.c b/gcc/testsuite/gcc.dg/format/ms_c99-strftime-1.c
new file mode 100644
index 00000000000..743972efab4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-strftime-1.c
@@ -0,0 +1,20 @@
+/* Test for strftime formats. Formats using C99 features. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat -Wformat-y2k" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175). */
+ /* Formats which are Y2K-compliant (no 2-digit years). */
+ strftime (s, m, "%a%A%b%B%d%H%I%j%m%M%p%S%U%w%W%X%Y%z%Z%%", tp);
+ /* Formats with 2-digit years. */
+ strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */
+ /* Formats with 2-digit years in some locales. */
+ strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */
+ strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_c99-strftime-2.c b/gcc/testsuite/gcc.dg/format/ms_c99-strftime-2.c
new file mode 100644
index 00000000000..9a6ae3545ae
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_c99-strftime-2.c
@@ -0,0 +1,20 @@
+/* Test for strftime formats. Rejection of extensions in pedantic mode. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp)
+{
+ /* %P is a lowercase version of %p. */
+ strftime (s, m, "%P", tp); /* { dg-warning "unknown" "strftime %P" } */
+ /* %k is %H but padded with a space rather than 0 if necessary. */
+ strftime (s, m, "%k", tp); /* { dg-warning "unknown" "strftime %k" } */
+ /* %l is %I but padded with a space rather than 0 if necessary. */
+ strftime (s, m, "%l", tp); /* { dg-warning "unknown" "strftime %l" } */
+ /* %s is the number of seconds since the Epoch. */
+ strftime (s, m, "%s", tp); /* { dg-warning "unknown" "strftime %s" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_cast-1.c b/gcc/testsuite/gcc.dg/format/ms_cast-1.c
new file mode 100644
index 00000000000..08659616e70
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_cast-1.c
@@ -0,0 +1,17 @@
+/* Test for strings cast through integer types: should not be treated
+ as format strings unless the types are of the same width as
+ pointers (intptr_t or similar). */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+f (int x)
+{
+ printf("%s", x); /* { dg-warning "format" } */
+ printf((char *)(size_t)"%s", x); /* { dg-warning "format" } */
+ printf((char *)(char)"%s", x); /* { dg-warning "cast from pointer to integer of different size" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_miss-1.c b/gcc/testsuite/gcc.dg/format/ms_miss-1.c
new file mode 100644
index 00000000000..b6c71c04f7b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_miss-1.c
@@ -0,0 +1,40 @@
+/* Test for warnings for missing format attributes. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ vprintf (fmt, ap); /* { dg-warning "candidate" "printf attribute warning" } */
+ va_end (ap);
+}
+
+void
+bar (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ vscanf (fmt, ap); /* { dg-warning "candidate" "scanf attribute warning" } */
+ va_end (ap);
+}
+
+__attribute__((__format__(__ms_printf__, 1, 2))) void
+foo2 (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ vprintf (fmt, ap);
+ va_end (ap);
+}
+
+void
+vfoo (const char *fmt, va_list arg)
+{
+ vprintf (fmt, arg); /* { dg-warning "candidate" "printf attribute warning 2" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_miss-2.c b/gcc/testsuite/gcc.dg/format/ms_miss-2.c
new file mode 100644
index 00000000000..e0dd465f889
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_miss-2.c
@@ -0,0 +1,17 @@
+/* Test for warnings for missing format attributes. Don't warn if no
+ relevant parameters for a format attribute; see c/1017. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, ...)
+{
+ va_list ap;
+ va_start (ap, i);
+ vprintf ("Foo %s bar %s", ap); /* { dg-bogus "candidate" "bogus printf attribute warning" } */
+ va_end (ap);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_miss-3.c b/gcc/testsuite/gcc.dg/format/ms_miss-3.c
new file mode 100644
index 00000000000..cf41756c063
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_miss-3.c
@@ -0,0 +1,27 @@
+/* Test warnings for missing format attributes on function pointers. */
+/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+typedef void (*noattr_t) (const char *, ...);
+typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
+
+typedef void (*vnoattr_t) (const char *, va_list);
+typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
+
+void
+foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
+{
+ noattr_t na1 = na;
+ noattr_t na2 = a; /* { dg-warning "candidate" "initialization warning" } */
+ attr_t a1 = na;
+ attr_t a2 = a;
+
+ vnoattr_t vna1 = vna;
+ vnoattr_t vna2 = va; /* { dg-warning "candidate" "initialization warning" } */
+ vattr_t va1 = vna;
+ vattr_t va2 = va;
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_miss-4.c b/gcc/testsuite/gcc.dg/format/ms_miss-4.c
new file mode 100644
index 00000000000..faacf5ce43b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_miss-4.c
@@ -0,0 +1,33 @@
+/* Test warnings for missing format attributes on function pointers. */
+/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+typedef void (*noattr_t) (const char *, ...);
+typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
+
+typedef void (*vnoattr_t) (const char *, va_list);
+typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
+
+void
+foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
+{
+ noattr_t na1, na2;
+ attr_t a1, a2;
+
+ vnoattr_t vna1, vna2;
+ vattr_t va1, va2;
+
+ na1 = na;
+ na2 = a; /* { dg-warning "candidate" "assignment warning" } */
+ a1 = na;
+ a2 = a;
+
+ vna1 = vna;
+ vna2 = va; /* { dg-warning "candidate" "assignment warning" } */
+ va1 = vna;
+ va1 = va;
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_miss-5.c b/gcc/testsuite/gcc.dg/format/ms_miss-5.c
new file mode 100644
index 00000000000..a9f54c3a8ce
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_miss-5.c
@@ -0,0 +1,49 @@
+/* Test warnings for missing format attributes on function pointers. */
+/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+typedef void (*noattr_t) (const char *, ...);
+typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
+
+typedef void (*vnoattr_t) (const char *, va_list);
+typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
+
+noattr_t
+foo1 (noattr_t na, attr_t a, int i)
+{
+ if (i)
+ return na;
+ else
+ return a; /* { dg-warning "candidate" "return type warning" } */
+}
+
+attr_t
+foo2 (noattr_t na, attr_t a, int i)
+{
+ if (i)
+ return na;
+ else
+ return a;
+}
+
+vnoattr_t
+foo3 (vnoattr_t vna, vattr_t va, int i)
+{
+ if (i)
+ return vna;
+ else
+ return va; /* { dg-warning "candidate" "return type warning" } */
+}
+
+vattr_t
+foo4 (vnoattr_t vna, vattr_t va, int i)
+{
+ if (i)
+ return vna;
+ else
+ return va;
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_miss-6.c b/gcc/testsuite/gcc.dg/format/ms_miss-6.c
new file mode 100644
index 00000000000..3e210deee50
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_miss-6.c
@@ -0,0 +1,32 @@
+/* Test warnings for missing format attributes on function pointers. */
+/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+typedef void (*noattr_t) (const char *, ...);
+typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
+
+typedef void (*vnoattr_t) (const char *, va_list);
+typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
+
+extern void foo1 (noattr_t);
+extern void foo2 (attr_t);
+extern void foo3 (vnoattr_t);
+extern void foo4 (vattr_t);
+
+void
+foo (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
+{
+ foo1 (na);
+ foo1 (a); /* { dg-warning "candidate" "parameter passing warning" } */
+ foo2 (na);
+ foo2 (a);
+
+ foo3 (vna);
+ foo3 (va); /* { dg-warning "candidate" "parameter passing warning" } */
+ foo4 (vna);
+ foo4 (va);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_multattr-1.c b/gcc/testsuite/gcc.dg/format/ms_multattr-1.c
new file mode 100644
index 00000000000..0936f5f6e0d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_multattr-1.c
@@ -0,0 +1,51 @@
+/* Test for multiple format attributes. Test for printf and scanf attributes
+ together. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+/* If we specify multiple attributes for a single function, they should
+ all apply. This should apply whether they are on the same declaration
+ or on different declarations. */
+
+extern void my_vprintf_scanf (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_printf__, 1, 0)))
+ __attribute__((__format__(__ms_scanf__, 3, 4)));
+
+extern void my_vprintf_scanf2 (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_scanf__, 3, 4)))
+ __attribute__((__format__(__ms_printf__, 1, 0)));
+
+extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_printf__, 1, 0)));
+extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_scanf__, 3, 4)));
+
+extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_scanf__, 3, 4)));
+extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_printf__, 1, 0)));
+
+void
+foo (va_list ap, int *ip, long *lp)
+{
+ my_vprintf_scanf ("%d", ap, "%d", ip);
+ my_vprintf_scanf ("%d", ap, "%ld", lp);
+ my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+ my_vprintf_scanf2 ("%d", ap, "%d", ip);
+ my_vprintf_scanf2 ("%d", ap, "%ld", lp);
+ my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+ my_vprintf_scanf3 ("%d", ap, "%d", ip);
+ my_vprintf_scanf3 ("%d", ap, "%ld", lp);
+ my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+ my_vprintf_scanf4 ("%d", ap, "%d", ip);
+ my_vprintf_scanf4 ("%d", ap, "%ld", lp);
+ my_vprintf_scanf4 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf4 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_multattr-2.c b/gcc/testsuite/gcc.dg/format/ms_multattr-2.c
new file mode 100644
index 00000000000..47e20e4d461
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_multattr-2.c
@@ -0,0 +1,40 @@
+/* Test for multiple format attributes. Test for printf and scanf attributes
+ together, in different places on the declarations. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+/* If we specify multiple attributes for a single function, they should
+ all apply, wherever they are placed on the declarations. */
+
+extern __attribute__((__format__(__ms_printf__, 1, 0))) void
+ my_vprintf_scanf (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_scanf__, 3, 4)));
+
+extern void (__attribute__((__format__(__ms_printf__, 1, 0))) my_vprintf_scanf2)
+ (const char *, va_list, const char *, ...)
+ __attribute__((__format__(__ms_scanf__, 3, 4)));
+
+extern __attribute__((__format__(__ms_scanf__, 3, 4))) void
+ (__attribute__((__format__(__ms_printf__, 1, 0))) my_vprintf_scanf3)
+ (const char *, va_list, const char *, ...);
+
+void
+foo (va_list ap, int *ip, long *lp)
+{
+ my_vprintf_scanf ("%d", ap, "%d", ip);
+ my_vprintf_scanf ("%d", ap, "%ld", lp);
+ my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+ my_vprintf_scanf2 ("%d", ap, "%d", ip);
+ my_vprintf_scanf2 ("%d", ap, "%ld", lp);
+ my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+ my_vprintf_scanf3 ("%d", ap, "%d", ip);
+ my_vprintf_scanf3 ("%d", ap, "%ld", lp);
+ my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
+ my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_multattr-3.c b/gcc/testsuite/gcc.dg/format/ms_multattr-3.c
new file mode 100644
index 00000000000..1a247a7a126
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_multattr-3.c
@@ -0,0 +1,29 @@
+/* Test for multiple format_arg attributes. Test for both branches
+ getting checked. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+extern char *ngettext (const char *, const char *, unsigned long int)
+ __attribute__((__format_arg__(1))) __attribute__((__format_arg__(2)));
+
+void
+foo (long l, int nfoo)
+{
+ printf (ngettext ("%d foo", "%d foos", nfoo), nfoo);
+ printf (ngettext ("%d foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf (ngettext ("%d foo", "%ld foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf (ngettext ("%ld foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ /* Should allow one case to have extra arguments. */
+ printf (ngettext ("1 foo", "%d foos", nfoo), nfoo);
+ printf (ngettext ("1 foo", "many foos", nfoo), nfoo); /* { dg-warning "too many" "too many args in all branches" } */
+ printf (ngettext ("", "%d foos", nfoo), nfoo);
+ printf (ngettext ("1 foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo);
+ printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo);
+ printf (ngettext ("%ld foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf (ngettext ("%d foo", (nfoo > 0) ? "%ld foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "%ld foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_no-exargs-1.c b/gcc/testsuite/gcc.dg/format/ms_no-exargs-1.c
new file mode 100644
index 00000000000..659ca3e0bfb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_no-exargs-1.c
@@ -0,0 +1,15 @@
+/* Test for warnings for extra format arguments being disabled by
+ -Wno-format-extra-args. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i)
+{
+ printf ("foo", i);
+ printf ("%1$d", i, i);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_no-exargs-2.c b/gcc/testsuite/gcc.dg/format/ms_no-exargs-2.c
new file mode 100644
index 00000000000..654241ddff4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_no-exargs-2.c
@@ -0,0 +1,28 @@
+/* Test for warnings for extra format arguments being disabled by
+ -Wno-format-extra-args. Test which warnings still apply with $
+ operand numbers. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, int *ip, va_list va)
+{
+ printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */
+ printf ("%2$d%1$d", i, i, i);
+ vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */
+ /* With scanf formats, gaps in the used arguments are allowed only if the
+ arguments are all pointers. In such a case, should only give the lesser
+ warning about unused arguments rather than the more serious one about
+ argument gaps. */
+ scanf ("%3$d%1$d", ip, ip, ip);
+ /* If there are non-pointer arguments unused at the end, this is also OK. */
+ scanf ("%3$d%1$d", ip, ip, ip, i);
+ scanf ("%3$d%1$d", ip, i, ip); /* { dg-warning "before used" "unused $ scanf non-pointer operand" } */
+ /* Can't check the arguments in the vscanf case, so should suppose the
+ lesser problem. */
+ vscanf ("%3$d%1$d", va);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_no-y2k-1.c b/gcc/testsuite/gcc.dg/format/ms_no-y2k-1.c
new file mode 100644
index 00000000000..aed760aab5f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_no-y2k-1.c
@@ -0,0 +1,13 @@
+/* Test for warnings for Y2K problems not being on by default. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp)
+{
+ strftime (s, m, "%y%c%x", tp);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_nonlit-1.c b/gcc/testsuite/gcc.dg/format/ms_nonlit-1.c
new file mode 100644
index 00000000000..b29c0080e0f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_nonlit-1.c
@@ -0,0 +1,14 @@
+/* Test for warnings for non-string-literal formats. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t i)
+{
+ printf ((const char *)i, i); /* { dg-warning "argument types" "non-literal" } */
+ printf (s, i); /* { dg-warning "argument types" "non-literal" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_nonlit-2.c b/gcc/testsuite/gcc.dg/format/ms_nonlit-2.c
new file mode 100644
index 00000000000..e60242187e0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_nonlit-2.c
@@ -0,0 +1,14 @@
+/* Test for warnings for non-string-literal formats. Test with -Wformat=2. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat=2" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t i)
+{
+ printf ((const char *)i, i); /* { dg-warning "argument types" "non-literal" } */
+ printf (s, i); /* { dg-warning "argument types" "non-literal" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_nonlit-3.c b/gcc/testsuite/gcc.dg/format/ms_nonlit-3.c
new file mode 100644
index 00000000000..e8c8933bc7c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_nonlit-3.c
@@ -0,0 +1,13 @@
+/* Test for warnings for non-string-literal formats. Test for strftime formats. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp, char *fmt)
+{
+ strftime (s, m, fmt, tp); /* { dg-warning "format string" "non-literal" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_nul-1.c b/gcc/testsuite/gcc.dg/format/ms_nul-1.c
new file mode 100644
index 00000000000..50bfd546d5a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_nul-1.c
@@ -0,0 +1,15 @@
+/* Test diagnostics for suppressing contains nul
+ -Wformat. -Wformat. */
+/* Origin: Bruce Korb <bkorb@gnu.org> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-Wformat -Wno-format-contains-nul" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (void)
+{
+ static char const fmt[] = "x%s\0%s\n\0abc";
+ printf (fmt+4, fmt+8); /* { dg-bogus "embedded.*in format" "bogus embed warning" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_nul-2.c b/gcc/testsuite/gcc.dg/format/ms_nul-2.c
new file mode 100644
index 00000000000..3dfc3c62f97
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_nul-2.c
@@ -0,0 +1,17 @@
+/* Test diagnostics for options used on their own without
+ -Wformat. -Wformat-. */
+/* Origin: Bruce Korb <bkorb@gnu.org> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-Wformat" } */
+
+/* { dg-warning "embedded .* in format" "ignored" { target *-*-* } 0 } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+fumble (void)
+{
+ static char const fmt[] = "x%s\0%s\n\0abc";
+ printf (fmt+4, fmt+8);
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_null-1.c b/gcc/testsuite/gcc.dg/format/ms_null-1.c
new file mode 100644
index 00000000000..91495016ebc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_null-1.c
@@ -0,0 +1,28 @@
+/* Test for some aspects of null format string handling. */
+/* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+extern void my_printf (const char *, ...) __attribute__((format(ms_printf,1,2)));
+extern const char *my_format (const char *, const char *)
+ __attribute__((format_arg(2)));
+
+void
+foo (int i1)
+{
+ /* Warning about a null format string has been decoupled from the actual
+ format check. However, we still expect to be warned about any excess
+ arguments after a null format string. */
+ my_printf (NULL);
+ my_printf (NULL, i1); /* { dg-warning "too many" "null format with arguments" } */
+
+ my_printf (my_format ("", NULL));
+ my_printf (my_format ("", NULL), i1); /* { dg-warning "too many" "null format_arg with arguments" } */
+
+ /* While my_printf allows a null argument, dgettext does not, so we expect
+ a null argument warning here. */
+ my_printf (dgettext ("", NULL)); /* { dg-warning "null" "null format with dgettext" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_plus-1.c b/gcc/testsuite/gcc.dg/format/ms_plus-1.c
new file mode 100644
index 00000000000..f6eba280acc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_plus-1.c
@@ -0,0 +1,21 @@
+/* Test for printf formats using string literal plus constant.
+ */
+/* Origin: Jakub Jelinek <jakub@redhat.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat=2" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i)
+{
+ printf ("%%d\n" + 1, i);
+ printf (5 + "%.-*d%3d\n", i);
+ printf ("%d%d" + 2, i, i); /* { dg-warning "arguments" "wrong number of args" } */
+ printf (3 + "%d\n"); /* { dg-warning "zero-length" "zero-length string" } */
+ printf ("%d\n" + i, i); /* { dg-warning "not a string" "non-constant addend" } */
+ printf ("%d\n" + 10); /* { dg-warning "not a string" "too large addend" } */
+ printf ("%d\n" - 1, i); /* { dg-warning "not a string" "minus constant" } */
+ printf ("%d\n" + -1, i); /* { dg-warning "not a string" "negative addend" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_sec-1.c b/gcc/testsuite/gcc.dg/format/ms_sec-1.c
new file mode 100644
index 00000000000..5f6b76726fc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_sec-1.c
@@ -0,0 +1,13 @@
+/* Test for security warning when non-literal format has no arguments. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu99 -Wformat -Wformat-security" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (char *s)
+{
+ printf (s); /* { dg-warning "no format arguments" "security warning" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_unnamed-1.c b/gcc/testsuite/gcc.dg/format/ms_unnamed-1.c
new file mode 100644
index 00000000000..aa4f6cb5f3d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_unnamed-1.c
@@ -0,0 +1,24 @@
+/* Test for warnings with possibly unnamed integer types. Bug 24329. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-Wformat" } */
+/* { dg-options "-Wformat -msse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+/* Definition of TItype follows same logic as in gcc.dg/titype-1.c,
+ but must be a #define to avoid giving the type a name. */
+#if defined(__LP64__) && !defined(__hppa__)
+#define TItype int __attribute__ ((mode (TI)))
+#else
+#define TItype long
+#endif
+
+void
+f (TItype x)
+{
+ printf("%d", x); /* { dg-warning "expects type" } */
+ printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects type" } */
+ /* { dg-warning "unsigned only|too large" "constant" { target *-*-* } 22 } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_va-1.c b/gcc/testsuite/gcc.dg/format/ms_va-1.c
new file mode 100644
index 00000000000..97d2979e8f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_va-1.c
@@ -0,0 +1,14 @@
+/* Test for strange warning in format checking. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-Wformat" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (void *p)
+{
+ printf ("%d", p); /* { dg-bogus "va_list" "wrong type in format warning" } */
+ /* { dg-warning "format" "format error" { target *-*-* } 12 } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ms_zero-length-1.c b/gcc/testsuite/gcc.dg/format/ms_zero-length-1.c
new file mode 100644
index 00000000000..d024458a4e4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms_zero-length-1.c
@@ -0,0 +1,16 @@
+/* Test the -Wno-format-zero-length option, which suppresses warnings
+ about zero-length formats. */
+/* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-format-zero-length" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (void)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134). */
+ /* Zero-length format strings are allowed. */
+ printf ("");
+}
diff --git a/gcc/testsuite/gcc.dg/format/multattr-1.c b/gcc/testsuite/gcc.dg/format/multattr-1.c
index 7691aba5bd8..c7404bedf8b 100644
--- a/gcc/testsuite/gcc.dg/format/multattr-1.c
+++ b/gcc/testsuite/gcc.dg/format/multattr-1.c
@@ -4,6 +4,7 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
/* If we specify multiple attributes for a single function, they should
@@ -11,22 +12,22 @@
or on different declarations. */
extern void my_vprintf_scanf (const char *, va_list, const char *, ...)
- __attribute__((__format__(__printf__, 1, 0)))
- __attribute__((__format__(__scanf__, 3, 4)));
+ __attribute__((__format__(gnu_attr___printf__, 1, 0)))
+ __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
extern void my_vprintf_scanf2 (const char *, va_list, const char *, ...)
- __attribute__((__format__(__scanf__, 3, 4)))
- __attribute__((__format__(__printf__, 1, 0)));
+ __attribute__((__format__(gnu_attr___scanf__, 3, 4)))
+ __attribute__((__format__(gnu_attr___printf__, 1, 0)));
extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
- __attribute__((__format__(__printf__, 1, 0)));
+ __attribute__((__format__(gnu_attr___printf__, 1, 0)));
extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
- __attribute__((__format__(__scanf__, 3, 4)));
+ __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
- __attribute__((__format__(__scanf__, 3, 4)));
+ __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
- __attribute__((__format__(__printf__, 1, 0)));
+ __attribute__((__format__(gnu_attr___printf__, 1, 0)));
void
foo (va_list ap, int *ip, long *lp)
diff --git a/gcc/testsuite/gcc.dg/format/multattr-2.c b/gcc/testsuite/gcc.dg/format/multattr-2.c
index 1d78840aecb..4011bf14585 100644
--- a/gcc/testsuite/gcc.dg/format/multattr-2.c
+++ b/gcc/testsuite/gcc.dg/format/multattr-2.c
@@ -4,21 +4,22 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
/* If we specify multiple attributes for a single function, they should
all apply, wherever they are placed on the declarations. */
-extern __attribute__((__format__(__printf__, 1, 0))) void
+extern __attribute__((__format__(gnu_attr___printf__, 1, 0))) void
my_vprintf_scanf (const char *, va_list, const char *, ...)
- __attribute__((__format__(__scanf__, 3, 4)));
+ __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
-extern void (__attribute__((__format__(__printf__, 1, 0))) my_vprintf_scanf2)
+extern void (__attribute__((__format__(gnu_attr___printf__, 1, 0))) my_vprintf_scanf2)
(const char *, va_list, const char *, ...)
- __attribute__((__format__(__scanf__, 3, 4)));
+ __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
-extern __attribute__((__format__(__scanf__, 3, 4))) void
- (__attribute__((__format__(__printf__, 1, 0))) my_vprintf_scanf3)
+extern __attribute__((__format__(gnu_attr___scanf__, 3, 4))) void
+ (__attribute__((__format__(gnu_attr___printf__, 1, 0))) my_vprintf_scanf3)
(const char *, va_list, const char *, ...);
void
diff --git a/gcc/testsuite/gcc.dg/format/null-1.c b/gcc/testsuite/gcc.dg/format/null-1.c
index 63501a3981e..ed714442be9 100644
--- a/gcc/testsuite/gcc.dg/format/null-1.c
+++ b/gcc/testsuite/gcc.dg/format/null-1.c
@@ -3,9 +3,10 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat" } */
+#define DONT_GNU_PROTOTYPE
#include "format.h"
-extern void my_printf (const char *, ...) __attribute__((format(printf,1,2)));
+extern void my_printf (const char *, ...) __attribute__((format(gnu_attr_printf,1,2)));
extern const char *my_format (const char *, const char *)
__attribute__((format_arg(2)));
diff --git a/gcc/testsuite/gcc.dg/format/sys_format.c b/gcc/testsuite/gcc.dg/format/sys_format.c
new file mode 100755
index 00000000000..b69ae5bc5b5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/sys_format.c
@@ -0,0 +1,14 @@
+/* Test system default printf formatter specifiers. */
+/* Origin: Kai Tietz <KaiTietz.@onevision.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=gnu89" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+__attribute__((format(printf, 1, 2))) void foo (const char *, ...);
+
+void bar (long long v1, long v2, int v3)
+{
+ foo ("%I64d %I32d %ld %d\n", v1, v2, v2, v3);
+}
diff --git a/gcc/testsuite/gcc.dg/pr30957-1.c b/gcc/testsuite/gcc.dg/pr30957-1.c
index 44cdf9db9b0..65b98fa533d 100644
--- a/gcc/testsuite/gcc.dg/pr30957-1.c
+++ b/gcc/testsuite/gcc.dg/pr30957-1.c
@@ -6,7 +6,7 @@
they can not co-exist; also under -funsafe-math-optimizations, so we
expect it to fail. */
/* { dg-require-effective-target hard_float } */
-/* { dg-options "-O2 -funroll-loops -funsafe-math-optimizations -fvariable-expansion-in-unroller -dL" } */
+/* { dg-options "-O2 -funroll-loops -funsafe-math-optimizations -fvariable-expansion-in-unroller -fdump-rtl-loop2_unroll" } */
extern void abort (void);
extern void exit (int);
diff --git a/gcc/testsuite/gcc.dg/pr35616.c b/gcc/testsuite/gcc.dg/pr35616.c
new file mode 100644
index 00000000000..ad2c9e99e99
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr35616.c
@@ -0,0 +1,43 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+typedef void (*listener_fun)(
+ int a,
+ int b,
+ int c);
+
+struct data_t
+{
+ int a;
+
+ listener_fun listener;
+
+ int b;
+ int c;
+ int d;
+};
+
+extern void abort(void);
+void function_calling_listener (struct data_t data);
+
+void function_calling_listener (struct data_t data)
+{
+ data.listener(data.a, data.c, data.d);
+}
+
+void my_listener(int a, int b, int c)
+{
+ if (a != 42 || b != 44 || c != 45)
+ abort ();
+}
+
+int main()
+{
+ struct data_t d;
+ d.a = 42;
+ d.b = 43;
+ d.c = 44;
+ d.d = 45;
+ d.listener = my_listener;
+ function_calling_listener (d);
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/sms-2.c b/gcc/testsuite/gcc.dg/sms-2.c
index 918f6c82378..04d0482ca8c 100644
--- a/gcc/testsuite/gcc.dg/sms-2.c
+++ b/gcc/testsuite/gcc.dg/sms-2.c
@@ -2,7 +2,7 @@
traversal of the loops after versioning. */
/* { dg-do compile } */
-/* { dg-options "-O2 -fmodulo-sched -dm" } */
+/* { dg-options "-O2 -fmodulo-sched -fdump-rtl-sms" } */
void
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-4.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-4.c
new file mode 100644
index 00000000000..7eabd1a7bd8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-4.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+/* We should be able to fold the comparison at least with the
+ first forwprop pass, if not a ccp pass before. */
+
+extern void link_error (void);
+void foo()
+{
+ int i;
+ char *p = (char *)&i;
+ long *q = (long *)p;
+ if (q == 0)
+ link_error ();
+}
+
+/* { dg-final { scan-tree-dump-not "link_error" "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c
index 1614f7e4de1..748c6e81434 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c
@@ -6,7 +6,7 @@
/* { dg-do compile { target i?86-*-* x86_64-*-* powerpc*-*-*} } */
/* { dg-require-effective-target nonpic } */
-/* { dg-options "-O2 -fdump-tree-final_cleanup" } */
+/* { dg-options "-O3 -fdump-tree-final_cleanup" } */
# define N 2000000
static double a[N],c[N];
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-16.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-16.c
new file mode 100644
index 00000000000..56d85e58e7f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-16.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre" } */
+
+/* FRE should be able to combine i and j and perform simplification
+ on the condition. */
+
+extern void link_error (void);
+int i;
+int foo(int b, int c)
+{
+ i = b + 1;
+ int j = i - 1;
+ if (b != j)
+ link_error ();
+}
+
+/* { dg-final { scan-tree-dump-not "link_error" "fre" } } */
+/* { dg-final { cleanup-tree-dump "fre" } } */
diff --git a/gcc/testsuite/gcc.dg/uninit-15.c b/gcc/testsuite/gcc.dg/uninit-15.c
new file mode 100644
index 00000000000..dee7a3b211c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-15.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+inline int foo (int i)
+{
+ if (i) return 1; /* { dg-warning "is used uninitialized" } */
+ return 0;
+}
+
+void baz();
+
+void bar()
+{
+ int j; /* { dg-message "was declared here" } */
+ for (; foo(j); ++j)
+ baz();
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-16.c b/gcc/testsuite/gcc.dg/uninit-16.c
new file mode 100644
index 00000000000..aefb5e5f7d2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-16.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+int foo, bar;
+
+void decode_reloc(int reloc, int *is_alt)
+{
+ if (reloc >= 20)
+ *is_alt = 1;
+ else if (reloc >= 10)
+ *is_alt = 0;
+}
+
+void testfunc()
+{
+ int alt_reloc;
+
+ decode_reloc(foo, &alt_reloc);
+
+ if (alt_reloc) /* { dg-warning "may be used uninitialized" } */
+ bar = 42;
+}
diff --git a/gcc/testsuite/gcc.dg/var-expand1.c b/gcc/testsuite/gcc.dg/var-expand1.c
index 707e346d63b..3904407c44d 100644
--- a/gcc/testsuite/gcc.dg/var-expand1.c
+++ b/gcc/testsuite/gcc.dg/var-expand1.c
@@ -2,7 +2,7 @@
/* We don't (and don't want to) perform this optimisation on soft-float
targets, where each addition is a library call. */
/* { dg-require-effective-target hard_float } */
-/* { dg-options "-O2 -funroll-loops --fast-math -fvariable-expansion-in-unroller -dL" } */
+/* { dg-options "-O2 -funroll-loops --fast-math -fvariable-expansion-in-unroller -fdump-rtl-loop2_unroll" } */
extern void abort (void);
diff --git a/gcc/testsuite/gcc.dg/var-expand3.c b/gcc/testsuite/gcc.dg/var-expand3.c
index 6ccf59ef7ee..e82fb3ceb28 100644
--- a/gcc/testsuite/gcc.dg/var-expand3.c
+++ b/gcc/testsuite/gcc.dg/var-expand3.c
@@ -1,5 +1,5 @@
/* { dg-do run { target { powerpc*-*-* && powerpc_altivec_ok } } }} */
-/* { dg-options "-O2 -funroll-loops -ffast-math -fvariable-expansion-in-unroller -maltivec -dL" } */
+/* { dg-options "-O2 -funroll-loops -ffast-math -fvariable-expansion-in-unroller -maltivec -fdump-rtl-loop2" } */
#include "altivec.h"
extern void abort (void);
diff --git a/gcc/testsuite/gcc.target/i386/pr14552.c b/gcc/testsuite/gcc.target/i386/pr14552.c
new file mode 100644
index 00000000000..659257c3290
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr14552.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mmmx" } */
+
+typedef short mmxw __attribute__ ((vector_size (8)));
+typedef int mmxdw __attribute__ ((vector_size (8)));
+
+mmxdw dw;
+mmxw w;
+
+void test()
+{
+ w+=w;
+ dw= (mmxdw)w;
+}
+
+/* { dg-final { scan-assembler-not "%mm" } } */
diff --git a/gcc/testsuite/gcc.target/ia64/visibility-1.c b/gcc/testsuite/gcc.target/ia64/visibility-1.c
index 53bc2c3f785..fdccab3c750 100644
--- a/gcc/testsuite/gcc.target/ia64/visibility-1.c
+++ b/gcc/testsuite/gcc.target/ia64/visibility-1.c
@@ -19,9 +19,11 @@ static struct A variable_l __attribute__((section (".sbss")));
struct A variable_m __attribute__((visibility ("hidden"), section(".sbss")));
struct A variable_n __attribute__((section (".sbss")));
-int foo (void)
+void foo (void)
{
- return variable_i + variable_j + variable_k;
+ variable_i = 0;
+ variable_j = 0;
+ variable_k = 0;
}
void bar (void)
diff --git a/gcc/testsuite/gfortran.dg/argument_checking_16.f90 b/gcc/testsuite/gfortran.dg/argument_checking_16.f90
new file mode 100644
index 00000000000..75b2eced122
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/argument_checking_16.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/35152 - implicit procedure with keyword=argument
+
+external bar
+
+call bar(a=5) ! { dg-error "requires explicit interface" }
+call foo(a=5) ! { dg-error "requires explicit interface" }
+end
+
diff --git a/gcc/testsuite/gfortran.dg/internal_pack_1.f90 b/gcc/testsuite/gfortran.dg/internal_pack_1.f90
new file mode 100644
index 00000000000..87565bee322
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/internal_pack_1.f90
@@ -0,0 +1,85 @@
+! { dg-do run }
+! Test that the internal pack and unpack routines work OK
+! for different data types
+
+program main
+ integer(kind=1), dimension(3) :: i1
+ integer(kind=2), dimension(3) :: i2
+ integer(kind=4), dimension(3) :: i4
+ integer(kind=8), dimension(3) :: i8
+ real(kind=4), dimension(3) :: r4
+ real(kind=8), dimension(3) :: r8
+
+ i1 = (/ -1, 1, -3 /)
+ call sub_i1(i1(1:3:2))
+ if (any(i1 /= (/ 3, 1, 2 /))) call abort
+
+ i2 = (/ -1, 1, -3 /)
+ call sub_i2(i2(1:3:2))
+ if (any(i2 /= (/ 3, 1, 2 /))) call abort
+
+ i4 = (/ -1, 1, -3 /)
+ call sub_i4(i4(1:3:2))
+ if (any(i4 /= (/ 3, 1, 2 /))) call abort
+
+ i8 = (/ -1, 1, -3 /)
+ call sub_i8(i8(1:3:2))
+ if (any(i8 /= (/ 3, 1, 2 /))) call abort
+
+ r4 = (/ -1.0, 1.0, -3.0 /)
+ call sub_r4(r4(1:3:2))
+ if (any(r4 /= (/ 3.0, 1.0, 2.0/))) call abort
+
+ r8 = (/ -1.0_8, 1.0_8, -3.0_8 /)
+ call sub_r8(r8(1:3:2))
+ if (any(r8 /= (/ 3.0_8, 1.0_8, 2.0_8/))) call abort
+
+end program main
+
+subroutine sub_i1(i)
+ integer(kind=1), dimension(2) :: i
+ if (i(1) /= -1) call abort
+ if (i(2) /= -3) call abort
+ i(1) = 3
+ i(2) = 2
+end subroutine sub_i1
+
+subroutine sub_i2(i)
+ integer(kind=2), dimension(2) :: i
+ if (i(1) /= -1) call abort
+ if (i(2) /= -3) call abort
+ i(1) = 3
+ i(2) = 2
+end subroutine sub_i2
+
+subroutine sub_i4(i)
+ integer(kind=4), dimension(2) :: i
+ if (i(1) /= -1) call abort
+ if (i(2) /= -3) call abort
+ i(1) = 3
+ i(2) = 2
+end subroutine sub_i4
+
+subroutine sub_i8(i)
+ integer(kind=8), dimension(2) :: i
+ if (i(1) /= -1) call abort
+ if (i(2) /= -3) call abort
+ i(1) = 3
+ i(2) = 2
+end subroutine sub_i8
+
+subroutine sub_r4(r)
+ real(kind=4), dimension(2) :: r
+ if (r(1) /= -1.) call abort
+ if (r(2) /= -3.) call abort
+ r(1) = 3.
+ r(2) = 2.
+end subroutine sub_r4
+
+subroutine sub_r8(r)
+ real(kind=8), dimension(2) :: r
+ if (r(1) /= -1._8) call abort
+ if (r(2) /= -3._8) call abort
+ r(1) = 3._8
+ r(2) = 2._8
+end subroutine sub_r8
diff --git a/gcc/testsuite/gfortran.dg/internal_pack_2.f90 b/gcc/testsuite/gfortran.dg/internal_pack_2.f90
new file mode 100644
index 00000000000..1966e7d05d2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/internal_pack_2.f90
@@ -0,0 +1,25 @@
+! { dg-do run }
+! { dg-require-effective-target fortran_large_real }
+! Test that the internal pack and unpack routines work OK
+! for our large real type.
+
+program main
+ implicit none
+ integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
+ real(kind=k), dimension(3) :: rk
+
+ rk = (/ -1.0_k, 1.0_k, -3.0_k /)
+ call sub_rk(rk(1:3:2))
+ if (any(rk /= (/ 3.0_k, 1.0_k, 2.0_k/))) call abort
+
+end program main
+
+subroutine sub_rk(r)
+ implicit none
+ integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
+ real(kind=k), dimension(2) :: r
+ if (r(1) /= -1._k) call abort
+ if (r(2) /= -3._k) call abort
+ r(1) = 3._k
+ r(2) = 2._k
+end subroutine sub_rk
diff --git a/gcc/testsuite/gfortran.dg/internal_pack_3.f90 b/gcc/testsuite/gfortran.dg/internal_pack_3.f90
new file mode 100644
index 00000000000..8312e1d2265
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/internal_pack_3.f90
@@ -0,0 +1,21 @@
+! { dg-do run }
+! { dg-require-effective-target fortran_large_int }
+! Test that the internal pack and unpack routines work OK
+! for our large integer type.
+
+program main
+ integer,parameter :: k = selected_int_kind (range (0_8) + 1)
+ integer(kind=k), dimension(3) :: ik
+
+ ik = (/ -1, 1, -3 /)
+ call sub_ik(ik(1:3:2))
+ if (any(ik /= (/ 3, 1, 2 /))) call abort
+end program main
+
+subroutine sub_ik(i)
+ integer(kind=k), dimension(2) :: i
+ if (i(1) /= -1) call abort
+ if (i(2) /= -3) call abort
+ i(1) = 3
+ i(2) = 2
+end subroutine sub_ik
diff --git a/gcc/testsuite/gfortran.dg/namelist_45.f90 b/gcc/testsuite/gfortran.dg/namelist_45.f90
new file mode 100644
index 00000000000..3512d08b7cc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/namelist_45.f90
@@ -0,0 +1,18 @@
+! { dg-do run }
+! PR35617 read namelist error with '!'
+program test
+ character(len=128) :: mhdpath
+ namelist /nbdrive_naml/ mhdpath
+ open(10, file='test.nml')
+
+ write(10,'(a)') "&nbdrive_naml"
+ write(10,'(a)')
+ write(10,'(a)') "!nstep_stop = 2 ! uncomment to bar"
+ write(10,'(a)') "!nstep_start = 2 ! uncomment to foo"
+ write(10,'(a)') " mhdpath = 'mypath.dat'"
+ write(10,'(a)') "/"
+
+ rewind(10)
+ read(10, nbdrive_naml)
+ close(10,status="delete")
+end program test
diff --git a/gcc/testsuite/gfortran.dg/namelist_46.f90 b/gcc/testsuite/gfortran.dg/namelist_46.f90
new file mode 100644
index 00000000000..0f048cf2100
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/namelist_46.f90
@@ -0,0 +1,23 @@
+! { dg-do run }
+! PR35627 Namelist read problem with short logical followed by read real
+program test
+ implicit none
+ LOGICAL :: nlco(200) ! (1:nbeam)
+ REAL(kind=8):: xlbtna(200) ! (1:nbeam)
+ NAMELIST/nbdrive_naml/ nlco, xlbtna
+ INTEGER :: nbshapa(200) ! (1:nbeam)
+ NAMELIST/nbdrive_naml/ nbshapa
+ nlco = .false.
+ xlbtna = 0.0_8
+ nbshapa = 0
+ open(10, file='t.nml')
+ write(10,'(a)') "&nbdrive_naml"
+ write(10,'(a)') "nlco = 4*T,"
+ write(10,'(a)') "xlbtna = 802.8, 802.8, 802.8, 802.8"
+ write(10,'(a)') "nbshapa = 4*1"
+ write(10,'(a)') "/"
+ rewind(10)
+ read(10, nbdrive_naml)
+ !write(*,nbdrive_naml)
+ close(10, status="delete")
+end program test