This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c++/28343: ICE with invalid asm specifier for struct member


The following invalid code triggers an ICE since GCC 4.0.0:

  struct A
  {
    static int i __asm__(int);
  };

bug.cc:3: error: expected string-literal before 'int'
bug.cc:3: error: expected `(' before 'int'
bug.cc:3: internal compiler error: tree check: expected string_cst, have error_mark in grokfield, at cp/decl2.c:841
Please submit a full bug report, [etc.]

This is because the frontend tries to extract the asmspec string from
asmspec_tree using TREE_STRING_POINTER. However, this macro cannot handle
error_mark_nodes and we get an ICE.
The patch fixes the ICE by not trying to extract a string from an
error_mark_node. asmspec remains NULL in this case.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?

Regards,
Volker

:ADDPATCH C++:


2006-07-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28343
	* decl.c (cp_finish_decl): Check asmspec_tree for error_mark_node.
	* decl2.c (grokfield): Likewise.

===================================================================
--- gcc/gcc/cp/decl.c	(revision 115324)
+++ gcc/gcc/cp/decl.c	(working copy)
@@ -4935,7 +4935,7 @@ cp_finish_decl (tree decl, tree init,
   /* If a name was specified, get the string.  */
   if (global_scope_p (current_binding_level))
     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
-  if (asmspec_tree)
+  if (asmspec_tree && asmspec_tree != error_mark_node)
     asmspec = TREE_STRING_POINTER (asmspec_tree);
 
   if (current_class_type
===================================================================
--- gcc/gcc/cp/decl2.c	(revision 115324)
+++ gcc/gcc/cp/decl2.c	(working copy)
@@ -880,7 +880,7 @@ grokfield (const cp_declarator *declarator,
       return void_type_node;
     }
 
-  if (asmspec_tree)
+  if (asmspec_tree && asmspec_tree != error_mark_node)
     asmspec = TREE_STRING_POINTER (asmspec_tree);
 
   if (init)
===================================================================

2006-07-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28343
	* g++.dg/ext/asmspec1.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/ext/asmspec1.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/ext/asmspec1.C	2006-07-11 16:02:35 +0200
@@ -0,0 +1,8 @@
+// PR c++/28343
+// { dg-do compile }
+
+struct A
+{
+  int i __asm__(int);         // { dg-error "before" }
+  static int j __asm__(int);  // { dg-error "before" }
+};
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]