This patch fixes an ICE-on-invalid with __atomic_*. We should check that we're dealing with a complete type before we're accessing its TYPE_SIZE_UNIT.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-07-04 Marek Polacek <pola...@redhat.com> PR c/81231 * c-common.c (sync_resolve_size): Give error for pointers to incomplete types. * gcc.dg/atomic-pr81231.c: New test. diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index f6a9d05..1b6ac8c 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -6485,6 +6485,9 @@ sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch) if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) goto incompatible; + if (!COMPLETE_TYPE_P (type)) + goto incompatible; + if (fetch && TREE_CODE (type) == BOOLEAN_TYPE) goto incompatible; diff --git gcc/testsuite/gcc.dg/atomic-pr81231.c gcc/testsuite/gcc.dg/atomic-pr81231.c index e69de29..304e428 100644 --- gcc/testsuite/gcc.dg/atomic-pr81231.c +++ gcc/testsuite/gcc.dg/atomic-pr81231.c @@ -0,0 +1,12 @@ +/* PR c/81231 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +enum E; + +void +foo (void) +{ + __atomic_load_n ((enum E *) 0, 0); /* { dg-error "incompatible" } */ + __atomic_load_n ((enum X *) 0, 0); /* { dg-error "incompatible" } */ +} Marek