Skip to content

Commit

Permalink
Ensure Hermes exits when code intentionally unreachable is reached in…
Browse files Browse the repository at this point in the history
… `BCGen`

Summary: This diff should kill a class of bugs we've seen with `llvm_unreachable` sometimes being misused as an assert in production and an input is able to continue execution despite failing a check or hitting a default case in a switch statement.

Reviewed By: werew

Differential Revision: D43513434

fbshipit-source-id: 574dedf197175e4208eaf0198a615ff491286dac
  • Loading branch information
0xedward authored and facebook-github-bot committed Mar 1, 2023
1 parent 6033ec3 commit a0a0365
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/BytecodeDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const char *stringKindTag(StringKind::Kind kind) {
return "i";
}

llvm_unreachable("Unrecognised String Kind.");
hermes_fatal("Unrecognised String Kind.");
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/HBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void lowerIR(Module *M, const BytecodeGenerationOptions &options) {
if (options.verifyIR &&
verifyModule(*M, &llvh::errs(), VerificationMode::IR_VALID)) {
M->dump();
llvm_unreachable("IR verification failed");
hermes_fatal("IR verification failed");
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ bool LowerArgumentsArray::runOnFunction(Function *F) {
}
}
} else {
llvm_unreachable("CreateArguments used for a non-Instruction.");
hermes_fatal("CreateArguments used for a non-Instruction.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/BCGen/HBC/SerializedLiteralGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void SerializedLiteralGenerator::serializeBuffer(
newTag = NullTag;
break;
default:
llvm_unreachable("Invalid Literal Kind");
hermes_fatal("Invalid Literal Kind");
}

if (newTag != lastTag || seqLength == SequenceMax) {
Expand Down Expand Up @@ -148,7 +148,7 @@ void SerializedLiteralGenerator::serializeBuffer(
/* no-op */
break;
default:
llvm_unreachable("Invalid Literal Kind");
hermes_fatal("Invalid Literal Kind");
}
}
// The last value in the buffer can't get serialized in the loop.
Expand Down

0 comments on commit a0a0365

Please sign in to comment.