Skip to content
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
5 changes: 5 additions & 0 deletions clang/lib/AST/ByteCode/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class Scope final {
return llvm::make_range(Descriptors.begin(), Descriptors.end());
}

llvm::iterator_range<LocalVectorTy::const_reverse_iterator>
locals_reverse() const {
return llvm::reverse(Descriptors);
}

private:
/// Object descriptors in this block.
LocalVectorTy Descriptors;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/InterpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void InterpFrame::initScope(unsigned Idx) {
}

void InterpFrame::destroy(unsigned Idx) {
for (auto &Local : Func->getScope(Idx).locals()) {
for (auto &Local : Func->getScope(Idx).locals_reverse()) {
S.deallocate(localBlock(Local.Offset));
}
}
Expand Down
23 changes: 23 additions & 0 deletions clang/test/AST/ByteCode/cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,3 +908,26 @@ namespace TemporaryInNTTP {
// expected-note {{created here}}
B<2> j2; /// Ok.
}

namespace LocalDestroy {
/// This is reduced from a libc++ test case.
/// The local f.TI.copied points to the local variable Copied, and we used to
/// destroy Copied before f, causing problems later on when a DeadBlock had a
/// pointer pointing to it that was already destroyed.
struct TrackInitialization {
bool *copied_;
};
struct TrackingPred : TrackInitialization {
constexpr TrackingPred(bool *copied) : TrackInitialization(copied) {}
};
struct F {
const TrackingPred &TI;
};
constexpr int f() {
bool Copied = false;
TrackingPred TI(&Copied);
F f{TI};
return 1;
}
static_assert(f() == 1);
}