Issue Details (XML | Word | Printable)

Key: PCC-339
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Iain Hibbert
Votes: 0
Watchers: 0

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

64-bit expression calculates wrong result

Created: 30/Apr/11 11:18 AM   Updated: 03/May/11 01:21 PM
Component/s: C frontend
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. File daddr.c (0.4 kB)

Environment: NetBSD/i386

 Description  « Hide
The following short example program (also attached as daddr.c) which has been
reduced from NetBSD kernel code dealing with calculation of disk addresses
given an inode number

#include <stdio.h>

unsigned long long ino = 2;

int fs_magic = 0x19540119;
int fs_ipg = 22400;
int fs_iblkno = 56;
int fs_inopb = 64;

int main(int ac, char *av[])
long long daddr =
fs_magic == 0x19540119
(ino / fs_ipg)
(ino / fs_ipg)
+ fs_iblkno
+ (((ino % fs_ipg) / fs_inopb) << 3)

printf("ino %llu daddr %lld\n", ino, daddr);
return 0;

when compiled and run with pcc produces the following output

ino 2 daddr 80

where the correct result should be 56 (resulting in pcc-generated code reading
the wrong disk block :)

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 02/May/11 09:52 PM
This bug is in gencode(), the function where instructions are printed out. It fails to detect that emitting a move between registers on one side will be trashed by move on the other side.

Anders Magnusson added a comment - 03/May/11 01:21 PM
Fixed now. The instruction emit code didn't take care of needed register moves early enough.