Skip to content

Commit

Permalink
Fix Namespaces.C
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Mar 7, 2024
1 parent df334e9 commit 7a6d7b4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tools/ClangPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ namespace clad {
std::string CustomModelName;
};

class CladExternalSource : public clang::ExternalSemaSource {
// ExternalSemaSource
void ReadUndefinedButUsed(
llvm::MapVector<clang::NamedDecl*, clang::SourceLocation>& Undefined)
override {
// namespace { double f_darg0(double x); } will issue a warning that
// f_darg0 has internal linkage but is not defined. This is because we
// have not yet started to differentiate it. The warning is triggered by
// Sema::ActOnEndOfTranslationUnit before Clad is given control.
// To avoid the warning we should remove the entry from here.
using namespace clang;
Undefined.remove_if([](std::pair<NamedDecl*, SourceLocation> P) {
NamedDecl* ND = P.first;

if (!ND->getDeclName().isIdentifier())
return false;

// FIXME: We should replace this comparison with the canonical decl
// from the differentiation plan...
return ND->getName().contains("_darg");
});
}
};
class CladPlugin : public clang::SemaConsumer {
clang::CompilerInstance& m_CI;
DifferentiationOptions m_DO;
Expand Down Expand Up @@ -202,12 +225,16 @@ namespace clad {

// SemaConsumer
void InitializeSema(clang::Sema& S) override {
// We are also a ExternalSemaSource.
S.addExternalSource(new CladExternalSource()); // Owned by Sema.
AppendDelayed({CallKind::InitializeSema, nullptr});
}
void ForgetSema() override {
AppendDelayed({CallKind::ForgetSema, nullptr});
}

// FIXME: We should hide ProcessDiffRequest when we implement proper
// handling of the differentiation plans.
clang::FunctionDecl* ProcessDiffRequest(DiffRequest& request);

private:
Expand Down

0 comments on commit 7a6d7b4

Please sign in to comment.