Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
* how to figure if a struct symbol is incomplete
@ 2024-10-17  9:09 Aurelien Aptel
  0 siblings, 0 replies; only message in thread
From: Aurelien Aptel @ 2024-10-17  9:09 UTC (permalink / raw)
  To: linux-sparse@vger.kernel.org

Hi,

I’m toying around with a new sparse-based program, trying to check for certain things in C structs definitions.

I’ve looked around at examples and ctags was the most useful as it’s using ‘file_scope’ as the symbol entry point instead of the sparse() return value, which allowed me to see the AST of the types.
After some trial and error, I've figured that I had to call examine_symbol_type() on each symbol before I dive into them to fully compute the bit_size & offset of all the struct members.

While doing that, I've noticed that I cannot tell an empty structure from an incompletely defined one.
I'd like to err out instead of silently using a size=0 struct when I see an undefined type.

struct empty {};
struct foo {
    int a;
    struct unknown b;
};

The symbol for 'struct empty' and the member 'b' both have a sym->size == 0, an empty sym->symbol_list and a sym->ctype.base_type == NULL.
How can you tell those 2 cases apart?

Thanks


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-17  9:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17  9:09 how to figure if a struct symbol is incomplete Aurelien Aptel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).