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, ...@@ -442,18 +442,11 @@ Node* RegExpBuiltinsAssembler::RegExpExecInternal(Node* const context,
// contains the uninitialized sentinel as a smi. // contains the uninitialized sentinel as a smi.
Node* const code = var_code.value(); Node* const code = var_code.value();
#ifdef DEBUG CSA_ASSERT_BRANCH(this, [=](Label* ok, Label* not_ok) {
{ GotoIfNot(TaggedIsSmi(code), ok);
Label next(this); Branch(SmiEqual(code, SmiConstant(JSRegExp::kUninitializedValue)), ok,
GotoIfNot(TaggedIsSmi(code), &next); not_ok);
});
CSA_ASSERT(this,
SmiEqual(code, SmiConstant(JSRegExp::kUninitializedValue)));
Goto(&next);
BIND(&next);
}
#endif
GotoIf(TaggedIsSmi(code), &runtime); GotoIf(TaggedIsSmi(code), &runtime);
CSA_ASSERT(this, HasInstanceType(code, CODE_TYPE)); CSA_ASSERT(this, HasInstanceType(code, CODE_TYPE));
......
...@@ -45,6 +45,23 @@ void CodeStubAssembler::HandleBreakOnNode() { ...@@ -45,6 +45,23 @@ void CodeStubAssembler::HandleBreakOnNode() {
BreakOnNode(node_id); 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, void CodeStubAssembler::Assert(const NodeGenerator& condition_body,
const char* message, const char* file, int line, const char* message, const char* file, int line,
Node* extra_node1, const char* extra_node1_name, Node* extra_node1, const char* extra_node1_name,
...@@ -74,7 +91,7 @@ void MaybePrintNodeWithName(CodeStubAssembler* csa, Node* node, ...@@ -74,7 +91,7 @@ void MaybePrintNodeWithName(CodeStubAssembler* csa, Node* node,
} // namespace } // namespace
#endif #endif
void CodeStubAssembler::Check(const NodeGenerator& condition_body, void CodeStubAssembler::Check(const BranchGenerator& branch,
const char* message, const char* file, int line, const char* message, const char* file, int line,
Node* extra_node1, const char* extra_node1_name, Node* extra_node1, const char* extra_node1_name,
Node* extra_node2, const char* extra_node2_name, Node* extra_node2, const char* extra_node2_name,
...@@ -88,9 +105,7 @@ void CodeStubAssembler::Check(const NodeGenerator& condition_body, ...@@ -88,9 +105,7 @@ void CodeStubAssembler::Check(const NodeGenerator& condition_body,
} else { } else {
Comment("[ Assert"); Comment("[ Assert");
} }
Node* condition = condition_body(); branch(&ok, &not_ok);
DCHECK_NOT_NULL(condition);
Branch(condition, &ok, &not_ok);
BIND(&not_ok); BIND(&not_ok);
DCHECK_NOT_NULL(message); DCHECK_NOT_NULL(message);
...@@ -119,6 +134,24 @@ void CodeStubAssembler::Check(const NodeGenerator& condition_body, ...@@ -119,6 +134,24 @@ void CodeStubAssembler::Check(const NodeGenerator& condition_body,
Comment("] Assert"); 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, Node* CodeStubAssembler::Select(SloppyTNode<BoolT> condition,
const NodeGenerator& true_body, const NodeGenerator& true_body,
const NodeGenerator& false_body, const NodeGenerator& false_body,
......
...@@ -323,8 +323,16 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -323,8 +323,16 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* InnerAllocate(Node* previous, Node* offset); Node* InnerAllocate(Node* previous, Node* offset);
Node* IsRegularHeapObjectSize(Node* size); Node* IsRegularHeapObjectSize(Node* size);
typedef std::function<void(Label*, Label*)> BranchGenerator;
typedef std::function<Node*()> NodeGenerator; 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, void Assert(const NodeGenerator& condition_body,
const char* message = nullptr, const char* file = nullptr, const char* message = nullptr, const char* file = nullptr,
int line = 0, Node* extra_node1 = nullptr, int line = 0, Node* extra_node1 = nullptr,
...@@ -333,6 +341,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -333,6 +341,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
const char* extra_node3_name = "", Node* extra_node4 = nullptr, const char* extra_node3_name = "", Node* extra_node4 = nullptr,
const char* extra_node4_name = "", Node* extra_node5 = nullptr, const char* extra_node4_name = "", Node* extra_node5 = nullptr,
const char* extra_node5_name = ""); 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, void Check(const NodeGenerator& condition_body, const char* message = nullptr,
const char* file = nullptr, int line = 0, const char* file = nullptr, int line = 0,
Node* extra_node1 = nullptr, const char* extra_node1_name = "", Node* extra_node1 = nullptr, const char* extra_node1_name = "",
...@@ -2167,8 +2182,8 @@ class ToDirectStringAssembler : public CodeStubAssembler { ...@@ -2167,8 +2182,8 @@ class ToDirectStringAssembler : public CodeStubAssembler {
CSA_ASSERT_STRINGIFY_EXTRA_VALUES_5(__VA_ARGS__, nullptr, nullptr, nullptr, \ CSA_ASSERT_STRINGIFY_EXTRA_VALUES_5(__VA_ARGS__, nullptr, nullptr, nullptr, \
nullptr, nullptr) nullptr, nullptr)
#define CSA_ASSERT_GET_CONDITION(x, ...) (x) #define CSA_ASSERT_GET_FIRST(x, ...) (x)
#define CSA_ASSERT_GET_CONDITION_STR(x, ...) #x #define CSA_ASSERT_GET_FIRST_STR(x, ...) #x
// CSA_ASSERT(csa, <condition>, <extra values to print...>) // CSA_ASSERT(csa, <condition>, <extra values to print...>)
...@@ -2178,11 +2193,19 @@ class ToDirectStringAssembler : public CodeStubAssembler { ...@@ -2178,11 +2193,19 @@ class ToDirectStringAssembler : public CodeStubAssembler {
(csa)->Assert( \ (csa)->Assert( \
[&]() -> compiler::Node* { \ [&]() -> compiler::Node* { \
return base::implicit_cast<compiler::SloppyTNode<Word32T>>( \ return base::implicit_cast<compiler::SloppyTNode<Word32T>>( \
EXPAND(CSA_ASSERT_GET_CONDITION(__VA_ARGS__))); \ EXPAND(CSA_ASSERT_GET_FIRST(__VA_ARGS__))); \
}, \ }, \
EXPAND(CSA_ASSERT_GET_CONDITION_STR(__VA_ARGS__)), __FILE__, __LINE__, \ EXPAND(CSA_ASSERT_GET_FIRST_STR(__VA_ARGS__)), __FILE__, __LINE__, \
CSA_ASSERT_STRINGIFY_EXTRA_VALUES(__VA_ARGS__)) 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) \ #define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
(csa)->Assert( \ (csa)->Assert( \
[&]() -> compiler::Node* { \ [&]() -> compiler::Node* { \
...@@ -2208,6 +2231,7 @@ class ToDirectStringAssembler : public CodeStubAssembler { ...@@ -2208,6 +2231,7 @@ class ToDirectStringAssembler : public CodeStubAssembler {
TVariable<type> name(CSA_DEBUG_INFO(name), __VA_ARGS__) TVariable<type> name(CSA_DEBUG_INFO(name), __VA_ARGS__)
#else // DEBUG #else // DEBUG
#define CSA_ASSERT(csa, ...) ((void)0) #define CSA_ASSERT(csa, ...) ((void)0)
#define CSA_ASSERT_BRANCH(csa, ...) ((void)0)
#define CSA_ASSERT_JS_ARGC_EQ(csa, expected) ((void)0) #define CSA_ASSERT_JS_ARGC_EQ(csa, expected) ((void)0)
#define BIND(label) Bind(label) #define BIND(label) Bind(label)
#define VARIABLE(name, ...) Variable name(this, __VA_ARGS__) #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