[cfe-dev] Helpers to compute sizeof/alignof/offsetof?

Steve Naroff snaroff at apple.com
Thu Jan 17 06:38:48 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?
>

Sounds good to me...

snaroff

> 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.
>
> 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.
>
> -Eli
> _______________________________________________
> 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