Commit 9e8bfcaf by Nicolas Capens Committed by Nicolas Capens

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/17428Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent ae7756e0
......@@ -58,10 +58,10 @@ namespace es
#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 @@ namespace es
#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_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment