From 9c6156c842056591258386bd7de192b5f600b3af Mon Sep 17 00:00:00 2001 From: Botond Baranyi Date: Mon, 7 Jun 2021 18:20:33 +0200 Subject: [PATCH 1/2] Fixed fatal error caused by using a constant initialized with a module parameter as array dimensions (issue #495) Signed-off-by: Botond Baranyi --- compiler2/Type_chk.cc | 9 ++++++++- function_test/Semantic_Analyser/Makefile.semantic | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc index 660e5b381..d462a299f 100644 --- a/compiler2/Type_chk.cc +++ b/compiler2/Type_chk.cc @@ -4196,7 +4196,14 @@ bool Type::chk_this_refd_value(Value *value, Common::Assignment *lhs, expected_v value->set_valuetype(Value::V_ERROR); return self_ref; case Assignment::A_CONST: - is_const = true; + if (expected_value == EXPECTED_CONSTANT && + ass->get_Value()->is_unfoldable(NULL, expected_value)) { + value->error("Referenced constant value cannot be evaluated at compile-time"); + error_flag = true; + } + else { + is_const = true; + } break; case Assignment::A_OBJECT: case Assignment::A_OS: { diff --git a/function_test/Semantic_Analyser/Makefile.semantic b/function_test/Semantic_Analyser/Makefile.semantic index 5f01b46a0..869444f0d 100644 --- a/function_test/Semantic_Analyser/Makefile.semantic +++ b/function_test/Semantic_Analyser/Makefile.semantic @@ -16,7 +16,7 @@ include ../../Makefile.personal SADIRS := ver param template any_from pattern_ref float recof_index \ port_translation mtc_and_system_clause port_map_connect deterministic invoking_function_from_specific_places \ -json realtime map_param oop defaultAlternative +json realtime map_param oop defaultAlternative issues ifdef RT2 SADIRS += deprecated erroneous_attributes template_concat endif -- GitLab From 5902bb56d21530912c42c504554b71781eb512bc Mon Sep 17 00:00:00 2001 From: Botond Baranyi Date: Mon, 7 Jun 2021 18:23:06 +0200 Subject: [PATCH 2/2] Added missing tests for issue #495 Signed-off-by: Botond Baranyi --- .../Semantic_Analyser/issues/.gitignore | 2 + .../Semantic_Analyser/issues/Issue495_SE.ttcn | 37 +++++++++++++++++++ .../Semantic_Analyser/issues/Makefile | 12 ++++++ function_test/Semantic_Analyser/issues/t | 9 +++++ 4 files changed, 60 insertions(+) create mode 100644 function_test/Semantic_Analyser/issues/.gitignore create mode 100644 function_test/Semantic_Analyser/issues/Issue495_SE.ttcn create mode 100644 function_test/Semantic_Analyser/issues/Makefile create mode 100755 function_test/Semantic_Analyser/issues/t diff --git a/function_test/Semantic_Analyser/issues/.gitignore b/function_test/Semantic_Analyser/issues/.gitignore new file mode 100644 index 000000000..e2d293255 --- /dev/null +++ b/function_test/Semantic_Analyser/issues/.gitignore @@ -0,0 +1,2 @@ +!Makefile +!*.ttcn diff --git a/function_test/Semantic_Analyser/issues/Issue495_SE.ttcn b/function_test/Semantic_Analyser/issues/Issue495_SE.ttcn new file mode 100644 index 000000000..17d4b671c --- /dev/null +++ b/function_test/Semantic_Analyser/issues/Issue495_SE.ttcn @@ -0,0 +1,37 @@ +/****************************************************************************** + * Copyright (c) 2000-2021 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html + * + * Contributors: + * Baranyi, Botond + * + ******************************************************************************/ + +module Issue495 //^In TTCN-3 module// +{ + +modulepar +{ + integer tsp_cl_num := 10; +} + + +type component MTC_CT {}; + + + testcase tc_Fatal_Error() runs on MTC_CT //^In testcase definition// + { + const integer cl_num0 := 10; + var integer Int0[cl_num0]; + + const integer cl_num := tsp_cl_num; + var integer Int[cl_num]; //^In variable definition// //^In array size// //Referenced constant value cannot be evaluated at compile-time// + + var integer Int2[tsp_cl_num]; //^In variable definition// //^In array size// //Reference to an \(evaluable\) constant value was expected instead of module parameter// + + } + +} diff --git a/function_test/Semantic_Analyser/issues/Makefile b/function_test/Semantic_Analyser/issues/Makefile new file mode 100644 index 000000000..7abfd0db9 --- /dev/null +++ b/function_test/Semantic_Analyser/issues/Makefile @@ -0,0 +1,12 @@ +############################################################################## +# Copyright (c) 2000-2021 Ericsson Telecom AB +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html +# +# Contributors: +# Baranyi, Botond +# +############################################################################## +include ../common.mk diff --git a/function_test/Semantic_Analyser/issues/t b/function_test/Semantic_Analyser/issues/t new file mode 100755 index 000000000..3a4b58ec1 --- /dev/null +++ b/function_test/Semantic_Analyser/issues/t @@ -0,0 +1,9 @@ +#!/usr/bin/perl +# note this is called through "perl -w" +use strict; + +my $self = $0; +$self =~ s!/t!!; + +exec('make check --no-print-directory -s -C ' . $self); + -- GitLab