diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index 23c22db96..fd6e239ce 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -4031,8 +4031,17 @@ and doExp (asconst: bool) (* This expression is used as a constant *) else E.s (error "Unary ~ on a non-integral type") - | A.UNARY(A.PLUS, e) -> doExp asconst e what - + | A.UNARY(A.PLUS, e) -> + let (se, e', t) = doExp asconst e (AExp None) in + if isIntegralType t then + let tres = integralPromotion t in + let e'' = makeCastT ~kind:IntegerPromotion ~e:e' ~oldt:t ~newt:tres in + finishExp se e'' tres + else + if isArithmeticType t then + finishExp se e' t + else + E.s (error "Unary + on a non-arithmetic type") | A.UNARY(A.ADDROF, e) -> begin match e with diff --git a/test/small1/unary-plus-promotion.c b/test/small1/unary-plus-promotion.c new file mode 100644 index 000000000..b29ac14e5 --- /dev/null +++ b/test/small1/unary-plus-promotion.c @@ -0,0 +1,13 @@ +#include "testharness.h" +#include + +int main() { + char c; + size_t csize = sizeof(c); + size_t pluscsize = sizeof(+c); + if (csize != sizeof(char)) + E(1); + if (pluscsize != sizeof(int)) + E(2); + SUCCESS; +} diff --git a/test/testcil.pl b/test/testcil.pl index 8a3ab3940..07ac32d9d 100644 --- a/test/testcil.pl +++ b/test/testcil.pl @@ -323,6 +323,7 @@ sub addToGroup { addTest("test_i/lineno"); addTest("test/list"); addTest("testrun/localinit "); +addTest("testrun/unary-plus-promotion"); addTest('testrun/longBlock', ''); addTest("testrun/perror");