ac/nir/llvm: Fix setting function attributes for intrinsics
authorDaniel Scharrer <daniel@constexpr.org>
Fri, 11 Nov 2016 20:36:36 +0000 (21:36 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Fri, 11 Nov 2016 21:40:32 +0000 (22:40 +0100)
This fixes a NULL pointer dereference for intrinsics with more than
one function attribute introduced in commit 2fdaf38.
The fix is ported from the lp_build_intrinsic changes in commit 8bdd52c.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_nir_to_llvm.c

index b7ccea88372bfc28c0226d1b9dc4e03324d9f1b4..aa2d488780e5521c96a593e2d82f69498dabe136 100644 (file)
@@ -1675,7 +1675,11 @@ emit_llvm_intrinsic(struct nir_to_llvm_context *ctx, const char *name,
                LLVMSetFunctionCallConv(function, LLVMCCallConv);
                LLVMSetLinkage(function, LLVMExternalLinkage);
 
-               ac_add_function_attr(function, 0, attrib_mask | AC_FUNC_ATTR_NOUNWIND);
+               attrib_mask |= AC_FUNC_ATTR_NOUNWIND;
+               while (attrib_mask) {
+                       enum ac_func_attr attr = 1u << u_bit_scan(&attrib_mask);
+                       ac_add_function_attr(function, -1, attr);
+               }
        }
        return LLVMBuildCall(ctx->builder, function, params, param_count, "");
 }