Skip to content

Commit

Permalink
hir: fix undefined behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Oct 30, 2012
1 parent f4eda0a commit 12a98f2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/hir.cc
Expand Up @@ -145,9 +145,10 @@ HIRInstruction* HIRGen::VisitFunction(AstNode* stmt) {
one->value("1");
one->length(1);

HIRInstruction* hone = Visit(one);
index = Add(new HIRBinOp(this, current_block(), BinOp::kAdd))
->AddArg(index)
->AddArg(Visit(one));
->AddArg(hone);
}
} else {
HIRInstruction* length = Add(HIRInstruction::kSizeof)
Expand Down Expand Up @@ -208,7 +209,8 @@ HIRInstruction* HIRGen::VisitAssign(AstNode* stmt) {


HIRInstruction* HIRGen::VisitReturn(AstNode* stmt) {
return Return(HIRInstruction::kReturn)->AddArg(Visit(stmt->lhs()));
HIRInstruction* lhs = Visit(stmt->lhs());
return Return(HIRInstruction::kReturn)->AddArg(lhs);
}


Expand Down Expand Up @@ -360,7 +362,8 @@ HIRInstruction* HIRGen::VisitUnOp(AstNode* stmt) {

return Visit(wrap);
} else if (op->subtype() == UnOp::kNot) {
return Add(HIRInstruction::kNot)->AddArg(Visit(op->lhs()));
HIRInstruction* lhs = Visit(op->lhs());
return Add(HIRInstruction::kNot)->AddArg(lhs);
} else {
UNEXPECTED
}
Expand Down Expand Up @@ -572,21 +575,25 @@ HIRInstruction* HIRGen::VisitCall(AstNode* stmt) {


HIRInstruction* HIRGen::VisitTypeof(AstNode* stmt) {
return Add(HIRInstruction::kTypeof)->AddArg(Visit(stmt->lhs()));
HIRInstruction* lhs = Visit(stmt->lhs());
return Add(HIRInstruction::kTypeof)->AddArg(lhs);
}


HIRInstruction* HIRGen::VisitKeysof(AstNode* stmt) {
return Add(HIRInstruction::kKeysof)->AddArg(Visit(stmt->lhs()));
HIRInstruction* lhs = Visit(stmt->lhs());
return Add(HIRInstruction::kKeysof)->AddArg(lhs);
}

HIRInstruction* HIRGen::VisitSizeof(AstNode* stmt) {
return Add(HIRInstruction::kSizeof)->AddArg(Visit(stmt->lhs()));
HIRInstruction* lhs = Visit(stmt->lhs());
return Add(HIRInstruction::kSizeof)->AddArg(lhs);
}


HIRInstruction* HIRGen::VisitClone(AstNode* stmt) {
return Add(HIRInstruction::kClone)->AddArg(Visit(stmt->lhs()));
HIRInstruction* lhs = Visit(stmt->lhs());
return Add(HIRInstruction::kClone)->AddArg(lhs);
}


Expand Down

0 comments on commit 12a98f2

Please sign in to comment.