Re: [eigen] Clang issue on MacOS when the set variable is used in the given data

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

The first version is indeed wrong. This is because 'foo' appears on
both sides and it might happens that foo(0) is set to zero before it
is read to apply the inverse.

Your second version should be ok because you do not read foo(0) after
it has been changed, but that's still a dangerous use.

btw, instead of .block(1,0,2,1), you can use .segment(1,2) or even,
..segment<2>(1).

gael


On Thu, Apr 18, 2013 at 8:58 AM, Arnaud BARRE <arnaud.barre@xxxxxxxxx> wrote:
> I've recently updated my Mac to MacOS 10.8 and then by default the compiler
> used is Clang.
>
> During the running of unit tests in my program I discovered a specific issue
> with Clang. The same unit tests passed for GCC 4.2 and MSVC 2008.
>
> For example, I have the following code:
> Eigen::Matrix<double,4,1> foo;
> foo << I, 1.0;
> foo << 0.0, rot * (inv * foo).block(1,0,2,1), 1.0;
> *JC = (local * foo).block(0,0,3,1);
>
> The content of the line 3 is wrong with Clang, while there is no problem
> with the other compilers. If I modified the code with the following:
> Eigen::Matrix<double,4,1> foo;
> foo << I, 1.0;
> foo = inv * foo;
> foo << 0.0, rot * foo.block(1,0,2,1), 1.0;
> *JC = (local * foo).block(0,0,3,1);
>
> Then everything is fine. The difference is how 'foo' is used during the
> comma initialisation.
>
> In general is is a bad idea to use the first code for any compiler, or
> should I write a bug report for this case? I read in this ML than the
> delivered version of Clang for Mac has some problem but I didn't find any
> page on the website which list these issues. Maybe somewhere in the
> documentation it should be written to be carefull with Clang (delivered by
> Apple)?
>
> Arnaud



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/