Patch for c++/4574

Unruh, Erwin Erwin.Unruh@fujitsu-siemens.com
Tue Nov 6 03:31:00 GMT 2001


Hello,

This is a patch to solve GNATS error c++/4574.
< http://gcc.gnu.org/ml/gcc-bugs/2001-10/msg00415.html >
< http://gcc.gnu.org/ml/gcc-bugs/2001-10/msg00643.html >
When using the value of an assignment to a bitfield, gcc 'and's a mask on
the value to the right. When this value is a long long constant, it used to run
into an abort.
My fix solves this special problem, although the place suggests a better
solution, allowing folding of any constants.
The patch was made relative to the official 3.0.2 source.

	Erwin

Testcase:

struct C76 {
    unsigned long long f1 : 8;
    unsigned long long c1 : 16;
};

int main() {
    struct C76 s;
    long long l;

    l = (s.c1 = 0xca9653c6396a5c63LL );

}

The patch:

        * expmed.c (expand_and): Handle 'long long constant' & 'long constant' 

Index: expmed.c
===================================================================
RCS file: /usr/local/cvscpp/archive/gcc/gcc/expmed.c,v
retrieving revision 1.1.1.2
diff -c -3 -p -r1.1.1.2 expmed.c
*** expmed.c    2001/06/19 12:21:35     1.1.1.2
--- expmed.c    2001/11/06 08:50:21
*************** expand_and (op0, op1, target)
*** 4163,4168 ****
--- 4163,4170 ----
      tem = expand_binop (mode, and_optab, op0, op1, target, 0, OPTAB_LIB_WIDEN)>;
    else if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT)
      tem = GEN_INT (INTVAL (op0) & INTVAL (op1));
+   else if (GET_CODE (op0) == CONST_DOUBLE && GET_CODE (op1) == CONST_INT)
+     tem = GEN_INT ( CONST_DOUBLE_LOW (op0) & INTVAL (op1));
    else
      abort ();



Erwin Unruh, Fujitsu Siemens Computers, C/C++ compiler group



More information about the Gcc-patches mailing list