the crashes tend to occur in random places. they vary from one build to the next. often in pdump. vc++ does crash somewhere in pdump, in differing places from build to build. compiling sans union type makes the problem disappear.
once i tracked the problem down and it was that gcc did not do structure assignments completely in parallel in all situations. with sufficiently complicated expressions of the form x = f(x), where x is a structure, it would sometimes think that it had correctly computed one of the fields, and assign it a value, when in fact the old value was still needed elsewhere in the expression. i wrote to the gcc developers and they got very defensive and quoted a section of the ansi standard, saying "well, we agree your expected behavior is reasonable but *technically* it's not required by the ansi standard." this only happened with mule and error-checking, because the expression was much more complicated that way. by rewriting it using temporaries, the problem went away.
debugging problems with pdump is extremely difficult so i'd rather not do it when it's almost certainly a compiler problem.
why is everyone so keen on union type? the vc++ debugger is broken anyway when handling unions, as are many other debuggers. (it chokes and does not let you call debug_print() on a union.) furthermore, you can't type a raw union into a debugger expression, unlike an int. there is no guarantee that a compiler will correctly optimize a 4-byte union into a register. if you want the compiler to convert your 4-byte union into an int, just use an int for god's sake!
and if it does turn out we're relying on undefined behavior, then my question goes doubly, why do we want the union? there is *NO* undefined behavior with ints.
------- Original Message -------
On
Sat, 21 Dec 2002 17:08:30 +0300 Dmitry Bely?wrote:
"Ben Wing" <wing(a)666.com> writes:
> yes, i definitely have discovered compiler problems in the past. there's
> another message in which i wrote about this yesterday, i think.
Hmm, I have not found anything concrete.
> when
> expressions got too complicated, gcc failed to do structure assignments
> completely in parallel.
You told that VC++ also suffers from this "union bug". Can I see a piece
of code that reproduces it for VC++ 6.0 sp5? (or at least can you tell me
where it crashes in XEmacs)
> the bugs only occur usually when you turn on
> error-checking and mule, because these options greatly increase the
> complexity of the expressions. OCaml may simply not have any code with the
> expression complexity that we have.
Maybe. But I would rather believe into the code with undefined behaviour
(you know, C is a sort of mine field :-)), than in VC++ union bug (until I
see an example :-))
- Dmitry Bely