================ @@ -4522,6 +4523,38 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E, BaseVal = MTE->getOrCreateValue(false); assert(BaseVal && "got reference to unevaluated temporary"); + } else if (const CompoundLiteralExpr *CLE = + dyn_cast_or_null<CompoundLiteralExpr>(Base)) { + // In C99, a CompoundLiteralExpr is an lvalue, and we defer evaluating + // the initializer until now for such expressions. Such an expression + // can't be an ICE in C, so this only matters for fold. + if (LValType.isVolatileQualified()) { + Info.FFDiag(E); + return CompleteObject(); + } + + // According to GCC info page: + // + // 6.28 Compound Literals + // + // As an optimization, G++ sometimes gives array compound literals + // longer lifetimes: when the array either appears outside a function or + // has a const-qualified type. If foo and its initializer had elements + // of type char *const rather than char *, or if foo were a global + // variable, the array would have static storage duration. But it is + // probably safest just to avoid the use of array compound literals in + // C++ code. + // + // Obey that rule by checking constness for converted array types. + if (QualType CLETy = CLE->getType(); CLETy->isArrayType() && + !LValType->isArrayType() && ---------------- efriedma-quic wrote:
Oh, I see, we do need something here... I suspect we want to revise this slightly, but this is fine for now. (I think the isArrayType checks might not be necessary.) https://github.com/llvm/llvm-project/pull/137163 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits