Skip to content

Commit 27fdb6b

Browse files
committed
[CIR] Upstream support for calling functions via member expressions
This adds support for calling functions via class member function pointers.
1 parent c89eb13 commit 27fdb6b

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,10 +1820,10 @@ CIRGenCallee CIRGenFunction::emitCallee(const clang::Expr *e) {
18201820
// Resolve direct calls.
18211821
const auto *funcDecl = cast<FunctionDecl>(declRef->getDecl());
18221822
return emitDirectCallee(funcDecl);
1823-
} else if (isa<MemberExpr>(e)) {
1824-
cgm.errorNYI(e->getSourceRange(),
1825-
"emitCallee: call to member function is NYI");
1826-
return {};
1823+
} else if (auto me = dyn_cast<MemberExpr>(e)) {
1824+
const auto *fd = cast<FunctionDecl>(me->getMemberDecl());
1825+
emitIgnoredExpr(me->getBase());
1826+
return emitDirectCallee(fd);
18271827
} else if (auto *pde = dyn_cast<CXXPseudoDestructorExpr>(e)) {
18281828
return CIRGenCallee::forPseudoDestructor(pde);
18291829
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
3+
// RUN: %clang_cc1 -std=c++20 -triple aarch64-none-linux-android21 -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
5+
// RUN: %clang_cc1 -std=c++20 -triple aarch64-none-linux-android21 -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
7+
8+
class A {
9+
public:
10+
static char *b(int);
11+
};
12+
13+
int h=0;
14+
15+
class F {
16+
public:
17+
const char *b();
18+
A g;
19+
};
20+
21+
const char *F::b() { return g.b(h); }
22+
23+
void fn1() { F f1; }
24+
25+
// CIR: cir.func {{.*}} @_ZN1F1bEv
26+
// CIR: %[[H_PTR:.*]] = cir.get_global @h : !cir.ptr<!s32i>
27+
// CIR: %[[H_VAL:.*]] = cir.load{{.*}} %[[H_PTR]] : !cir.ptr<!s32i>, !s32i
28+
// CIR: %[[RET:.*]] = cir.call @_ZN1A1bEi(%[[H_VAL]]) : (!s32i) -> !cir.ptr<!s8i>
29+
30+
// LLVM: define {{.*}} ptr @_ZN1F1bEv
31+
// LLVM: %[[VAR_H:.*]] = load i32, ptr @h
32+
// LLVM: %[[RET:.*]] = call ptr @_ZN1A1bEi(i32 %[[VAR_H]])
33+
34+
// OGCG: define {{.*}} ptr @_ZN1F1bEv
35+
// OGCG: %[[VAR_H:.*]] = load i32, ptr @h
36+
// OGCG: %[[RET:.*]] = call noundef ptr @_ZN1A1bEi(i32 noundef %[[VAR_H]])

0 commit comments

Comments
 (0)