Add debug macro for returning on assert.

While in general one should strive to never hit an assert, and thus we
should not worry about what happens in release mode when the condition
is false, there are cases in which it becomes very hard to prove that a
condition will always be true. For instance when another layer is
responsible for validation, but the code experiences a lot of change,
it could inadvertently expose an untested bad edge case which is only
detected much later. For these cases, it is wise to still perform a
less harmful action than just continue.

The ASSERT_OR_RETURN macro will cause a return from the calling
function when the condition is false.

Bug b/73656151

Change-Id: I36953bb5c477ecca67647ae1a7e2fb97e7e4fca6
Reviewed-on: https://swiftshader-review.googlesource.com/17428
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/OpenGL/common/debug.h b/src/OpenGL/common/debug.h
index 51957d8..aadb535 100644
--- a/src/OpenGL/common/debug.h
+++ b/src/OpenGL/common/debug.h
@@ -58,10 +58,10 @@
 #undef ASSERT
 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
 #define ASSERT(expression) do { \
-	if(!(expression)) \
+	if(!(expression)) { \
 		ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
 		assert(expression); \
-	} while(0)
+	} } while(0)
 #else
 #define ASSERT(expression) (void(0))
 #endif
@@ -88,6 +88,14 @@
 	#define UNREACHABLE(value) ERR("\t! Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value)
 #endif
 
-#endif   // __ANDROID__
+#endif   // !__ANDROID__
+
+// A macro asserting a condition and outputting failures to the debug log, or return when in release mode.
+#undef ASSERT_OR_RETURN
+#define ASSERT_OR_RETURN(expression) do { \
+	if(!(expression)) { \
+		ASSERT(expression); \
+		return; \
+	} } while(0)
 
 #endif   // COMMON_DEBUG_H_