gallivm: push LLVM version guard into assert
authorMihai Preda <mhpreda@gmail.com>
Sat, 23 Jul 2022 05:45:55 +0000 (08:45 +0300)
committerMarge Bot <emma+marge@anholt.net>
Sat, 23 Jul 2022 17:34:08 +0000 (17:34 +0000)
The asserts that check the pointer element type can't be used on LLVM >= 15.
Instead of using precompiler #if, use boolean shortcut in assert.

Reviewed-by: Brian Paul <brianp@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17650>

src/gallium/auxiliary/gallivm/lp_bld_struct.c

index 1007090..be579c4 100644 (file)
@@ -51,11 +51,7 @@ lp_build_struct_get_ptr(struct gallivm_state *gallivm,
    LLVMValueRef indices[2];
    LLVMValueRef member_ptr;
    assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
-
-   /* Starting with LLVM 15, we're not supposed to look at pointer element type anymore. */
-#if LLVM_VERSION_MAJOR < 15
-   assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
-#endif
+   assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
 
    indices[0] = lp_build_const_int32(gallivm, 0);
    indices[1] = lp_build_const_int32(gallivm, member);
@@ -73,9 +69,7 @@ lp_build_struct_get(struct gallivm_state *gallivm,
    LLVMValueRef member_ptr;
    LLVMValueRef res;
    assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
-#if LLVM_VERSION_MAJOR < 15
-   assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
-#endif
+   assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
    member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name);
    res = LLVMBuildLoad(gallivm->builder, member_ptr, "");
    lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
@@ -92,11 +86,7 @@ lp_build_struct_get_ptr2(struct gallivm_state *gallivm,
    LLVMValueRef indices[2];
    LLVMValueRef member_ptr;
    assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
-
-   /* Starting with LLVM 15, we're not supposed to look at pointer element type anymore. */
-#if LLVM_VERSION_MAJOR < 15
-   assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
-#endif
+   assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
 
    indices[0] = lp_build_const_int32(gallivm, 0);
    indices[1] = lp_build_const_int32(gallivm, member);
@@ -115,9 +105,7 @@ lp_build_struct_get2(struct gallivm_state *gallivm,
    LLVMValueRef member_ptr;
    LLVMValueRef res;
    assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
-#if LLVM_VERSION_MAJOR < 15
-   assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
-#endif
+   assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
    member_ptr = lp_build_struct_get_ptr2(gallivm, ptr_type, ptr, member, name);
    res = LLVMBuildLoad(gallivm->builder, member_ptr, "");
    lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);