Commit 0840e207 authored by bradnelson's avatar bradnelson Committed by Commit bot

Reject lack of "use asm" marker in asm typer.

Until now we've been allowing unmarked asm code
through the typer. Start rejecting it.

Adding a cctest that asm modules missing an export return
fail validation.

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=test-asm-validator
R=aseemgarg@chromium.org,titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1569423002

Cr-Commit-Position: refs/heads/master@{#33199}
parent 4938aca2
......@@ -76,6 +76,13 @@ void AsmTyper::VisitAsmModule(FunctionLiteral* fun) {
Scope* scope = fun->scope();
if (!scope->is_function_scope()) FAIL(fun, "not at function scope");
ExpressionStatement* use_asm = fun->body()->first()->AsExpressionStatement();
if (use_asm == NULL) FAIL(fun, "missing \"use asm\"");
Literal* use_asm_literal = use_asm->expression()->AsLiteral();
if (use_asm_literal == NULL) FAIL(fun, "missing \"use asm\"");
if (!use_asm_literal->raw_value()->AsString()->IsOneByteEqualTo("use asm"))
FAIL(fun, "missing \"use asm\"");
// Module parameters.
for (int i = 0; i < scope->num_parameters(); ++i) {
Variable* param = scope->parameter(i);
......
......@@ -309,6 +309,52 @@ TEST(ValidateMinimum) {
}
TEST(MissingUseAsm) {
const char test_function[] =
"function foo() {\n"
" function bar() {}\n"
" return { bar: bar };\n"
"}\n";
v8::V8::Initialize();
HandleAndZoneScope handles;
Zone* zone = handles.main_zone();
ZoneVector<ExpressionTypeEntry> types(zone);
CHECK_EQ("asm: line 1: missing \"use asm\"\n",
Validate(zone, test_function, &types));
}
TEST(WrongUseAsm) {
const char test_function[] =
"function foo() {\n"
" \"use wasm\"\n"
" function bar() {}\n"
" return { bar: bar };\n"
"}\n";
v8::V8::Initialize();
HandleAndZoneScope handles;
Zone* zone = handles.main_zone();
ZoneVector<ExpressionTypeEntry> types(zone);
CHECK_EQ("asm: line 1: missing \"use asm\"\n",
Validate(zone, test_function, &types));
}
TEST(MissingReturnExports) {
const char test_function[] =
"function foo() {\n"
" \"use asm\"\n"
" function bar() {}\n"
"}\n";
v8::V8::Initialize();
HandleAndZoneScope handles;
Zone* zone = handles.main_zone();
ZoneVector<ExpressionTypeEntry> types(zone);
CHECK_EQ("asm: line 2: last statement in module is not a return\n",
Validate(zone, test_function, &types));
}
#define HARNESS_STDLIB() \
"var Infinity = stdlib.Infinity;\n" \
"var NaN = stdlib.NaN;\n" \
......
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