From 061e91d6c42642dccdf7ceb63d90d51c143f7930 Mon Sep 17 00:00:00 2001
From: "James K. Lowden" <jklowden@symas.com>
Date: Thu, 26 Sep 2024 14:14:51 -0400
Subject: [PATCH] UAT 390 fails

---
 gcc/cobol/parse.y      |  4 ++--
 gcc/cobol/parse_ante.h | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 71c3c4f19621..568d182ed5a5 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -12333,11 +12333,11 @@ eval_subject_t::compare( int token ) {
 }
 
 cbl_field_t *
-eval_subject_t::compare( relop_t op, const cbl_refer_t& object ) {
+eval_subject_t::compare( relop_t op, const cbl_refer_t& object, bool deciding ) {
   auto subject(*pcol);
   if( compatible(object.field) ) {
     if( ! is_conditional(subject.field) ) {
-      auto result = new_temporary(FldConditional);
+      auto result = deciding? this->result : new_temporary(FldConditional);
       parser_relop(result, subject, op, object);
       return result;
       }
diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index fd2d7284fa1a..8944aebefc6e 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -640,10 +640,12 @@ static T* use_any( list<T>& src, T *tgt) {
   return tgt;
 }
 
+class evaluate_t;
 /*
  * Evaluate
  */
 class eval_subject_t {
+  friend evaluate_t;
   struct { cbl_label_t *done, *yeah, *when; } labels;
   cbl_field_t *result;
   relop_t abbr_relop;
@@ -681,7 +683,7 @@ class eval_subject_t {
   // compare sets result 
   cbl_field_t * compare( int token ); 
   cbl_field_t * compare( relop_t op, 
-                         const cbl_refer_t& object);
+                         const cbl_refer_t& object, bool deciding = false);
   cbl_field_t * compare( const cbl_refer_t& object,
                          const cbl_refer_t& object2 = nullptr);
 
@@ -732,7 +734,9 @@ class eval_subject_t {
   }
   bool decide( relop_t op, const cbl_refer_t& object, bool invert ) {
     if( pcol == columns.end() ) return false;
-    if( compare(op, object) ) {
+    if( yydebug ) warnx("%s() if not %s goto %s", __func__,
+			result->name, when()->name);
+    if( compare(op, object, true) ) {
       if( invert ) {
         parser_logop( result, NULL, not_op, result );
       }
@@ -769,7 +773,16 @@ public:
   }
   void free()  { assert(!empty()); pop(); }
 
-  eval_subject_t&  current() { assert(!empty()); return top(); }
+  eval_subject_t&  current() {
+    assert(!empty());
+    if( yydebug ) {
+      auto& ev( top() );
+      yywarnv("eval_subject: res: %s, When %s, Yeah %s, Done %s",
+	      ev.result->name,
+	      ev.when()->name, ev.yeah()->name, ev.done()->name);
+    }
+    return top();
+  }
 
 } eval_stack;
 
-- 
GitLab