From a28343a33ed28b4d5c83c37e350aceaf09b5246f Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc@chromium.org>
Date: Thu, 5 Dec 2019 13:09:21 -0600
Subject: Add string parameter to WASM_UNREACHABLE (#2499)

This works more like llvm's unreachable handler in that is preserves
information even in release builds.
---
 src/wasm/wasm-stack.cpp | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

(limited to 'src/wasm/wasm-stack.cpp')

diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index f1aaff93e..0f12a2f2b 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -152,7 +152,7 @@ void BinaryInstWriter::visitLoad(Load* curr) {
       case anyref: // anyref cannot be loaded from memory
       case exnref: // exnref cannot be loaded from memory
       case none:
-        WASM_UNREACHABLE();
+        WASM_UNREACHABLE("unexpected type");
     }
   } else {
     o << int8_t(BinaryConsts::AtomicPrefix);
@@ -169,7 +169,7 @@ void BinaryInstWriter::visitLoad(Load* curr) {
             o << int8_t(BinaryConsts::I32AtomicLoad);
             break;
           default:
-            WASM_UNREACHABLE();
+            WASM_UNREACHABLE("invalid load size");
         }
         break;
       }
@@ -188,14 +188,14 @@ void BinaryInstWriter::visitLoad(Load* curr) {
             o << int8_t(BinaryConsts::I64AtomicLoad);
             break;
           default:
-            WASM_UNREACHABLE();
+            WASM_UNREACHABLE("invalid load size");
         }
         break;
       }
       case unreachable:
         return;
       default:
-        WASM_UNREACHABLE();
+        WASM_UNREACHABLE("unexpected type");
     }
   }
   emitMemoryAccess(curr->align, curr->bytes, curr->offset);
@@ -253,7 +253,7 @@ void BinaryInstWriter::visitStore(Store* curr) {
       case exnref: // exnref cannot be stored in memory
       case none:
       case unreachable:
-        WASM_UNREACHABLE();
+        WASM_UNREACHABLE("unexpected type");
     }
   } else {
     o << int8_t(BinaryConsts::AtomicPrefix);
@@ -270,7 +270,7 @@ void BinaryInstWriter::visitStore(Store* curr) {
             o << int8_t(BinaryConsts::I32AtomicStore);
             break;
           default:
-            WASM_UNREACHABLE();
+            WASM_UNREACHABLE("invalid store size");
         }
         break;
       }
@@ -289,12 +289,12 @@ void BinaryInstWriter::visitStore(Store* curr) {
             o << int8_t(BinaryConsts::I64AtomicStore);
             break;
           default:
-            WASM_UNREACHABLE();
+            WASM_UNREACHABLE("invalid store size");
         }
         break;
       }
       default:
-        WASM_UNREACHABLE();
+        WASM_UNREACHABLE("unexpected type");
     }
   }
   emitMemoryAccess(curr->align, curr->bytes, curr->offset);
@@ -318,7 +318,7 @@ void BinaryInstWriter::visitAtomicRMW(AtomicRMW* curr) {
             o << int8_t(BinaryConsts::I32AtomicRMW##Op);                       \
             break;                                                             \
           default:                                                             \
-            WASM_UNREACHABLE();                                                \
+            WASM_UNREACHABLE("invalid rmw size");                              \
         }                                                                      \
         break;                                                                 \
       case i64:                                                                \
@@ -336,11 +336,11 @@ void BinaryInstWriter::visitAtomicRMW(AtomicRMW* curr) {
             o << int8_t(BinaryConsts::I64AtomicRMW##Op);                       \
             break;                                                             \
           default:                                                             \
-            WASM_UNREACHABLE();                                                \
+            WASM_UNREACHABLE("invalid rmw size");                              \
         }                                                                      \
         break;                                                                 \
       default:                                                                 \
-        WASM_UNREACHABLE();                                                    \
+        WASM_UNREACHABLE("unexpected type");                                   \
     }                                                                          \
     break
 
@@ -352,7 +352,7 @@ void BinaryInstWriter::visitAtomicRMW(AtomicRMW* curr) {
     CASE_FOR_OP(Xor);
     CASE_FOR_OP(Xchg);
     default:
-      WASM_UNREACHABLE();
+      WASM_UNREACHABLE("unexpected op");
   }
 #undef CASE_FOR_OP
 
@@ -374,7 +374,7 @@ void BinaryInstWriter::visitAtomicCmpxchg(AtomicCmpxchg* curr) {
           o << int8_t(BinaryConsts::I32AtomicCmpxchg);
           break;
         default:
-          WASM_UNREACHABLE();
+          WASM_UNREACHABLE("invalid size");
       }
       break;
     case i64:
@@ -392,11 +392,11 @@ void BinaryInstWriter::visitAtomicCmpxchg(AtomicCmpxchg* curr) {
           o << int8_t(BinaryConsts::I64AtomicCmpxchg);
           break;
         default:
-          WASM_UNREACHABLE();
+          WASM_UNREACHABLE("invalid size");
       }
       break;
     default:
-      WASM_UNREACHABLE();
+      WASM_UNREACHABLE("unexpected type");
   }
   emitMemoryAccess(curr->bytes, curr->bytes, curr->offset);
 }
@@ -415,7 +415,7 @@ void BinaryInstWriter::visitAtomicWait(AtomicWait* curr) {
       break;
     }
     default:
-      WASM_UNREACHABLE();
+      WASM_UNREACHABLE("unexpected type");
   }
 }
 
@@ -648,7 +648,7 @@ void BinaryInstWriter::visitConst(Const* curr) {
     case exnref: // there's no exnref.const
     case none:
     case unreachable:
-      WASM_UNREACHABLE();
+      WASM_UNREACHABLE("unexpected type");
   }
 }
 
@@ -990,7 +990,7 @@ void BinaryInstWriter::visitUnary(Unary* curr) {
         << U32LEB(BinaryConsts::I32x4WidenHighUI16x8);
       break;
     case InvalidUnary:
-      WASM_UNREACHABLE();
+      WASM_UNREACHABLE("invalid unary op");
   }
 }
 
@@ -1532,7 +1532,7 @@ void BinaryInstWriter::visitBinary(Binary* curr) {
       break;
 
     case InvalidBinary:
-      WASM_UNREACHABLE();
+      WASM_UNREACHABLE("invalid binary op");
   }
 }
 
@@ -1664,7 +1664,7 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() {
       mappedLocals[i] = index + currLocalsByType[exnref] - 1;
       continue;
     }
-    WASM_UNREACHABLE();
+    WASM_UNREACHABLE("unexpected type");
   }
   // Emit them.
   o << U32LEB((numLocalsByType[i32] ? 1 : 0) + (numLocalsByType[i64] ? 1 : 0) +
@@ -1708,7 +1708,7 @@ int32_t BinaryInstWriter::getBreakIndex(Name name) { // -1 if not found
       return breakStack.size() - 1 - i;
     }
   }
-  WASM_UNREACHABLE();
+  WASM_UNREACHABLE("break index not found");
 }
 
 void StackIRGenerator::emit(Expression* curr) {
@@ -1738,7 +1738,7 @@ void StackIRGenerator::emitScopeEnd(Expression* curr) {
   } else if (curr->is<Try>()) {
     stackInst = makeStackInst(StackInst::TryEnd, curr);
   } else {
-    WASM_UNREACHABLE();
+    WASM_UNREACHABLE("unexpected expr type");
   }
   stackIR.push_back(stackInst);
 }
@@ -1796,7 +1796,7 @@ void StackIRToBinaryWriter::write() {
         break;
       }
       default:
-        WASM_UNREACHABLE();
+        WASM_UNREACHABLE("unexpected op");
     }
   }
   writer.emitFunctionEnd();
-- 
cgit v1.2.3