[PATCH] D156175: [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr
Nick Desaulniers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 24 15:23:13 PDT 2023
nickdesaulniers created this revision.
Herald added a subscriber: inglorion.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156175
Files:
clang/lib/CodeGen/CGExprConstant.cpp
Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1127,6 +1127,13 @@
case CK_ConstructorConversion:
return Visit(subExpr, destType);
+ case CK_NullToPointer: {
+ if (llvm::Constant *C = Visit(subExpr, destType))
+ if (C->isNullValue())
+ return CGM.EmitNullConstant(destType);
+ return nullptr;
+ }
+
case CK_IntToOCLSampler:
llvm_unreachable("global sampler variables are not generated");
@@ -1183,7 +1190,6 @@
case CK_IntegralComplexToFloatingComplex:
case CK_PointerToIntegral:
case CK_PointerToBoolean:
- case CK_NullToPointer:
case CK_IntegralCast:
case CK_BooleanToSignedIntegral:
case CK_IntegralToPointer:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156175.543718.patch
Type: text/x-patch
Size: 855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230724/91ffd074/attachment.bin>
More information about the cfe-commits
mailing list