Issue Details (XML | Word | Printable)

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

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

64-bit expression miscalculates

Created: 05/May/11 10:07 PM   Updated: 09/May/11 10:11 PM
Component/s: Common code
Affects Version/s: None
Fix Version/s: None

Environment: NetBSD/i386


 Description  « Hide
The following short example program

#include <stdio.h>

int
main(int ac, char *av[])
{

        unsigned long long u = 175;
        int d = 50;
        int e = ((u + (d - 1)) / d) * d;

        printf("u %llu, d %d, => %d\n", u, d, e);
        return 0;
}

which expression is designed to round up the value of u to the next integer
multiple of d, when compiled with pcc will output the following

u 175, d 50, => 2500

the correct value is 200, I think a register used in the final multiplication has been
tainted, as the partial result of (u + (d - 1)) / d is calculated correctly.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 06/May/11 05:24 PM
One more case where instructions are emitted in the wrong order.

Anders Magnusson added a comment - 09/May/11 10:11 PM
Fixed now, even though not the preferred fix. A table entry with NLEFT and NRES and also RLEFT may overwrite the left side registers in its eager to avoid register trashing(!). Fixed by setting reclaim to RDEST. It should work by using RLEFT also, but that requires some reorganization of insnwalk() and gencode().