Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,12 @@ Expr* ReverseModeVisitor::getStdInitListSizeExpr(const Expr* E) {
initDiff.getExpr(), baseTSI,
{placementArg});
} else if (CI->isDelegatingInitializer()) {
auto* thisDRE = cast<DeclRefExpr>(thisExpr);
auto* thisVD = cast<VarDecl>(thisDRE->getDecl());
Expr* newInit = utils::BuildCXXNewExpr(m_Sema, baseTy, nullptr,
initDiff.getExpr(), baseTSI);
SetDeclInit(thisVD, newInit);
// Placement-new into the malloc'd `_this` (paired with free(_this)),
// as the base-initializer path above does. An allocating
// `new ClassTy(args)` here would be freed with free() -- a mismatch.
initCall =
utils::BuildCXXNewExpr(m_Sema, baseTy, /*arraySize=*/nullptr,
initDiff.getExpr(), baseTSI, {thisExpr});
}
}
CompoundStmt* block = endBlock(direction::reverse);
Expand Down
8 changes: 4 additions & 4 deletions test/Gradient/Constructors.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// RUN: ./Constructors.out | %filecheck_exec %s
// RUN: %cladclang -Xclang -plugin-arg-clad -Xclang -disable-tbr -Xclang -plugin-arg-clad -Xclang -enable-va %s -I%S/../../include -oConstructors.out
// RUN: ./Constructors.out | %filecheck_exec %s
// FIXME: real new/free mismatch for delegating constructors; drop when fixed.
// XFAIL: valgrind

#include "clad/Differentiator/Differentiator.h"
#include "clad/Differentiator/STLBuiltins.h"
Expand Down Expand Up @@ -368,15 +366,17 @@ double fn6(double x, double y) {
} // x^2 * y

// CHECK: static clad::ValueAndAdjoint<argByValWrapper, argByValWrapper> constructor_reverse_forw(clad::Tag<argByValWrapper>, double v, double u, double _d_v, double _d_u) {
// CHECK-NEXT: argByValWrapper *_this = new argByValWrapper(v);
// CHECK-NEXT: argByValWrapper *_this = (argByValWrapper *)malloc(sizeof(argByValWrapper));
// CHECK-NEXT: argByValWrapper *_d_this = (argByValWrapper *)malloc(sizeof(argByValWrapper));
// CHECK-NEXT: memset(_d_this, 0, sizeof(argByValWrapper));
// CHECK-NEXT: new (_this) argByValWrapper(v);
// CHECK-NEXT: _this->z = _this->y * u;
// CHECK-NEXT: return {*_this, *_d_this};
// CHECK-NEXT: }

// CHECK: static void constructor_pullback(double v, double u, argByValWrapper *_d_this, double *_d_v, double *_d_u) {
// CHECK-NEXT: argByValWrapper *_this = new argByValWrapper(v);
// CHECK-NEXT: argByValWrapper *_this = (argByValWrapper *)malloc(sizeof(argByValWrapper));
// CHECK-NEXT: new (_this) argByValWrapper(v);
// CHECK-NEXT: _this->z = _this->y * u;
// CHECK-NEXT: {
// CHECK-NEXT: double _r_d0 = _d_this->z;
Expand Down
Loading