Expr constructor question
Ian Lance Taylor
ian@wasabisystems.com
Wed Mar 10 14:35:00 GMT 2004
"Weihaw Chuang" <weihawchuang@hotmail.com> writes:
> This problem is motivated by trying to add the x86 bounds instruction
> to Greg McGary's bounds checker. The x86 bounds instruction takes two
> arguments:
> bounds reg, [mem]
> meaning bounds address, [ptr of <low bounds, high bounds>]
> If address exceeds the bounds, an exception occurs.
>
> McGary's bounds checker turns pointers into fat pointers with the
> representation <ptr, low, high>.
>
> Consider the case of global, statically defined arrays. Its bounds
> are known at compile time, and with the current McGary infrastructure,
> it does not create a fat pointer to access the array. To use this
> bounds instruction I always need to have a bounds object <low bounds,
> high bounds> allocated in memory and initialized.
>
> My hack is to create a fat pointer from the array base address, and
> bounds. I then rebind the array identifier name, to the fat pointer.
> Unfortunately the problem described earlier manifests itself when the
> "array" (now a pointer) is used as an initializer to another pointer:
>
> int somearray[18]; // hack is to first handle
> declaration normally, then create a
> // fat ptr, and bind
> somearray name to fat pointer
> int* someptr = somearray; // initialization of someptr to fat
> ptr not allowed.
If I understand what you are saying, then it seems to me that someptr
ought to be a fat pointer, which would presumably fix the problem.
> >That is an error because in C you are only permitted to initialize a
> >global variable to a constant. "&object" is a constant--object is not
> >going to move at runtime. "ptr" is not a constant.
> >
> >The rules are different for C++. In C++ ptr2 will be initialized
> >using a static constructor function. C does not support this usage.
>
>
> Do you have pointers to the C++ machinery? Which TREE attributes are
> set to allow the digest_init to work properly?
C++ doesn't use digest_init. I'm not really sure how the C++ code
works, although it is probably in cp/decl.c and cp/decl2.c. It will
presumably creates a constructor function.
Ian
More information about the Gcc
mailing list