This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] avoid error_mark_node in -Wsizeof-pointer-memaccess (PR 88065)
- From: Martin Sebor <msebor at gmail dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 17 Nov 2018 15:45:10 -0700
- Subject: [PATCH] avoid error_mark_node in -Wsizeof-pointer-memaccess (PR 88065)
-Wsizeof-pointer-memaccess fails with an ICE when one of
the arguments is ill-formed (error_mark_node). To avoid
the error the attached patch has the function bail in this
case.
Martin
PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy
gcc/c-family/ChangeLog:
PR c/88065
* c-warn.c (sizeof_pointer_memaccess_warning): Bail if source
or destination is an error.
gcc/testsuite/ChangeLog:
PR c/88065
* gcc.dg/Wsizeof-pointer-memaccess2.c: New test.
Index: gcc/c-family/c-warn.c
===================================================================
--- gcc/c-family/c-warn.c (revision 266240)
+++ gcc/c-family/c-warn.c (working copy)
@@ -784,7 +784,10 @@ sizeof_pointer_memaccess_warning (location_t *size
if (idx >= 3)
return;
- if (sizeof_arg[idx] == NULL || sizeof_arg[idx] == error_mark_node)
+ if (src == error_mark_node
+ || dest == error_mark_node
+ || sizeof_arg[idx] == NULL
+ || sizeof_arg[idx] == error_mark_node)
return;
type = TYPE_P (sizeof_arg[idx])
Index: gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess2.c
===================================================================
--- gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess2.c (nonexistent)
+++ gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess2.c (working copy)
@@ -0,0 +1,24 @@
+/* PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+char* strncpy (char*, const char*, size_t);
+
+struct S { char a[4], b[6]; };
+
+void test_invalid_dst (struct S *p)
+{
+ strncpy (q->a, p->b, sizeof p->b); /* { dg-error ".q. undeclared" } */
+}
+
+void test_invalid_src (struct S *p)
+{
+ strncpy (p->a, q->b, sizeof p->b); /* { dg-error ".q. undeclared" } */
+}
+
+void test_invalid_bound (struct S *p)
+{
+ strncpy (p->a, p->b, sizeof q->b); /* { dg-error ".q. undeclared" } */
+}