From f39d2560e0c5d304fee5cd90b2ec9e52c1482e69 Mon Sep 17 00:00:00 2001 From: Phil Mesnier Date: Mon, 14 Jun 2021 16:51:26 -0500 Subject: [PATCH 1/4] Fix and test for incorrect handling of empty enum-based union labels that happen to alias the default case. --- TAO/TAO_IDL/ast/ast_union_branch.cpp | 16 ++++----- .../IDLv4/annotations/annotation_tests.cpp | 35 ++++++++++++++++++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/TAO/TAO_IDL/ast/ast_union_branch.cpp b/TAO/TAO_IDL/ast/ast_union_branch.cpp index 8952cdfab21ea..075a88c7739cc 100644 --- a/TAO/TAO_IDL/ast/ast_union_branch.cpp +++ b/TAO/TAO_IDL/ast/ast_union_branch.cpp @@ -1,3 +1,5 @@ +// $Id$ + /* COPYRIGHT @@ -181,22 +183,16 @@ AST_UnionBranch::label_list_length (void) void AST_UnionBranch::add_labels (AST_Union *u) { + const bool enum_labels = (u->udisc_type () == AST_Expression::EV_enum); for (UTL_LabellistActiveIterator i (this->pd_ll); !i.is_done (); i.next ()) { if (AST_UnionLabel::UL_default == i.item ()->label_kind ()) - { - return; - } - } + { + continue; + } - const bool enum_labels = (u->udisc_type () == AST_Expression::EV_enum); - - for (UTL_LabellistActiveIterator i (this->pd_ll); - !i.is_done (); - i.next ()) - { AST_Expression *ex = i.item ()->label_val (); UTL_ScopedName *n = ex->n (); diff --git a/TAO/tests/IDLv4/annotations/annotation_tests.cpp b/TAO/tests/IDLv4/annotations/annotation_tests.cpp index 73b2359c17848..83c16e7f8743f 100644 --- a/TAO/tests/IDLv4/annotations/annotation_tests.cpp +++ b/TAO/tests/IDLv4/annotations/annotation_tests.cpp @@ -4,7 +4,9 @@ #include #include #include - +#include +#include +#include #include namespace { @@ -1060,6 +1062,37 @@ annotation_tests () } } catch (Failed const &) {} + /* ------------------------------------------------------------------------- + * Empty union cases aliasing the default case must always be evaluated + * ------------------------------------------------------------------------- + * When the union has an enum discriminator, and one or more empty cases + * acting as an alias to the default case the IDL compiler was failing to + * resolve the ordinal value for these empty labels and this causes trouble + * for at least OpenDDS. + * + * This test is designed to verify that the condition is corrected by + * parsing a specially crafted union and validating the value of the + * label aliasing the default case. + */ + try { + Annotation_Test t ("empty union branch label"); + AST_Union *test_union = t.run ( + "enum disc {A, B, C};\n" + "union empty_union switch (disc) {\n" + "case A: long along;\n" + "case B: short bshort;\n" + "case C:\n" + "default: float cfloat;\n" + "};\n").assert_node("::empty_union"); + AST_Field **af = 0; + test_union->field(af,2); + AST_UnionBranch *ub = dynamic_cast(*af); + AST_UnionLabel *ul = ub->label (); + if (ul->label_val()->ev()->u.ulval != 2) { + t.failed("did not get the correct label value"); + } + } catch (Failed const &) {} + // Done, Print Overall Results Annotation_Test::results (); } From 2e2cb43b91ee0c0903feb7a25f33f98bffb01931 Mon Sep 17 00:00:00 2001 From: Phil Mesnier Date: Mon, 14 Jun 2021 17:00:30 -0500 Subject: [PATCH 2/4] Fuzz fix --- TAO/TAO_IDL/ast/ast_union_branch.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/TAO/TAO_IDL/ast/ast_union_branch.cpp b/TAO/TAO_IDL/ast/ast_union_branch.cpp index 075a88c7739cc..35e137c91c04a 100644 --- a/TAO/TAO_IDL/ast/ast_union_branch.cpp +++ b/TAO/TAO_IDL/ast/ast_union_branch.cpp @@ -1,5 +1,3 @@ -// $Id$ - /* COPYRIGHT From b1f713b0baf1e199151ae5b54cdbbe8a159cbc1a Mon Sep 17 00:00:00 2001 From: Phil Mesnier Date: Tue, 15 Jun 2021 08:22:10 -0500 Subject: [PATCH 3/4] applying suggested whitespace changes. --- TAO/TAO_IDL/ast/ast_union_branch.cpp | 6 +++--- TAO/tests/IDLv4/annotations/annotation_tests.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TAO/TAO_IDL/ast/ast_union_branch.cpp b/TAO/TAO_IDL/ast/ast_union_branch.cpp index 35e137c91c04a..b7da6dff6c3f1 100644 --- a/TAO/TAO_IDL/ast/ast_union_branch.cpp +++ b/TAO/TAO_IDL/ast/ast_union_branch.cpp @@ -187,9 +187,9 @@ AST_UnionBranch::add_labels (AST_Union *u) i.next ()) { if (AST_UnionLabel::UL_default == i.item ()->label_kind ()) - { - continue; - } + { + continue; + } AST_Expression *ex = i.item ()->label_val (); UTL_ScopedName *n = ex->n (); diff --git a/TAO/tests/IDLv4/annotations/annotation_tests.cpp b/TAO/tests/IDLv4/annotations/annotation_tests.cpp index 83c16e7f8743f..5f5381b2f63af 100644 --- a/TAO/tests/IDLv4/annotations/annotation_tests.cpp +++ b/TAO/tests/IDLv4/annotations/annotation_tests.cpp @@ -1085,7 +1085,7 @@ annotation_tests () "default: float cfloat;\n" "};\n").assert_node("::empty_union"); AST_Field **af = 0; - test_union->field(af,2); + test_union->field(af, 2); AST_UnionBranch *ub = dynamic_cast(*af); AST_UnionLabel *ul = ub->label (); if (ul->label_val()->ev()->u.ulval != 2) { From 9b6353b6f0b64b46099ef57cb8e6305f6ea0cabc Mon Sep 17 00:00:00 2001 From: Phil Mesnier Date: Tue, 15 Jun 2021 13:38:28 -0500 Subject: [PATCH 4/4] more whitespace cleanup Co-authored-by: Fred Hornsey --- TAO/tests/IDLv4/annotations/annotation_tests.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TAO/tests/IDLv4/annotations/annotation_tests.cpp b/TAO/tests/IDLv4/annotations/annotation_tests.cpp index 5f5381b2f63af..35bcc728a83a4 100644 --- a/TAO/tests/IDLv4/annotations/annotation_tests.cpp +++ b/TAO/tests/IDLv4/annotations/annotation_tests.cpp @@ -1088,9 +1088,10 @@ annotation_tests () test_union->field(af, 2); AST_UnionBranch *ub = dynamic_cast(*af); AST_UnionLabel *ul = ub->label (); - if (ul->label_val()->ev()->u.ulval != 2) { - t.failed("did not get the correct label value"); - } + if (ul->label_val()->ev()->u.ulval != 2) + { + t.failed("did not get the correct label value"); + } } catch (Failed const &) {} // Done, Print Overall Results