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 regression with pointer-to-member constants


The following patch fixes a regression in compiling the C++ testcase:

  struct C { int i; };

  typedef int C::*mPtr;
  const mPtr m = &C::i;

  int main() { return 0; }

The mainline, while putting |m| in read-only data (as 3.3.1 does),
generates initialization code to fill in the value rather than putting
the correct value in the read-only data section (so the executable
segfaults when executing the initialization code).  This patch causes
the correct value to be in the read-only data section instead, with no
initialization code, as 3.3.1 did.  (And it even makes some sense to me
given how little I know about the code.)

I tested this with a "make bootstrap" on i686-pc-linux-gnu and also
tested that it allows the Mozilla compiled by the mainline to run again.

-David


2003-09-15  L. David Baron  <dbaron@dbaron.org>

        PR c++/12218
        * fold-const.c (fold_convert): Handle OFFSET_TYPE.


Index: fold-const.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.303
diff -c -3 -p -r1.303 fold-const.c
*** fold-const.c	14 Sep 2003 14:49:06 -0000	1.303
--- fold-const.c	15 Sep 2003 04:24:08 -0000
*************** fold_convert (tree t, tree arg1)
*** 1560,1566 ****
    tree type = TREE_TYPE (t);
    int overflow = 0;
  
!   if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type))
      {
        if (TREE_CODE (arg1) == INTEGER_CST)
  	{
--- 1560,1567 ----
    tree type = TREE_TYPE (t);
    int overflow = 0;
  
!   if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type)
!       || TREE_CODE (type) == OFFSET_TYPE)
      {
        if (TREE_CODE (arg1) == INTEGER_CST)
  	{

-- 
L. David Baron                                <URL: http://dbaron.org/ >


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