diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index a40a9ed15..98501190f 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -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); } diff --git a/test/Gradient/Functors.C b/test/Gradient/Functors.C index 334978e87..76e52477d 100644 --- a/test/Gradient/Functors.C +++ b/test/Gradient/Functors.C @@ -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 @@ -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; @@ -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; diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index 2d39c112a..eebf66365 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -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 @@ -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; @@ -1145,7 +1144,7 @@ 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; @@ -1153,9 +1152,7 @@ double g(double a, double b) { } //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); diff --git a/test/Hessian/Functors.C b/test/Hessian/Functors.C index b462b0b9b..d9a07290b 100644 --- a/test/Hessian/Functors.C +++ b/test/Hessian/Functors.C @@ -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 @@ -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); diff --git a/test/ValidCodeGen/ValidCodeGen.C b/test/ValidCodeGen/ValidCodeGen.C index 0e454de51..5fa3d1dfa 100644 --- a/test/ValidCodeGen/ValidCodeGen.C +++ b/test/ValidCodeGen/ValidCodeGen.C @@ -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 @@ -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 struct Test2 { @@ -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;