[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] pkl: emit error for `int<1>' types
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] pkl: emit error for `int<1>' types |
Date: |
Mon, 23 Jan 2023 22:49:38 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Hi Mohammad.
> For signed integers, we need, at least, two bits: one for sign and
> one for the magnitude.
I could swear we already fixed this long ago.
But I clearly was dreaming or something.
OK for master!
>
> 2023-01-23 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
>
> * libpoke/pkl-typify.c (pkl_typify1_ps_type_integral): Reject
> `int<1>' as invalid type.
> * testsuite/poke.cmd/sdiff-10.pk: s/int<1>/uint<1>/.
> * testsuite/poke.map/maps-int-structs-6.pk: Likewise.
> * testsuite/poke.map/maps-int-structs-11.pk: Likewise.
> * testsuite/poke.pkl/cast-integers-12.pk: Likewise.
> * testsuite/poke.pkl/eq-integers-5.pk: Likewise.
> * testsuite/poke.pkl/eq-offsets-8.pk: Likewise.
> * testsuite/poke.pkl/mod-offsets-3.pk: Likewise.
> * testsuite/poke.pkl/mod-offsets-4.pk: Likewise.
> * testsuite/poke.pkl/int-type.pk: Remove `int<1>'.
> * testsuite/poke.pkl/int-type-diag-4.pk: New test.
> * testsuite/Makefile.am (EXTRA_DIST): Add new test.
> ---
> ChangeLog | 16 ++++++++++++++++
> libpoke/pkl-typify.c | 7 +++++--
> testsuite/Makefile.am | 1 +
> testsuite/poke.cmd/sdiff-10.pk | 2 +-
> testsuite/poke.map/maps-int-structs-11.pk | 6 +++---
> testsuite/poke.map/maps-int-structs-6.pk | 6 +++---
> testsuite/poke.pkl/cast-integers-12.pk | 8 ++++----
> testsuite/poke.pkl/eq-integers-5.pk | 4 ++--
> testsuite/poke.pkl/eq-offsets-8.pk | 4 ++--
> testsuite/poke.pkl/int-type-diag-4.pk | 4 ++++
> testsuite/poke.pkl/int-type.pk | 1 -
> testsuite/poke.pkl/mod-offsets-3.pk | 2 +-
> testsuite/poke.pkl/mod-offsets-4.pk | 2 +-
> 13 files changed, 43 insertions(+), 20 deletions(-)
> create mode 100644 testsuite/poke.pkl/int-type-diag-4.pk
>
> diff --git a/ChangeLog b/ChangeLog
> index 4365991e..65cff30d 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,19 @@
> +2023-01-23 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
> +
> + * libpoke/pkl-typify.c (pkl_typify1_ps_type_integral): Reject
> + `int<1>' as invalid type.
> + * testsuite/poke.cmd/sdiff-10.pk: s/int<1>/uint<1>/.
> + * testsuite/poke.map/maps-int-structs-6.pk: Likewise.
> + * testsuite/poke.map/maps-int-structs-11.pk: Likewise.
> + * testsuite/poke.pkl/cast-integers-12.pk: Likewise.
> + * testsuite/poke.pkl/eq-integers-5.pk: Likewise.
> + * testsuite/poke.pkl/eq-offsets-8.pk: Likewise.
> + * testsuite/poke.pkl/mod-offsets-3.pk: Likewise.
> + * testsuite/poke.pkl/mod-offsets-4.pk: Likewise.
> + * testsuite/poke.pkl/int-type.pk: Remove `int<1>'.
> + * testsuite/poke.pkl/int-type-diag-4.pk: New test.
> + * testsuite/Makefile.am (EXTRA_DIST): Add new test.
> +
> 2023-01-23 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
>
> * poked/poked.c (poked_version): Don't use year range.
> diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
> index e4173386..7df71a63 100644
> --- a/libpoke/pkl-typify.c
> +++ b/libpoke/pkl-typify.c
> @@ -1696,12 +1696,15 @@ PKL_PHASE_END_HANDLER
> PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_integral)
> {
> pkl_ast_node type = PKL_PASS_NODE;
> + int signed_p = PKL_AST_TYPE_I_SIGNED_P (type);
> + int width_min = signed_p ? 2 : 1;
>
> - if (PKL_AST_TYPE_I_SIZE (type) < 1
> + if (PKL_AST_TYPE_I_SIZE (type) < width_min
> || PKL_AST_TYPE_I_SIZE (type) > 64)
> {
> PKL_ERROR (PKL_AST_LOC (type),
> - "the width of an integral type should be in the [1,64]
> range");
> + "the width of %s integral type should be in the [%d,64] "
> + "range", signed_p ? "a signed" : "an unsigned", width_min);
> PKL_TYPIFY_PAYLOAD->errors++;
> PKL_PASS_ERROR;
> }
> diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
> index 7afd92e2..cff03d63 100644
> --- a/testsuite/Makefile.am
> +++ b/testsuite/Makefile.am
> @@ -1595,6 +1595,7 @@ EXTRA_DIST = \
> poke.pkl/int-type-diag-1.pk \
> poke.pkl/int-type-diag-2.pk \
> poke.pkl/int-type-diag-3.pk \
> + poke.pkl/int-type-diag-4.pk \
> poke.pkl/int-type.pk \
> poke.pkl/int-union-1.pk \
> poke.pkl/int-union-2.pk \
> diff --git a/testsuite/poke.cmd/sdiff-10.pk b/testsuite/poke.cmd/sdiff-10.pk
> index 6abab82a..8dfcf340 100644
> --- a/testsuite/poke.cmd/sdiff-10.pk
> +++ b/testsuite/poke.cmd/sdiff-10.pk
> @@ -2,7 +2,7 @@
> /* { dg-data {c*} {0x00 0x27 0x28 0x00 0x22 0x33 0x44 0xbc} foo } */
> /* { dg-data {c*} {0x01 0x29 0x30 0x31 0x00 0x33 0x9a 0xbc} bar } */
>
> -type Foo = struct { int<2> a; int<2> b; int<3> c; int<1> d; };
> +type Foo = struct { int<2> a; int<2> b; int<3> c; uint<1> d; };
> type Bar = struct { byte x; Foo y; };
>
> /* { dg-command {.file foo} } */
> diff --git a/testsuite/poke.map/maps-int-structs-11.pk
> b/testsuite/poke.map/maps-int-structs-11.pk
> index d8b52a61..73e03071 100644
> --- a/testsuite/poke.map/maps-int-structs-11.pk
> +++ b/testsuite/poke.map/maps-int-structs-11.pk
> @@ -6,7 +6,7 @@
> type Foo =
> struct int<16>
> {
> - int<1> s;
> + uint<1> s;
> offset<uint<15>,3> m;
> };
>
> @@ -14,8 +14,8 @@ type Foo =
>
> /* { dg-command { .set endian little } } */
> /* { dg-command { Foo @ 0#B } } */
> -/* { dg-output "Foo {s=\\(int<1>\\) 0b0,m=\\(uint<15>\\)
> 0b010001110000000#3}" } */
> +/* { dg-output "Foo {s=\\(uint<1>\\) 0b0,m=\\(uint<15>\\)
> 0b010001110000000#3}" } */
>
> /* { dg-command { .set endian big } } */
> /* { dg-command { Foo @ 0#B } } */
> -/* { dg-output "\nFoo {s=\\(int<1>\\) 0b1,m=\\(uint<15>\\)
> 0b000000000100011#3}" } */
> +/* { dg-output "\nFoo {s=\\(uint<1>\\) 0b1,m=\\(uint<15>\\)
> 0b000000000100011#3}" } */
> diff --git a/testsuite/poke.map/maps-int-structs-6.pk
> b/testsuite/poke.map/maps-int-structs-6.pk
> index a4f58019..547b597e 100644
> --- a/testsuite/poke.map/maps-int-structs-6.pk
> +++ b/testsuite/poke.map/maps-int-structs-6.pk
> @@ -6,7 +6,7 @@
> type Foo =
> struct int<16>
> {
> - int<1> s;
> + uint<1> s;
> uint<15> m;
> };
>
> @@ -14,8 +14,8 @@ type Foo =
>
> /* { dg-command { .set endian little } } */
> /* { dg-command { Foo @ 0#B } } */
> -/* { dg-output "Foo {s=\\(int<1>\\) 0b0,m=\\(uint<15>\\) 0b010001110000000}"
> } */
> +/* { dg-output "Foo {s=\\(uint<1>\\) 0b0,m=\\(uint<15>\\)
> 0b010001110000000}" } */
>
> /* { dg-command { .set endian big } } */
> /* { dg-command { Foo @ 0#B } } */
> -/* { dg-output "\nFoo {s=\\(int<1>\\) 0b1,m=\\(uint<15>\\)
> 0b000000000100011}" } */
> +/* { dg-output "\nFoo {s=\\(uint<1>\\) 0b1,m=\\(uint<15>\\)
> 0b000000000100011}" } */
> diff --git a/testsuite/poke.pkl/cast-integers-12.pk
> b/testsuite/poke.pkl/cast-integers-12.pk
> index c89f15b5..2db0e8ad 100644
> --- a/testsuite/poke.pkl/cast-integers-12.pk
> +++ b/testsuite/poke.pkl/cast-integers-12.pk
> @@ -2,9 +2,9 @@
>
> var x = 0;
>
> -/* { dg-command { x as int<1> } } */
> -/* { dg-output "\\(int<1>\\) 0" } */
> +/* { dg-command { x as uint<1> } } */
> +/* { dg-output "\\(uint<1>\\) 0" } */
>
> /* For constant folding: */
> -/* { dg-command { 0 as int<1> } } */
> -/* { dg-output "\n\\(int<1>\\) 0" } */
> +/* { dg-command { 0 as uint<1> } } */
> +/* { dg-output "\n\\(uint<1>\\) 0" } */
> diff --git a/testsuite/poke.pkl/eq-integers-5.pk
> b/testsuite/poke.pkl/eq-integers-5.pk
> index f8997b15..cf8f78ea 100644
> --- a/testsuite/poke.pkl/eq-integers-5.pk
> +++ b/testsuite/poke.pkl/eq-integers-5.pk
> @@ -3,9 +3,9 @@
> var x = 10U;
> var y = 10U;
>
> -/* { dg-command { x as int<1> == y } } */
> +/* { dg-command { x as uint<1> == y } } */
> /* { dg-output "0" } */
>
> /* For constant folding: */
> -/* { dg-command { 10U as int<1> == 10U } } */
> +/* { dg-command { 10U as uint<1> == 10U } } */
> /* { dg-output "\n0" } */
> diff --git a/testsuite/poke.pkl/eq-offsets-8.pk
> b/testsuite/poke.pkl/eq-offsets-8.pk
> index 783370f1..b5b6c4ac 100644
> --- a/testsuite/poke.pkl/eq-offsets-8.pk
> +++ b/testsuite/poke.pkl/eq-offsets-8.pk
> @@ -3,9 +3,9 @@
> var x = 10U#B;
> var y = 10U#B;
>
> -/* { dg-command { x as offset<int<1>,B> == y } } */
> +/* { dg-command { x as offset<uint<1>,B> == y } } */
> /* { dg-output "0" } */
>
> /* For constant folding: */
> -/* { dg-command { 10U#B as offset<int<1>,B> == 10U#B } } */
> +/* { dg-command { 10U#B as offset<uint<1>,B> == 10U#B } } */
> /* { dg-output "\n0" } */
> diff --git a/testsuite/poke.pkl/int-type-diag-4.pk
> b/testsuite/poke.pkl/int-type-diag-4.pk
> new file mode 100644
> index 00000000..3844bb9e
> --- /dev/null
> +++ b/testsuite/poke.pkl/int-type-diag-4.pk
> @@ -0,0 +1,4 @@
> +/* { dg-do compile } */
> +
> +type int1 =
> + int<1>; /* { dg-error "width of a signed integral.*.2,64. range" } */
> diff --git a/testsuite/poke.pkl/int-type.pk b/testsuite/poke.pkl/int-type.pk
> index b234a04e..c7612e12 100644
> --- a/testsuite/poke.pkl/int-type.pk
> +++ b/testsuite/poke.pkl/int-type.pk
> @@ -2,7 +2,6 @@
>
> /* Type constructor. */
>
> -type int1 = int<1>;
> type uint1 = uint<1>;
>
> type int2 = int<2>;
> diff --git a/testsuite/poke.pkl/mod-offsets-3.pk
> b/testsuite/poke.pkl/mod-offsets-3.pk
> index fcf02060..4aeb064b 100644
> --- a/testsuite/poke.pkl/mod-offsets-3.pk
> +++ b/testsuite/poke.pkl/mod-offsets-3.pk
> @@ -1,6 +1,6 @@
> /* { dg-do run } */
>
> -type Packet = struct { int<1>[5]; };
> +type Packet = struct { uint<1>[5]; };
> var x = 2#Packet;
>
> /* { dg-command { x % 1#B } } */
> diff --git a/testsuite/poke.pkl/mod-offsets-4.pk
> b/testsuite/poke.pkl/mod-offsets-4.pk
> index 3be900a9..653fe2cf 100644
> --- a/testsuite/poke.pkl/mod-offsets-4.pk
> +++ b/testsuite/poke.pkl/mod-offsets-4.pk
> @@ -1,6 +1,6 @@
> /* { dg-do run } */
>
> -type Packet = struct { int<1>[5]; };
> +type Packet = struct { uint<1>[5]; };
> type Byte = byte;
>
> var x = 2#Packet;