Skip to content

Commit d119980

Browse files
[clang][ConstExprEmitter] handle ArrayToPointerDecay ImplicitCastExpr of StringLiterals
Consider the following statement: const char* foo = "foo"; For the sub-AST: `-ImplicitCastExpr <col:19> 'const char *' <NoOp> `-ImplicitCastExpr <col:19> 'char *' <ArrayToPointerDecay> `-StringLiteral <col:19> 'char[4]' lvalue "foo" The address of the StringLiteral can be emitted as the Constant. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D156185
1 parent e1bdf32 commit d119980

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,11 @@ class ConstExprEmitter :
11271127
case CK_ConstructorConversion:
11281128
return Visit(subExpr, destType);
11291129

1130+
case CK_ArrayToPointerDecay:
1131+
if (const auto *S = dyn_cast<StringLiteral>(subExpr))
1132+
return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
1133+
return nullptr;
1134+
11301135
case CK_IntToOCLSampler:
11311136
llvm_unreachable("global sampler variables are not generated");
11321137

@@ -1164,7 +1169,6 @@ class ConstExprEmitter :
11641169
case CK_CPointerToObjCPointerCast:
11651170
case CK_BlockPointerToObjCPointerCast:
11661171
case CK_AnyPointerToBlockPointerCast:
1167-
case CK_ArrayToPointerDecay:
11681172
case CK_FunctionToPointerDecay:
11691173
case CK_BaseToDerived:
11701174
case CK_DerivedToBase:

0 commit comments

Comments
 (0)