Commit c57c529f authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[code-assembler] Check that a variable's value is never accessed outside a block.

We should only ever call value() on a variable while we are inside a block.
This CL adds a DEBUG check to this effect.

Bug: 
Change-Id: Ic85fae70e2c3543ff79e3234ba26e1daa234f7e3
Reviewed-on: https://chromium-review.googlesource.com/772233Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49492}
parent a9cab08e
......@@ -105,6 +105,8 @@ CodeAssembler::~CodeAssembler() {}
void CodeAssemblerState::PrintCurrentBlock(std::ostream& os) {
raw_assembler_->PrintCurrentBlock(os);
}
bool CodeAssemblerState::InsideBlock() { return raw_assembler_->InsideBlock(); }
#endif
void CodeAssemblerState::SetInitialDebugInformation(const char* msg,
......@@ -1334,11 +1336,14 @@ Node* CodeAssemblerVariable::value() const {
if (!IsBound()) {
std::stringstream str;
str << "#Use of unbound variable:"
<< "#\n Variable: " << *this << "#\n Current Block: ";
state_->PrintCurrentBlock(str);
FATAL(str.str().c_str());
}
if (!state_->InsideBlock()) {
std::stringstream str;
str << "#Accessing variable value outside a block:"
<< "#\n Variable: " << *this;
if (state_) {
str << "#\n Current Block: ";
state_->PrintCurrentBlock(str);
}
FATAL(str.str().c_str());
}
#endif // DEBUG
......
......@@ -1208,6 +1208,7 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
#if DEBUG
void PrintCurrentBlock(std::ostream& os);
bool InsideBlock();
#endif // DEBUG
void SetInitialDebugInformation(const char* msg, const char* file, int line);
......
......@@ -405,6 +405,8 @@ void RawMachineAssembler::PrintCurrentBlock(std::ostream& os) {
os << CurrentBlock();
}
bool RawMachineAssembler::InsideBlock() { return current_block_ != nullptr; }
void RawMachineAssembler::SetInitialDebugInformation(
AssemblerDebugInfo debug_info) {
CurrentBlock()->set_debug_info(debug_info);
......
......@@ -831,6 +831,7 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
void Bind(RawMachineLabel* label, AssemblerDebugInfo info);
void SetInitialDebugInformation(AssemblerDebugInfo info);
void PrintCurrentBlock(std::ostream& os);
bool InsideBlock();
#endif // DEBUG
// Add success / exception successor blocks and ends the current block ending
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment