Mesa (master): glsl: turn runtime asserts of compile-time value into compile-time asserts

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Sep 25 21:15:07 UTC 2019


Module: Mesa
Branch: master
Commit: b3e3af0e374c5db0e6f74c3963d28b39c9fc286c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b3e3af0e374c5db0e6f74c3963d28b39c9fc286c

Author: Eric Engestrom <eric.engestrom at intel.com>
Date:   Tue Sep 24 16:58:31 2019 +0100

glsl: turn runtime asserts of compile-time value into compile-time asserts

Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>

---

 src/compiler/glsl/ir_constant_expression.cpp | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index 1605e571758..5b1b5aa8eff 100644
--- a/src/compiler/glsl/ir_constant_expression.cpp
+++ b/src/compiler/glsl/ir_constant_expression.cpp
@@ -73,7 +73,8 @@ dot_d(ir_constant *op0, ir_constant *op1)
 static float
 bitcast_u2f(unsigned int u)
 {
-   assert(sizeof(float) == sizeof(unsigned int));
+   static_assert(sizeof(float) == sizeof(unsigned int),
+                 "float and unsigned int size mismatch");
    float f;
    memcpy(&f, &u, sizeof(f));
    return f;
@@ -82,7 +83,8 @@ bitcast_u2f(unsigned int u)
 static unsigned int
 bitcast_f2u(float f)
 {
-   assert(sizeof(float) == sizeof(unsigned int));
+   static_assert(sizeof(float) == sizeof(unsigned int),
+                 "float and unsigned int size mismatch");
    unsigned int u;
    memcpy(&u, &f, sizeof(f));
    return u;
@@ -91,7 +93,8 @@ bitcast_f2u(float f)
 static double
 bitcast_u642d(uint64_t u)
 {
-   assert(sizeof(double) == sizeof(uint64_t));
+   static_assert(sizeof(double) == sizeof(uint64_t),
+                 "double and uint64_t size mismatch");
    double d;
    memcpy(&d, &u, sizeof(d));
    return d;
@@ -100,7 +103,8 @@ bitcast_u642d(uint64_t u)
 static double
 bitcast_i642d(int64_t i)
 {
-   assert(sizeof(double) == sizeof(int64_t));
+   static_assert(sizeof(double) == sizeof(int64_t),
+                 "double and int64_t size mismatch");
    double d;
    memcpy(&d, &i, sizeof(d));
    return d;
@@ -109,7 +113,8 @@ bitcast_i642d(int64_t i)
 static uint64_t
 bitcast_d2u64(double d)
 {
-   assert(sizeof(double) == sizeof(uint64_t));
+   static_assert(sizeof(double) == sizeof(uint64_t),
+                 "double and uint64_t size mismatch");
    uint64_t u;
    memcpy(&u, &d, sizeof(d));
    return u;
@@ -118,7 +123,8 @@ bitcast_d2u64(double d)
 static int64_t
 bitcast_d2i64(double d)
 {
-   assert(sizeof(double) == sizeof(int64_t));
+   static_assert(sizeof(double) == sizeof(int64_t),
+                 "double and int64_t size mismatch");
    int64_t i;
    memcpy(&i, &d, sizeof(d));
    return i;




More information about the mesa-commit mailing list