89 lines
1.3 KiB
Go
89 lines
1.3 KiB
Go
package generator
|
|
|
|
import "testing"
|
|
|
|
func TestValueCastSlicePointer (test *testing.T) {
|
|
testString (test,
|
|
`%Index = type i64
|
|
define void @main() {
|
|
0:
|
|
%1 = alloca { ptr, %Index }
|
|
%2 = getelementptr { ptr, %Index }, ptr %1, i32 0, i32 0
|
|
%3 = load ptr, ptr %2
|
|
%4 = alloca ptr
|
|
store ptr %3, ptr %4
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
slice: *:Byte
|
|
pointer: *Byte = [~*Byte slice]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestValueCastIntegerIneffectual (test *testing.T) {
|
|
testString (test,
|
|
`%A = type i64
|
|
define void @main() {
|
|
0:
|
|
%1 = alloca i64
|
|
store i64 5, ptr %1
|
|
%2 = load i64, ptr %1
|
|
%3 = alloca %A
|
|
store i64 %2, ptr %3
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
A: Int
|
|
[main] = {
|
|
x:Int = 5
|
|
y:A = [~A x]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestValueCastStringIneffectual (test *testing.T) {
|
|
testString (test,
|
|
`%Index = type i64
|
|
%String = type { ptr, %Index }
|
|
define void @main() {
|
|
0:
|
|
%1 = alloca { ptr, %Index }
|
|
%2 = load { ptr, %Index }, ptr %1
|
|
%3 = alloca %String
|
|
store { ptr, %Index } %2, ptr %3
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
y:*:Byte
|
|
x:String = [~String y]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestBitCastStringIneffectual (test *testing.T) {
|
|
testString (test,
|
|
`%Index = type i64
|
|
%String = type { ptr, %Index }
|
|
define void @main() {
|
|
0:
|
|
%1 = alloca { ptr, %Index }
|
|
%2 = load { ptr, %Index }, ptr %1
|
|
%3 = alloca %String
|
|
store { ptr, %Index } %2, ptr %3
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
y:*:Byte
|
|
x:String = [~~String y]
|
|
}
|
|
`)
|
|
}
|