From 51a8f0673123874777ed98cd836f0239ba95a250 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Mon, 5 May 2025 09:32:43 -0700 Subject: [PATCH 1/2] handle calls to unresolved member methods --- Sources/idt/idt.cc | 13 +++++++++++++ Tests/TemplateCallsPrivateMethod.hh | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Tests/TemplateCallsPrivateMethod.hh diff --git a/Sources/idt/idt.cc b/Sources/idt/idt.cc index a394fd0..cfc7d2b 100644 --- a/Sources/idt/idt.cc +++ b/Sources/idt/idt.cc @@ -514,6 +514,19 @@ class visitor : public clang::RecursiveASTVisitor { return true; } + // Visit every unresolved member expression in the compilation unit to + // determine if there are overloaded private methods that might be called. In + // this uncommon case, the private method should be annotated. + bool VisitUnresolvedMemberExpr(clang::UnresolvedMemberExpr *E) { + // Iterate over potential declarations + for (const clang::NamedDecl *ND : E->decls()) + if (const auto *MD = llvm::dyn_cast(ND)) + if (MD->getAccess() == clang::AccessSpecifier::AS_private) + export_function_if_needed(MD); + + return true; + } + // Visit every constructor call in the compilation unit to determine if there // are any inline calls to private constructors. In this uncommon case, the // private constructor must be annotated for export. Constructor calls are not diff --git a/Tests/TemplateCallsPrivateMethod.hh b/Tests/TemplateCallsPrivateMethod.hh new file mode 100644 index 0000000..0799963 --- /dev/null +++ b/Tests/TemplateCallsPrivateMethod.hh @@ -0,0 +1,20 @@ +// RUN: %idt --export-macro IDT_TEST_ABI %s 2>&1 | %FileCheck %s + +class TemplateCallsPrivateMethod { +public: + // CHECK-NOT: TemplateCallsPrvateMethod.hh:[[@LINE+1]]:{{.*}} + template void publicTemplateMethod(T x) { + privateMethodForTemplate(x); + } + +private: + // NOTE: we use CHECK-DAG here because these remarks may come out of order and + // we cannot control the order by rearranging members. + + // CHECK-DAG: TemplateCallsPrivateMethod.hh:[[@LINE+1]]:3: remark: unexported public interface 'privateMethodForTemplate' + void privateMethodForTemplate(long x) const; + + // CHECK-DAG: TemplateCallsPrivateMethod.hh:[[@LINE+1]]:3: remark: unexported public interface 'privateMethodForTemplate' + void privateMethodForTemplate(int x) const; +}; + From 4521713b9c7a9597e2ff7a3ed231d43650809029 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Mon, 5 May 2025 15:28:01 -0700 Subject: [PATCH 2/2] use -fno-delayed-template-parsing so new tests pass on Windows --- Tests/TemplateCallsPrivateMethod.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/TemplateCallsPrivateMethod.hh b/Tests/TemplateCallsPrivateMethod.hh index 0799963..9c66401 100644 --- a/Tests/TemplateCallsPrivateMethod.hh +++ b/Tests/TemplateCallsPrivateMethod.hh @@ -1,4 +1,4 @@ -// RUN: %idt --export-macro IDT_TEST_ABI %s 2>&1 | %FileCheck %s +// RUN: %idt --extra-arg="-fno-delayed-template-parsing" --export-macro IDT_TEST_ABI %s 2>&1 | %FileCheck %s class TemplateCallsPrivateMethod { public: