Skip to content

Commit 2c26397

Browse files
[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
1 parent 4e1b55a commit 2c26397

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,10 @@ class ConstExprEmitter :
11311131
if (const auto *S = dyn_cast<StringLiteral>(subExpr))
11321132
return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
11331133
return nullptr;
1134+
case CK_NullToPointer:
1135+
if (llvm::Constant *C = Visit(subExpr, destType))
1136+
return CGM.EmitNullConstant(destType);
1137+
return nullptr;
11341138

11351139
case CK_IntToOCLSampler:
11361140
llvm_unreachable("global sampler variables are not generated");
@@ -1187,7 +1191,6 @@ class ConstExprEmitter :
11871191
case CK_IntegralComplexToFloatingComplex:
11881192
case CK_PointerToIntegral:
11891193
case CK_PointerToBoolean:
1190-
case CK_NullToPointer:
11911194
case CK_IntegralCast:
11921195
case CK_BooleanToSignedIntegral:
11931196
case CK_IntegralToPointer:

0 commit comments

Comments
 (0)