Skip to content

Commit 51a8f06

Browse files
committed
handle calls to unresolved member methods
1 parent c48649d commit 51a8f06

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Sources/idt/idt.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ class visitor : public clang::RecursiveASTVisitor<visitor> {
514514
return true;
515515
}
516516

517+
// Visit every unresolved member expression in the compilation unit to
518+
// determine if there are overloaded private methods that might be called. In
519+
// this uncommon case, the private method should be annotated.
520+
bool VisitUnresolvedMemberExpr(clang::UnresolvedMemberExpr *E) {
521+
// Iterate over potential declarations
522+
for (const clang::NamedDecl *ND : E->decls())
523+
if (const auto *MD = llvm::dyn_cast<clang::CXXMethodDecl>(ND))
524+
if (MD->getAccess() == clang::AccessSpecifier::AS_private)
525+
export_function_if_needed(MD);
526+
527+
return true;
528+
}
529+
517530
// Visit every constructor call in the compilation unit to determine if there
518531
// are any inline calls to private constructors. In this uncommon case, the
519532
// private constructor must be annotated for export. Constructor calls are not

Tests/TemplateCallsPrivateMethod.hh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %idt --export-macro IDT_TEST_ABI %s 2>&1 | %FileCheck %s
2+
3+
class TemplateCallsPrivateMethod {
4+
public:
5+
// CHECK-NOT: TemplateCallsPrvateMethod.hh:[[@LINE+1]]:{{.*}}
6+
template <typename T> void publicTemplateMethod(T x) {
7+
privateMethodForTemplate(x);
8+
}
9+
10+
private:
11+
// NOTE: we use CHECK-DAG here because these remarks may come out of order and
12+
// we cannot control the order by rearranging members.
13+
14+
// CHECK-DAG: TemplateCallsPrivateMethod.hh:[[@LINE+1]]:3: remark: unexported public interface 'privateMethodForTemplate'
15+
void privateMethodForTemplate(long x) const;
16+
17+
// CHECK-DAG: TemplateCallsPrivateMethod.hh:[[@LINE+1]]:3: remark: unexported public interface 'privateMethodForTemplate'
18+
void privateMethodForTemplate(int x) const;
19+
};
20+

0 commit comments

Comments
 (0)