Skip to content

Commit

Permalink
Fix collectDataFromPredecessors to collect data from the passed branch (
Browse files Browse the repository at this point in the history
vgvassilev#1051)

Before the fix, we didn't collect data from varsData at all, and it wasn't merge afterward either. Now, we start collecting data from varsData, ensuring the final data of the CFG block is correct.

Fixes:vgvassilev#855
  • Loading branch information
ovdiiuv authored Aug 22, 2024
1 parent 397e3b0 commit b680a0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Differentiator/TBRAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ TBRAnalyzer::collectDataFromPredecessors(VarsData* varsData,
std::unordered_map<const clang::VarDecl*, VarData*> result;
if (varsData != limit) {
// Copy data from every predecessor.
for (auto* pred = varsData->m_Prev; pred != limit; pred = pred->m_Prev) {
for (auto* pred = varsData; pred != limit; pred = pred->m_Prev) {
// If a variable from 'pred' is not present in 'result', place it there.
for (auto& pair : *pred)
if (result.find(pair.first) == result.end())
Expand Down
12 changes: 11 additions & 1 deletion test/Analyses/TBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ double f1(double x) {
return t;
} // == x^3

double f2(double val) {
double res = 0;
for (int i=1; i<5; ++i) {
if (i == 3)
continue;
res += i * val;
}
return res;
}

#define TEST(F, x) { \
result[0] = 0; \
auto F##grad = clad::gradient<clad::opts::enable_tbr>(F);\
Expand All @@ -21,5 +31,5 @@ double f1(double x) {
int main() {
double result[3] = {};
TEST(f1, 3); // CHECK-EXEC: {27.00}

TEST(f2, 3); // CHECK-EXEC: {9.00}
}

0 comments on commit b680a0c

Please sign in to comment.