Skip to content

Commit 808fc84

Browse files
committed
[clang][Interp] Fix dummy DeclRefExprs for function pointers
1 parent 1b377db commit 808fc84

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,8 +3722,16 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
37223722
}
37233723
}
37243724

3725-
if (std::optional<unsigned> I = P.getOrCreateDummy(D))
3726-
return this->emitGetPtrGlobal(*I, E);
3725+
if (std::optional<unsigned> I = P.getOrCreateDummy(D)) {
3726+
if (!this->emitGetPtrGlobal(*I, E))
3727+
return false;
3728+
// Convert the dummy pointer to another pointer type if we have to.
3729+
if (PrimType PT = classifyPrim(E); PT != PT_Ptr) {
3730+
if (!this->emitDecayPtr(PT_Ptr, PT, E))
3731+
return false;
3732+
}
3733+
return true;
3734+
}
37273735

37283736
return this->emitInvalidDeclRef(E, E);
37293737
}

clang/test/AST/Interp/functions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,3 +617,9 @@ namespace {
617617
void bir [[clang::annotate("B", {1, 2, 3, 4})]] (); // both-error {{'annotate' attribute requires parameter 1 to be a constant expression}} \
618618
// both-note {{subexpression not valid in a constant expression}}
619619
}
620+
621+
namespace FuncPtrParam {
622+
void foo(int(&a)()) {
623+
*a; // both-warning {{expression result unused}}
624+
}
625+
}

0 commit comments

Comments
 (0)