Skip to content

Commit

Permalink
Do not make a short cut when moving the union as it might cause UB.
Browse files Browse the repository at this point in the history
That can happen if the types are different then we will have to change manually
the active value.
  • Loading branch information
vgvassilev committed Nov 20, 2023
1 parent fbe90b8 commit 42a9ac1
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions include/clad/Differentiator/TBRAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,16 @@ class TBRAnalyzer : public clang::RecursiveASTVisitor<TBRAnalyzer> {
}
VarData& operator=(const VarData& other) = delete;
VarData& operator=(VarData&& other) noexcept {
if (this!=&other) {
type = other.type;
if (type == FUND_TYPE) {
val.m_FundData = other.val.m_FundData;
} else if (type == OBJ_TYPE || type == ARR_TYPE) {
val.m_ArrData = std::move(other.val.m_ArrData);
other.val.m_ArrData = nullptr;
} else if (type == REF_TYPE) {
val.m_RefData = other.val.m_RefData;
}
other.type = UNDEFINED;
type = other.type;
if (type == FUND_TYPE) {
val.m_FundData = other.val.m_FundData;
} else if (type == OBJ_TYPE || type == ARR_TYPE) {
val.m_ArrData = std::move(other.val.m_ArrData);
other.val.m_ArrData = nullptr;
} else if (type == REF_TYPE) {
val.m_RefData = other.val.m_RefData;
}
other.type = UNDEFINED;
return *this;
}

Expand Down

0 comments on commit 42a9ac1

Please sign in to comment.