Skip to content

Commit

Permalink
Return type adjusted to depend on called function's return type
Browse files Browse the repository at this point in the history
This commit changes the return type of 0 that is returned in case all arguments
are constant literals. In particular it used to give warnings when
differentiating NaN(or __builtin_nanf (const char * str )) which is crucial for
the future fmax custom derivative implementation.

Fixes: vgvassilev#908.
  • Loading branch information
ovdiiuv authored and MihailMihov committed Jun 5, 2024
1 parent 6368542 commit efb0938
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/Differentiator/BaseForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) {
validLoc, llvm::MutableArrayRef<Expr*>(CallArgs),
validLoc)
.get();
auto* zero =
ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0);
auto* zero = ConstantFolder::synthesizeLiteral(CE->getType(), m_Context,
/*val=*/0);
return StmtDiff(call, zero);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/FirstDerivative/FunctionCallsWithResults.C
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ double fn4(double i, double j) {
// CHECK: double fn4_darg0(double i, double j) {
// CHECK-NEXT: double _d_i = 1;
// CHECK-NEXT: double _d_j = 0;
// CHECK-NEXT: double _d_res = 0;
// CHECK-NEXT: double _d_res = 0.;
// CHECK-NEXT: double res = nonRealParamFn(0, 0);
// CHECK-NEXT: _d_res += _d_i;
// CHECK-NEXT: res += i;
Expand Down Expand Up @@ -266,7 +266,7 @@ double fn8(double i, double j) {
// CHECK-NEXT: clad::ValueAndPushforward<double, double> _t1 = check_and_return_pushforward(_t0.value, 'a', _t0.pushforward, 0);
// CHECK-NEXT: double &_t2 = _t1.value;
// CHECK-NEXT: double _t3 = std::tanh(1.);
// CHECK-NEXT: return _t1.pushforward * _t3 + _t2 * 0;
// CHECK-NEXT: return _t1.pushforward * _t3 + _t2 * 0.;
// CHECK-NEXT: }

double g (double x) { return x; }
Expand Down

0 comments on commit efb0938

Please sign in to comment.