diff options
Diffstat (limited to 'source/slang/slang-ir-autodiff-rev.cpp')
| -rw-r--r-- | source/slang/slang-ir-autodiff-rev.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/source/slang/slang-ir-autodiff-rev.cpp b/source/slang/slang-ir-autodiff-rev.cpp index f0ac428c7..36093518a 100644 --- a/source/slang/slang-ir-autodiff-rev.cpp +++ b/source/slang/slang-ir-autodiff-rev.cpp @@ -512,11 +512,12 @@ InstPair BackwardDiffTranscriber::transcribeFuncHeader(IRBuilder* inBuilder, IRF { // If primal parameter is mutable, we need to pass in a temp var. auto tempVar = builder.emitVar(primalParamPtrType->getValueType()); - if (primalParamPtrType->getOp() == kIROp_InOutType) - { - // If the primal parameter is inout, we need to set the initial value. - builder.emitStore(tempVar, primalArg); - } + + // We also need to setup the initial value of the temp var, otherwise + // the temp var will be uninitialized which could cause undefined behavior + // in the primal function. + builder.emitStore(tempVar, primalArg); + primalArgs.add(tempVar); } else |
