-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" } */ +}