How to get the name of the bit field referenced by BIT_FIELD_REF?

I want to get the name of the field with which it was declared from the GENERIC view. I have a BIT_FIELD_REF tree and DECL_NAME is zero. For instance,

struct { int a; unsigned b:1; } s; ... if (sb) ... 

For sb, I will get BIT_FIELD_REF, and there is no obvious way to get "b", which is the original name of the field. How to do it?

+4
source share
2 answers

Try call debug_c_tree (tree_var) or call debug_tree (tree_var) from GDB and see if that name knows. If so, redesign the beautiful printer.

+1
source

What exactly I did: researching the material in tree-dump.c I realized that the field names of the bits where they are known come from structural DIEs and are difficult to track.

Then I decided to get a name from type BIT_FIELD_REF argument 0 (a reference to the structure), which is equal to RECORD_TYPE and saves all field sizes and offsets.

The problem was understanding that BIT_FIELD_REF does not refer to the bits themselves: it is used as BIT_FIELD_REF & INTEGER_CST , where the constant acts like a mask. Realizing this, I quickly calculated the offsets and got the name from the type.

0
source

Source: https://habr.com/ru/post/1397040/


All Articles