Issue Details (XML | Word | Printable)

Key: PCC-376
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Nicolas Joly
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

__builtin_offsetof result is not a constant

Created: 29/Aug/11 04:14 PM   Updated: 03/Sep/11 11:10 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

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  « Hide
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


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson made changes - 03/Sep/11 09:44 AM
Field Original Value New Value
Assignee Anders Magnusson [ ragge ]
Anders Magnusson added a comment - 03/Sep/11 09:46 AM
Fixed now. Needed one more rmpconv() when discarding casts.

Anders Magnusson made changes - 03/Sep/11 09:46 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Nicolas Joly added a comment - 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.