Block,
Loop,
Try,
+ CatchAll,
If,
Else,
Undefined,
case Loop:
return {"loop", "end_loop"};
case Try:
- return {"try", "end_try"};
+ return {"try", "end_try/delegate"};
+ case CatchAll:
+ return {"catch_all", "end_try"};
case If:
return {"if", "end_if"};
case Else:
if (pop(Name, Try))
return true;
push(Try);
+ } else if (Name == "catch_all") {
+ if (pop(Name, Try))
+ return true;
+ push(CatchAll);
} else if (Name == "end_if") {
if (pop(Name, If, Else))
return true;
} else if (Name == "end_try") {
+ if (pop(Name, Try, CatchAll))
+ return true;
+ } else if (Name == "delegate") {
if (pop(Name, Try))
return true;
} else if (Name == "end_loop") {
ControlFlowStack.push_back(std::make_pair(ControlFlowCounter, false));
EHPadStack.push_back(ControlFlowCounter);
DelegateStack.push_back(ControlFlowCounter++);
+ EHInstStack.push_back(TRY);
return;
case WebAssembly::END_LOOP:
case WebAssembly::END_TRY:
case WebAssembly::END_TRY_S:
- if (ControlFlowStack.empty()) {
+ if (ControlFlowStack.empty() || EHInstStack.empty()) {
printAnnotation(OS, "End marker mismatch!");
} else {
printAnnotation(
OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':');
+ EHInstStack.pop_back();
}
return;
case WebAssembly::CATCH_S:
case WebAssembly::CATCH_ALL:
case WebAssembly::CATCH_ALL_S:
- if (EHPadStack.empty() || DelegateStack.empty()) {
+ // There can be multiple catch instructions for one try instruction, so
+ // we print a label only for the first 'catch' label.
+ if (EHInstStack.empty()) {
printAnnotation(OS, "try-catch mismatch!");
- } else {
- printAnnotation(OS, "catch" + utostr(EHPadStack.pop_back_val()) + ':');
- DelegateStack.pop_back();
+ } else if (EHInstStack.back() == CATCH_ALL) {
+ printAnnotation(OS, "catch/catch_all cannot occur after catch_all");
+ } else if (EHInstStack.back() == TRY) {
+ if (EHPadStack.empty() || DelegateStack.empty()) {
+ printAnnotation(OS, "try-catch mismatch!");
+ } else {
+ printAnnotation(OS,
+ "catch" + utostr(EHPadStack.pop_back_val()) + ':');
+ DelegateStack.pop_back();
+ }
+ EHInstStack.pop_back();
+ if (Opc == WebAssembly::CATCH || Opc == WebAssembly::CATCH_S) {
+ EHInstStack.push_back(CATCH);
+ } else {
+ EHInstStack.push_back(CATCH_ALL);
+ }
}
return;
case WebAssembly::DELEGATE:
case WebAssembly::DELEGATE_S:
if (ControlFlowStack.empty() || EHPadStack.empty() ||
- DelegateStack.empty()) {
+ DelegateStack.empty() || EHInstStack.empty()) {
printAnnotation(OS, "try-delegate mismatch!");
} else {
// 'delegate' is
": ";
EHPadStack.pop_back();
DelegateStack.pop_back();
+ EHInstStack.pop_back();
uint64_t Depth = MI->getOperand(0).getImm();
if (Depth >= DelegateStack.size()) {
Label += "to caller";
# CHECK: Block construct type mismatch, expected: end_block, instead got: end_if
end_if
try
+# CHECK: Block construct type mismatch, expected: end_try/delegate, instead got: end_block
+ end_block
loop
-# CHECK: Block construct type mismatch, expected: end_loop, instead got: end_function
+ try
+ catch_all
+ catch_all
+# CHECK: error: Block construct type mismatch, expected: end_try, instead got: catch_all
+ end
+# CHECK: Block construct type mismatch, expected: end_try, instead got: end_function
+# CHECK: error: Unmatched block construct(s) at function end: catch_all
# CHECK: error: Unmatched block construct(s) at function end: loop
# CHECK: error: Unmatched block construct(s) at function end: try
# CHECK: error: Unmatched block construct(s) at function end: block