Author: ycwu Date: 2011-08-09 04:35:42 -0400 (Tue, 09 Aug 2011) New Revision: 3713
Modified: trunk/osprey/be/cg/whirl2ops.cxx Log: fixed EBO phase BUG in -O1 with DBG compiler Bug description: ---------------- test case: #pragma pack (2) struct S4 { short a; short b : 11; int e : 18; }; #pragma pack (0) void test_4(void) { struct S4 s; s.e = -6619; vfy_S4(&s); } When the above test case is compiled with the following command, $ opencc min.c -c -O1 the following assertion is hit: ### Gen_Literal_TN: 4-byte literal 0xf989400000000000 is out-of-range This assertion failure is within a routine called Gen_Literal_TN, which is given a size of 4 and a constant value of -465770717711958016, which is outside the value range of 4 bytes. Gen_Literal_TN makes a constant TN with the given size and value. The routine is called from inside Fold_Constant_Expression for the following OP. TN149 :- ldc32 (0xffffffffffffe625) ; TN153 :- shli64 TN149 (0x2e) ; Here, TN149 has -6619 in 4 byte storage and it is shifted to the left by 46 bits (0x2e). Thus the resulting value of this shift left operation is outside the range of the 4 byte storage of TN153. The source code for the above CG IR is as follows. struct S4 s; s.e = -6619; And the above CG IR is generated from the following WHIRL. I4INTCONST -6619 (0xffffffffffffe625) I8STBITS 0 <bofst:27 bsize:18> <2,1,s> T<5,.predef_I8,8> {line: 18} The problem is that the size of TN153 is generated from the kid of STBITS, which is I4. As can be seen from the above WHIRL IR, the result type of the kid (I4) does not match the descriptor type of the parent(I8). This problem does not occur with -O0 because constant folding is not invoked. Also, it does not occur with -O2 and above because the WOPT converts the above WHIRL into the following. I8I8LDID 0 <2,1,s> T<5,.predef_I8,8> I8INTCONST -6619 (0xffffffffffffe625) I8COMPOSE_BITS <bofst:27 bsize:18> I8STID 0 <2,1,s> T<5,.predef_I8,8> {line: 1/18} So, this is a problem only at -O1 level. Modified: trunk/osprey/be/cg/whirl2ops.cxx =================================================================== --- trunk/osprey/be/cg/whirl2ops.cxx 2011-08-09 08:24:33 UTC (rev 3712) +++ trunk/osprey/be/cg/whirl2ops.cxx 2011-08-09 08:35:42 UTC (rev 3713) @@ -2894,12 +2894,24 @@ result = field_tn; } else { variant = Memop_Variant(stbits); - field_tn = Allocate_Result_TN (kid, NULL); + // U4CONSTANT 1 + // for U8STBITS + // allocate a larger TN if bit deposit may run out of range + if(MTYPE_byte_size(rtype) > MTYPE_byte_size(WN_rtype(kid))) + field_tn = Build_TN_Of_Mtype (rtype); + else + field_tn = Allocate_Result_TN (kid, NULL); Last_Mem_OP = OPS_last(&New_OPs); Exp_Load(rtype, desc, field_tn, WN_st(stbits), WN_load_offset(stbits), &New_OPs, variant); // must do an unsigned load Set_OP_To_WN_Map(stbits); - result = Allocate_Result_TN (kid, NULL); + // U4CONSTANT 1 + // for U8STBITS + // allocate a larger TN if bit deposit may run out of range + if(MTYPE_byte_size(rtype) > MTYPE_byte_size(WN_rtype(kid))) + result = Build_TN_Of_Mtype (rtype); + else + result = Allocate_Result_TN (kid, NULL); } #ifdef TARG_PPC32 @@ -3105,10 +3117,21 @@ WN *kid0 = WN_kid0(istbits); WN *kid1 = WN_kid1(istbits); TN *bits_tn = Expand_Expr (kid0, istbits, NULL); - TN *field_tn = Allocate_Result_TN (kid0, NULL); - TN *result = Allocate_Result_TN (kid0, NULL); + TN *field_tn; + TN *result; TYPE_ID desc = Mtype_TransferSign(MTYPE_U4, WN_desc(istbits)); TYPE_ID rtype = desc; + // U4CONSTANT 1 + // Addr + // for U8ISTBITS + // allocate larger TNs if bit deposit may run out of range + if(MTYPE_byte_size(rtype) > MTYPE_byte_size(WN_rtype(kid0))) { + result = Build_TN_Of_Mtype (rtype); + field_tn = Build_TN_Of_Mtype (rtype); + }else{ + result = Allocate_Result_TN (kid0, NULL); + field_tn = Allocate_Result_TN (kid0, NULL); + } // guard against U1MPY or U2MPY if (MTYPE_byte_size(rtype) < 4) ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ Open64-devel mailing list Open64-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open64-devel