Author: Timm Bäder Date: 2024-05-27T15:43:12+02:00 New Revision: 6a197b35db0805e77d5103382b5b516ca0c2db1d
URL: https://github.com/llvm/llvm-project/commit/6a197b35db0805e77d5103382b5b516ca0c2db1d DIFF: https://github.com/llvm/llvm-project/commit/6a197b35db0805e77d5103382b5b516ca0c2db1d.diff LOG: [clang][Interp] Fix returning references to functions Previously, we pushed a pointer to the stack and later tried to use it as if it was a function pointer, which doesn't work. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/functions.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 737bef85e2fc8..37c45e4311afb 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3775,13 +3775,13 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) { return this->emitGetPtrLocal(Offset, E); } else if (auto GlobalIndex = P.getGlobal(D)) { if (IsReference) - return this->emitGetGlobalPtr(*GlobalIndex, E); + return this->emitGetGlobal(classifyPrim(E), *GlobalIndex, E); return this->emitGetPtrGlobal(*GlobalIndex, E); } else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) { if (auto It = this->Params.find(PVD); It != this->Params.end()) { if (IsReference || !It->second.IsPtr) - return this->emitGetParamPtr(It->second.Offset, E); + return this->emitGetParam(classifyPrim(E), It->second.Offset, E); return this->emitGetPtrParam(It->second.Offset, E); } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index e95ade8ef51b7..10c62a43ef33b 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -623,3 +623,9 @@ namespace FuncPtrParam { *a; // both-warning {{expression result unused}} } } + +namespace { + void f() noexcept; + void (&r)() = f; + void (&cond3)() = r; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits