
Bug: Returning, assigning into array and testing against 0 fails
Your analysis is spot on! Jeff Peil and I looked at this today and we came
to the same conclusion. It is an IL codegen bug in the C++ FE. We will also
verify whether it is in addition a JIT codegen bug since specifically with
the value 0 it should work.
Ronald Laeremans
Visual C++ compiler and libraries team
Quote:
> I am not sure whether this is the reason but the line
> if ((f[0] = Zero()) == 0)
> compiles to this il code
> //000018: if ((f[0] = Zero()) == 0)
> IL_0009: ldloc.0
> IL_000a: ldc.i4.0
> IL_000b: call string
> modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)
> ?A0x3d035f1e.Zero()
> IL_0010: stelem.ref
> IL_0011: ldloc.0
> IL_0012: ldc.i4.0
> IL_0013: ldelem.u4 // I changed this manually to ldelem.ref, then it
> works
> IL_0014: brtrue.s IL_0022
> whereas
> if ((f[0]) == 0)
> compiles to this
> //000018: if ((f[0]) == 0)
> IL_0009: ldloc.0
> IL_000a: ldc.i4.0
> IL_000b: ldelem.ref
> IL_000c: brtrue.s IL_001a
> > == on Object* or on any other reference type will compare pointer
values.
> > Non const inited strings aren't interned so the pointer values will be
> > different. You will need to call compare on the strings.
> > Ronald Laeremans
> > Visual C++ compiler and libraries team
> > > I'm having bad luck today. It wasn't two minutes after I worked
around
> > the
> > > value/enum compiler bugs that I stumbled into another one:
> > > #using <mscorlib.dll>
> > > using namespace System;
> > > static String *Zero() {return 0;}
> > > void main() {
> > > String *f[] = new String*[1];
> > > if ((f[0] = Zero()) == 0)
> > > Console::WriteLine(S"Zero() == 0");
> > > else
> > > Console::WriteLine(S"Zero() != 0");
> > > }
> > > Even though Zero() returns 0, it will take the 'else' path.
> > > -Sean