[llvm] r339495 - Fix WebAssembly instruction printer after r339474

Richard Trieu via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 10 21:18:06 PDT 2018


Author: rtrieu
Date: Fri Aug 10 21:18:05 2018
New Revision: 339495

URL: http://llvm.org/viewvc/llvm-project?rev=339495&view=rev
Log:
Fix WebAssembly instruction printer after r339474

Treat the stack variants of control instructions the same as regular
instructions.  Otherwise, the vector ControlFlowStack will be the wrong
size and have out-of-bounds access.  This was detected by MemorySanitizer.

Modified:
    llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp

Modified: llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp?rev=339495&r1=339494&r2=339495&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp Fri Aug 10 21:18:05 2018
@@ -73,20 +73,24 @@ void WebAssemblyInstPrinter::printInst(c
     switch (MI->getOpcode()) {
     default:
       break;
-    case WebAssembly::LOOP: {
+    case WebAssembly::LOOP:
+    case WebAssembly::LOOP_S: {
       printAnnotation(OS, "label" + utostr(ControlFlowCounter) + ':');
       ControlFlowStack.push_back(std::make_pair(ControlFlowCounter++, true));
       break;
     }
     case WebAssembly::BLOCK:
+    case WebAssembly::BLOCK_S:
       ControlFlowStack.push_back(std::make_pair(ControlFlowCounter++, false));
       break;
     case WebAssembly::END_LOOP:
+    case WebAssembly::END_LOOP_S:
       // Have to guard against an empty stack, in case of mismatched pairs
       // in assembly parsing.
       if (!ControlFlowStack.empty()) ControlFlowStack.pop_back();
       break;
     case WebAssembly::END_BLOCK:
+    case WebAssembly::END_BLOCK_S:
       if (!ControlFlowStack.empty()) printAnnotation(
           OS, "label" + utostr(ControlFlowStack.pop_back_val().first) + ':');
       break;




More information about the llvm-commits mailing list