Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5876,12 +5876,10 @@ and createAutoLocal ((((n, ndt, a, cloc) : A.name), (inite: A.init_expression))
else
match inite with
| SINGLE_INIT exp ->
(match doPureExp exp with
| Some exp ->
let t = Cil.typeOf exp in
(match doExp false exp (AExp None) with (* doExp with AExp handles array and function types (AType would not!) *)
| (_, _, t) ->
let specs = t,NoStorage,false,[] in
createLocal specs name
| None -> E.s (error "__auto_type but init not pure")
)
| _ -> E.s (error "__auto_type but not SINGLE_INIT")
(* Must catch the Static local variables. Make them global *)
Expand Down
14 changes: 14 additions & 0 deletions test/small1/auto_type1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct dummmy {
char arr[0x0bad];
};

extern volatile struct dummmy side_effect1;
struct dummmy side_effect2(struct dummmy);

void *fn() {
__auto_type x = side_effect2(side_effect1);
static struct S1 {
int a : __builtin_choose_expr(sizeof(x) == 0x0bad, 1, -1);
} s1 = {0};
return &s1;
}
26 changes: 26 additions & 0 deletions test/small1/auto_type2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#define ASSERT_TYPE3(_expr, _type, _c) \
struct assertType##_c { \
int x: _Generic(_expr, _type : 1, default : -1); \
} assertValue##_c = {0}
#define ASSERT_TYPE2(_expr, _type, _c) ASSERT_TYPE3(_expr, _type, _c)
#define ASSERT_TYPE(_expr, _type) ASSERT_TYPE2(_expr, _type, __COUNTER__)

void fn1(const int arg[128]) {
const int local[128] = {0};

typeof(arg) ptr4;
typeof(local) ptr5 = {0};
__auto_type ptr6 = arg;
__auto_type ptr7 = local;

ASSERT_TYPE(&ptr4, const int **);
ASSERT_TYPE(&ptr5, const int (*)[128]);
ASSERT_TYPE(&ptr6, const int **);
ASSERT_TYPE(&ptr7, const int **);
}

int main() {
int arg[128] = {0};
fn1(arg);
return 0;
}
2 changes: 2 additions & 0 deletions test/testcil.pl
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ sub addToGroup {


addTest("testrun/typeof1 ");
addTest("test/auto_type1");
addTest("testrun/auto_type2");
addTest("testrun/semicolon _GNUCC=1");

addTest("merge-ar ");
Expand Down