ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
536 stars 39 forks source link

`__builtin_offsetof` unsupported #31

Closed aytey closed 2 years ago

aytey commented 3 years ago

GCC version:

gcc (SUSE Linux) 10.2.1 20201202 [revision e563687cf9d3d1278f45aaebd03e0f66531076c9]

clang version:

clang version 11.0.1

Output of gcc -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of clang -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of cnip $FNAME

memset.c:4:28 error: expected expression got `struct'
  return __builtin_offsetof(struct s, i);
                            ^

(return code 0)

Content of file

struct s {
  char i;
};
int offset() {
  return __builtin_offsetof(struct s, i);
}

psychec version

commit d10dc1ddfb7ea845f59274a4d6ca5d021ab31423
Author: Leandro T. C. Melo <LTCMELO@GMAIL.COM>
Date:   Tue Mar 9 21:18:30 2021 -0300

    fix postfixing on compound literal
aytey commented 3 years ago

Likely to be the same issue, but with "more interesting" error messages

GCC version:

gcc (SUSE Linux) 10.2.1 20201202 [revision e563687cf9d3d1278f45aaebd03e0f66531076c9]

clang version:

clang version 11.0.1

Output of gcc -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of clang -Werror -Wall -Wextra -Wpedantic -pedantic -std=c11 -c $FNAME

(return code 0)

Output of cnip $FNAME

v2.c:5:2 warning: missing type specifier, assume `int'
  foo(&reg_stat, 0, __builtin_offsetof(struct reg_stat, sign_bit_copies));
  ^
v2.c:5:6 warning: missing type specifier, assume `int'
  foo(&reg_stat, 0, __builtin_offsetof(struct reg_stat, sign_bit_copies));
      ^
v2.c:5:6 error: expected `)', got `&'
  foo(&reg_stat, 0, __builtin_offsetof(struct reg_stat, sign_bit_copies));
      ^

(return code 0)

Content of file

struct reg_stat {
  char sign_bit_copies;
} reg_stat;
void *foo(void *, int, int);
void __attribute__init_reg_last() {
  foo(&reg_stat, 0, __builtin_offsetof(struct reg_stat, sign_bit_copies));
}

psychec version

commit d10dc1ddfb7ea845f59274a4d6ca5d021ab31423
Author: Leandro T. C. Melo <LTCMELO@GMAIL.COM>
Date:   Tue Mar 9 21:18:30 2021 -0300

    fix postfixing on compound literal
ltcmelo commented 3 years ago

Labeling as a C extension.

ltcmelo commented 2 years ago

Fixed by #82