Skip to content

Commit b0f8f32

Browse files
authored
[ExprConst] Handle floating- and char literals in FastEvaluateAsRValue (#118294)
This is part of a three-patch series that results in some nice (but not substantial) compile-time improvements: http://llvm-compile-time-tracker.com/compare.php?from=fe1c4f0106fe4fd6d61c38ba46e71fda8f4d1573&to=0824d621b2c035a3befb564153b31309a9a79d97&stat=instructions%3Au The results for just this patch are here: http://llvm-compile-time-tracker.com/compare.php?from=fe1c4f0106fe4fd6d61c38ba46e71fda8f4d1573&to=6f7f51b476a37dc7c80427fede077e6798a83be8&stat=instructions:u
1 parent 0e7f187 commit b0f8f32

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16536,7 +16536,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1653616536
const ASTContext &Ctx, bool &IsConst) {
1653716537
// Fast-path evaluations of integer literals, since we sometimes see files
1653816538
// containing vast quantities of these.
16539-
if (const IntegerLiteral *L = dyn_cast<IntegerLiteral>(Exp)) {
16539+
if (const auto *L = dyn_cast<IntegerLiteral>(Exp)) {
1654016540
Result.Val = APValue(APSInt(L->getValue(),
1654116541
L->getType()->isUnsignedIntegerType()));
1654216542
IsConst = true;
@@ -16549,6 +16549,18 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1654916549
return true;
1655016550
}
1655116551

16552+
if (const auto *FL = dyn_cast<FloatingLiteral>(Exp)) {
16553+
Result.Val = APValue(FL->getValue());
16554+
IsConst = true;
16555+
return true;
16556+
}
16557+
16558+
if (const auto *L = dyn_cast<CharacterLiteral>(Exp)) {
16559+
Result.Val = APValue(Ctx.MakeIntValue(L->getValue(), L->getType()));
16560+
IsConst = true;
16561+
return true;
16562+
}
16563+
1655216564
if (const auto *CE = dyn_cast<ConstantExpr>(Exp)) {
1655316565
if (CE->hasAPValueResult()) {
1655416566
APValue APV = CE->getAPValueResult();

0 commit comments

Comments
 (0)