Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
gojakuch committed Sep 14, 2024
1 parent 668ddee commit b53646a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
CallArgs.insert(CallArgs.begin(), Clone(OCE->getArg(0)));
call = CXXOperatorCallExpr::Create(
m_Context, OCE->getOperator(), Clone(CE->getCallee()), CallArgs,
FD->getCallResultType(), VK_LValue, Loc,
FD->getCallResultType(), OCE->getValueKind(), Loc,
CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParamsOverride());
return StmtDiff(call);
}
Expand Down
25 changes: 23 additions & 2 deletions lib/Differentiator/VisitorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,35 @@ namespace clad {
std::vector<NestedNameSpecifier*> NNChain;
CXXScopeSpec CSS;
while (NNS) {
llvm::errs() << '\n' << "BDR";
llvm::errs() << '\n';
D->print(llvm::errs());
llvm::errs() << '\n';
if (NNS->getKind() == NestedNameSpecifier::Namespace)
llvm::errs() << "Namespace: " << NNS->getAsNamespace()->getNameAsString() << '\n';
else if (NNS->getKind() == NestedNameSpecifier::TypeSpec)
llvm::errs() << "Record \n"; // << const_cast<RecordType*>(NNS->getAsType()->getAs<RecordType>())->getDecl()->getNameAsString() << '\n';
llvm::errs() << "isDependent: " << (int)NNS->isDependent() << '\n';
// FIXME: proper support for dependent NNS needs to be added.
//if (!NNS->isDependent()) return BuildDeclRef(D);

NNChain.push_back(NNS);
NNS = NNS->getPrefix();
}

// clang::NamespaceDecl *OuterNamespace = ...;
// clang::NamespaceDecl *InnerNamespace = ...;

clang::NestedNameSpecifier *OuterNNS = clang::NestedNameSpecifier::Create(Context, nullptr, OuterNamespace);
clang::NestedNameSpecifier *FullNNS = clang::NestedNameSpecifier::Create(Context, OuterNNS, InnerNamespace);

CSS.MakeTrivial();

std::reverse(NNChain.begin(), NNChain.end());

for (auto& n : NNChain) {
NNS = n;
for (size_t i = 0; i < NNChain.size(); ++i) {
NNS = NNChain[i];
// FIXME: this needs to be extended to support more NNS kinds. An inspiration can be take from getFullyQualifiedNestedNameSpecifier in llvm-project/clang/lib/AST/QualTypeNames.cpp
if (NNS->getKind() == NestedNameSpecifier::Namespace) {
NamespaceDecl* NS = NNS->getAsNamespace();
CSS.Extend(m_Context, NS, noLoc, noLoc);
Expand Down
5 changes: 2 additions & 3 deletions test/Gradient/Lambdas.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// RUN: ./Lambdas.out | %filecheck_exec %s
// RUN: %cladclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oLambdas.out
// RUN: ./Lambdas.out | %filecheck_exec %s
// CHECK-NOT: {{.*error|warning|note:.*}}

#include "clad/Differentiator/Differentiator.h"

Expand All @@ -14,7 +13,7 @@ double f1(double i, double j) {
}

// CHECK: inline void operator_call_pullback(double t, double _d_y, double *_d_t) const;
// CHECK-NEXT: void f1_grad(double i, double j, double *_d_i, double *_d_j) {
// CHECK: void f1_grad(double i, double j, double *_d_i, double *_d_j) {
// CHECK-NEXT: auto _f = []{{ ?}}(double t) {
// CHECK-NEXT: return t * t + 1.;
// CHECK-NEXT: }{{;?}}
Expand All @@ -35,7 +34,7 @@ double f2(double i, double j) {
}

// CHECK: inline void operator_call_pullback(double t, double k, double _d_y, double *_d_t, double *_d_k) const;
// CHECK-NEXT: void f2_grad(double i, double j, double *_d_i, double *_d_j) {
// CHECK: void f2_grad(double i, double j, double *_d_i, double *_d_j) {
// CHECK-NEXT: auto _f = []{{ ?}}(double t, double k) {
// CHECK-NEXT: return t + k;
// CHECK-NEXT: }{{;?}}
Expand Down

0 comments on commit b53646a

Please sign in to comment.