Improves the ability of ConstExprEmitter to evaluate constants.
Found by adding asserts to ConstantEmitter::tryEmitPrivate to find cases
where ConstExprEmitter::Visit() fails to resolve (obvious) constants.
Differential D156154
[clang][ConstExprEmitter] handle IntegerLiterals nickdesaulniers on Jul 24 2023, 10:44 AM. Authored by
Details
Improves the ability of ConstExprEmitter to evaluate constants. Found by adding asserts to ConstantEmitter::tryEmitPrivate to find cases
Diff Detail
Event TimelineComment Actions As a practical matter, I'm not sure this helps much; ExprConstant should be reasonably fast for simple integers. The performance issues only really show for structs/arrays. But maybe it helps a little to handle a few of the most common integer expressions.
Comment Actions Perhaps, but after D151587, ConstExprEmitter will be tried first before ExprConstant::Evaluate (or rather Evaluate in ExprConstant.cpp; god, why is that a static function and not a method???). So it seems bad if we can't just evaluate the constant then and there. Comment Actions We don't completely fall back if a subexpression fails to evaluate. EmitArrayInitialization etc. don't recursively visit; they use tryEmitPrivateForMemory, so we can fallback for subexpressions. (tryEmitPrivateForMemory can still fail for certain constructs, like the MaterializeTemporary cases we spent so much time on, but the most common cases should work.) Comment Actions That said, skipping all those abstraction layers for the simplest cases is probably worth it; LGTM. Comment Actions As of D151587... From the commit message Improves the ability of ConstExprEmitter to evaluate constants. Stated another way:
int y = 2; ^ is 2 a constant expression? Comment Actions
Nice! |
This doesn't look right; I suspect this will return an integer with the wrong width.