Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Unified Diff: src/asmjs/asm-wasm-builder.cc

Issue 2372823004: [wasm] asm.js: Work around parser converting !0 and !1 to boolean. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/asmjs/asm-typer.cc ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/asmjs/asm-wasm-builder.cc
diff --git a/src/asmjs/asm-wasm-builder.cc b/src/asmjs/asm-wasm-builder.cc
index d446c4e0a323aac07579442837fa5e4b5fc35274..301f7f45cf2783f3aae319c059f77dde3e34cc22 100644
--- a/src/asmjs/asm-wasm-builder.cc
+++ b/src/asmjs/asm-wasm-builder.cc
@@ -589,7 +589,9 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
void VisitLiteral(Literal* expr) {
Handle<Object> value = expr->value();
- if (!value->IsNumber() || (scope_ != kFuncScope && scope_ != kInitScope)) {
+ if (!(value->IsNumber() || expr->raw_value()->IsTrue() ||
+ expr->raw_value()->IsFalse()) ||
+ (scope_ != kFuncScope && scope_ != kInitScope)) {
return;
}
AsmType* type = typer_->TypeOf(expr);
@@ -610,6 +612,18 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
int32_t i = static_cast<int32_t>(u);
byte code[] = {WASM_I32V(i)};
current_function_builder_->EmitCode(code, sizeof(code));
+ } else if (type->IsA(AsmType::Int())) {
+ // The parser can collapse !0, !1 etc to true / false.
+ // Allow these as int literals.
+ if (expr->raw_value()->IsTrue()) {
+ byte code[] = {WASM_I32V(1)};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ } else if (expr->raw_value()->IsFalse()) {
+ byte code[] = {WASM_I32V(0)};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ } else {
+ UNREACHABLE();
+ }
} else if (type->IsA(AsmType::Double())) {
double val = expr->raw_value()->AsNumber();
byte code[] = {WASM_F64(val)};
« no previous file with comments | « src/asmjs/asm-typer.cc ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698