coverbee icon indicating copy to clipboard operation
coverbee copied to clipboard

C parser misbehaves for conditional macro + compound literal

Open YutaroHayakawa opened this issue 1 year ago • 0 comments

With this kind of the code pattern

struct per_cluster_ct_map4_inner_map {
		__uint(type, CT_MAP_TYPE);
		__type(key, struct ipv4_ct_tuple);
		__type(value, struct ct_entry);
		__uint(max_entries, CT_MAP_SIZE_TCP);
#ifndef HAVE_LRU_HASH_MAP_TYPE
# ifndef HAVE_LRU_HASH_MAP_TYPE
		__uint(map_flags, CONDITIONAL_PREALLOC);
# endif
#ifndef BPF_TEST
};
#else
} per_cluster_ct_tcp4_1 __section_maps_btf,
  per_cluster_ct_tcp4_2 __section_maps_btf,
  per_cluster_ct_any4_1 __section_maps_btf,
  per_cluster_ct_any4_2 __section_maps_btf;
#endif

Coverbee C parser misbehaves and generates an error like this.

error while interpolating using source files: cparser parse file: parse external deceleration: parse function definition: parse compound statement: parse block item: parse statement: parse selection statement: parse statement: can't find closing bracket for '{'

This happens because Coverbee doesn't handle conditional macro currently. Since Coverbee treats all macros as a single-line comment, it sees the closing bracket twice.

YutaroHayakawa avatar Mar 13 '23 08:03 YutaroHayakawa