Skip to content

Commit

Permalink
[clang][ConstExprEmitter] handle IntegerLiterals
Browse files Browse the repository at this point in the history
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.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D156154
  • Loading branch information
nickdesaulniers committed Jul 25, 2023
1 parent 070358e commit 15a484b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,10 @@ class ConstExprEmitter :
return Visit(E->getSubExpr(), T);
}

llvm::Constant *VisitIntegerLiteral(IntegerLiteral *I, QualType T) {
return llvm::ConstantInt::get(CGM.getLLVMContext(), I->getValue());
}

llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
assert(CAT && "can't emit array init for non-constant-bound array");
Expand Down

0 comments on commit 15a484b

Please sign in to comment.