Commit 1c10c4a2 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[CSA] Add CSA_ASSERT_BRANCH to assert on branch results

The new macro takes a void(Label* ok, Label* not_ok), which should
generate statements that branch to one of the labels. If the not_ok
Label is reached, it will abort just like CSA_ASSERT.

Also replaces an instance of #ifdef DEBUG ... #endif with this pattern
in builtins-regexp-gen.cc

Change-Id: Ie7ec87e041c040c03f9c528dccc8e709e50ed9b9
Reviewed-on: https://chromium-review.googlesource.com/906933Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51178}
parent 9606052b
......@@ -442,18 +442,11 @@ Node* RegExpBuiltinsAssembler::RegExpExecInternal(Node* const context,
// contains the uninitialized sentinel as a smi.
Node* const code = var_code.value();
#ifdef DEBUG
{
Label next(this);
GotoIfNot(TaggedIsSmi(code), &next);
CSA_ASSERT(this,
SmiEqual(code, SmiConstant(JSRegExp::kUninitializedValue)));
Goto(&next);
BIND(&next);
}
#endif
CSA_ASSERT_BRANCH(this, [=](Label* ok, Label* not_ok) {
GotoIfNot(TaggedIsSmi(code), ok);
Branch(SmiEqual(code, SmiConstant(JSRegExp::kUninitializedValue)), ok,
not_ok);
});
GotoIf(TaggedIsSmi(code), &runtime);
CSA_ASSERT(this, HasInstanceType(code, CODE_TYPE));
......
......@@ -45,6 +45,23 @@ void CodeStubAssembler::HandleBreakOnNode() {
BreakOnNode(node_id);
}
void CodeStubAssembler::Assert(const BranchGenerator& branch,
const char* message, const char* file, int line,
Node* extra_node1, const char* extra_node1_name,
Node* extra_node2, const char* extra_node2_name,
Node* extra_node3, const char* extra_node3_name,
Node* extra_node4, const char* extra_node4_name,
Node* extra_node5,
const char* extra_node5_name) {
#if defined(DEBUG)
if (FLAG_debug_code) {
Check(branch, message, file, line, extra_node1, extra_node1_name,
extra_node2, extra_node2_name, extra_node3, extra_node3_name,
extra_node4, extra_node4_name, extra_node5, extra_node5_name);
}
#endif
}
void CodeStubAssembler::Assert(const NodeGenerator& condition_body,
const char* message, const char* file, int line,
Node* extra_node1, const char* extra_node1_name,
......@@ -74,7 +91,7 @@ void MaybePrintNodeWithName(CodeStubAssembler* csa, Node* node,
} // namespace
#endif
void CodeStubAssembler::Check(const NodeGenerator& condition_body,
void CodeStubAssembler::Check(const BranchGenerator& branch,
const char* message, const char* file, int line,
Node* extra_node1, const char* extra_node1_name,
Node* extra_node2, const char* extra_node2_name,
......@@ -88,9 +105,7 @@ void CodeStubAssembler::Check(const NodeGenerator& condition_body,
} else {
Comment("[ Assert");
}
Node* condition = condition_body();
DCHECK_NOT_NULL(condition);
Branch(condition, &ok, &not_ok);
branch(&ok, &not_ok);
BIND(&not_ok);
DCHECK_NOT_NULL(message);
......@@ -119,6 +134,24 @@ void CodeStubAssembler::Check(const NodeGenerator& condition_body,
Comment("] Assert");
}
void CodeStubAssembler::Check(const NodeGenerator& condition_body,
const char* message, const char* file, int line,
Node* extra_node1, const char* extra_node1_name,
Node* extra_node2, const char* extra_node2_name,
Node* extra_node3, const char* extra_node3_name,
Node* extra_node4, const char* extra_node4_name,
Node* extra_node5, const char* extra_node5_name) {
BranchGenerator branch = [=](Label* ok, Label* not_ok) {
Node* condition = condition_body();
DCHECK_NOT_NULL(condition);
Branch(condition, ok, not_ok);
};
Check(branch, message, file, line, extra_node1, extra_node1_name, extra_node2,
extra_node2_name, extra_node3, extra_node3_name, extra_node4,
extra_node4_name, extra_node5, extra_node5_name);
}
Node* CodeStubAssembler::Select(SloppyTNode<BoolT> condition,
const NodeGenerator& true_body,
const NodeGenerator& false_body,
......
......@@ -323,8 +323,16 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* InnerAllocate(Node* previous, Node* offset);
Node* IsRegularHeapObjectSize(Node* size);
typedef std::function<void(Label*, Label*)> BranchGenerator;
typedef std::function<Node*()> NodeGenerator;
void Assert(const BranchGenerator& branch, const char* message = nullptr,
const char* file = nullptr, int line = 0,
Node* extra_node1 = nullptr, const char* extra_node1_name = "",
Node* extra_node2 = nullptr, const char* extra_node2_name = "",
Node* extra_node3 = nullptr, const char* extra_node3_name = "",
Node* extra_node4 = nullptr, const char* extra_node4_name = "",
Node* extra_node5 = nullptr, const char* extra_node5_name = "");
void Assert(const NodeGenerator& condition_body,
const char* message = nullptr, const char* file = nullptr,
int line = 0, Node* extra_node1 = nullptr,
......@@ -333,6 +341,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
const char* extra_node3_name = "", Node* extra_node4 = nullptr,
const char* extra_node4_name = "", Node* extra_node5 = nullptr,
const char* extra_node5_name = "");
void Check(const BranchGenerator& branch, const char* message = nullptr,
const char* file = nullptr, int line = 0,
Node* extra_node1 = nullptr, const char* extra_node1_name = "",
Node* extra_node2 = nullptr, const char* extra_node2_name = "",
Node* extra_node3 = nullptr, const char* extra_node3_name = "",
Node* extra_node4 = nullptr, const char* extra_node4_name = "",
Node* extra_node5 = nullptr, const char* extra_node5_name = "");
void Check(const NodeGenerator& condition_body, const char* message = nullptr,
const char* file = nullptr, int line = 0,
Node* extra_node1 = nullptr, const char* extra_node1_name = "",
......@@ -2167,22 +2182,30 @@ class ToDirectStringAssembler : public CodeStubAssembler {
CSA_ASSERT_STRINGIFY_EXTRA_VALUES_5(__VA_ARGS__, nullptr, nullptr, nullptr, \
nullptr, nullptr)
#define CSA_ASSERT_GET_CONDITION(x, ...) (x)
#define CSA_ASSERT_GET_CONDITION_STR(x, ...) #x
#define CSA_ASSERT_GET_FIRST(x, ...) (x)
#define CSA_ASSERT_GET_FIRST_STR(x, ...) #x
// CSA_ASSERT(csa, <condition>, <extra values to print...>)
// We have to jump through some hoops to allow <extra values to print...> to be
// empty.
#define CSA_ASSERT(csa, ...) \
(csa)->Assert( \
[&]() -> compiler::Node* { \
return base::implicit_cast<compiler::SloppyTNode<Word32T>>( \
EXPAND(CSA_ASSERT_GET_CONDITION(__VA_ARGS__))); \
}, \
EXPAND(CSA_ASSERT_GET_CONDITION_STR(__VA_ARGS__)), __FILE__, __LINE__, \
#define CSA_ASSERT(csa, ...) \
(csa)->Assert( \
[&]() -> compiler::Node* { \
return base::implicit_cast<compiler::SloppyTNode<Word32T>>( \
EXPAND(CSA_ASSERT_GET_FIRST(__VA_ARGS__))); \
}, \
EXPAND(CSA_ASSERT_GET_FIRST_STR(__VA_ARGS__)), __FILE__, __LINE__, \
CSA_ASSERT_STRINGIFY_EXTRA_VALUES(__VA_ARGS__))
// CSA_ASSERT_BRANCH(csa, [](Label* ok, Label* not_ok) {...},
// <extra values to print...>)
#define CSA_ASSERT_BRANCH(csa, ...) \
(csa)->Assert(EXPAND(CSA_ASSERT_GET_FIRST(__VA_ARGS__)), \
EXPAND(CSA_ASSERT_GET_FIRST_STR(__VA_ARGS__)), __FILE__, \
__LINE__, CSA_ASSERT_STRINGIFY_EXTRA_VALUES(__VA_ARGS__))
#define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
(csa)->Assert( \
[&]() -> compiler::Node* { \
......@@ -2208,6 +2231,7 @@ class ToDirectStringAssembler : public CodeStubAssembler {
TVariable<type> name(CSA_DEBUG_INFO(name), __VA_ARGS__)
#else // DEBUG
#define CSA_ASSERT(csa, ...) ((void)0)
#define CSA_ASSERT_BRANCH(csa, ...) ((void)0)
#define CSA_ASSERT_JS_ARGC_EQ(csa, expected) ((void)0)
#define BIND(label) Bind(label)
#define VARIABLE(name, ...) Variable name(this, __VA_ARGS__)
......
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