+
+ if (ir_tag_fc) {
+ /*
+ * At this point the trace IR selector
+ * (enumeration) field class already exists if
+ * the variant is tagged (`ir_tag_fc`). This one
+ * already contains range sets for its mappings,
+ * so we just reuse the same, finding them by
+ * matching a variant field class's option's
+ * _original_ name (with a leading underscore,
+ * possibly) with a selector field class's
+ * mapping name.
+ */
+ if (fc->tag_fc->base.is_signed) {
+ const bt_field_class_signed_enumeration_mapping *mapping =
+ find_ir_enum_field_class_mapping_by_label(
+ ir_tag_fc,
+ named_fc->orig_name->str, true);
+ const bt_integer_range_set_signed *range_set;
+
+ BT_ASSERT(mapping);
+ range_set =
+ bt_field_class_signed_enumeration_mapping_borrow_ranges_const(
+ mapping);
+ BT_ASSERT(range_set);
+ ret = bt_field_class_variant_with_signed_selector_append_option(
+ ir_fc, named_fc->name->str,
+ option_ir_fc, range_set);
+ } else {
+ const bt_field_class_unsigned_enumeration_mapping *mapping =
+ find_ir_enum_field_class_mapping_by_label(
+ ir_tag_fc,
+ named_fc->orig_name->str,
+ false);
+ const bt_integer_range_set_unsigned *range_set;
+
+ BT_ASSERT(mapping);
+ range_set =
+ bt_field_class_unsigned_enumeration_mapping_borrow_ranges_const(
+ mapping);
+ BT_ASSERT(range_set);
+ ret = bt_field_class_variant_with_unsigned_selector_append_option(
+ ir_fc, named_fc->name->str,
+ option_ir_fc, range_set);
+ }
+ } else {
+ ret = bt_field_class_variant_without_selector_append_option(
+ ir_fc, named_fc->name->str, option_ir_fc);
+ }
+