summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/gallivm/lp_bld_const.h
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-12-16 10:13:02 -0700
committerBrian Paul <brianp@vmware.com>2010-12-16 10:19:16 -0700
commitee16e97ed1d0921c533c77688b278bef393d9922 (patch)
tree3ddbc79232669412d4538249b2040bebe7929800 /src/gallium/auxiliary/gallivm/lp_bld_const.h
parentb7e150605d402224cdd8fa3d186924bdee3c6c49 (diff)
gallivm: work around LLVM 2.6 bug when calling C functions
Create a constant int pointer to the C function, then cast it to the function's type. This avoids using trampoline code which seem to be inadvertantly freed by LLVM in some situations (which leads to segfaults). The root issue and work-around were found by José. NOTE: This is a candidate for the 7.10 branch
Diffstat (limited to 'src/gallium/auxiliary/gallivm/lp_bld_const.h')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h
index c749a7a315..680211fbbd 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h
@@ -125,4 +125,22 @@ lp_build_const_float(struct gallivm_state *gallivm, float x)
}
+/** Return constant-valued pointer to int */
+static INLINE LLVMValueRef
+lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr)
+{
+ LLVMTypeRef int_type;
+ LLVMValueRef v;
+
+ /* int type large enough to hold a pointer */
+ int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *));
+ v = LLVMConstInt(int_type, (unsigned long long) ptr, 0);
+ v = LLVMBuildIntToPtr(gallivm->builder, v,
+ LLVMPointerType(int_type, 0),
+ "cast int to ptr");
+ return v;
+}
+
+
+
#endif /* !LP_BLD_CONST_H */