Issue Details (XML | Word | Printable)

Key: PCC-311
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Chris Spiegel
Votes: 0
Watchers: 0

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

Unary minus and int promotion

Created: 12/Apr/11 11:04 PM   Updated: 13/Apr/11 05:10 PM
Component/s: pcc backend
Affects Version/s: None
Fix Version/s: None

Environment: pcc 20110412 on 32-bit Linux x86.

 Description  « Hide

#include <stdio.h>
int main(void)
  unsigned char v = 233;

  printf("%d\n", -v);

  return 0;

Here, -v ought to have the value -233: v should be promoted to int (C99 before the - is applied, with the result being - applied to an expression with type int and value 233, yielding -233 (the type of a unary minus expression is the promoted type).

pcc gives a value of 23, presumably as a result of converting -233 back to unsigned char, which should not happen.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 13/Apr/11 05:10 PM
Good catch, thanks for reporting this! There has never been any promotion code for these operands before. Fixed now.