Skip to content

Commit 3cb35d1

Browse files
committed
[ExprConst] Handle floating- and char literals in FastEvaluateAsRValue
1 parent ccc471f commit 3cb35d1

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
@@ -16473,7 +16473,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1647316473
const ASTContext &Ctx, bool &IsConst) {
1647416474
// Fast-path evaluations of integer literals, since we sometimes see files
1647516475
// containing vast quantities of these.
16476-
if (const IntegerLiteral *L = dyn_cast<IntegerLiteral>(Exp)) {
16476+
if (const auto *L = dyn_cast<IntegerLiteral>(Exp)) {
1647716477
Result.Val = APValue(APSInt(L->getValue(),
1647816478
L->getType()->isUnsignedIntegerType()));
1647916479
IsConst = true;
@@ -16486,6 +16486,18 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1648616486
return true;
1648716487
}
1648816488

16489+
if (const auto *FL = dyn_cast<FloatingLiteral>(Exp)) {
16490+
Result.Val = APValue(FL->getValue());
16491+
IsConst = true;
16492+
return true;
16493+
}
16494+
16495+
if (const auto *L = dyn_cast<CharacterLiteral>(Exp)) {
16496+
Result.Val = APValue(Ctx.MakeIntValue(L->getValue(), L->getType()));
16497+
IsConst = true;
16498+
return true;
16499+
}
16500+
1648916501
if (const auto *CE = dyn_cast<ConstantExpr>(Exp)) {
1649016502
if (CE->hasAPValueResult()) {
1649116503
APValue APV = CE->getAPValueResult();

0 commit comments

Comments
 (0)