#! /bin/sh -e

# All lines beginning with `# DPATCH:' are a description of the patch.
# DP: Description: use -Wno-format on tests that cannot be adjusted other ways.
# DP: Author: Kees Cook <kees@ubuntu.com>
# DP: Ubuntu: https://bugs.launchpad.net/bugs/344502

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p1 < $0
        #cd ${dir}gcc && autoconf
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
        #rm ${dir}gcc/configure
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- /dev/null
+++ b/src/gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.x
@@ -0,0 +1,5 @@
+# Implement "/* { dg-options "-U_FORITFY_SOURCE" } */", due to
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20567
+
+set additional_flags "-U_FORTIFY_SOURCE"
+return 0
--- /dev/null
+++ b/src/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.x
@@ -0,0 +1,5 @@
+# Implement "/* { dg-options "-U_FORITFY_SOURCE" } */", due to
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20567
+
+set additional_flags "-U_FORTIFY_SOURCE"
+return 0
--- a/src/gcc/testsuite/gcc.dg/charset/builtin2.c
+++ b/src/gcc/testsuite/gcc.dg/charset/builtin2.c
@@ -3,7 +3,7 @@
 
 /* { dg-do compile } */
 /* { dg-require-iconv "IBM1047" } */
-/* { dg-options "-O2 -fexec-charset=IBM1047" } */
+/* { dg-options "-O2 -fexec-charset=IBM1047 -Wno-format" } */
 /* { dg-final { scan-assembler-not "printf" } } */
 /* { dg-final { scan-assembler-not "fprintf" } } */
 /* { dg-final { scan-assembler-not "sprintf" } } */
--- a/src/gcc/testsuite/gcc.dg/format/format.exp
+++ b/src/gcc/testsuite/gcc.dg/format/format.exp
@@ -26,7 +26,7 @@
 load_lib torture-options.exp
 
 torture-init
-set-torture-options [list { } { -DWIDE } ]
+set-torture-options [list { -Wformat=0 } { -DWIDE -Wformat=0 } ]
 
 dg-init
 gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] ""
--- a/src/gcc/testsuite/gcc.dg/pr30473.c
+++ b/src/gcc/testsuite/gcc.dg/pr30473.c
@@ -1,7 +1,7 @@
 /* PR middle-end/30473 */
 /* Make sure this doesn't ICE.  */
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -Wno-format" } */
 
 extern int sprintf (char *, const char *, ...);
 
--- a/src/gcc/testsuite/gcc.dg/pr38902.c
+++ b/src/gcc/testsuite/gcc.dg/pr38902.c
@@ -1,6 +1,6 @@
 /* PR target/38902 */
 /* { dg-do run } */
-/* { dg-options "-O2 -fstack-protector" } */
+/* { dg-options "-O2 -fstack-protector -Wno-format" } */
 /* { dg-require-effective-target fstack_protector } */
 
 #ifdef DEBUG
