aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-11-28 23:04:09 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-11-28 16:04:09 -0700
commit04864ec855832e92a6be3b0686fdb8b621276e67 (patch)
tree86c31dd4e824dcb05e04d8850dd75321d515e2a7
parent15684250225252a6ef74a7c3779294ca5aa0c16c (diff)
downloadgcc-04864ec855832e92a6be3b0686fdb8b621276e67.zip
gcc-04864ec855832e92a6be3b0686fdb8b621276e67.tar.gz
gcc-04864ec855832e92a6be3b0686fdb8b621276e67.tar.bz2
PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy
PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy PR c/87297 - ICE on strncpy with an undeclared argument gcc/c-family/ChangeLog: PR c/88065 PR c/87297 * c-warn.c (sizeof_pointer_memaccess_warning): Bail if source or destination is an error. gcc/testsuite/ChangeLog: PR c/88065 PR c/87297 * c-c++-common/Wsizeof-pointer-memaccess4.c: New test. From-SVN: r266594
-rw-r--r--gcc/c-family/ChangeLog7
-rw-r--r--gcc/c-family/c-warn.c7
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess4.c36
4 files changed, 55 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index bc85a93..ee193d9 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,10 @@
+2018-11-28 Martin Sebor <msebor@redhat.com>
+
+ PR c/88065
+ PR c/87297
+ * c-warn.c (sizeof_pointer_memaccess_warning): Bail if source
+ or destination is an error.
+
2018-11-28 Jakub Jelinek <jakub@redhat.com>
PR c++/88215
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 93c343a..798ad1b 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -784,7 +784,12 @@ sizeof_pointer_memaccess_warning (location_t *sizeof_arg_loc, tree callee,
if (idx >= 3)
return;
- if (sizeof_arg[idx] == NULL || sizeof_arg[idx] == error_mark_node)
+ /* Use error_operand_p to detect non-error arguments with an error
+ type that the C++ front-end constructs. */
+ if (error_operand_p (src)
+ || error_operand_p (dest)
+ || !sizeof_arg[idx]
+ || error_operand_p (sizeof_arg[idx]))
return;
type = TYPE_P (sizeof_arg[idx])
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0ba033a..07b8e84 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-28 Martin Sebor <msebor@redhat.com>
+
+ PR c/88065
+ PR c/87297
+ * c-c++-common/Wsizeof-pointer-memaccess4.c: New test.
+
2018-11-28 Marek Polacek <polacek@redhat.com>
Implement P1094R2, Nested inline namespaces.
diff --git a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess4.c b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess4.c
new file mode 100644
index 0000000..b2052f3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess4.c
@@ -0,0 +1,36 @@
+/* PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy
+ PR c/87297 - ICE on strncpy with an undeclared argument
+ { dg-do compile }
+ { dg-options "-Wall -Wsizeof-pointer-memaccess" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+char* strncpy (char*, const char*, size_t);
+
+struct A { char a[4], b[6]; };
+
+void test_invalid_dst (struct A *p)
+{
+ strncpy (q->a, p->b, sizeof p->b); /* { dg-error ".q. undeclared|not declared" } */
+}
+
+void test_invalid_src (struct A *p)
+{
+ strncpy (p->a, q->b, sizeof p->b); /* { dg-error ".q. undeclared|not declared" } */
+}
+
+void test_invalid_bound (struct A *p)
+{
+ strncpy (p->a, p->b, sizeof q->b); /* { dg-error ".q. undeclared|not declared" } */
+}
+
+/* Verify the C++ front end doesn't ICE (the verifies that the fix
+ for PR c/87297 uses error_operand_p to detect the invalid source
+ argument rather than just checking its equality to error_mark_node. */
+struct B { char a[4]; };
+
+void test_cxx_invalid_dst (struct B *p, const char *s)
+{
+ struct T x; /* { dg-error "storage size|incomplete type|unused" } */
+ __builtin_strncpy (x, s, sizeof p->a);
+}