[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED] pkl: fix the checking of array initializer indexes
From: |
Jose E. Marchesi |
Subject: |
[COMMITTED] pkl: fix the checking of array initializer indexes |
Date: |
Thu, 23 Dec 2021 12:38:44 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
2021-12-23 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/pkl-trans.c (pkl_trans1_ps_array): Emit an error instead
of an ICE in case of a non-constant index in array initializer.
* libpoke/pkl-anal.c (pkl_anal2_ps_array): Remove.
(pkl_phase_anal2): Update accordingly.
* testsuite/poke.pkl/arrays-initializer-diag-1.pk: New test.
* testsuite/poke.pkl/arrays-initializer-diag-2.pk: Likewise.
* testsuite/Makefile.am (EXTRA_DIST): Add new tests.
---
ChangeLog | 10 ++++++++
libpoke/pkl-anal.c | 32 -------------------------
libpoke/pkl-trans.c | 5 ++--
testsuite/Makefile.am | 2 ++
testsuite/poke.pkl/arrays-initializer-diag-1.pk | 4 ++++
testsuite/poke.pkl/arrays-initializer-diag-2.pk | 4 ++++
6 files changed, 23 insertions(+), 34 deletions(-)
create mode 100644 testsuite/poke.pkl/arrays-initializer-diag-1.pk
create mode 100644 testsuite/poke.pkl/arrays-initializer-diag-2.pk
diff --git a/ChangeLog b/ChangeLog
index 4b59d1a9..7a15281a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2021-12-23 Jose E. Marchesi <jemarch@gnu.org>
+ * libpoke/pkl-trans.c (pkl_trans1_ps_array): Emit an error instead
+ of an ICE in case of a non-constant index in array initializer.
+ * libpoke/pkl-anal.c (pkl_anal2_ps_array): Remove.
+ (pkl_phase_anal2): Update accordingly.
+ * testsuite/poke.pkl/arrays-initializer-diag-1.pk: New test.
+ * testsuite/poke.pkl/arrays-initializer-diag-2.pk: Likewise.
+ * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+
+2021-12-23 Jose E. Marchesi <jemarch@gnu.org>
+
* libpoke/pkl-ast.c (pkl_ast_sizeof_type): Do not add location
info to internally generated AST nodes.
* libpoke/pkl-fold.c (OP_UNARY_OO): Likewise.
diff --git a/libpoke/pkl-anal.c b/libpoke/pkl-anal.c
index fe05a63e..8e82e361 100644
--- a/libpoke/pkl-anal.c
+++ b/libpoke/pkl-anal.c
@@ -906,37 +906,6 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal2_ps_type_struct)
}
PKL_PHASE_END_HANDLER
-/* The indexes in array initializers shall be constant. */
-
-PKL_PHASE_BEGIN_HANDLER (pkl_anal2_ps_array)
-{
- pkl_ast_node array = PKL_PASS_NODE;
- pkl_ast_node initializers
- = PKL_AST_ARRAY_INITIALIZERS (array);
- pkl_ast_node initializer;
-
- for (initializer = initializers;
- initializer;
- initializer = PKL_AST_CHAIN (initializer))
- {
- pkl_ast_node index
- = PKL_AST_ARRAY_INITIALIZER_INDEX (initializer);
-
- /* pkl_trans1_ps_array should install indexes in all
- initializers. */
- assert (index);
-
- if (PKL_AST_CODE (index) != PKL_AST_INTEGER)
- {
- PKL_ERROR (PKL_AST_LOC (index),
- "indexes in array initializers shall be constant");
- PKL_ANAL_PAYLOAD->errors++;
- PKL_PASS_ERROR;
- }
- }
-}
-PKL_PHASE_END_HANDLER
-
struct pkl_phase pkl_phase_anal2 =
{
PKL_PHASE_PS_HANDLER (PKL_AST_SRC, pkl_anal_ps_src),
@@ -949,7 +918,6 @@ struct pkl_phase pkl_phase_anal2 =
PKL_PHASE_PS_HANDLER (PKL_AST_RETURN_STMT, pkl_anal2_ps_return_stmt),
PKL_PHASE_PS_HANDLER (PKL_AST_FUNCALL, pkl_anal2_ps_funcall),
PKL_PHASE_PS_HANDLER (PKL_AST_STRUCT_TYPE_FIELD,
pkl_anal2_ps_struct_type_field),
- PKL_PHASE_PS_HANDLER (PKL_AST_ARRAY, pkl_anal2_ps_array),
PKL_PHASE_PS_TYPE_HANDLER (PKL_TYPE_STRUCT, pkl_anal2_ps_type_struct),
PKL_PHASE_PS_DEFAULT_HANDLER (pkl_anal_ps_default),
};
diff --git a/libpoke/pkl-trans.c b/libpoke/pkl-trans.c
index 912de165..6e1239f4 100644
--- a/libpoke/pkl-trans.c
+++ b/libpoke/pkl-trans.c
@@ -1042,8 +1042,9 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_array)
if (PKL_AST_CODE (initializer_index_node)
!= PKL_AST_INTEGER)
{
- PKL_ICE (PKL_AST_NOLOC,
- "array initialize index should be an integer node");
+ PKL_ERROR (PKL_AST_LOC (initializer_index_node),
+ "indexes in array initializers shall be constant");
+ PKL_TRANS_PAYLOAD->errors++;
PKL_PASS_ERROR;
}
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 73bcef89..e222e740 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -659,6 +659,8 @@ EXTRA_DIST = \
poke.pkl/arrays-index-diag-1.pk \
poke.pkl/arrays-index-diag-2.pk \
poke.pkl/arrays-index-diag-3.pk \
+ poke.pkl/arrays-initializer-diag-1.pk \
+ poke.pkl/arrays-initializer-diag-2.pk \
poke.pkl/ass-1.pk \
poke.pkl/ass-2.pk \
poke.pkl/ass-3.pk \
diff --git a/testsuite/poke.pkl/arrays-initializer-diag-1.pk
b/testsuite/poke.pkl/arrays-initializer-diag-1.pk
new file mode 100644
index 00000000..1d203f93
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-initializer-diag-1.pk
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+
+var a = 10;
+[.[2 + a] = 666]; /* { dg-error "constant" } */
diff --git a/testsuite/poke.pkl/arrays-initializer-diag-2.pk
b/testsuite/poke.pkl/arrays-initializer-diag-2.pk
new file mode 100644
index 00000000..e2fc77d2
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-initializer-diag-2.pk
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+
+fun a = int: { return 10; }
+[.[2 + a] = 666]; /* { dg-error "constant" } */
--
2.11.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [COMMITTED] pkl: fix the checking of array initializer indexes,
Jose E. Marchesi <=