[Lldb-commits] [lldb] [lldb] Add LLDB_ASSERT_OR_RETURN macro and make use of it (PR #71175)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 3 08:53:16 PDT 2023


================
@@ -139,4 +139,16 @@
 #define LLDB_DEPRECATED_FIXME(MSG, FIX) LLDB_DEPRECATED(MSG)
 #endif
 
+// When asserts are enabled, use an assert to check expr. If they are not
+// enabled, return the value retval if expr is not true. Used when a hard
+// failure is useful during development but in a release build without asserts
+// you need to return to prevent corrupting state.
+#ifdef NDEBUG
+#define LLDB_ASSERT_OR_RETURN(expr, retval)                                    \
+  if (!(expr))                                                                 \
+    return retval;
+#else
+#define LLDB_ASSERT_OR_RETURN(expr, retval) assert(expr);
+#endif
----------------
adrian-prantl wrote:

I would find this easier to read:
```
#define LLDB_ASSERT_AND_RETURN(expr, retval)                                    \
  assert(expr); \
  if (!(expr))                                                                 \
    return retval;
```

https://github.com/llvm/llvm-project/pull/71175


More information about the lldb-commits mailing list