Author: Timm Bäder Date: 2024-05-21T12:02:19+02:00 New Revision: 808fc8406973f958fa76acba2d7648d215d9681b
URL: https://github.com/llvm/llvm-project/commit/808fc8406973f958fa76acba2d7648d215d9681b DIFF: https://github.com/llvm/llvm-project/commit/808fc8406973f958fa76acba2d7648d215d9681b.diff LOG: [clang][Interp] Fix dummy DeclRefExprs for function pointers 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 ee83947196c6e..640311e1444bf 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3722,8 +3722,16 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) { } } - if (std::optional<unsigned> I = P.getOrCreateDummy(D)) - return this->emitGetPtrGlobal(*I, E); + if (std::optional<unsigned> I = P.getOrCreateDummy(D)) { + if (!this->emitGetPtrGlobal(*I, E)) + return false; + // Convert the dummy pointer to another pointer type if we have to. + if (PrimType PT = classifyPrim(E); PT != PT_Ptr) { + if (!this->emitDecayPtr(PT_Ptr, PT, E)) + return false; + } + return true; + } return this->emitInvalidDeclRef(E, E); } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index a5bb9f1a19aaa..e95ade8ef51b7 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -617,3 +617,9 @@ namespace { void bir [[clang::annotate("B", {1, 2, 3, 4})]] (); // both-error {{'annotate' attribute requires parameter 1 to be a constant expression}} \ // both-note {{subexpression not valid in a constant expression}} } + +namespace FuncPtrParam { + void foo(int(&a)()) { + *a; // both-warning {{expression result unused}} + } +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits