Skip to content

Commit e21285a

Browse files
authored
Merge pull request #200 from goblint/unary-plus-promotion
Add missing integer promotion to unary plus
2 parents 4bd1804 + 5be0b1d commit e21285a

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/frontc/cabs2cil.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,8 +4031,17 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
40314031
else
40324032
E.s (error "Unary ~ on a non-integral type")
40334033

4034-
| A.UNARY(A.PLUS, e) -> doExp asconst e what
4035-
4034+
| A.UNARY(A.PLUS, e) ->
4035+
let (se, e', t) = doExp asconst e (AExp None) in
4036+
if isIntegralType t then
4037+
let tres = integralPromotion t in
4038+
let e'' = makeCastT ~kind:IntegerPromotion ~e:e' ~oldt:t ~newt:tres in
4039+
finishExp se e'' tres
4040+
else
4041+
if isArithmeticType t then
4042+
finishExp se e' t
4043+
else
4044+
E.s (error "Unary + on a non-arithmetic type")
40364045

40374046
| A.UNARY(A.ADDROF, e) -> begin
40384047
match e with

test/small1/unary-plus-promotion.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "testharness.h"
2+
#include <stdlib.h>
3+
4+
int main() {
5+
char c;
6+
size_t csize = sizeof(c);
7+
size_t pluscsize = sizeof(+c);
8+
if (csize != sizeof(char))
9+
E(1);
10+
if (pluscsize != sizeof(int))
11+
E(2);
12+
SUCCESS;
13+
}

test/testcil.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ sub addToGroup {
323323
addTest("test_i/lineno");
324324
addTest("test/list");
325325
addTest("testrun/localinit ");
326+
addTest("testrun/unary-plus-promotion");
326327

327328
addTest('testrun/longBlock', '');
328329
addTest("testrun/perror");

0 commit comments

Comments
 (0)