================ @@ -119,12 +121,26 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) { template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { if (!isActive()) return true; - EvalResult.setPointer(S.Stk.pop<Pointer>()); + + const Pointer &Ptr = S.Stk.pop<Pointer>(); + // Implicitly convert lvalue to rvalue, if requested. + if (ConvertResultToRValue) { + if (std::optional<APValue> V = Ptr.toRValue(Ctx)) { + EvalResult.setValue(*V); + } else { + return false; + } + } else { + EvalResult.setPointer(Ptr); + } + return true; } template <> bool EvalEmitter::emitRet<PT_FnPtr>(const SourceInfo &Info) { if (!isActive()) return true; + // Function pointers are always lvalues to us and cannot be converted + // to rvalues, so don't do any conversion here. ---------------- tbaederr wrote:
I can't get any sample to hit the `evaluteAsRValue()` code path: ```c int foo() { return 0; } auto f = foo; const auto ff = &foo; ``` even for C. I can add an `assert(!ConvertResultToRValue)` if that makes sense. https://github.com/llvm/llvm-project/pull/80662 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits