diff mbox

C PATCH for c/79730, ICE on invalid with DECL_HARD_REGISTER

Message ID 20170329180701.GT3172@redhat.com
State New
Headers show

Commit Message

Marek Polacek March 29, 2017, 6:07 p.m. UTC
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  <polacek@redhat.com>

	PR c/79730
	* c-decl.c (finish_decl): Check VAR_P.

	* gcc.dg/pr79730.c: New test.


	Marek

Comments

Jeff Law March 29, 2017, 7:28 p.m. UTC | #1
On 03/29/2017 12:07 PM, Marek Polacek wrote:
> 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  <polacek@redhat.com>
>
> 	PR c/79730
> 	* c-decl.c (finish_decl): Check VAR_P.
>
> 	* gcc.dg/pr79730.c: New test.
OK.
jeff
diff mbox

Patch

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