[LLVMdev] Seeing a crash with ConstantFP::get
Dale Johannesen
dalej at apple.com
Thu Sep 6 07:31:33 PDT 2007
On Sep 6, 2007, at 6:01 AM, Neil Booth wrote:
> Dale Johannesen wrote:-
>
>>> I spent some time walking through what?s going on with a friend of
>>> mine from VStudio. Category is given 2 bits in the APFloat class
>>> definition. It?s sign extending the enum value for the comparisons
>>> when it loads it out of the class, so the 2 becomes a -2 and the
>>> comparison fails. He sent me a piece of code which I might be able
>>> to use to force the issue. I?ll update when I try that out.
>> OK. This possibility occurred to me, I checked the C++ standard, and
>> the code is valid; this is explicitly required to work, and there's
>> an example.
>
> Thought this might be my bug for a moment.
>
> 4.5p3 right? "If the bit-field has an enumerated type, it is
> treated as any other value of that type for promotion purposes".
> So the bitfield promotes like the enumeration constant itself and
> the comparison should be good.
You might argue with that one if you didn't feel like changing your
compiler, but 9 .6p4 is quite explicit:
... If the value of an enumerator is stored into a bitfield
of the same enumeration type and the number of bits in the bitfield
is large enough to hold all the values of that enumeration type, the
original enumerator value and the value of the bitfield
shall compare equal. [Example:
enum BOOL { f=0, t=1 };
struct A {
BOOL b:1;
};
A a;
void f() {
a.b = t;
if (a.b == t) // shall yield true
{ /* ... */ }
}
—end example]
Looks just like your code.
> It would be pretty sad indeed if
> assigning an enum of that type to the bitfield didn't then compare
> equal to itself :)
I agree. So did the committee.
>> However VStudio is what it is. I expect expanding the field to
>> 3 bits is good enough. I don't think that will hurt anything.
>
> MSVC--.
>
> Neil.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list