Skip to content

Commit

Permalink
Produce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Nov 25, 2024
1 parent 7372dd0 commit 26e815e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
12 changes: 5 additions & 7 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,13 +1471,11 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
DC->addDecl(VDDiff);
DC->makeDeclVisibleInContext(VDDiff);
plugin::ProcessTopLevelDecl(m_CladPlugin, VDDiff);
// diag(DiagnosticsEngine::Warning,
// VD->getLocation(),
// "The gradient utilizes a global variable '%0' and its adjoint
// '%1'"
// ". Please make sure to properly reset '%0' and '%1' before
// re-running the gradient.",
// {VD->getNameAsString(), nameDiff_str});
diag(DiagnosticsEngine::Warning, VD->getLocation(),
"The gradient utilizes a global variable '%0' and its adjoint '%1'"
". Please make sure to properly reset '%0' and '%1' before re-running "
"the gradient.",
{VD->getNameAsString(), nameDiff_str});
return BuildDeclRef(VDDiff);
}

Expand Down
6 changes: 4 additions & 2 deletions test/Gradient/Functors.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %cladclang %s -I%S/../../include -oFunctors.out 2>&1 | %filecheck %s
// RUN: %cladclang %s -I%S/../../include -oFunctors.out -Xclang -verify 2>&1 | %filecheck %s
// RUN: ./Functors.out | %filecheck_exec %s
// RUN: %cladclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oFunctors.out
// RUN: ./Functors.out | %filecheck_exec %s
Expand Down Expand Up @@ -145,7 +145,7 @@ double FunctorAsArgWrapper(double i, double j) {
E##Ref_grad.execute(7, 9, &res[0], &res[1]); \
printf("%.2f %.2f\n", res[0], res[1]);

double x = 3;
double x = 3; // expected-warning {{The gradient utilizes a global variable 'x' and its adjoint '_d_x'. Please make sure to properly reset 'x' and '_d_x' before re-running the gradient.}}

int main() {
Experiment E(3, 5), d_E, d_E_Const;
Expand All @@ -166,6 +166,8 @@ int main() {

auto lambdaWithCapture = [&](double ii, double j) { return x * ii * j; };

// CHECK: double _d_x = 0.;

// CHECK: inline void operator_call_grad(double ii, double j, double *_d_ii, double *_d_j) const {
// CHECK-NEXT: {
// CHECK-NEXT: _d_x += 1 * j * ii;
Expand Down
9 changes: 3 additions & 6 deletions test/Gradient/Gradients.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %cladnumdiffclang %s -std=c++17 -I%S/../../include -oGradients.out 2>&1 | %filecheck %s
// RUN: %cladnumdiffclang %s -std=c++17 -I%S/../../include -oGradients.out -Xclang -verify 2>&1 | %filecheck %s
// RUN: ./Gradients.out | %filecheck_exec %s
// RUN: %cladnumdiffclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oGradients.out
// RUN: ./Gradients.out | %filecheck_exec %s
Expand Down Expand Up @@ -665,9 +665,8 @@ float running_sum(float* p, int n) {
// CHECK-NEXT: }
// CHECK-NEXT: }

double global = 7;
double global = 7; // expected-warning {{The gradient utilizes a global variable 'global' and its adjoint '_d_global'. Please make sure to properly reset 'global' and '_d_global' before re-running the gradient.}}
// CHECK: double _d_global = 0.;
// expected-warning {{The gradient utilizes a global variable 'global' and its adjoint '_d_global'. Please make sure to properly reset 'global' and '_d_global' before re-running the gradient.}}

double fn_global_var_use(double i, double j) {
double& ref = global;
Expand Down Expand Up @@ -1145,17 +1144,15 @@ double f_ref_in_rhs(double x, double y) {
//CHECK-NEXT: }
//CHECK-NEXT: }

double glob1 = 5;
double glob1 = 5; // expected-warning {{The gradient utilizes a global variable 'glob1' and its adjoint '_d_glob1'. Please make sure to properly reset 'glob1' and '_d_glob1' before re-running the gradient.}}

double g(double a, double b) {
glob1 = b;
return a;
}

//CHECK: void g_pullback(double a, double b, double _d_y, double *_d_a, double *_d_b);

//CHECK: double _d_glob1 = 0.;
// expected-warning {{The gradient utilizes a global variable 'glob1' and its adjoint '_d_glob1'. Please make sure to properly reset 'glob1' and '_d_glob1' before re-running the gradient.}}

double f_reuse_global(double x, double t) {
t = g(t, x);
Expand Down
6 changes: 3 additions & 3 deletions test/Hessian/Functors.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %cladclang %s -I%S/../../include -oFunctors.out 2>&1 | %filecheck %s
// RUN: %cladclang %s -I%S/../../include -oFunctors.out -Xclang -verify 2>&1 | %filecheck %s
// RUN: ./Functors.out | %filecheck_exec %s
// RUN: %cladclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oFunctors.out
// RUN: ./Functors.out | %filecheck_exec %s
Expand Down Expand Up @@ -122,8 +122,8 @@ namespace outer {
printf("{%.2f, %.2f, %.2f, %.2f}\n", result[0], result[1], result[2], \
result[3]);

double x = 3;
double y = 5;
double x = 3; // expected-warning {{The gradient utilizes a global variable 'x' and its adjoint '_d_x'. Please make sure to properly reset 'x' and '_d_x' before re-running the gradient.}}
double y = 5; // expected-warning {{The gradient utilizes a global variable 'y' and its adjoint '_d_y'. Please make sure to properly reset 'y' and '_d_y' before re-running the gradient.}}
int main() {
double result[4];
Experiment E(3, 5);
Expand Down
6 changes: 4 additions & 2 deletions test/ValidCodeGen/ValidCodeGen.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %cladclang -std=c++14 %s -I%S/../../include -oValidCodeGen.out 2>&1 | %filecheck %s
// RUN: %cladclang -std=c++14 %s -I%S/../../include -oValidCodeGen.out -Xclang -verify 2>&1 | %filecheck %s
// RUN: ./ValidCodeGen.out | %filecheck_exec %s
// RUN: %cladclang -std=c++14 -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oValidCodeGenWithTBR.out
// RUN: ./ValidCodeGenWithTBR.out | %filecheck_exec %s
Expand All @@ -10,7 +10,7 @@
#include "../PrintOverloads.h"

namespace TN {
int coefficient = 3;
int coefficient = 3; // expected-warning {{The gradient utilizes a global variable 'coefficient' and its adjoint '_d_coefficient'. Please make sure to properly reset 'coefficient' and '_d_coefficient' before re-running the gradient.}}

template <typename T>
struct Test2 {
Expand Down Expand Up @@ -57,6 +57,8 @@ int main() {
//CHECK-NEXT: return _d_x * TN::coefficient + x * 0;
//CHECK-NEXT: }

//CHECK: int _d_coefficient = 0;

//CHECK: void fn_grad(double x, double *_d_x) {
//CHECK-NEXT: {
//CHECK-NEXT: *_d_x += 1 * TN::coefficient;
Expand Down

0 comments on commit 26e815e

Please sign in to comment.