- Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathabi.ts
81 lines (68 loc) · 1.74 KB
/
abi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// NOTE: this test mostly relies on comparing to the fixture because the ABI affects emitted
// instructions, not semantics.
// exported functions should wrap their returns
exportfunctionexported(): i8{
return<i8>128;
}
// internal functions should not wrap their returns
functioninternal(): i8{
return<i8>128;
}
// calling a function that already wraps its return should not wrap again
exportfunctionexportedExported(): i8{
returnexported();
}
// calling a function that does not wrap its return should wrap it
exportfunctionexportedInternal(): i8{
returninternal();
}
internal();// keep alive
varcondition=!0;
// locals not marked as wrapped should be wrapped when necessaray
{
letx: i8;
x=<i8>256;// overflows to 0
assert(!x);// should wrap
}
// locals not marked as wrapped in all branches should be wrapped when necessary
{
letx: i8;
x=<i8>256;// overflows to 0
if(condition){
x=x/2;// should sign-extend x on input
}else{
x=x/2;// ^
}
assert(!x);// should wrap x
}
// locals marked as wrapped in all branches should not be wrapped again
{
letx: i8;// local
x=<i8>256;// overflows to 0
if(condition){
x=x>>24;// should mark result as wrapped
}else{
x=x&127;// ^
}
assert(!x);// should not wrap
}
// unlike locals, globals are wrapped on assignment
vary: i8;
{
y=<i8>256;// should wrap
assert(!y);// should not wrap
}
// certain operations do not overflow, depending on target type
{
letb: bool;
b=<bool>ctz(2);
assert(b);// should wrap
b=<bool>clz(1);
assert(b);// should wrap
letx: i8;
x=<i8>ctz(2);
assert(x);// should not wrap
x=<i8>clz(1);
assert(x);// should not wrap
// TODO: test more?
}