Author: Nick Desaulniers Date: 2023-07-25T15:27:08-07:00 New Revision: d1199808afa5b46dfb6738f123b869d0e2fa050a
URL: https://github.com/llvm/llvm-project/commit/d1199808afa5b46dfb6738f123b869d0e2fa050a DIFF: https://github.com/llvm/llvm-project/commit/d1199808afa5b46dfb6738f123b869d0e2fa050a.diff LOG: [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 Added: Modified: clang/lib/CodeGen/CGExprConstant.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 836561a0fb7325..88dde7c9178829 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -1127,6 +1127,11 @@ class ConstExprEmitter : case CK_ConstructorConversion: return Visit(subExpr, destType); + 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"); @@ -1164,7 +1169,6 @@ class ConstExprEmitter : case CK_CPointerToObjCPointerCast: case CK_BlockPointerToObjCPointerCast: case CK_AnyPointerToBlockPointerCast: - case CK_ArrayToPointerDecay: case CK_FunctionToPointerDecay: case CK_BaseToDerived: case CK_DerivedToBase: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits