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:
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:
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits