[PATCH] D156185: [clang][ConstExprEmitter] handle ArrayToPointerDecay ImplicitCastExpr of StringLiterals
Nick Desaulniers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 24 16:10:33 PDT 2023
nickdesaulniers created this revision.
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:
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156185
Files:
clang/lib/CodeGen/CGExprConstant.cpp
Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1133,6 +1133,10 @@
return CGM.EmitNullConstant(destType);
return nullptr;
}
+ case CK_ArrayToPointerDecay:
+ if (const auto *S = dyn_cast<StringLiteral>(subExpr))
+ return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
+ return nullptr;
case CK_IntToOCLSampler:
llvm_unreachable("global sampler variables are not generated");
@@ -1171,7 +1175,6 @@
case CK_CPointerToObjCPointerCast:
case CK_BlockPointerToObjCPointerCast:
case CK_AnyPointerToBlockPointerCast:
- case CK_ArrayToPointerDecay:
case CK_FunctionToPointerDecay:
case CK_BaseToDerived:
case CK_DerivedToBase:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156185.543740.patch
Type: text/x-patch
Size: 866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230724/2c394f06/attachment-0001.bin>
More information about the cfe-commits
mailing list