modernc.org/ccgo/v3@v3.16.14/lib/testdata/bug/union3.c (about)

     1  typedef int Length;
     2  typedef int TSStateId;
     3  typedef int int32_t;
     4  typedef unsigned char bool;
     5  typedef unsigned char uint8_t;
     6  typedef unsigned short uint16_t;
     7  typedef unsigned uint32_t;
     8  typedef void* TSSymbol;
     9  
    10  typedef struct {
    11    bool is_inline : 1;
    12    bool visible : 1;
    13    bool named : 1;
    14    bool extra : 1;
    15    bool has_changes : 1;
    16    bool is_missing : 1;
    17    bool is_keyword : 1;
    18    uint8_t symbol;
    19    uint8_t padding_bytes;
    20    uint8_t size_bytes;
    21    uint8_t padding_columns;
    22    uint8_t padding_rows : 4;
    23    uint8_t lookahead_bytes : 4;
    24    uint16_t parse_state;
    25  } SubtreeInlineData;
    26  
    27  typedef struct {
    28    volatile uint32_t ref_count;
    29    Length padding;
    30    Length size;
    31    uint32_t lookahead_bytes;
    32    uint32_t error_cost;
    33    uint32_t child_count;
    34    TSSymbol symbol;
    35    TSStateId parse_state;
    36  
    37    bool visible : 1;
    38    bool named : 1;
    39    bool extra : 1;
    40    bool fragile_left : 1;
    41    bool fragile_right : 1;
    42    bool has_changes : 1;
    43    bool has_external_tokens : 1;
    44    bool depends_on_column: 1;
    45    bool is_missing : 1;
    46    bool is_keyword : 1;
    47  
    48    union {
    49      // Non-terminal subtrees (`child_count > 0`)
    50      struct {
    51        uint32_t visible_child_count;
    52        uint32_t named_child_count;
    53        uint32_t node_count;
    54        uint32_t repeat_depth;
    55        int32_t dynamic_precedence;
    56        uint16_t production_id;
    57        struct {
    58          void* symbol;
    59          int parse_state;
    60        } first_leaf;
    61      };
    62  
    63      // External terminal subtrees (`child_count == 0 && has_external_tokens`)
    64      int external_scanner_state;
    65  
    66      // Error terminal subtrees (`child_count == 0 && symbol == ts_builtin_sym_error`)
    67      int32_t lookahead_char;
    68    };
    69  } SubtreeHeapData;
    70  
    71  typedef union {
    72    SubtreeInlineData data;
    73    const SubtreeHeapData *ptr;
    74  } Subtree;
    75  
    76  static inline uint32_t ts_subtree_repeat_depth(Subtree self) {
    77    return self.data.is_inline ? 0 : self.ptr->repeat_depth;
    78  }
    79  
    80  int main() {
    81  	SubtreeHeapData data;
    82  	data.repeat_depth = 42;
    83  	Subtree tree;
    84  	tree.ptr = &data;
    85  	return ts_subtree_repeat_depth(tree) != 42;
    86  }