diff options
| author | Alasdair | 2019-03-09 17:41:14 +0000 |
|---|---|---|
| committer | Alasdair | 2019-03-09 17:45:23 +0000 |
| commit | 9c4c0e8770a43bb097df243050163afd1b31cc8f (patch) | |
| tree | 7ff1dd6122a3dbaa5a2a7b0d46f7f2d6df6c082e /test/c | |
| parent | 1d854bb23ffd4bdfad05621ddb8842e7d465baa7 (diff) | |
C: Fix miscompilation of constrained struct field access
For a Int-parameterised struct F('x: Int) = ... the optimizer would
attempt to optimize field access in cases where 'x was known to
constrain the types of the struct fields only locally. Which would
create a type error in the generated C. Now we always use the type
from the global struct type.
However, we previously weren't using struct type quantifiers to
optimize the field representation, which we now do.
Also rename some utility functions to better match the List
functions in the OCaml stdlib.
Diffstat (limited to 'test/c')
| -rw-r--r-- | test/c/int_struct.expect | 1 | ||||
| -rw-r--r-- | test/c/int_struct.sail | 24 | ||||
| -rw-r--r-- | test/c/int_struct_constrained.expect | 1 | ||||
| -rw-r--r-- | test/c/int_struct_constrained.sail | 24 |
4 files changed, 50 insertions, 0 deletions
diff --git a/test/c/int_struct.expect b/test/c/int_struct.expect new file mode 100644 index 00000000..f70f10e4 --- /dev/null +++ b/test/c/int_struct.expect @@ -0,0 +1 @@ +A diff --git a/test/c/int_struct.sail b/test/c/int_struct.sail new file mode 100644 index 00000000..42554593 --- /dev/null +++ b/test/c/int_struct.sail @@ -0,0 +1,24 @@ +default Order dec + +$include <prelude.sail> + +val print = "print_endline" : string -> unit + +struct Foo('n: Int) = { + field: bits('n) +} + +type Foo32 = Foo(32) + +function bar(foo: Foo32) -> unit = { + if foo.field == 0xFFFF_FFFF then { + print("A") + } else { + print("B") + } +} + +function main((): unit) -> unit = { + let x: Foo32 = struct { field = 0xFFFF_FFFF }; + bar(x) +}
\ No newline at end of file diff --git a/test/c/int_struct_constrained.expect b/test/c/int_struct_constrained.expect new file mode 100644 index 00000000..f70f10e4 --- /dev/null +++ b/test/c/int_struct_constrained.expect @@ -0,0 +1 @@ +A diff --git a/test/c/int_struct_constrained.sail b/test/c/int_struct_constrained.sail new file mode 100644 index 00000000..95cb6e9b --- /dev/null +++ b/test/c/int_struct_constrained.sail @@ -0,0 +1,24 @@ +default Order dec + +$include <prelude.sail> + +val print = "print_endline" : string -> unit + +struct Foo('n: Int), 'n <= 64 = { + field: bits('n) +} + +type Foo32 = Foo(32) + +function bar(foo: Foo32) -> unit = { + if foo.field == 0xFFFF_FFFF then { + print("A") + } else { + print("B") + } +} + +function main((): unit) -> unit = { + let x: Foo32 = struct { field = 0xFFFF_FFFF }; + bar(x) +}
\ No newline at end of file |
