diff options
author | Martin Sebor <msebor@redhat.com> | 2021-07-06 13:41:02 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-07-06 13:43:11 -0600 |
commit | 6d3bab5d5adb3e28ddb16c97b0831efdea23cf7d (patch) | |
tree | e01626f7d19dbd576102341cc414accad07f4fbb /gcc/testsuite | |
parent | 03b634c8e0d3e8628ced79fc4f40873e12a3039c (diff) | |
download | gcc-6d3bab5d5adb3e28ddb16c97b0831efdea23cf7d.zip gcc-6d3bab5d5adb3e28ddb16c97b0831efdea23cf7d.tar.gz gcc-6d3bab5d5adb3e28ddb16c97b0831efdea23cf7d.tar.bz2 |
Improve warning suppression for inlined functions.
Resolves:
PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration site
PR middle-end/98512 - #pragma GCC diagnostic ignored ineffective in conjunction with alias attribute
gcc/ChangeLog:
* builtins.c (warn_string_no_nul): Remove %G.
(maybe_warn_for_bound): Same.
(warn_for_access): Same.
(check_access): Same.
(check_strncat_sizes): Same.
(expand_builtin_strncat): Same.
(expand_builtin_strncmp): Same.
(expand_builtin): Same.
(expand_builtin_object_size): Same.
(warn_dealloc_offset): Same.
(maybe_emit_free_warning): Same.
* calls.c (maybe_warn_alloc_args_overflow): Same.
(maybe_warn_nonstring_arg): Same.
(maybe_warn_rdwr_sizes): Same.
* expr.c (expand_expr_real_1): Remove %K.
* gimple-fold.c (gimple_fold_builtin_strncpy): Remove %G.
(gimple_fold_builtin_strncat): Same.
* gimple-ssa-sprintf.c (format_directive): Same.
(handle_printf_call): Same.
* gimple-ssa-warn-alloca.c (pass_walloca::execute): Same.
* gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same.
(maybe_diag_access_bounds): Same. Call gimple_location.
(check_bounds_or_overlap): Same.
* trans-mem.c (ipa_tm_scan_irr_block): Remove %K. Simplify.
* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Remove %G.
* tree-ssa-strlen.c (maybe_warn_overflow): Same.
(maybe_diag_stxncpy_trunc): Same.
(handle_builtin_stxncpy_strncat): Same.
(maybe_warn_pointless_strcmp): Same.
* tree-ssa-uninit.c (maybe_warn_operand): Same.
gcc/testsuite/ChangeLog:
* gcc.dg/Wobjsize-1.c: Prune expected output.
* gcc.dg/Warray-bounds-71.c: New test.
* gcc.dg/Warray-bounds-71.h: New test header.
* gcc.dg/Warray-bounds-72.c: New test.
* gcc.dg/Warray-bounds-73.c: New test.
* gcc.dg/Warray-bounds-74.c: New test.
* gcc.dg/Warray-bounds-75.c: New test.
* gcc.dg/Wfree-nonheap-object-4.c: Adjust expected output.
* gcc.dg/Wfree-nonheap-object-5.c: New test.
* gcc.dg/Wfree-nonheap-object-6.c: New test.
* gcc.dg/pragma-diag-10.c: New test.
* gcc.dg/pragma-diag-9.c: New test.
* gcc.dg/uninit-suppress_3.c: New test.
* gcc.dg/pr79214.c: Xfail tests.
* gcc.dg/tree-ssa/builtin-sprintf-warn-27.c: New test.
* gcc.dg/format/c90-printf-1.c: Adjust expected output.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds-71.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds-71.h | 46 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds-72.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds-73.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds-74.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds-75.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c | 46 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c | 49 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wobjsize-1.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/c90-printf-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr79214.c | 22 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pragma-diag-10.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pragma-diag-9.c | 141 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-27.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-suppress_3.c | 98 |
16 files changed, 492 insertions, 28 deletions
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-71.c b/gcc/testsuite/gcc.dg/Warray-bounds-71.c new file mode 100644 index 0000000..425bb12 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-71.c @@ -0,0 +1,7 @@ +/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic + works at any call site in an inlining stack + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +#define IGNORE '1' +#include "Warray-bounds-71.h" diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-71.h b/gcc/testsuite/gcc.dg/Warray-bounds-71.h new file mode 100644 index 0000000..89d1068 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-71.h @@ -0,0 +1,46 @@ +/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic + works at any call site in an inlining stack + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +int a[4]; + +void f1 (int *p, int i) +{ +#pragma GCC diagnostic push +#if IGNORE == '1' +# pragma GCC diagnostic ignored "-Warray-bounds" +#endif + p[i + 1] = 0; +#pragma GCC diagnostic pop +} + +void f2 (int *p, int i) +{ +#pragma GCC diagnostic push +#if IGNORE == '2' +# pragma GCC diagnostic ignored "-Warray-bounds" +#endif + f1 (p + 1, i + 1); +#pragma GCC diagnostic pop +} + +void f3 (int *p, int i) +{ +#pragma GCC diagnostic push +#if IGNORE == '3' +# pragma GCC diagnostic ignored "-Warray-bounds" +#endif + f2 (p + 1, i + 1); +#pragma GCC diagnostic pop +} + +void f4 (void) +{ +#pragma GCC diagnostic push +#if IGNORE == '4' +# pragma GCC diagnostic ignored "-Warray-bounds" +#endif + f3 (a, 1); +#pragma GCC diagnostic pop +} diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-72.c b/gcc/testsuite/gcc.dg/Warray-bounds-72.c new file mode 100644 index 0000000..eb3f664 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-72.c @@ -0,0 +1,7 @@ +/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic + works at any call site in an inlining stack + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +#define IGNORE '2' +#include "Warray-bounds-71.h" diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-73.c b/gcc/testsuite/gcc.dg/Warray-bounds-73.c new file mode 100644 index 0000000..50e2083 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-73.c @@ -0,0 +1,7 @@ +/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic + works at any call site in an inlining stack + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +#define IGNORE '3' +#include "Warray-bounds-71.h" diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-74.c b/gcc/testsuite/gcc.dg/Warray-bounds-74.c new file mode 100644 index 0000000..c59a876 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-74.c @@ -0,0 +1,7 @@ +/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic + works at any call site in an inlining stack + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +#define IGNORE '4' +#include "Warray-bounds-71.h" diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-75.c b/gcc/testsuite/gcc.dg/Warray-bounds-75.c new file mode 100644 index 0000000..306b176 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-75.c @@ -0,0 +1,12 @@ +/* Sanity test for Warray-bounds-7[1-4].c. Also verify the expected + inlining stack. + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +#include "Warray-bounds-71.h" + +// { dg-regexp "In function 'f1'," "In function f1" { target *-*-* } 0 } +// { dg-regexp "inlined from 'f2' at \[^\\n\\r\]+\[\\n\\r\]" "inlined from f2" { target *-*-* } 0 } +// { dg-regexp "inlined from 'f3' at \[^\\n\\r\]+\[\\n\\r\]" "inlined from f3" { target *-*-* } 0 } +// { dg-regexp "inlined from 'f4' at \[^\\n\\r\]+\[\\n\\r\]" "inlined from f4" { target *-*-* } 0 } +// { dg-message "Warray-bounds-71.h:\\d+:\\d+: warning: array subscript 6 is outside array bounds of 'int\\\[4]'" "warning" { target *-*-* } 0 } diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c index a7d9212..e459b24 100644 --- a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c +++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c @@ -10,23 +10,23 @@ struct A void *p; }; -void f0 (struct A *p, void *q) { p->p = q; } -void f1 (struct A *p, void *q) { f0 (p, q); } -void f2 (struct A *p, void *q) { f1 (p, q); } +static void f0 (struct A *p, void *q) { p->p = q; } +static void f1 (struct A *p, void *q) { f0 (p, q); } +static void f2 (struct A *p, void *q) { f1 (p, q); } -void g0 (struct A *p) +static void g0 (struct A *p) { __builtin_free (p->p); // { dg-warning "\\\[-Wfree-nonheap-object" } } -void g1 (struct A *p) { g0 (p); } -void g2 (struct A *p) { g1 (p); } +static void g1 (struct A *p) { g0 (p); } +static void g2 (struct A *p) { g1 (p); } # 26 "Wfree-nonheap-object-4.c" #define NOIPA __attribute__ ((noipa)) -extern int array[]; +extern int array[]; // { dg-message "declared here" "note on line 29" } /* Verify the warning is issued even for calls in a system header inlined into a function outside the header. */ @@ -39,7 +39,7 @@ NOIPA void warn_g0 (struct A *p) g0 (p); } -// { dg-message "inlined from 'warn_g0'" "" { target *-*-* } 0 } +// { dg-message "inlined from 'warn_g0'" "note on line 42" { target *-*-* } 0 } /* Also verify the warning can be suppressed. */ @@ -65,8 +65,8 @@ NOIPA void warn_g1 (struct A *p) g1 (p); } -// { dg-message "inlined from 'g1'" "" { target *-*-* } 0 } -// { dg-message "inlined from 'warn_g1'" "" { target *-*-* } 0 } +// { dg-message "inlined from 'g1'" "note on line 68" { target *-*-* } 0 } +// { dg-message "inlined from 'warn_g1'" "note on line 69" { target *-*-* } 0 } NOIPA void nowarn_g1 (struct A *p) @@ -90,8 +90,8 @@ NOIPA void warn_g2 (struct A *p) g2 (p); } -// { dg-message "inlined from 'g2'" "" { target *-*-* } 0 } -// { dg-message "inlined from 'warn_g2'" "" { target *-*-* } 0 } +// { dg-message "inlined from 'g2'" "note on line 93" { target *-*-* } 0 } +// { dg-message "inlined from 'warn_g2'" "note on line 94" { target *-*-* } 0 } NOIPA void nowarn_g2 (struct A *p) diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c new file mode 100644 index 0000000..026cd45 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c @@ -0,0 +1,46 @@ +/* Similar to Wfree-nonheap-object-4.c but without system headers: + verify that warnings for the same call site from distinct callers + include the correct function names in the inlining stack. + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +struct A +{ + void *p; +}; + +static void f0 (struct A *p) +{ + __builtin_free (p->p); // { dg-warning "\\\[-Wfree-nonheap-object" } +} + +// Expect two instances of the text below: +// { dg-regexp "In function 'f0'," "first f0 prefix" { target *-*-* } 0 } +// { dg-regexp "In function 'f0'," "second f0 prefix" { target *-*-* } 0 } + +static void f1 (struct A *p) { f0 (p); } +static void f2 (struct A *p) { f1 (p); } + +extern int array[]; +// Also expect two instances of the note: +// { dg-regexp "declared here" "first note on line 24" { target *-*-* } .-2 } +// { dg-regexp "declared here" "second note on line 24" { target *-*-* } .-3 } + +void foo (struct A *p) +{ + p->p = array + 1; + f0 (p); +} + +// { dg-regexp " +inlined from 'foo' at \[^:\]+Wfree-nonheap-object-5.c:32:\\d+:" "note on line 32" } + + +void bar (struct A *p) +{ + p->p = array + 2; + f2 (p); +} + +// { dg-regexp " +inlined from 'f1' at \[^:\]+Wfree-nonheap-object-5.c:21:\\d+," "inlined from f1" } +// { dg-regexp " +inlined from 'f2' at \[^:\]+Wfree-nonheap-object-5.c:22:\\d+," "inlined from f2" } +// { dg-regexp " +inlined from 'bar' at \[^:\]+Wfree-nonheap-object-5.c:41:\\d+:" "inlined from bar" } diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c new file mode 100644 index 0000000..c109558 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c @@ -0,0 +1,49 @@ +/* Similar to Wfree-nonheap-object-5.c but with attribute artificial: + verify that warnings for the same call site from distinct callers + include the correct function names in the inlining stack. + { dg-do compile } + { dg-options "-O1 -Wall" } */ + +struct A +{ + void *p; +}; + +__attribute__ ((always_inline, artificial)) +inline void f0 (struct A *p) +{ + __builtin_free (p->p); // { dg-warning "\\\[-Wfree-nonheap-object" } +} + +// Expect two instances of the text below: +// { dg-regexp "In function 'f0'," "first f0 prefix" { target *-*-* } 0 } +// { dg-regexp "In function 'f0'," "second f0 prefix" { target *-*-* } 0 } + +__attribute__ ((always_inline, artificial)) +inline void f1 (struct A *p) { f0 (p); } +__attribute__ ((always_inline, artificial)) +inline void f2 (struct A *p) { f1 (p); } + +extern int array[]; +// Also expect two instances of the note: +// { dg-regexp "declared here" "first note for array" { target *-*-* } .-2 } +// { dg-regexp "declared here" "second note for array" { target *-*-* } .-3 } + +void foo (struct A *p) +{ + p->p = array + 1; + f0 (p); +} + +// { dg-regexp " +inlined from 'foo' at \[^:\]+Wfree-nonheap-object-6.c:35:\\d+:" "inlined from foo" } + + +void bar (struct A *p) +{ + p->p = array + 2; + f2 (p); +} + +// { dg-regexp " +inlined from 'f1' at \[^:\]+Wfree-nonheap-object-6.c:23:\\d+," "inlined from f1" } +// { dg-regexp " +inlined from 'f2' at \[^:\]+Wfree-nonheap-object-6.c:25:\\d+," "inlined from f2" } +// { dg-regexp " +inlined from 'bar' at \[^:\]+Wfree-nonheap-object-6.c:44:\\d+:" "inlined from bar" } diff --git a/gcc/testsuite/gcc.dg/Wobjsize-1.c b/gcc/testsuite/gcc.dg/Wobjsize-1.c index e80c8ad..2bd2f93 100644 --- a/gcc/testsuite/gcc.dg/Wobjsize-1.c +++ b/gcc/testsuite/gcc.dg/Wobjsize-1.c @@ -4,13 +4,17 @@ #include "Wobjsize-1.h" char buf[6]; -/* { dg-warning "writing" "" { target *-*-* } .-1 } */ int main(int argc, char **argv) { - strcpy (buf,"hello "); + strcpy (buf,"hello "); /* { dg-warning "\\\[-Wstringop-overflow" } */ return 0; } -/* { dg-message "file included" "included" { target *-*-* } 0 } */ -/* { dg-message "inlined from" "inlined" { target *-*-* } 0 } */ +/* { dg-message "file included" "included" { target *-*-* } 0 } + { dg-message "inlined from" "inlined" { target *-*-* } 0 } + + The test might emit two warnings, one for the strcpy call and + another for the inlined call to __builtin___strcpy_chk() called + from strcpy(). + { dg-prune-output "writing 7 bytes into a region of size 6" } */ diff --git a/gcc/testsuite/gcc.dg/format/c90-printf-1.c b/gcc/testsuite/gcc.dg/format/c90-printf-1.c index c8652fc..8ffd63f 100644 --- a/gcc/testsuite/gcc.dg/format/c90-printf-1.c +++ b/gcc/testsuite/gcc.dg/format/c90-printf-1.c @@ -240,7 +240,7 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, printf ("%n", cn); /* { dg-warning "3:constant" "%n with const" } */ printf ((const char *)L"foo"); /* { dg-warning "25:wide" "wide string" } */ printf ("%n", (int *)0); /* { dg-warning "3:null" "%n with NULL" } */ - printf ("%s", (char *)0); /* { dg-warning "3:null" "%s with NULL" } */ + printf ("%s", (char *)0); /* { dg-warning "12:'%s' directive argument is null" "%s with NULL" } */ /* Test for correct column locations within strings with embedded escape sequences. */ printf ("\\\a\n \"\t%5n\n", n); /* { dg-warning "25:width" "width with %n" } */ diff --git a/gcc/testsuite/gcc.dg/pr79214.c b/gcc/testsuite/gcc.dg/pr79214.c index 3f5d935..2f93eed 100644 --- a/gcc/testsuite/gcc.dg/pr79214.c +++ b/gcc/testsuite/gcc.dg/pr79214.c @@ -22,67 +22,67 @@ static size_t range (void) void test_bzero (void) { - bzero (d, range ()); /* { dg-warning ".__builtin_(bzero|memset). writing 4 or more bytes into a region of size 3 overflows the destination" } */ + bzero (d, range ()); /* { dg-warning ".__builtin_(bzero|memset). writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } void test_memcpy (void) { - memcpy (d, s, range ()); /* { dg-warning ".__builtin_memcpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */ + memcpy (d, s, range ()); /* { dg-warning ".__builtin_memcpy. writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } void test_memmove (void) { - memmove (d, d + 1, range ()); /* { dg-warning ".__builtin_memmove. writing 4 or more bytes into a region of size 3 overflows the destination" } */ + memmove (d, d + 1, range ()); /* { dg-warning ".__builtin_memmove. writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } void test_mempcpy (void) { - mempcpy (d, s, range ()); /* { dg-warning ".__builtin_mempcpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */ + mempcpy (d, s, range ()); /* { dg-warning ".__builtin_mempcpy. writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } void test_memset (int n) { - memset (d, n, range ()); /* { dg-warning ".__builtin_memset. writing 4 or more bytes into a region of size 3 overflows the destination" } */ + memset (d, n, range ()); /* { dg-warning ".__builtin_memset. writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } void test_strcat (int i) { const char *s = i < 0 ? "123" : "4567"; - strcat (d, s); /* { dg-warning ".__builtin_strcat. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */ + strcat (d, s); /* { dg-warning ".__builtin_strcat. writing between 4 and 5 bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } char* test_stpcpy (int i) { const char *s = i < 0 ? "123" : "4567"; - return stpcpy (d, s); /* { dg-warning ".__builtin_stpcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */ + return stpcpy (d, s); /* { dg-warning ".__builtin_stpcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } char* test_stpncpy (int i) { const char *s = i < 0 ? "123" : "4567"; - return stpncpy (d, s, range ()); /* { dg-warning ".__builtin_stpncpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */ + return stpncpy (d, s, range ()); /* { dg-warning ".__builtin_stpncpy. writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } char* test_strcpy (int i) { const char *s = i < 0 ? "123" : "4567"; - return strcpy (d, s); /* { dg-warning ".__builtin_strcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */ + return strcpy (d, s); /* { dg-warning ".__builtin_strcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } char* test_strncpy (int i) { const char *s = i < 0 ? "123" : "4567"; - return strncpy (d, s, range ()); /* { dg-warning ".__builtin_strncpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */ + return strncpy (d, s, range ()); /* { dg-warning ".__builtin_strncpy. writing 4 or more bytes into a region of size 3 overflows the destination" "pr?????" { xfail { *-*-* } } } */ } char* test_strncat (int i) { const char *s = i < 0 ? "123" : "4567"; - return strncat (d, s, range ()); /* { dg-warning ".__builtin_strncat. specified bound \\\[4, \[0-9\]+] exceeds destination size 3" } */ + return strncat (d, s, range ()); /* { dg-warning ".__builtin_strncat. specified bound \\\[4, \[0-9\]+] exceeds destination size 3" "pr?????" { xfail { *-*-* } } } */ } diff --git a/gcc/testsuite/gcc.dg/pragma-diag-10.c b/gcc/testsuite/gcc.dg/pragma-diag-10.c new file mode 100644 index 0000000..127b299 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pragma-diag-10.c @@ -0,0 +1,20 @@ +/* PR middle-end/98512 - #pragma GCC diagnostic ignored ineffective + in conjunction with alias attribute + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +void * +__rawmemchr_ppc (const void *s, int c) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#pragma GCC diagnostic ignored "-Wstringop-overread" + if (c != 0) + return __builtin_memchr (s, c, (unsigned long)-1); // { dg-bogus "specified bound \\d+ exceeds maximum object size" } +#pragma GCC diagnostic pop + + return (char *)s + __builtin_strlen (s); +} + +extern __typeof (__rawmemchr_ppc) __EI___rawmemchr_ppc + __attribute__((alias ("__rawmemchr_ppc"))); diff --git a/gcc/testsuite/gcc.dg/pragma-diag-9.c b/gcc/testsuite/gcc.dg/pragma-diag-9.c new file mode 100644 index 0000000..9aac379 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pragma-diag-9.c @@ -0,0 +1,141 @@ +/* Verify that #pragma GCC diagnostic down the inlining stack suppresses + a warning that would otherwise be issued for inlined calls higher up + the inlining stack. + { dg-do compile } + { dg-options "-O2 -Wall -Wno-array-bounds" } */ + +extern void* memset (void*, int, __SIZE_TYPE__); + +static void warn0 (int *p) +{ + memset (p, __LINE__, 3); // { dg-warning "\\\[-Wstringop-overflow" } +} + +static void warn1 (int *p) +{ + warn0 (p + 1); +} + +static void warn2 (int *p) +{ + warn1 (p + 1); +} + +int a2[2]; // { dg-message "at offset 12 into destination object 'a2' of size 8" } + +void warn3 (void) +{ + warn2 (a2 + 1); +} + + +// Verify suppression at the innermost frame of the inlining stack. + +static void ignore0 (int *p) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" + memset (p, __LINE__, 3); +#pragma GCC diagnostic pop +} + +static void nowarn1_ignore0 (int *p) +{ + ignore0 (p + 1); +} + +static void nowarn2_ignore0 (int *p) +{ + nowarn1_ignore0 (p + 1); +} + +int b2[2]; + +void nowarn3_ignore0 (void) +{ + nowarn2_ignore0 (b2 + 1); +} + + +// Verify suppression at the second innermost frame of the inlining stack. + +static void nowarn0_ignore1 (int *p) +{ + memset (p, __LINE__, 3); +} + +static void ignore1 (int *p) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" + nowarn0_ignore1 (p + 1); +#pragma GCC diagnostic pop +} + +void nowarn2_ignore1 (int *p) +{ + ignore1 (p + 1); +} + +int c2[2]; + +void nowarn3_ignore1 (void) +{ + nowarn2_ignore1 (c2 + 1); +} + + +// Verify suppression at the third innermost frame of the inlining stack. + +static void nowarn0_ignore2 (int *p) +{ + memset (p, __LINE__, 3); +} + +static void nowarn1_ignore2 (int *p) +{ + nowarn0_ignore2 (p + 1); +} + +static void ignore2 (int *p) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" + nowarn1_ignore2 (p + 1); +#pragma GCC diagnostic pop +} + +int d2[2]; + +void nowarn3_ignore2 (void) +{ + ignore2 (c2 + 1); +} + + +// Verify suppression at the outermost frame of the inlining stack. + +static void nowarn0_ignore3 (int *p) +{ + memset (p, __LINE__, 3); +} + +static void nowarn1_ignore3 (int *p) +{ + nowarn0_ignore3 (p + 1); +} + +static void nowarn2_ignore3 (int *p) +{ + nowarn1_ignore3 (p + 1); +} + +int e2[2]; + +void ignore3 (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" + nowarn2_ignore3 (e2 + 1); +#pragma GCC diagnostic pop +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-27.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-27.c new file mode 100644 index 0000000..8188dd8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-27.c @@ -0,0 +1,20 @@ +/* PR middle-end/100325 - missing warning with -O0 on sprintf overflow with + pointer plus offset + { dg-do compile } + { dg-options "-O0 -Wall" } */ + +#define S(n) (&"0123456789"[10 - n]) + +extern int sprintf (char*, const char*, ...); + +char d[10]; + +void nowarn_d10_s9 () +{ + sprintf (d, "%s", S (9)); // { dg-bogus "-Wformat-overflow" } +} + +void warn_d10_s10 () +{ + sprintf (d, "%s", S (10)); // { dg-warning "-Wformat-overflow" } +} diff --git a/gcc/testsuite/gcc.dg/uninit-suppress_3.c b/gcc/testsuite/gcc.dg/uninit-suppress_3.c new file mode 100644 index 0000000..7bbe9ed --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-suppress_3.c @@ -0,0 +1,98 @@ +/* PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration + site + { dg-do compile } + { dg-options "-O1 -Wall" } */ + +struct A +{ + int x; +}; + +// Verify that suppression works at every inlining level. + +static int f0 (int *x) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + + return ++*x; + +#pragma GCC diagnostic pop +} + +static int f1 (int *p, int n) +{ + struct A a; + for (int i = 0; i < n; ++i) { + if (p[i] > 1) { + a = (struct A){p[i]}; + } + } + + return f0 (&a.x); +} + +int f2 (void) +{ + int a[] = { 1, 2, 3, 4 }; + return f1 (a, 4); +} + + +static int g0 (int *x) +{ + return ++*x; +} + +static int g1 (int *p, int n) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + + struct A a; + for (int i = 0; i < n; ++i) { + if (p[i] > 1) { + a = (struct A){p[i]}; + } + } + + return g0 (&a.x); + +#pragma GCC diagnostic pop +} + +int g2 (void) +{ + int a[] = { 1, 2, 3, 4, 5 }; + return g1 (a, 5); +} + + +static int h0 (int *x) +{ + return ++*x; +} + +static int h1 (int *p, int n) +{ + struct A a; + for (int i = 0; i < n; ++i) { + if (p[i] > 1) { + a = (struct A){p[i]}; + } + } + + return h0 (&a.x); +} + +int h2 (void) +{ + int a[] = { 1, 2, 3, 4, 5, 6 }; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + + return h1 (a, 6); + +#pragma GCC diagnostic pop +} |