summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-autodiff-rev.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-01-02 14:29:57 -0600
committerGitHub <noreply@github.com>2025-01-02 12:29:57 -0800
commitd48cd130aacbab34bb98d51bb237ad38ff37348c (patch)
tree9fc9643233ad0cd7ff1aa65155f9f5ca64f677f7 /source/slang/slang-ir-autodiff-rev.cpp
parente3b71cf0356692bda5f0b3a06aed9d49ad3314a4 (diff)
Correct IR generation for no-diff pointer type (#5976)
* Correct IR generation for no-diff pointer type Close #5805 There is an issue on checking whether a pointer type parameter is no_diff, we should first check whether this parameter is an Attribute type first, then check the data type. In the back-propagate pass, for the pointer type parameter, we should load this parameter to a temp variable, then pass it to the primal function call. Otherwise, the temp variable will no be initialized, which will cause the following calculation wrong.
Diffstat (limited to 'source/slang/slang-ir-autodiff-rev.cpp')
-rw-r--r--source/slang/slang-ir-autodiff-rev.cpp11
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