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++/27601: ICE with __builtin_offsetof for a static member


The following invalid code snippet triggers an ICE:

  struct bar {
    static int foo;
  };

  int a = __builtin_offsetof(bar, foo);

bug.cc:5: internal compiler error: in fold_offsetof_1, at c-common.c:6019
Please submit a full bug report, [etc.]

The problem is that fold_offsetof_1 does not handle static members
(VAR_DECLs). The following patch emits an appropriate error message
in this case and returns an error_mark_node to fix the ICE.

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

Regards,
Volker

:ADDPATCH C++:


2006-06-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27601
	* c-common.c (fold_offsetof_1): Handle static members.

===================================================================
--- gcc/gcc/c-common.c	2006-06-03 01:27:05 +0200
+++ gcc/gcc/c-common.c	2006-06-03 01:24:59 +0200
@@ -5980,6 +5980,10 @@ fold_offsetof_1 (tree expr)
     case ERROR_MARK:
       return expr;
 
+    case VAR_DECL:
+      error ("offset taken of static member %qD", expr);
+      return error_mark_node;
+
     case INDIRECT_REF:
       return size_zero_node;
 
===================================================================

2006-06-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27601
	* g++.dg/ext/offsetof1.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/ext/offsetof1.C	2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/ext/offsetof1.C	2006-06-03 01:32:19 +0200
@@ -0,0 +1,9 @@
+// PR c++/27601
+// Origin: Patrik Hägglund  <patrik.hagglund@bredband.net>
+// { dg-do compile }
+
+struct bar {
+  static int foo;
+};
+
+int a = __builtin_offsetof(bar, foo);  // { dg-error "static member" }
===================================================================



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