[cfe-dev] Helpers to compute sizeof/alignof/offsetof?
Chris Lattner
clattner at apple.com
Thu Jan 17 19:35:58 PST 2008
On Jan 17, 2008, at 9:05 AM, Ted Kremenek wrote:
>> The only big gotcha will be sizeof(VLA), which doesn't return a
>> constant. I don't think there is a good way to represent this
>> without
>> knowing the client. The code generator (f.e.) needs to expand this
>> out to LLVM IR instructions.
>
> Agreed, clients will need to perform their own reasoning about VLAs.
> What the code generator and (say) the static analysis engine do are
> context specific.
Right.
> For the "generic" method that returns the sizeof, we may consider
> having it return a variant type that wraps an integer primitive. The
> variant could also have a flag indicating whether or the not the
> sizeof returned is valid. This way we can have the generic method
> return "unknown" for VLAs if clients just blindly call sizeof on VLA
> types. For example:
How about a really simple variant: int64_t :)
Define -1 to be "invalid" and -2 to be "vla" and you're golden.
-Chris
>
>
> class SizeofVariant {
> unsigned value; // probably will use something other than
> unsigned, but you get the idea
> bool IsValid;
> public:
> SizeOfVariant(unsigned V) : value(V), IsValid(true) {}
> explicit SizeOfVariant() : value(0), IsValid(false) {}
>
> unsigned getValue() const { assert (IsValid); return value; }
> bool isValid() const { return IsValid; };
>
> operator bool() const { return isValid(); }
> operator unsigned() const { return getValue(); }
> };
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list