[cfe-dev] Helpers to compute sizeof/alignof/offsetof?
eli.friedman at gmail.com
Thu Jan 17 05:11:54 CST 2008
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.
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
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.
More information about the cfe-dev