aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-03-13 10:28:26 -0600
committerMartin Sebor <msebor@redhat.com>2020-03-13 10:28:26 -0600
commitf2e9fe5f97d88fc876c44e6ffa57a2e85150adf9 (patch)
tree4efc5313286608ccae0b5b9224a5c4381b76064c /gcc/testsuite
parent9ae8bc027743d7c2d25f90d6752a1f4e0dc153cf (diff)
downloadgcc-f2e9fe5f97d88fc876c44e6ffa57a2e85150adf9.zip
gcc-f2e9fe5f97d88fc876c44e6ffa57a2e85150adf9.tar.gz
gcc-f2e9fe5f97d88fc876c44e6ffa57a2e85150adf9.tar.bz2
PR c/94040 - ICE on a call to an invalid redeclaration of strftime
gcc/c/ChangeLog: PR c/94040 * c-decl.c (builtin_structptr_type_count): New constant. (match_builtin_function_types): Reject decls that are incompatible in types pointed to by pointers. (diagnose_mismatched_decls): Adjust comments. gcc/testsuite/ChangeLog: PR c/94040 * gcc.dg/Wbuiltin-declaration-mismatch-12.c: Relax test to look for warning name rather than the exact text. * gcc.dg/Wbuiltin-declaration-mismatch-14.c: New test. * gcc.dg/Wbuiltin-declaration-mismatch-15.c: New test. * gcc.dg/pr62090.c: Prune expected warning. * gcc.dg/pr89314.c: Look for warning name rather than text.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c4
-rw-r--r--gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-14.c77
-rw-r--r--gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-15.c56
-rw-r--r--gcc/testsuite/gcc.dg/pr62090.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr89314.c2
6 files changed, 148 insertions, 3 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e7b8c88..a379b40 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2020-03-13 Martin Sebor <msebor@redhat.com>
+
+ PR c/94040
+ * gcc.dg/Wbuiltin-declaration-mismatch-12.c: Relax test to look
+ for warning name rather than the exact text.
+ * gcc.dg/Wbuiltin-declaration-mismatch-14.c: New test.
+ * gcc.dg/Wbuiltin-declaration-mismatch-15.c: New test.
+ * gcc.dg/pr62090.c: Prune expected warning.
+ * gcc.dg/pr89314.c: Look for warning name rather than text.
+
2020-03-13 Uroš Bizjak <ubizjak@gmail.com>
* gcc.target/i386/pr64409.c: Do not limit compilation to x32 targets.
diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c
index 6bf9762..f12ef6a 100644
--- a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c
+++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c
@@ -3,6 +3,6 @@
{ dg-do compile }
{ dg-options "-Wbuiltin-declaration-mismatch -Wextra" } */
-extern void __clear_cache (char*, char*); /* { dg-warning "mismatch in argument 1 type of built-in function .__clear_cache.; expected .void \\\*." } */
+extern void __clear_cache (char*, char*); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch" }
-void __builtin_prefetch (const char *, ...); /* { dg-warning "mismatch in argument 1 type of built-in function .__builtin_prefetch.; expected .const void \\\*." } */
+void __builtin_prefetch (const char *, ...); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch" }
diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-14.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-14.c
new file mode 100644
index 0000000..cc536d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-14.c
@@ -0,0 +1,77 @@
+/* PR c/94040 - ICE on a call to an invalid redeclaration of strftime
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+struct tm;
+
+size_t strftime (char *, size_t, int *, struct tm *); // { dg-warning "-Wbuiltin-declaration-mismatch" }
+
+size_t call_strftime (char *d, size_t n, int *f, struct tm *t)
+{
+ size_t r = 0;
+ r += strftime (0, 0, 0, 0);
+ r += strftime (d, 0, 0, 0);
+ r += strftime (d, n, 0, 0);
+ r += strftime (d, n, f, 0);
+ r += strftime (d, n, f, t);
+ return r;
+}
+
+
+char* strchr (char*, char*); // { dg-warning "-Wbuiltin-declaration-mismatch" }
+
+// Verify that missing/extra qualifiers aren't diagnosed without -Wextra.
+
+int strcmp (char*, char*);
+int strncmp (volatile char*, volatile char*, size_t);
+
+// Verify that a difference in pointers is diagnosed.
+
+size_t strlen (const char**);
+// { dg-warning "-Wbuiltin-declaration-mismatch" "pointer" { target *-*-* } .-1 }
+
+ size_t strnlen (const char* const*, size_t);
+// { dg-warning "-Wbuiltin-declaration-mismatch" "pointer" { target *-*-* } .-1 }
+
+
+// Verify that calls to the compatibly-redeclared built-ins are treated
+// as those to the built-ins and diagnosed.
+
+int test_builtin_calls (size_t n)
+{
+ int r = 0;
+ r += strcmp ((char*)0, ""); // { dg-warning "\\\[-Wnonnull]" }
+ r += strcmp ("", (char*)0); // { dg-warning "\\\[-Wnonnull]" }
+
+ r += strncmp ((char*)0, "", n); // { dg-warning "\\\[-Wnonnull]" }
+ r += strncmp ("", (char*)0, n); // { dg-warning "\\\[-Wnonnull]" }
+
+ return r;
+}
+
+
+// Verify that calls to the incompatibly-redeclared built-ins are not
+// treated as those to the built-ins by the middle-end. It doesn't
+// matter if the front-end diagnoses them but the middle-end should
+// not because it shouldn't recognize them as built-ins.
+
+#pragma GCC optimize "2"
+
+size_t test_nonbuiltin_calls (char *s, int c)
+{
+ void *null = 0;
+
+ char *r;
+ r = strchr ((char*)null, s);
+ r = strchr (r, (char*)null);
+ *s = *r; // use the result
+
+ size_t n = 0;
+ n += strftime (0, 0, 0, 0);
+ n += strlen ((const char**)null);
+ n += strnlen ((const char**)null, n);
+
+ return n;
+}
diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-15.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-15.c
new file mode 100644
index 0000000..3c32a5f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-15.c
@@ -0,0 +1,56 @@
+/* PR c/94040 - ICE on a call to an invalid redeclaration of strftime
+ { dg-do compile }
+ { dg-options "-Wall -Wextra" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+struct tm;
+
+size_t strftime (const char *, size_t, char *, struct tm *);
+// { dg-warning "-Wbuiltin-declaration-mismatch" "arg 1" { target *-*-* } .-1 }
+
+// Verify that missing/extra qualifiers are diagnosed with -Wextra.
+
+int strcmp (char*, const char*);
+// { dg-warning "-Wbuiltin-declaration-mismatch" "arg 1" { target *-*-* } .-1 }
+
+int strncmp (const char*, volatile char*, size_t);
+// { dg-warning "-Wbuiltin-declaration-mismatch" "arg 2" { target *-*-* } .-1 }
+
+size_t strlen (char*);
+// { dg-warning "-Wbuiltin-declaration-mismatch" "arg 1" { target *-*-* } .-1 }
+
+
+// Verify that calls to built-ins declared with missing/extra qualifiers
+// are still treated as those to built-ins by the front-end.
+
+int test_builtin_calls_fe (size_t n)
+{
+ int r = 0;
+ r += strcmp ((char*)0, ""); // { dg-warning "\\\[-Wnonnull]" }
+ r += strcmp ("", (char*)0); // { dg-warning "\\\[-Wnonnull]" }
+
+ r += strncmp ((char*)0, "", n); // { dg-warning "\\\[-Wnonnull]" }
+ r += strncmp ("", (char*)0, n); // { dg-warning "\\\[-Wnonnull]" }
+
+ r += strlen ((char*)0); // { dg-warning "\\\[-Wnonnull]" }
+ return r;
+}
+
+
+// Ditto but by the middle-end.
+
+#pragma GCC optimize "2"
+
+int test_builtin_calls_me (void)
+{
+ char *null1 = 0;
+ char *null2 = null1;
+ char *null3 = null2;
+
+ int r = 0;
+ r += strcmp (null1, "123"); // { dg-warning "\\\[-Wnonnull]" }
+ r += strncmp ("2345", null2, 4); // { dg-warning "\\\[-Wnonnull]" }
+ r += strlen (null3); // { dg-warning "\\\[-Wnonnull]" }
+ return r;
+}
diff --git a/gcc/testsuite/gcc.dg/pr62090.c b/gcc/testsuite/gcc.dg/pr62090.c
index 53089cf..42f1345 100644
--- a/gcc/testsuite/gcc.dg/pr62090.c
+++ b/gcc/testsuite/gcc.dg/pr62090.c
@@ -15,3 +15,5 @@ log_bad_request ()
{
b += sprintf (0, "foo");
}
+
+/* { dg-prune-output "\\\[-Wbuiltin-declaration-mismatch]" } */
diff --git a/gcc/testsuite/gcc.dg/pr89314.c b/gcc/testsuite/gcc.dg/pr89314.c
index e35dd8c..27b3a51 100644
--- a/gcc/testsuite/gcc.dg/pr89314.c
+++ b/gcc/testsuite/gcc.dg/pr89314.c
@@ -2,7 +2,7 @@
/* { dg-do compile } */
/* { dg-options "-O2 -Wbuiltin-declaration-mismatch -Wextra" } */
-extern __SIZE_TYPE__ strlen (const float *); /* { dg-warning "mismatch in argument 1 type of built-in function" } */
+extern __SIZE_TYPE__ strlen (const float *); /* { dg-warning "\\\[-Wbuiltin-declaration-mismatch" } */
void bar (void);
void