Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Fix use-after-free cases found by valgrind #122394

Merged
merged 1 commit into from
Jan 14, 2025
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
4 changes: 2 additions & 2 deletions flang/include/flang/Evaluate/traverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Traverse {
return visitor_(x.base());
}
Result operator()(const Triplet &x) const {
return Combine(x.lower(), x.upper(), x.stride());
return Combine(x.GetLower(), x.GetUpper(), x.GetStride());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so the old code was visiting a chain of automatic instances, instead of pointers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code ends up visiting heap objects that had already been destroyed because they had been owned by local variables that had gone out of scope.

}
Result operator()(const Subscript &x) const { return visitor_(x.u); }
Result operator()(const ArrayRef &x) const {
Expand All @@ -151,7 +151,7 @@ class Traverse {
}
Result operator()(const DataRef &x) const { return visitor_(x.u); }
Result operator()(const Substring &x) const {
return Combine(x.parent(), x.lower(), x.upper());
return Combine(x.parent(), x.GetLower(), x.GetUpper());
}
Result operator()(const ComplexPart &x) const {
return visitor_(x.complex());
Expand Down
6 changes: 6 additions & 0 deletions flang/include/flang/Evaluate/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,14 @@ class Substring {
}

Expr<SubscriptInteger> lower() const;
const Expr<SubscriptInteger> *GetLower() const {
return lower_.has_value() ? &lower_->value() : nullptr;
}
Substring &set_lower(Expr<SubscriptInteger> &&);
std::optional<Expr<SubscriptInteger>> upper() const;
const Expr<SubscriptInteger> *GetUpper() const {
return upper_.has_value() ? &upper_->value() : nullptr;
}
Substring &set_upper(Expr<SubscriptInteger> &&);
const Parent &parent() const { return parent_; }
Parent &parent() { return parent_; }
Expand Down
Loading