This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: constructor problem
- To: <gcc at gcc dot gnu dot org>
- Subject: Re: constructor problem
- From: Drew Hess <dhess at ilm dot com>
- Date: Fri, 15 Jun 2001 17:25:33 -0700 (PDT)
- cc: Florian Kainz <kainz at ilm dot com>, Jim Hourihan <jimh at ilm dot com>
This bug turns out to be a memory aliasing problem for structures with
variable addresses. It was fixed by Mark in rev 1.326 of expr.c:
revision 1.326
date: 2001/06/12 11:17:09; author: mmitchel; state: Exp; lines: +10 -1
* expr.c (store_field): Don't set MEM_ALIAS_SET for a field
in a structure at a variable address.
here:
/* If the address of the structure varies, then it might be on
the stack. And, stack slots may be shared across scopes.
So, two different structures, of different types, can end up
at the same location. We will give the structures alias set
zero; here we must be careful not to give non-zero alias sets
to their fields. */
if (!rtx_varies_p (addr, /*for_alias=*/0))
MEM_ALIAS_SET (to_rtx) = alias_set;
else
MEM_ALIAS_SET (to_rtx) = 0;
thanks Mark!!
-dwh-
On Thu, 7 Jun 2001, Drew Hess wrote:
>
> gnats bug 2860 describes a bug in g++ 3.x that goes back at least as far
> as the 3.0 branch. I think the problem is that constructors with
> arguments of user-defined types don't honor those types when copying the
> arguments.
>
> In the RTL generated for the example code in bug 2860 (also attached
> below), the load instructions for the Box2f constructor have machine mode
> SImode. Shouldn't these be SFmode, since they're copying SF values?
>
> The bug manifests itself during the CSE pass with -O2 or -O3 as follows:
>
> 1. during construction of temporary object V2i(1,2), 1 and 2 are written
> to stack frame offsets -32 and -28, respectively.
>
> 2. later, during construction of temporary object V2f(1.5,2.5), 1.5 and
> 2.5 are written to stack frame offsets -32 and -28, respectively.
>
> 3. in the first CSE pass, the lookup() called on line 5112 of cse.c
> (gcc-3_0-branch) calls exp_equiv_p() and finds the lowest-cost equivalent
> for an SImode load to [frame - 32], which is a constant 1. That's fine
> for the construction of a1 (type Box2i), but it's wrong for the
> construction of a2 (type Box2f). As a result, a2.min gets improperly
> initialized.
>
> If anyone needs more info, let me know. I can point you at the exact
> insns where the problem occurs in the example code. Unfortunately,
> parsing RTL and debugging cse.c is about the extent of my gcc expertise,
> so I'm at a loss for exactly where or how to fix this bug.
>
>
> -dwh-
>
>
>
> ---
>
> //
> // xxx.C
> //
>
> #include <iostream>
>
> template <class T>
> struct Vec2
> {
> T x, y;
> Vec2 () {}
> Vec2 (T a, T b) {x = a; y = b;}
> Vec2 (const Vec2 &v) {x = v.x; y = v.y;}
> };
>
> typedef Vec2 <int> V2i;
> typedef Vec2 <float> V2f;
>
> template <class T>
> struct Box
> {
> T min;
> T max;
> Box (const T& minT, const T& maxT) {min = minT; max = maxT;}
> };
>
> typedef Box <V2i> Box2i;
> typedef Box <V2f> Box2f;
>
> int
> main ()
> {
> Box2i a1 (V2i (1, 2), V2i (3, 4));
> Box2f a2 (V2f (1.5, 2.5), V2f (3.5, 4.5));
>
> std::cout << "a1: " <<
> a1.min.x << ", " <<
> a1.min.y << ", " <<
> a1.max.x << ", " <<
> a1.max.y << std::endl;
>
> std::cout << "a2: " <<
> a2.min.x << ", " <<
> a2.min.y << ", " <<
> a2.max.x << ", " <<
> a2.max.y << std::endl;
> }
>
>
>