[PATCH] D156154: [clang][ConstExprEmitter] handle IntegerLiterals and IntegralCasts
Nick Desaulniers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 24 10:44:46 PDT 2023
nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156154
Files:
clang/lib/CodeGen/CGExprConstant.cpp
Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1125,6 +1125,7 @@
case CK_NonAtomicToAtomic:
case CK_NoOp:
case CK_ConstructorConversion:
+ case CK_IntegralCast:
return Visit(subExpr, destType);
case CK_IntToOCLSampler:
@@ -1184,7 +1185,6 @@
case CK_PointerToIntegral:
case CK_PointerToBoolean:
case CK_NullToPointer:
- case CK_IntegralCast:
case CK_BooleanToSignedIntegral:
case CK_IntegralToPointer:
case CK_IntegralToBoolean:
@@ -1215,6 +1215,10 @@
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");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156154.543636.patch
Type: text/x-patch
Size: 1089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230724/3ffded31/attachment.bin>
More information about the cfe-commits
mailing list