[clang] 2c26397 - [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 26 12:53:11 PDT 2023
Author: Nick Desaulniers
Date: 2023-07-26T12:53:02-07:00
New Revision: 2c26397f76d9b8d2a0dc8207eeca5b0d3216f3f0
URL: https://github.com/llvm/llvm-project/commit/2c26397f76d9b8d2a0dc8207eeca5b0d3216f3f0
DIFF: https://github.com/llvm/llvm-project/commit/2c26397f76d9b8d2a0dc8207eeca5b0d3216f3f0.diff
LOG: [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr
Consider the following statement:
void* foo = ((void *)0);
For the sub-AST:
| `-ImplicitCastExpr 'const void *' <NullToPointer>
| `-CStyleCastExpr 'void *' <NullToPointer>
| `-IntegerLiteral 'int' 0
If the subexpression of the cast is itself the NULL constant, then
ImplicitCastExpr should emit the NULL pointer constant.
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D156175
Added:
Modified:
clang/lib/CodeGen/CGExprConstant.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 88dde7c9178829..9ad07f7d2220a7 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1131,6 +1131,10 @@ class ConstExprEmitter :
if (const auto *S = dyn_cast<StringLiteral>(subExpr))
return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
return nullptr;
+ case CK_NullToPointer:
+ if (llvm::Constant *C = Visit(subExpr, destType))
+ return CGM.EmitNullConstant(destType);
+ return nullptr;
case CK_IntToOCLSampler:
llvm_unreachable("global sampler variables are not generated");
@@ -1187,7 +1191,6 @@ class ConstExprEmitter :
case CK_IntegralComplexToFloatingComplex:
case CK_PointerToIntegral:
case CK_PointerToBoolean:
- case CK_NullToPointer:
case CK_IntegralCast:
case CK_BooleanToSignedIntegral:
case CK_IntegralToPointer:
More information about the cfe-commits
mailing list