[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] pkl: Disallow labels in pinned structs
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH 2/2] pkl: Disallow labels in pinned structs |
Date: |
Tue, 18 Jan 2022 11:07:22 +0330 |
2022-01-18 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
labels in pinned structs.
* doc/poke.texi (Pinned Structs): Update.
* testsuite/poke.pkl/scons-label-diag-1.pk: New test.
* testsuite/Makefile.am (EXTRA_DIST): Update.
---
ChangeLog | 8 ++++++++
doc/poke.texi | 1 +
libpoke/pkl-typify.c | 21 ++++++++++++++++++++-
testsuite/Makefile.am | 1 +
testsuite/poke.pkl/scons-label-diag-1.pk | 7 +++++++
5 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 testsuite/poke.pkl/scons-label-diag-1.pk
diff --git a/ChangeLog b/ChangeLog
index 1778c324..5cb20652 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-01-18 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
+ labels in pinned structs.
+ * doc/poke.texi (Pinned Structs): Update.
+ * testsuite/poke.pkl/scons-label-diag-1.pk: New test.
+ * testsuite/Makefile.am (EXTRA_DIST): Update.
+
2022-01-18 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
diff --git a/doc/poke.texi b/doc/poke.texi
index 6e221f03..88e2996e 100644
--- a/doc/poke.texi
+++ b/doc/poke.texi
@@ -10810,6 +10810,7 @@ type Ctf_Stype_V1 =
@end example
Note that integral structs cannot be pinned. @xref{Integral Structs}.
+And field labels are not allowed in pinned structs.
@node The OFFSET variable
@subsection The OFFSET variable
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index b9609cec..411e6392 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -1786,7 +1786,7 @@ PKL_PHASE_END_HANDLER
Pinned unions are not allowed.
- Labels are not allowed in integral structs.
+ Labels are not allowed in integral structs and pinned structs.
Optional fields are not allowed in integral structs. */
PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_struct)
@@ -1876,6 +1876,25 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_struct)
PKL_TYPIFY_PAYLOAD->errors++;
PKL_PASS_ERROR;
}
+
+ if (PKL_AST_TYPE_S_PINNED_P (struct_type))
+ {
+ for (field = PKL_AST_TYPE_S_ELEMS (struct_type);
+ field;
+ field = PKL_AST_CHAIN (field))
+ {
+ if (PKL_AST_CODE (field) != PKL_AST_STRUCT_TYPE_FIELD)
+ continue;
+
+ if (PKL_AST_STRUCT_TYPE_FIELD_LABEL (field))
+ {
+ PKL_ERROR (PKL_AST_LOC (field),
+ "labels are not allowed in pinned structs");
+ PKL_TYPIFY_PAYLOAD->errors++;
+ PKL_PASS_ERROR;
+ }
+ }
+ }
}
PKL_PHASE_END_HANDLER
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 357897ba..24f75ea8 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -1788,6 +1788,7 @@ EXTRA_DIST = \
poke.pkl/scons-int-struct-4.pk \
poke.pkl/scons-int-struct-5.pk \
poke.pkl/scons-label-1.pk \
+ poke.pkl/scons-label-diag-1.pk \
poke.pkl/scons-offset-1.pk \
poke.pkl/scons-offset-2.pk \
poke.pkl/scons-offset-3.pk \
diff --git a/testsuite/poke.pkl/scons-label-diag-1.pk
b/testsuite/poke.pkl/scons-label-diag-1.pk
new file mode 100644
index 00000000..b20704c5
--- /dev/null
+++ b/testsuite/poke.pkl/scons-label-diag-1.pk
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+
+type T = pinned struct
+ {
+ uint32 x;
+ uint16 y @ 2#B; /* { dg-error "pinned" } */
+ };
--
2.34.1