[LLVMdev] Incorrect execution of global constructor with JIT on ARM
Renato Golin
rengolin at systemcall.org
Wed Feb 17 02:23:33 PST 2010
On 15 February 2010 14:49, Martins Mozeiko <49640f8a at gmail.com> wrote:
> #include <stdio.h>
> struct Global {
> typedef unsigned char ArrayType[4];
> ArrayType value;
> Global(const ArrayType& arg) {
> for (int i = 0; i < 4; i++) this->value[i] = arg[i];
> }
> };
> static const unsigned char arr[] = { 1, 2, 3, 4 };
> static const Global Constant(arr);
> int main() {
> for (int i=0; i<4; i++) printf("%i", Constant.value[i]);
> }
Compiling with clang I got lots of errors, but boils down to two problems:
> typedef unsigned char ArrayType[4];
const_array.cpp:3:2: error: type name does not allow storage class to
be specified
typedef unsigned char ArrayType[4];
^
Which, as far as I can tell, it's confusing ArrayType[4] by a
declaration of an unsigned char[4] type.
I've changed your code slightly to make it compile with clang, but I
haven't been able to make it print 4444, not even with your own code,
not even at -O3. There seems to be nothing wrong with the LLVM IR
generated by your code, too, even at -O3.
#include <stdio.h>
typedef unsigned char ArrayType;
struct Global {
ArrayType value[4];
Global(const ArrayType* arg) {
for (int i = 0; i < 4; i++) this->value[i] = arg[i];
}
};
static const unsigned char arr[] = { 1, 2, 3, 4 };
static const struct Global Constant(arr);
int main() {
for (int i=0; i<4; i++) printf("%i", Constant.value[i]);
}
See if that helps. I think it has nothing to do with code generation, though.
cheers,
--renato
http://systemcall.org/
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm
More information about the llvm-dev
mailing list