diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index 6d03c15682298acc609a53f167f24af772ad4ecf..7a94b0d245b8f20554d1d34715a1b0fe25ea6151 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -2616,7 +2616,10 @@ symbol_field_alias2( struct symbol_elem_t *e, struct symbol_elem_t *e2, * For a group, create new fields and copy members recursively. * Precondition: both fields exist in the symbol table. * Postcondition: return final element copied. -*/ + * + * "The condition-name entries for a particular conditional variable + * shall immediately follow the entry describing the item...." + */ struct symbol_elem_t * symbol_field_same_as( cbl_field_t *tgt, const cbl_field_t *src ) { @@ -2629,47 +2632,44 @@ symbol_field_same_as( cbl_field_t *tgt, const cbl_field_t *src ) { symbol_elem_t *eog = symbol_at_impl(end_of_group(isrc), true); if( src->type != FldGroup ) { - // For scalar, check for Level 88. Find next field with other parent. + // For scalar, check for Level 88, which if extant must follow immediately. eog = std::find_if( bog + 1, symbols_end(), - [parent = isrc]( const auto& elem ) { + []( const auto& elem ) { if( elem.type == SymField ) { auto f = cbl_field_of(&elem); - assert(parent != f->parent || f->level == 88); - return parent != f->parent; + return f->level != 88; } return true; } ); } - if( bog + 1 < eog ) { - cbl_field_t dup = { .parent = field_index(tgt), .line = tgt->line }; - - // for each duplicate, map src index to duplicate index - std::map<size_t, size_t> orig; - orig[isrc] = field_index(tgt); - - class group_t { - const symbol_elem_t *bog, *eog; - public: - group_t( const symbol_elem_t *bog, const symbol_elem_t *eog ) - : bog(bog), eog(eog) {} - const symbol_elem_t *begin() const { return bog; } - const symbol_elem_t *end() const { return eog; } - }; - - group_t group(++bog, eog); - - for( const auto& elem : group ) { - const auto& that(*cbl_field_of(&elem)); - memcpy(dup.name, that.name, sizeof(dup.name)); - dup.parent = orig.at(that.parent); - dup.level = tgt->level + that.level; - dup.same_as( that ); - - last_elem = symbol_field_add( last_elem->program, &dup ); - orig[ symbol_index(&elem) ] = symbol_index(last_elem); - } + cbl_field_t dup = { .parent = field_index(tgt), .line = tgt->line }; + + // for each duplicate, map src index to duplicate index + std::map<size_t, size_t> orig; + orig[isrc] = field_index(tgt); + + class group_t { + const symbol_elem_t *bog, *eog; + public: + group_t( const symbol_elem_t *bog, const symbol_elem_t *eog ) + : bog(bog), eog(eog) {} + const symbol_elem_t *begin() const { return bog; } + const symbol_elem_t *end() const { return eog; } + }; + + group_t group(++bog, eog); + + for( const auto& elem : group ) { + const auto& that(*cbl_field_of(&elem)); + memcpy(dup.name, that.name, sizeof(dup.name)); + dup.parent = orig.at(that.parent); + dup.level = tgt->level + that.level; + dup.same_as( that ); + + last_elem = symbol_field_add( last_elem->program, &dup ); + orig[ symbol_index(&elem) ] = symbol_index(last_elem); } return last_elem;