Unexpected type error when using offsetof

35 views
Skip to first unread message

Johan Harmsen

unread,
Aug 31, 2020, 3:38:38 PM8/31/20
to cpacheck...@googlegroups.com
Hello

When I try to process the following piece of code with CPA checker
# include	<stddef.h>

typedef struct   
{
   int		id;
   char		name[16];
} tStruct;
static tStruct *pStruct;

# define Off(id) offsetof(tStruct, id)
# define Siz(id) sizeof((pStruct->id))

struct
{
	char	*Name;
	size_t	Offset;
	size_t	Size;
	int		Type;
} VarDef[] =
{
	{ "id", Off(id), Siz(id), 1 },
	{ "Name", Off(name), Siz(name), 2 }
};


I get the following error :

Error: Parsing failed (lines 752-760: unexpected type tStruct  in __builtin_offsetof argument: __builtin_offsetof (
# 25 "offset.c"
        tStruct
# 25 "offset.c" 3 4
        ,
# 25 "offset.c"
        id
# 25 "offset.c" 3 4
        ) (full line is struct
{
 char *Name;
 size_t Offset;


The code compiles fine with gcc:

# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)

# cpp --version
cpp (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# ldd --version
ldd (Debian GLIBC 2.28-10) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

CPAchecker 1.9.1 / default (OpenJDK 64-Bit Server VM 11.0.8) started (CPAchecker.run, INFO)

Do you have any idea what the problem might be ?

Best regards

Johan Harmsen

Johan Harmsen

unread,
Sep 8, 2020, 3:20:08 AM9/8/20
to CPAchecker Users
Works if changed as follows:
typedef struct _tStruct
   int id;
  char name[16];
} tStruct; 
static tStruct *pStruct; 
# define Off(id) __builtin_offsetof(struct _tStruct, id) 
# define Siz(id) sizeof((pStruct->id))  

Philipp Wendler

unread,
Sep 8, 2020, 6:56:22 AM9/8/20
to cpacheck...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Johan,

sorry for the delay and thanks for your mail and the investigation.
Indeed the problem was the typedef, which we failed to resolve in
arguments of __builtin_offsetof.
This is now fixed in the development version of CPAchecker.

Greetings
Philipp


Am 08.09.20 um 09:20 schrieb Johan Harmsen:
- --
Philipp Wendler
Software and Computational Systems Lab
LMU Munich, Germany
Oettingenstr. 67 Raum F008 - Tel.: 089/2180-9181
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEGdWhCy2XiNh8vuXtYsD3jDGp3owFAl9XY1MACgkQYsD3jDGp
3owgAQ//ZTHyN/GZiF/vnge9+FdFBKuwm33qIMr1wcXNFZ5rvrkmGgRG2LUOB+cj
SV7ugJAMGVL83b0sbQdWCKr2fe/yi/QRsVfWq8dBr5P4OxK6NEke2clZ+rrjaQbs
7oDxj+tQgNYxEoTotmLA2rO3G18SRHTKVZruM7cQ7Z/dulRXTCxAdx73Th/DdzXO
zJJD0zVO6ob1DmhgwKQT8JGjrSxRnK8Ih7Fqq4nN1ApPgdkouFENRZAPkn8QvVAG
Z/GqxBpmkTWJcKJS41XReyp5v2G6Ioj9qNGrgnS7wd/GK7GQA2jZsqCPsUoRLtY5
11WeIxK9UIL7AsuGBCEI5e3AWesrkJT4EuBtC6zZapykVRBbQ7xA6/m9xi97zdfh
BcXLvQE/nC2Ot6cbS+tezgQkdRR7kjKwN4YlvjMjsGD2DccSQyVSUjEZrqzNQOiM
vvmU42V/SDlGjhxL+kmOd1lw92yRTisdsnmCX0joWFMa8/x7a5rYKODRkoUEn87S
O1hweZMd6llm+IOUihn0WeICiA/QlovixgpVs8KjCkYOFBxoncAcycJVUwowhujd
Q0o7/ya2AUkK8q/twc/Arptnb9ePhHCpvySD9U5Uq6E63heGhcO8CaSWO/t0WEk+
JVJFI0Jvn60eDBa1FGnHF0tUndQDzUrxdYykt9MRyz9vqnGgMxo=
=T02/
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages