<< Back to previous view

[PCC-376] __builtin_offsetof result is not a constant Created: 29/Aug/11  Updated: 03/Sep/11

Status: Resolved
Project: pcc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Nicolas Joly Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: NetBSD lanfeust.sis.pasteur.fr 5.99.55 NetBSD 5.99.55 (LANFEUST) #0: Mon Aug 29 13:17:23 CEST 2011 njoly@lanfeust.sis.pasteur.fr:/local/src/NetBSD/obj.amd64/sys/arch/amd64/compile/LANFEUST amd64
pcc 1.1.0.DEVEL 20110829 for x86_64-unknown-netbsd5.99.55


 Description   
The following piece of code (extracted from GNU m4), does not compile with pcc (no problem with gcc) ... __builtin_offsetof result is not a constant.

njoly@lanfeust [check/pcc]> cat offsetof.c
#include <stddef.h>

struct s { char c; };
enum { e = offsetof(struct s, c) };

int main() { return 0; }

njoly@lanfeust [check/pcc]> pcc offsetof.c; echo $?
offsetof.c, line 4: constant expected
1
njoly@lanfeust [check/pcc]> gcc offsetof.c; echo $?
0


 Comments   
Comment by Anders Magnusson [ 03/Sep/11 09:46 AM ]
Fixed now. Needed one more rmpconv() when discarding casts.
Comment by Nicolas Joly [ 03/Sep/11 11:10 AM ]
Thanks.

I just encountered a similar behavior when using offsetof for bit-field definitons.

njoly@petaure [~]> cat offsetof.c
#include <stddef.h>

struct s1 { char c1; char c2; };
struct s2 { int i : offsetof(struct s1, c2) ? 1 : -1; };

int main() { return 0; }

njoly@petaure [~]> pcc offsetof.c; echo $?
offsetof.c, line 4: constant expected
1
njoly@petaure [~]> gcc offsetof.c; echo $?
0

NB: Using sizeof(struct s1) instead of offsetof here, does not exhibit the problem.
Generated at Fri Aug 22 17:43:14 CEST 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.