From 0854b3516147bddb0ead361602fccd61a37a792a Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Tue, 17 Jan 2017 15:43:09 +0100
Subject: [PATCH] Fixed select statement code generation when goto is present
 (Bug 510562)

Change-Id: I6d645f5c5ec822f10e89f218993daeacae6fa39f
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 compiler2/ttcn3/Statement.cc                  |  6 ++--
 .../compileonly/selectCase/selectCase.ttcn    | 31 +++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/compiler2/ttcn3/Statement.cc b/compiler2/ttcn3/Statement.cc
index 54c0bec7d..28418078b 100644
--- a/compiler2/ttcn3/Statement.cc
+++ b/compiler2/ttcn3/Statement.cc
@@ -6334,7 +6334,9 @@ error:
     char *expr_name=select.expr->generate_code_tmp(0, expr_init);
     if (expr_init[0]) { // some init code was generated
       str = update_location_object(str);
-      str = mputstr(str, "{\n");
+    }
+    str = mputstr(str, "{\n");
+    if (expr_init[0]) {
       str = mputstr(str, expr_init);
     }
     
@@ -6357,7 +6359,7 @@ error:
       str=select.scs->generate_code(str, tmp_prefix.c_str(), tmp_id.c_str());
     }
     Free(expr_name);
-    if (expr_init[0]) str=mputstr(str, "}\n");
+    str=mputstr(str, "}\n");
     Free(expr_init);
     return str;
   }
diff --git a/regression_test/compileonly/selectCase/selectCase.ttcn b/regression_test/compileonly/selectCase/selectCase.ttcn
index 7db3788b1..ae0f4f42d 100644
--- a/regression_test/compileonly/selectCase/selectCase.ttcn
+++ b/regression_test/compileonly/selectCase/selectCase.ttcn
@@ -8,6 +8,7 @@
  * Contributors:
  *   Balasko, Jeno
  *   Baranyi, Botond
+ *   Szabo, Bence Janos
  *
  ******************************************************************************/
 
@@ -78,4 +79,34 @@ function f_embeddedEmptyRecord() {
   }
 }
 
+function f_with_goto() {
+  var boolean v_result;
+  var charstring pl_messageType := "s";
+  v_result := true;
+  if (not v_result) { goto END_EXECUTION };
+
+  select (pl_messageType) {
+    case ("SAR")  {
+       v_result := false;
+     }
+  }
+  label END_EXECUTION;
+  log(v_result);
+}
+
+function f_with_goto_int() {
+  var integer v_result;
+  var charstring pl_messageType := "s";
+  v_result := 3;
+  if (v_result == 2) { goto END_EXECUTION };
+
+  select (v_result) {
+    case (4)  {
+       v_result := 3;
+     }
+  }
+  label END_EXECUTION;
+  log(v_result);
+}
+
 }
-- 
GitLab