Issue Details (XML | Word | Printable)

Key: PCC-269
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

comparisons between uint8_t type value and sizeof(x) may give unexpected results

Created: 02/Mar/11 01:16 AM   Updated: 02/Mar/11 06:38 PM
Component/s: amd64 target
Affects Version/s: None
Fix Version/s: None

Environment:
NetBSD petaure.lan 5.99.47 NetBSD 5.99.47 (PETAURE) #13: Tue Mar 1 23:17:27 CET 2011 njoly@petaure.lan:/local/src/NetBSD/obj.amd64/sys/arch/amd64/compile/PETAURE amd64
pcc 1.1.0.DEVEL 20110221 for x86_64-unknown-netbsd5.99.47, njoly@petaure.lan


 Description  « Hide
Comparisons between uint8_t type value and sizeof(x) may give unexpected results.

The following sample code fails with pcc, but succeed with gcc.

njoly@petaure [tmp/pcc]> cat sample.c
#include <assert.h>
#include <stdint.h>
#include <stdio.h>

int main() {
  uint8_t u8 = 0;
  uint8_t sz[128];

  printf("u8 %u, sizeof(sz) %zu\n", u8, sizeof(sz));
  assert(u8 < sizeof(sz));

  return 0; }

njoly@petaure [tmp/pcc]> pcc -g -o sample sample.c
njoly@petaure [tmp/pcc]> ./sample
u8 0, sizeof(sz) 128
assertion "u8 < sizeof(sz)" failed: file "sample.c", line 10, function "main"
zsh: abort (core dumped) ./sample

njoly@petaure [tmp/pcc]> gcc -g -o sample sample.c
njoly@petaure [tmp/pcc]> ./sample
u8 0, sizeof(sz) 128


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 02/Mar/11 06:38 PM
Fixed now. It was the result of an erroneous optimization.