Skip to content

Commit 88f988c

Browse files
committed
use fixed-width integer types in C code
1 parent 50a37ca commit 88f988c

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
lines changed

Diff for: src/tools/miri/tests/native-lib/ptr_read_access.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
#include <stdio.h>
2+
#include <stdint.h>
23

34
// See comments in build_native_lib()
45
#define EXPORT __attribute__((visibility("default")))
56

67
/* Test: test_access_pointer */
78

8-
EXPORT void print_pointer(const int *ptr) {
9+
EXPORT void print_pointer(const int32_t *ptr) {
910
printf("printing pointer dereference from C: %d\n", *ptr);
1011
}
1112

1213
/* Test: test_access_simple */
1314

1415
typedef struct Simple {
15-
int field;
16+
int32_t field;
1617
} Simple;
1718

18-
EXPORT int access_simple(const Simple *s_ptr) {
19+
EXPORT int32_t access_simple(const Simple *s_ptr) {
1920
return s_ptr->field;
2021
}
2122

2223
/* Test: test_access_nested */
2324

2425
typedef struct Nested {
25-
int value;
26+
int32_t value;
2627
struct Nested *next;
2728
} Nested;
2829

2930
// Returns the innermost/last value of a Nested pointer chain.
30-
EXPORT int access_nested(const Nested *n_ptr) {
31+
EXPORT int32_t access_nested(const Nested *n_ptr) {
3132
// Edge case: `n_ptr == NULL` (i.e. first Nested is None).
3233
if (!n_ptr) { return 0; }
3334

@@ -41,10 +42,10 @@ EXPORT int access_nested(const Nested *n_ptr) {
4142
/* Test: test_access_static */
4243

4344
typedef struct Static {
44-
int value;
45+
int32_t value;
4546
struct Static *recurse;
4647
} Static;
4748

48-
EXPORT int access_static(const Static *s_ptr) {
49+
EXPORT int32_t access_static(const Static *s_ptr) {
4950
return s_ptr->recurse->recurse->value;
5051
}

Diff for: src/tools/miri/tests/native-lib/ptr_write_access.c

+23-23
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
/* Test: test_increment_int */
88

9-
EXPORT void increment_int(int *ptr) {
9+
EXPORT void increment_int(int32_t *ptr) {
1010
*ptr += 1;
1111
}
1212

1313
/* Test: test_init_int */
1414

15-
EXPORT void init_int(int *ptr, int val) {
15+
EXPORT void init_int(int32_t *ptr, int32_t val) {
1616
*ptr = val;
1717
}
1818

1919
/* Test: test_init_array */
2020

21-
EXPORT void init_array(int *array, size_t len, int val) {
21+
EXPORT void init_array(int32_t *array, size_t len, int32_t val) {
2222
for (size_t i = 0; i < len; i++) {
2323
array[i] = val;
2424
}
@@ -27,83 +27,83 @@ EXPORT void init_array(int *array, size_t len, int val) {
2727
/* Test: test_init_static_inner */
2828

2929
typedef struct SyncPtr {
30-
int *ptr;
30+
int32_t *ptr;
3131
} SyncPtr;
3232

33-
EXPORT void init_static_inner(const SyncPtr *s_ptr, int val) {
33+
EXPORT void init_static_inner(const SyncPtr *s_ptr, int32_t val) {
3434
*(s_ptr->ptr) = val;
3535
}
3636

3737
/* Tests: test_exposed, test_pass_dangling */
3838

39-
EXPORT void ignore_ptr(__attribute__((unused)) const int *ptr) {
39+
EXPORT void ignore_ptr(__attribute__((unused)) const int32_t *ptr) {
4040
return;
4141
}
4242

4343
/* Test: test_expose_int */
44-
EXPORT void expose_int(const int *int_ptr, const int **pptr) {
44+
EXPORT void expose_int(const int32_t *int_ptr, const int32_t **pptr) {
4545
*pptr = int_ptr;
4646
}
4747

4848
/* Test: test_swap_ptr */
4949

50-
EXPORT void swap_ptr(const int **pptr0, const int **pptr1) {
51-
const int *tmp = *pptr0;
50+
EXPORT void swap_ptr(const int32_t **pptr0, const int32_t **pptr1) {
51+
const int32_t *tmp = *pptr0;
5252
*pptr0 = *pptr1;
5353
*pptr1 = tmp;
5454
}
5555

5656
/* Test: test_swap_ptr_tuple */
5757

5858
typedef struct Tuple {
59-
int *ptr0;
60-
int *ptr1;
59+
int32_t *ptr0;
60+
int32_t *ptr1;
6161
} Tuple;
6262

6363
EXPORT void swap_ptr_tuple(Tuple *t_ptr) {
64-
int *tmp = t_ptr->ptr0;
64+
int32_t *tmp = t_ptr->ptr0;
6565
t_ptr->ptr0 = t_ptr->ptr1;
6666
t_ptr->ptr1 = tmp;
6767
}
6868

6969
/* Test: test_overwrite_dangling */
7070

71-
EXPORT void overwrite_ptr(const int **pptr) {
71+
EXPORT void overwrite_ptr(const int32_t **pptr) {
7272
*pptr = NULL;
7373
}
7474

7575
/* Test: test_swap_ptr_triple_dangling */
7676

7777
typedef struct Triple {
78-
int *ptr0;
79-
int *ptr1;
80-
int *ptr2;
78+
int32_t *ptr0;
79+
int32_t *ptr1;
80+
int32_t *ptr2;
8181
} Triple;
8282

8383
EXPORT void swap_ptr_triple_dangling(Triple *t_ptr) {
84-
int *tmp = t_ptr->ptr0;
84+
int32_t *tmp = t_ptr->ptr0;
8585
t_ptr->ptr0 = t_ptr->ptr2;
8686
t_ptr->ptr2 = tmp;
8787
}
8888

89-
EXPORT const int *return_ptr(const int *ptr) {
89+
EXPORT const int32_t *return_ptr(const int32_t *ptr) {
9090
return ptr;
9191
}
9292

9393
/* Test: test_pass_ptr_as_int */
9494

95-
EXPORT void pass_ptr_as_int(uintptr_t ptr, int set_to_val) {
96-
*(int*)ptr = set_to_val;
95+
EXPORT void pass_ptr_as_int(uintptr_t ptr, int32_t set_to_val) {
96+
*(int32_t*)ptr = set_to_val;
9797
}
9898

9999
/* Test: test_pass_ptr_via_previously_shared_mem */
100100

101-
int** shared_place;
101+
int32_t** shared_place;
102102

103-
EXPORT void set_shared_mem(int** ptr) {
103+
EXPORT void set_shared_mem(int32_t** ptr) {
104104
shared_place = ptr;
105105
}
106106

107-
EXPORT void init_ptr_stored_in_shared_mem(int val) {
107+
EXPORT void init_ptr_stored_in_shared_mem(int32_t val) {
108108
**shared_place = val;
109109
}

Diff for: src/tools/miri/tests/native-lib/scalar_arguments.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include <stdio.h>
2+
#include <stdint.h>
23

34
// See comments in build_native_lib()
45
#define EXPORT __attribute__((visibility("default")))
56

6-
EXPORT int add_one_int(int x) {
7+
EXPORT int32_t add_one_int(int32_t x) {
78
return 2 + x;
89
}
910

@@ -13,23 +14,23 @@ EXPORT void printer(void) {
1314

1415
// function with many arguments, to test functionality when some args are stored
1516
// on the stack
16-
EXPORT int test_stack_spill(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) {
17+
EXPORT int32_t test_stack_spill(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f, int32_t g, int32_t h, int32_t i, int32_t j, int32_t k, int32_t l) {
1718
return a+b+c+d+e+f+g+h+i+j+k+l;
1819
}
1920

20-
EXPORT unsigned int get_unsigned_int(void) {
21+
EXPORT uint32_t get_unsigned_int(void) {
2122
return -10;
2223
}
2324

24-
EXPORT short add_int16(short x) {
25+
EXPORT short add_int16(int16_t x) {
2526
return x + 3;
2627
}
2728

28-
EXPORT long add_short_to_long(short x, long y) {
29+
EXPORT long add_short_to_long(int16_t x, int64_t y) {
2930
return x + y;
3031
}
3132

3233
// To test that functions not marked with EXPORT cannot be called by Miri.
33-
int not_exported(void) {
34+
int32_t not_exported(void) {
3435
return 0;
3536
}

0 commit comments

Comments
 (0)