aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/swr/rasterizer/common
diff options
context:
space:
mode:
authorTim Rowley <[email protected]>2016-05-02 11:37:37 -0600
committerTim Rowley <[email protected]>2016-05-05 14:49:56 -0500
commitb39c530f88454addd507ea1ddc167597d3f333ae (patch)
tree0e6436097607f8cb0dadba22e5221bd19d80451b /src/gallium/drivers/swr/rasterizer/common
parentdb084f48ebb1d255fb73fe7e9728e7653fc39eaf (diff)
swr: [rasterizer] Add SWR_ASSUME / SWR_ASSUME_ASSERT macros
Fix static code analysis errors found by coverity on Linux Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr/rasterizer/common')
-rw-r--r--src/gallium/drivers/swr/rasterizer/common/swr_assert.h50
1 files changed, 45 insertions, 5 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/common/swr_assert.h b/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
index a805acc777c..04d768191b4 100644
--- a/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
+++ b/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
@@ -28,6 +28,41 @@
#error swr_assert.h should not be included directly, please include "common/os.h" instead.
#endif
+//=============================================================================
+//
+// MACROS defined in this file:
+//
+// - SWR_ASSUME(expression, ...): Tell compiler that the expression is true.
+// Helps with static code analysis as well.
+// DO NOT USE if code after this dynamically
+// checks for errors and handles them. The
+// compiler may optimize out the error check.
+//
+// - SWR_ASSERT(expression, ...): Inform the user is expression is false.
+// This check is only conditionally made,
+// usually only in debug mode.
+//
+// - SWR_REL_ASSERT(expression, ...): Unconditionally enabled version of SWR_ASSERT
+//
+// - SWR_ASSUME_ASSERT(expression, ...): Conditionally enabled SWR_ASSERT. Uses
+// SWR_ASSUME if SWR_ASSERT is disabled.
+// DO NOT USE in combination with actual
+// error checking (see SWR_ASSUME)
+//
+// - SWR_REL_ASSUME_ASSERT(expression, ...): Same as SWR_REL_ASSERT.
+//
+//=============================================================================
+
+#if defined(_WIN32)
+#define SWR_ASSUME(e, ...) __assume(e)
+#elif defined(__clang__)
+#define SWR_ASSUME(e, ...) __builtin_assume(e)
+#elif defined(__GNUC__)
+#define SWR_ASSUME(e, ...) ((e) ? ((void)0) : __builtin_unreachable())
+#else
+#define SWR_ASSUME(e, ...) ASSUME(e)
+#endif
+
#if !defined(SWR_ENABLE_ASSERTS)
#if !defined(NDEBUG)
@@ -79,28 +114,33 @@ bool SwrAssert(
}
#if SWR_ENABLE_ASSERTS
-#define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
+#define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
+#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSERT(e, ##__VA_ARGS__)
#if defined(assert)
#undef assert
#endif
#define assert(exp) SWR_ASSERT(exp)
-#endif
+#endif // SWR_ENABLE_ASSERTS
#if SWR_ENABLE_REL_ASSERTS
-#define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
+#define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
+#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_REL_ASSERT(e, ##__VA_ARGS__)
#endif
+
#endif // C++
#endif // SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
#if !SWR_ENABLE_ASSERTS
-#define SWR_ASSERT(e, ...) (void)(0)
+#define SWR_ASSERT(e, ...) (void)(0)
+#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
#endif
#if !SWR_ENABLE_REL_ASSERTS
-#define SWR_REL_ASSERT(e, ...) (void)(0)
+#define SWR_REL_ASSERT(e, ...) (void)(0)
+#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
#endif
#define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)