Skip to content

Commit b574ee6

Browse files
authored
[BUGFIX] correctly emitting calls with addressoff operator (#224)
[BUGFIX] correctly emitting calls with addressoff operator Formatting moved test to cgeist dir reduced lit test reduced lit test Co-authored-by: pietro.ghiglio <[email protected]>
1 parent aa82f7f commit b574ee6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tools/cgeist/Lib/clang-mlir.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,10 @@ const clang::FunctionDecl *MLIRScanner::EmitCallee(const Expr *E) {
15481548
// Look through template substitutions.
15491549
} else if (auto NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
15501550
return EmitCallee(NTTP->getReplacement());
1551+
} else if (auto UOp = dyn_cast<clang::UnaryOperator>(E)) {
1552+
if (UOp->getOpcode() == UnaryOperatorKind::UO_AddrOf) {
1553+
return EmitCallee(UOp->getSubExpr());
1554+
}
15511555
}
15521556

15531557
return nullptr;

tools/cgeist/Test/addressoff_call.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: cgeist %s --function=_Z1fv -S | FileCheck %s
2+
unsigned long foo(unsigned);
3+
inline unsigned long inlineFunc(unsigned i) noexcept {
4+
return foo(i);
5+
}
6+
7+
struct S {
8+
static unsigned long bar() noexcept {
9+
return (&inlineFunc)(0);
10+
}
11+
};
12+
13+
void f(){
14+
auto res = S::bar();
15+
}
16+
// CHECK: func.func @_Z10inlineFuncj(%arg0: i32) -> i64 attributes {llvm.linkage = #llvm.linkage<linkonce_odr>} {
17+
// CHECK-NEXT: %0 = call @_Z3fooj(%arg0) : (i32) -> i64
18+
// CHECK-NEXT: return %0 : i64
19+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)