[cfe-dev] Helpers to compute sizeof/alignof/offsetof?
Chris Lattner
clattner at apple.com
Thu Jan 17 08:47:33 PST 2008
On Jan 17, 2008, at 3:11 AM, Eli Friedman wrote:
> Currently, there are multiple places that need the values for
> sizeof/alignof/offsetof (at least two places in isIntegerConstantExpr
> and the visitor methods in CGExprScalar.cpp). However, there is no
> common method to compute the needed information. There really should
> be common methods (probably in ASTContext?) to get the result of
> evaluating these expressions, because the logic isn't trivial.
>
> Sound reasonable?
>
> The reason I came upon this is that sizeof(void) currently crashes,
> and there are currently three places that have to be changed to get it
> right.
Sounds good to me.
> Implementation notes:
> The two versions in isIntegerConstantExpr for sizeof/alignof (which
> appear to be the same) look mostly correct, although they don't handle
> sizeof(void) correctly... the version in CGExprScalar.cpp also
> mishandles "sizeof(void ())" (and a theoretical arch where CHAR_BIT !=
> 8...). Also, ASTContext::getTypeInfo currently mishandles references
> in order to get the sizeof case correct, so once an alternative
> exists, that should be fixed.
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.
-Chris
More information about the cfe-dev
mailing list