DECL_HARD_REGISTER only expects a VAR_DECL, so check for that first (C++'s make_rtl_for_nonlocal_decl does that, too).
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-03-29 Marek Polacek <pola...@redhat.com> PR c/79730 * c-decl.c (finish_decl): Check VAR_P. * gcc.dg/pr79730.c: New test. diff --git gcc/c/c-decl.c gcc/c/c-decl.c index a0dc5bc..53c390c 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -5066,7 +5066,7 @@ finish_decl (tree decl, location_t init_loc, tree init, when a tentative file-scope definition is seen. But at end of compilation, do output code for them. */ DECL_DEFER_OUTPUT (decl) = 1; - if (asmspec && C_DECL_REGISTER (decl)) + if (asmspec && VAR_P (decl) && C_DECL_REGISTER (decl)) DECL_HARD_REGISTER (decl) = 1; rest_of_decl_compilation (decl, true, 0); } diff --git gcc/testsuite/gcc.dg/pr79730.c gcc/testsuite/gcc.dg/pr79730.c index e69de29..497823a 100644 --- gcc/testsuite/gcc.dg/pr79730.c +++ gcc/testsuite/gcc.dg/pr79730.c @@ -0,0 +1,6 @@ +/* PR c/79730 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu11" } */ + +register int x() asm (""); /* { dg-error "invalid storage class" } */ +register float y() asm (""); /* { dg-error "invalid storage class" } */ Marek