[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 6 01:53:27 PDT 2025


================
@@ -168,16 +168,95 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+                                         ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+      C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+      ArrayRef<SourceLocation>(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
----------------
awson wrote:

Perhaps, but it is a string literal only in the innermost leaf, otherwise it may be parens, of generic or predefined or choose.

https://github.com/llvm/llvm-project/pull/156846


More information about the cfe-commits mailing list