I tried to compiling ToT on the Maemo VM.
"gcc --version" says: sbox-arm-linux-gcc (GCC) 3.4.4 (release) (CodeSourcery ARM 2005q3-2)
There are reinterpret_cast-s in the JIT infrastructure what casts
void*-s to function pointers and vica versa. My compiler does not like this (I heard that the problem
is typical in gcc-3) so I get such errors: "ISO C++ forbids casting between pointer-to-function and pointer-to-object".
Created attachment 34969 [details]
Using bitwise casts when reinterpret_cast leads to compile error.
I am tempted to r- this patch, as webkit requires gcc-4.x or higher to build so i'm surprised you can get beyond jsc ...
Comment on attachment 34969 [details]
No your fault, but I went to look up WTF::bitwise_cast, only to find that the comment next to bitwise_cast is basically useless:
* C++'s idea of a reinterpret_cast lacks sufficient cojones.
template<typename TO, typename FROM>
TO bitwise_cast(FROM from)
COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal);
u.from = from;
And I would expect that bitwise_cast violates the c++ standard, since I've been told that only the last union member you write to is valid to read from, any other member is undefined. (I've also been told the GCC does define this behavior and that our use of unions here will work for GCC. I'm anything bug a C++ standards expert though.)
I agree with oliver, GCC 3.x is not supported for WebKit. I don't think we should take one-off patches for it, since it's undoubtably going to break again.
Looks like Gavin and Geoff wrote that comment. :) http://trac.webkit.org/changeset/39958
This post seems to quote the relevant sections of the standard: http://learningcppisfun.blogspot.com/2008/07/c-unions-can-have-functions.html
It concludes that it's legal to do this cast as long as both members are POD types or structs containing only POD types with the same layout. So whether this cast is legal or not depends on what FROM and TO are.
My bad on the comment, I should make this more descriptive. That said, I reassert my statement about reinterpret_cast lacking cojones. :-)
The real intention of the cast was to cast between POD types, (int64_t and double), so it sounds like this is safe, but I'll look into this more at some point.
If this is not safe, maybe we should more explicitly limit this (maybe we can do a kind of compile assert with a template specialization to guard against bitwise_cast being used with pointers, if that helps), or we could remove the generic cast from WTF and just make this an explicit cast within JSImmediate to prevent further use. Or we can always implement this in inline asm, if absolutely necessary. (Oh, c++, why are you so dumb).
I did not think I would start such an interesting conversation :)
Anyway, my original wish (to be able to compile webkit with gcc-3.x) was not a valid conception, so I would close the bug. Should I close it, or you guys want to move on with the casting debate here? :-)
Nah, we can close. Thank you for the patch though! And thanks to Gavin and Joe for following up with the C++ lesson. :) I certainly learned something!