Skip to content

Commit

Permalink
Create LookupQualifiedName function
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Nov 6, 2024
1 parent 21ad43f commit c874ca5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 10 additions & 0 deletions include/clad/Differentiator/CladUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ namespace clad {
clang::DeclContext* DC1,
clang::DeclContext* DC2);

/// Finds the qualified name `name` in the declaration context `DC`.
///
/// \param[in] name
/// \param[in] S
/// \param[in] DC
/// \returns lookup result.
clang::LookupResult LookupQualifiedName(llvm::StringRef name,
clang::Sema& S,
clang::DeclContext* DC = nullptr);

/// Finds namespace 'namespc` under the declaration context `DC` or the
/// translation unit declaration if `DC` is null.
///
Expand Down
12 changes: 12 additions & 0 deletions lib/Differentiator/CladUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ namespace clad {
return DC->getPrimaryContext();
}

LookupResult LookupQualifiedName(llvm::StringRef name, clang::Sema& S,
clang::DeclContext* DC) {
ASTContext& C = S.getASTContext();
DeclarationName declName = &C.Idents.get(name);
LookupResult Result(S, declName, SourceLocation(),
Sema::LookupOrdinaryName);
if (!DC)
DC = C.getTranslationUnitDecl();
S.LookupQualifiedName(Result, DC);
return Result;
}

NamespaceDecl* LookupNSD(Sema& S, llvm::StringRef namespc, bool shouldExist,
DeclContext* DC) {
ASTContext& C = S.getASTContext();
Expand Down
10 changes: 2 additions & 8 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,14 +1924,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
BuildVarDecl(dArgTy, "_r", getZeroInit(dArgTy));

// Create the cudaMemcpyDeviceToHost argument
IdentifierInfo* deviceToHostIdInfo =
&m_Context.Idents.get("cudaMemcpyDeviceToHost");
DeclarationName deviceToHostName(deviceToHostIdInfo);
LookupResult deviceToHostResult(m_Sema, deviceToHostName,
SourceLocation(),
Sema::LookupOrdinaryName);
m_Sema.LookupQualifiedName(deviceToHostResult,
m_Context.getTranslationUnitDecl());
LookupResult deviceToHostResult =
utils::LookupQualifiedName("cudaMemcpyDeviceToHost", m_Sema);
if (deviceToHostResult.empty()) {
diag(DiagnosticsEngine::Error, CE->getEndLoc(),
"Failed to create cudaMemcpy call; cudaMemcpyDeviceToHost not "
Expand Down

0 comments on commit c874ca5

Please sign in to comment.