appleseedlab / maki

A tool for analyzing syntactic and semantic properties of C Preprocessor macros in C programs
8 stars 3 forks source link

Check for local types in `sizeof()` and cast expressions #46

Closed PappasBrent closed 2 months ago

PappasBrent commented 2 months ago

Maki does not check if an expansion references a locally-defined type via a sizeof() or cast expression.

For example, for the following code:

#define SIZE_OF_MY_STRUCT() (sizeof(struct my_struct))
#define SIZE_OF_MY_TYPEDEFD_STRUCT() (sizeof(my_typedefd_struct))

#define CAST_TO_MY_STRUCT(X) ((struct my_struct) X)
#define CAST_TO_MY_TYPEDEFD_STRUCT(X) ((my_typedefd_struct) X)

int main(void) {
    struct my_struct {
        int x;
    };

    typedef struct my_typedefd_struct {
        int y;
    } my_typedefd_struct;

    SIZE_OF_MY_STRUCT();
    SIZE_OF_MY_TYPEDEFD_STRUCT();

    CAST_TO_MY_STRUCT({});
    CAST_TO_MY_TYPEDEFD_STRUCT({});

    return 0;
}

Maki would set DoesSubexpressionExpandedFromBodyHaveLocalType to false for all the above expansions, when it should be set to true because the argument to each of the sizeof() and cast expressions is a locally-defined type.