Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -65,7 +65,9 @@ - Fix a crash when evaluating a multi-dimensional array's array filler expression is element-dependent. This fixes `Issue 50601 `_. - +- Fixed a crash-on-valid with consteval evaluation of a list-initialized + constructor for a temporary object. This fixes + `Issue 55871 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Index: clang/lib/CodeGen/CGExprConstant.cpp =================================================================== --- clang/lib/CodeGen/CGExprConstant.cpp +++ clang/lib/CodeGen/CGExprConstant.cpp @@ -1395,15 +1395,13 @@ llvm::Constant *ConstantEmitter::tryEmitConstantExpr(const ConstantExpr *CE) { if (!CE->hasAPValueResult()) return nullptr; - const Expr *Inner = CE->getSubExpr()->IgnoreImplicit(); - QualType RetType; - if (auto *Call = dyn_cast(Inner)) - RetType = Call->getCallReturnType(CGM.getContext()); - else if (auto *Ctor = dyn_cast(Inner)) - RetType = Ctor->getType(); - llvm::Constant *Res = - emitAbstract(CE->getBeginLoc(), CE->getAPValueResult(), RetType); - return Res; + + QualType RetType = CE->getType(); + if (CE->isGLValue()) + RetType = CGM.getContext().getLValueReferenceType(RetType); + assert(!RetType.isNull() && "Not certain of the constant expression's type"); + + return emitAbstract(CE->getBeginLoc(), CE->getAPValueResult(), RetType); } llvm::Constant * Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp =================================================================== --- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp +++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp @@ -56,3 +56,18 @@ // CHECK: define{{.*}} signext i8 @_ZN10Issue545782f2IcEEcT_( // CHECK: ret i8 4 } + +namespace Issue55871 { +struct Item { + consteval Item(char c) :_char{c}{} + char _char; +}; + +int function(const Item& item1, const Item& item2) { + return 0; +} + +int foo() { + return function(Item{'a'}, Item{'a'}); +} +} // namespace Issue58871