Skip to content

Commit dcf4836

Browse files
committed
Add type parameter to CreateCall
Use LLVMBuildCall2 instead of LLVMBuildCall, to be compatible with LLVM 15.
1 parent f0899d9 commit dcf4836

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

executionengine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestFactorial(t *testing.T) {
4848
builder.SetInsertPointAtEnd(iffalse)
4949
n_minus := builder.CreateSub(n, ConstInt(Int32Type(), 1, false), "subtmp")
5050
call_fac_args := []Value{n_minus}
51-
call_fac := builder.CreateCall(fac, call_fac_args, "calltmp")
51+
call_fac := builder.CreateCall(fac_type, fac, call_fac_args, "calltmp")
5252
res_iffalse := builder.CreateMul(n, call_fac, "multmp")
5353
builder.CreateBr(end)
5454

ir.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ func (v Value) SetVisibility(vi Visibility) { C.LLVMSetVisibility(v.C, C.LLVMVis
10581058
func (v Value) Alignment() int { return int(C.LLVMGetAlignment(v.C)) }
10591059
func (v Value) SetAlignment(a int) { C.LLVMSetAlignment(v.C, C.unsigned(a)) }
10601060
func (v Value) SetUnnamedAddr(ua bool) { C.LLVMSetUnnamedAddr(v.C, boolToLLVMBool(ua)) }
1061+
func (v Value) GlobalValueType() (t Type) { t.C = C.LLVMGlobalGetValueType(v.C); return }
10611062

10621063
// Operations on global variables
10631064
func AddGlobal(m Module, t Type, name string) (v Value) {
@@ -1318,6 +1319,10 @@ func (v Value) CalledValue() (rv Value) {
13181319
rv.C = C.LLVMGetCalledValue(v.C)
13191320
return
13201321
}
1322+
func (v Value) CalledFunctionType() (t Type) {
1323+
t.C = C.LLVMGetCalledFunctionType(v.C)
1324+
return
1325+
}
13211326

13221327
// Operations on call instructions (only)
13231328
func (v Value) IsTailCall() bool { return C.LLVMIsTailCall(v.C) != 0 }
@@ -1365,6 +1370,7 @@ func (v Value) Indices() []uint32 {
13651370
func (v Value) IntPredicate() IntPredicate { return IntPredicate(C.LLVMGetICmpPredicate(v.C)) }
13661371
func (v Value) FloatPredicate() FloatPredicate { return FloatPredicate(C.LLVMGetFCmpPredicate(v.C)) }
13671372

1373+
13681374
//-------------------------------------------------------------------------
13691375
// llvm.Builder
13701376
//-------------------------------------------------------------------------
@@ -1412,11 +1418,11 @@ func (b Builder) GetCurrentDebugLocation() (loc DebugLoc) {
14121418
func (b Builder) SetInstDebugLocation(v Value) { C.LLVMSetInstDebugLocation(b.C, v.C) }
14131419
func (b Builder) InsertDeclare(module Module, storage Value, md Value) Value {
14141420
f := module.NamedFunction("llvm.dbg.declare")
1421+
ftyp := FunctionType(VoidType(), []Type{storage.Type(), md.Type()}, false)
14151422
if f.IsNil() {
1416-
ftyp := FunctionType(VoidType(), []Type{storage.Type(), md.Type()}, false)
14171423
f = AddFunction(module, "llvm.dbg.declare", ftyp)
14181424
}
1419-
return b.CreateCall(f, []Value{storage, md}, "")
1425+
return b.CreateCall(ftyp, f, []Value{storage, md}, "")
14201426
}
14211427

14221428
// Terminators
@@ -1865,11 +1871,11 @@ func (b Builder) CreatePHI(t Type, name string) (v Value) {
18651871
v.C = C.LLVMBuildPhi(b.C, t.C, cname)
18661872
return
18671873
}
1868-
func (b Builder) CreateCall(fn Value, args []Value, name string) (v Value) {
1874+
func (b Builder) CreateCall(t Type, fn Value, args []Value, name string) (v Value) {
18691875
cname := C.CString(name)
18701876
defer C.free(unsafe.Pointer(cname))
18711877
ptr, nvals := llvmValueRefs(args)
1872-
v.C = C.LLVMBuildCall(b.C, fn.C, ptr, nvals, cname)
1878+
v.C = C.LLVMBuildCall2(b.C, t.C, fn.C, ptr, nvals, cname)
18731879
return
18741880
}
18751881

0 commit comments

Comments
 (0)