Skip to content

Commit 6b95716

Browse files
Permit non-pure expressions in __auto_type
1 parent e21285a commit 6b95716

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/frontc/cabs2cil.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5876,12 +5876,11 @@ and createAutoLocal ((((n, ndt, a, cloc) : A.name), (inite: A.init_expression))
58765876
else
58775877
match inite with
58785878
| SINGLE_INIT exp ->
5879-
(match doPureExp exp with
5880-
| Some exp ->
5879+
(match doExp true exp (AExp None) with
5880+
| (_, exp, _) ->
58815881
let t = Cil.typeOf exp in
58825882
let specs = t,NoStorage,false,[] in
58835883
createLocal specs name
5884-
| None -> E.s (error "__auto_type but init not pure")
58855884
)
58865885
| _ -> E.s (error "__auto_type but not SINGLE_INIT")
58875886
(* Must catch the Static local variables. Make them global *)

test/small1/auto_type1.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct dummmy {
2+
char arr[0x0bad];
3+
};
4+
5+
extern volatile struct dummmy side_effect1;
6+
struct dummmy side_effect2(struct dummmy);
7+
8+
void *fn() {
9+
__auto_type x = side_effect2(side_effect1);
10+
static struct S1 {
11+
int a : __builtin_choose_expr(sizeof(x) == 0x0bad, 1, -1);
12+
} s1 = {0};
13+
return &s1;
14+
}

0 commit comments

Comments
 (0)