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

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 3 10:07:29 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
----------------
DavidSpickett wrote:

So I had that at first, but tried to be fancy and not emit the if if the assert was going to be there. I could go with either.

I also wondered if a static analyser would tell us that the if could never fail given the assert above it.

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


More information about the lldb-commits mailing list