diff options
author | Martin Sebor <msebor@redhat.com> | 2021-07-27 16:02:54 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-07-27 16:02:54 -0600 |
commit | 6aacd901b800ee8a2a03123669b299a08aad0504 (patch) | |
tree | 92b704e894cabafe841d622922d28b8ad2dfa540 /gcc/testsuite/gcc.dg/uninit-41.c | |
parent | 9360d6cd1706882dfffd3c7a08b5956c37207a11 (diff) | |
download | gcc-6aacd901b800ee8a2a03123669b299a08aad0504.zip gcc-6aacd901b800ee8a2a03123669b299a08aad0504.tar.gz gcc-6aacd901b800ee8a2a03123669b299a08aad0504.tar.bz2 |
Let -Wuninitialized assume built-ins don't change const arguments [PR101584].
PR tree-optimization/101584 - missing -Wuninitialized with an allocated object after a built-in call
gcc/ChangeLog:
PR tree-optimization/101584
* tree-ssa-uninit.c (builtin_call_nomodifying_p): New function.
(check_defs): Call it.
gcc/testsuite/ChangeLog:
PR tree-optimization/101584
* gcc.dg/uninit-38.c: Remove assertions.
* gcc.dg/uninit-41.c: New test.
Diffstat (limited to 'gcc/testsuite/gcc.dg/uninit-41.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-41.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/uninit-41.c b/gcc/testsuite/gcc.dg/uninit-41.c new file mode 100644 index 0000000..b485611 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-41.c @@ -0,0 +1,121 @@ +/* Verify that calls to non-modifying built-ins aren't considered + potentially modifying. + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +typedef __SIZE_TYPE__ size_t; + +void* alloca (size_t); +void* calloc (size_t, size_t); +void* malloc (size_t); +int printf (const char *, ...); +int scanf (const char *, ...); +int sprintf (char *, const char *, ...); +int snprintf (char *, size_t, const char *, ...); +int puts (const char *); +char* strcpy (char*, const char*); +size_t strlen (const char*); + +void noproto (); + +void sink (int, ...); + +extern char a[]; + +void nowarn_noproto (const char *fmt) +{ + int i; + noproto (&i); + sink (i); +} + +void nowarn_scanf (const char *fmt) +{ + int i; + scanf ("%i", &i); + sink (i); +} + +void test_puts_sprintf_alloca (const char *fmt) +{ + char *p; + { + p = alloca (8); + sprintf (a, fmt, p); // fmt might contain %n + puts (p); + } + + { + p = alloca (8); + snprintf (0, 0, fmt, p); // same as above + puts (p); + } +} + +void test_puts_alloca (const char *s) +{ + char *p = alloca (8); + + { + char a[] = "foo"; + puts (a); + } + + puts (p); // { dg-warning "-Wuninitialized" } + + { + p = alloca (strlen (s) + 1); + strcpy (p, s); + puts (p); + } + + { + /* Verify that the puts() calls above isn't considered to have + potentially modified *P, and same for the one below. */ + p = alloca (strlen (s)); + puts (p); // { dg-warning "-Wuninitialized" } + puts (p + 1); // { dg-warning "-Wuninitialized" } + } +} + + +void test_puts_malloc (const char *s, const char *t) +{ + char *p; + + { + p = malloc (strlen (s) + 1); + strcpy (p, s); + puts (p); + } + + { + p = malloc (strlen (t)); + puts (p); // { dg-warning "-Wuninitialized" } + } +} + + +void test_puts_vla (const char *s, const char *t) +{ + { + char a[strlen (s) + 1]; + strcpy (a, s); + puts (a); + } + + { + char b[strlen (t)]; + puts (b); // { dg-warning "-Wuninitialized" } + } +} + + +void test_printf_puts (const char *s) +{ + char *p = __builtin_malloc (1); + + printf ("%s", s); + + puts (p); // { dg-warning "-Wuninitialized" } +} |