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]

Re: [C++] Fix PR middle-end/44100




Sent from my iPhone

On May 17, 2010, at 12:20 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:

Hi,

this is the failure of g++.dg/init/struct2.C on Alpha/Tru64, a regression
introduced by my Tree level constants uniquization patch posted at:
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01531.html


The varasm.c machinery (decode_addr_const) chockes on the 1st member of the
initializer:


void saveOrLoad() {
   struct Track {
       char soundName[15];
   };
   struct SaveLoadEntry {
       int offs;
       int type;
       int size;
   };

struct SaveLoadEntry trackEntries = {
((long) (__SIZE_TYPE__) (&((struct Track *) 42)->soundName [0])) - 42,
0, 1
};
saveLoadEntries(&trackEntries);
}


because the expression is too complex to be decoded there.

While this machinery could be enhanced, it's worth noting that the same code
compiles fine with the C compiler on the same platform. That's because the
offsetof-like expression is folded in build_unary_op:


/* ??? Cope with user tricks that amount to offsetof. Delete this
when we have proper support for integer constant expressions. */
val = get_base_address (arg);
if (val && TREE_CODE (val) == INDIRECT_REF
&& TREE_CONSTANT (TREE_OPERAND (val, 0)))
{
tree op0 = fold_convert_loc (location, sizetype,
fold_offsetof (arg, val)), op1;


op1 = fold_convert_loc (location, argtype, TREE_OPERAND (val, 0));
ret = fold_build2_loc (location, POINTER_PLUS_EXPR, argtype, op1, op0);
goto return_build_unary_op;


So the proposed fix is to implement the same folding in the C++ compiler, in
cp_build_unary_op. This yields a couple of regressions:


FAIL: g++.dg/parse/array-size2.C  (test for errors, line 16)
FAIL: g++.dg/parse/array-size2.C  (test for errors, line 17)

because the C++ compiler can now compile the testcase (as the C compiler can
compile the counterpart gcc.dg/pr25682.c).


Well this is not a constant intergal expression so it should be rejected with -pedantic-errors. Well and maybe even by default for C++ front-end. This is what that test is testing I think.

Tested on i586-suse-linux and x86_64-suse-linux, OK for mainline?



2010-05-17 Eric Botcazou <ebotcazou@adacore.com>


   PR middle-end/44100
   * typeck.c (cp_build_unary_op): Fold offsetof-like computations.


2010-05-17 Eric Botcazou <ebotcazou@adacore.com>


* g++.dg/parse/array-size2.C: Remove dg-error directives.


-- Eric Botcazou <pr44100.diff>


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