Skip to content

Commit 2a6a28e

Browse files
Format regression tests that were added or changed since #481.
- Run clang-format and apply exclusions as appropriate. - Manually fix an over-length comment.
1 parent e5d5073 commit 2a6a28e

18 files changed

+99
-83
lines changed

clang/test/3C/add_struct_init.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
55
// RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %s --
66
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/add_struct_init.c -- | diff %t.checked/add_struct_init.c -
77

8-
98
struct foo {};
10-
struct bar { int *a; };
9+
struct bar {
10+
int *a;
11+
};
1112
//CHECK: struct bar { _Ptr<int> a; };
12-
struct fiz { int *a; };
13-
struct buz { struct bar a; };
14-
struct baz { struct buz a; };
15-
struct fuz { struct baz a; struct fiz b; };
16-
struct biz { struct fiz b; };
13+
struct fiz {
14+
int *a;
15+
};
16+
struct buz {
17+
struct bar a;
18+
};
19+
struct baz {
20+
struct buz a;
21+
};
22+
struct fuz {
23+
struct baz a;
24+
struct fiz b;
25+
};
26+
struct biz {
27+
struct fiz b;
28+
};
1729

1830
void test() {
1931
struct foo a;

clang/test/3C/arrctxsenbounds.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,33 @@
66
Context-sensitive array-bounds inference.
77
*/
88
typedef long size_t;
9-
extern _Itype_for_any(T) void *malloc(size_t size) : itype(_Array_ptr<T>) byte_count(size);
9+
extern _Itype_for_any(T) void *malloc(size_t size)
10+
: itype(_Array_ptr<T>) byte_count(size);
1011
struct foo {
11-
int *x;
12-
unsigned olol;
13-
int *y;
14-
unsigned fail_y_len;
12+
int *x;
13+
unsigned olol;
14+
int *y;
15+
unsigned fail_y_len;
1516
};
1617
//CHECK: _Array_ptr<int> x : count(olol);
1718
//CHECK: _Array_ptr<int> y;
1819

1920
void ctx_(struct foo *f, struct foo *f2) {
20-
f2->y = f->x;
21-
f2->y[0] = 1;
21+
f2->y = f->x;
22+
f2->y[0] = 1;
2223
}
2324
//CHECK: void ctx_(_Ptr<struct foo> f, _Ptr<struct foo> f2) {
2425

2526
int main(int argc, char **argv) {
26-
char *PN = argv[0];
27-
unsigned n = 10;
28-
struct foo po, po2;
29-
po.x = malloc(n*sizeof(int));
30-
po.x[0] = 0;
31-
po.olol = n;
32-
po2.fail_y_len = n;
33-
ctx_(&po, &po2);
34-
return 0;
27+
char *PN = argv[0];
28+
unsigned n = 10;
29+
struct foo po, po2;
30+
po.x = malloc(n * sizeof(int));
31+
po.x[0] = 0;
32+
po.olol = n;
33+
po2.fail_y_len = n;
34+
ctx_(&po, &po2);
35+
return 0;
3536
}
3637
//CHECK: int main(int argc, _Array_ptr<_Ptr<char>> argv : count(argc)) {
3738
//CHECK: _Ptr<char> PN = argv[0];

clang/test/3C/base_subdir/canwrite_constraints.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ int *bar(int *q) {
3636
return foo_var;
3737
}
3838

39-
4039
int gar(intptr a) {
41-
int* b = a;
42-
//CHECK_LOWER: int* b = a;
43-
//CHECK_HIGHER: _Ptr<int> b = a;
44-
return *b;
40+
int *b = a;
41+
//CHECK_LOWER: int* b = a;
42+
//CHECK_HIGHER: _Ptr<int> b = a;
43+
return *b;
4544
}
46-
47-

clang/test/3C/canwrite_constraints.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int *foo_var = ((void *)0);
2020
void strtol_like(int *p : itype(_Ptr<int>));
2121
void atol_like() {
2222
// expected-warning@+1 {{Expression in non-writable file}}
23-
strtol_like((int *) 0);
23+
strtol_like((int *)0);
2424
}
2525

2626
// Make sure we do not add checked regions in non-writable files. This happened
@@ -32,7 +32,7 @@ inline void no_op() {}
3232
// In the lower case, this should stay wild
3333
// In the higher case, this should solve to checked
3434
// expected-warning@+1 {{Declaration in non-writable file}}
35-
typedef int* intptr;
35+
typedef int *intptr;
3636
// CHECK_HIGHER: typedef _Ptr<int> intptr;
3737
// Test the unwritable cast internal warning
3838
// (https://github.com/correctcomputation/checkedc-clang/issues/454) using the

clang/test/3C/difftypes1b.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
// The desired behavior in this case is to fail, so other checks are omitted
66

7-
int * foo(int, char *);
7+
int *foo(int, char *);

clang/test/3C/difftypes2.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ void foo(char *x);
1111
void foo(char **y) {
1212
// this is the body
1313
}
14-

clang/test/3C/difftypes3.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ void foo(char **y) {
1111
}
1212

1313
void foo(char *x);
14-

clang/test/3C/inline_anon_structs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ void foo2(int *x) {
135135
//CHECK: struct {
136136
//CHECK-NEXT: _Ptr<int> c;
137137
//CHECK-NEXT: } b = {};
138-
struct {int *i;} *f;
139-
struct {int *il} *g, *h, *i;
138+
struct {
139+
int *i;
140+
} * f;
141+
struct {
142+
int *il
143+
} * g, *h, *i;
140144
}

clang/test/3C/k_and_r.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %s --
66
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/k_and_r.c -- | diff %t.checked/k_and_r.c -
77

8+
// clang-format doesn't seem to understand K&R function declarations and makes a
9+
// mess.
10+
// clang-format off
11+
812
void test0(a)
913
int *a;
1014
{}
@@ -26,7 +30,7 @@ void test2(a, b)
2630

2731
int *test3(a)
2832
int *a;
29-
{return a;}
33+
{ return a; }
3034
//CHECK: _Ptr<int> test3(_Ptr<int> a)
3135
//CHECK: _Checked {return a;}
3236

@@ -55,9 +59,9 @@ void test5(a, b, c, d, e, f, g, h)
5559
struct yy_buffer_state {};
5660
typedef struct yy_buffer_state *YY_BUFFER_STATE;
5761
#ifdef YY_USE_PROTOS
58-
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
62+
void yy_init_buffer(YY_BUFFER_STATE b, FILE *file)
5963
#else
60-
void yy_init_buffer( b, file )
64+
void yy_init_buffer(b, file)
6165
YY_BUFFER_STATE b;
6266
int *file;
6367
//CHECK: void yy_init_buffer(YY_BUFFER_STATE b, _Ptr<int> file)
@@ -73,4 +77,6 @@ void compress_block(s, ltree, dtree)
7377
const ct_data *ltree;
7478
const ct_data *dtree;
7579
//CHECK: void compress_block(_Ptr<deflate_state> s, _Ptr<const ct_data> ltree, _Ptr<const ct_data> dtree)
76-
{ }
80+
{}
81+
82+
// clang-format on

clang/test/3C/liberal_itypes_fp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ void fptr_itype_test(void) {
108108
}
109109

110110
void fn_ptrptr(int **a) { *a = 1; }
111-
void fptr_ptrptr_test() {
112-
void (*fn)(int **) = &fn_ptrptr;
113-
}
111+
void fptr_ptrptr_test() { void (*fn)(int **) = &fn_ptrptr; }
114112
//CHECK: void fn_ptrptr(int **a : itype(_Ptr<_Ptr<int>>)) { *a = 1; }
115113
//CHECK: void fptr_ptrptr_test() _Checked {
116114
//CHECK: _Ptr<void (int ** : itype(_Ptr<_Ptr<int>>))> fn = &fn_ptrptr;

clang/test/3C/macro_function_call.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
// Unsafe call in macro. This would require an _Assume_bounds_cast, but we
1818
// can't insert it. Constraints are generated so that the cast isn't needed.
1919

20-
#define macro0 \
21-
void caller0(int *a) {\
22-
fn0(a);\
23-
}
20+
#define macro0 \
21+
void caller0(int *a) { fn0(a); }
2422
void fn0(int *b) {}
2523
macro0
2624

@@ -31,16 +29,21 @@ macro0
3129
//CHECK: void fn0(int *b) {}
3230
//CHECK: macro0
3331

32+
// clang-format messes up this part of the file because it mistakes macro
33+
// references for other syntactic constructs.
34+
// clang-format off
3435

35-
// Same as above, but the cast is requried on the return.
36+
// Same as above, but the cast is required on the return.
3637

3738
#define macro1 fn1();
3839
int *fn1(void) { return 0; }
3940
void caller1() {
40-
int *a = (int *) 1;
41+
int *a = (int *)1;
4142
a = macro1
4243
}
4344

45+
// clang-format on
46+
4447
//CHECK: #define macro1 fn1();
4548
//CHECK: int *fn1(void) { return 0; }
4649
//CHECK: void caller1() {
@@ -53,22 +56,19 @@ void caller1() {
5356

5457
#define macro2 fn2(a);
5558
void fn2(int *b) {}
56-
void caller2(int *a) {
57-
macro2
58-
}
59+
void caller2(int *a) { macro2 }
5960
//CHECK: #define macro2 fn2(a);
6061
//CHECK: void fn2(_Ptr<int> b) _Checked {}
6162
//CHECK: void caller2(_Ptr<int> a) _Checked {
6263
//CHECK: macro2
6364
//CHECK: }
6465

65-
6666
// Like the first test case, but pointer to a pointer.
6767

6868
#define macro3 fn3(a);
6969
void fn3(int **g) {}
7070
void caller3() {
71-
int **a = (int **) 1;
71+
int **a = (int **)1;
7272
macro3
7373
}
7474
//CHECK: #define macro3 fn3(a);
@@ -83,8 +83,8 @@ void caller3() {
8383
void fn4a(int *g) {}
8484
void fn4b(int *g) {}
8585
void caller4() {
86-
int *a = (int *) 1;
87-
void (*fn)(int *) = fn4a;
86+
int *a = (int *)1;
87+
void (*fn)(int *) = fn4a;
8888
if (0)
8989
fn = fn4b;
9090
macro4

clang/test/3C/merge_fp1_xfail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
// When this file is first it fails.
99

1010
// possible assert failure - nothing should merge into undeclared params
11-
int * primary_merge(int * (*secondary_merge)());
11+
int *primary_merge(int *(*secondary_merge)());
1212
// CHECK: _Ptr<int> primary_merge(_Ptr<_Ptr<int> (int *)> secondary_merge);

clang/test/3C/merge_fp2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
// When this file is first it succeeds, when second it fails.
77

8-
int * primary_merge(int * (*secondary_merge)(int*));
8+
int *primary_merge(int *(*secondary_merge)(int *));
99
// CHECK: _Ptr<int> primary_merge(_Ptr<_Ptr<int> (int *)> secondary_merge);
1010

1111
// need this to produce changes (0 is safe, and clang merged the declarations)
12-
int * primary_merge(int * (*secondary_merge)()) {
13-
// CHECK: _Ptr<int> primary_merge(_Ptr<_Ptr<int> (int *)> secondary_merge) {
12+
int *primary_merge(int *(*secondary_merge)()) {
13+
// CHECK: _Ptr<int> primary_merge(_Ptr<_Ptr<int> (int *)> secondary_merge) {
1414

1515
return ((*secondary_merge)(0));
1616
}

clang/test/3C/overconstrained_merge.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
// RUN: 3c -base-dir=%S -output-dir=%t.checked -alltypes %s --
55
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/overconstrained_merge.c -- | diff %t.checked/overconstrained_merge.c -
66

7-
// Test checks for merging a function after the generics code adds a constraint
8-
// The merge succeeds because it happens earlier in the codebase than the addition
7+
// Test checks for merging a function after the generics code adds a constraint.
8+
// The merge succeeds because it happens earlier in the codebase than the
9+
// addition.
910

1011
// This test only uses -alltypes because of the use of _Array_ptr in the example
1112
// (to distinguish from the _Ptr that will be added).

clang/test/3C/root_cause.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ void (*f)(void *); // expected-warning {{Default void* type}}
5050
typedef struct {
5151
int x;
5252
float f;
53-
} A, *PA; // expected-warning {{Unable to rewrite a typedef with multiple names}}
53+
} A, *PA;
54+
// expected-warning@-1 {{Unable to rewrite a typedef with multiple names}}

clang/test/3C/type_params_macro.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
#define baz foo<int>(i);
1010
#define buz foo(i);
11-
#define buzzy foo(i); foo(j);
11+
#define buzzy \
12+
foo(i); \
13+
foo(j);
1214

13-
_Itype_for_any(T) void foo(void *x : itype(_Ptr<T>));
15+
_Itype_for_any(T) void foo(void *x : itype(_Ptr<T>));
1416

1517
void test_none() {
1618
int *i = 0;
@@ -45,4 +47,3 @@ void test_two() {
4547
// CHECK: int *i = 0;
4648
// CHECK: int *j = 0;
4749
// CHECK: buzzy
48-

clang/test/3C/typedefs.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ intptr bar(intptr x) {
3131
return x;
3232
}
3333

34-
typedef int* integer;
34+
typedef int *integer;
3535
//CHECK: typedef _Ptr<int> integer;
3636
int foo(void) {
3737
//CHECK: int foo(void) {
@@ -45,14 +45,13 @@ int foo(void) {
4545
bad b = (int *)3;
4646
//CHECK: bad b = (int *)3;
4747
badP b2 = (intptr *)3;
48-
typedef int nat;
49-
const nat z = 3;
50-
const nat* cnstp = &z;
51-
//CHECK: _Ptr<const nat> cnstp = &z;
52-
int w = 34;
53-
const integer c = &w;
54-
//CHECK: const integer c = &w;
55-
48+
typedef int nat;
49+
const nat z = 3;
50+
const nat *cnstp = &z;
51+
//CHECK: _Ptr<const nat> cnstp = &z;
52+
int w = 34;
53+
const integer c = &w;
54+
//CHECK: const integer c = &w;
5655

5756
return *p;
5857
}
@@ -75,14 +74,12 @@ void barfoo(intptr x) {
7574
*x = 5;
7675
}
7776

78-
#define MYDECL typedef int* ZZZ;
77+
#define MYDECL typedef int *ZZZ;
7978
MYDECL
8079
void zzz(void) {
8180
int x = 3;
8281
ZZZ z = &x;
8382
}
84-
typedef int * * const a;
83+
typedef int **const a;
8584
//CHECK: typedef const _Ptr<_Ptr<int>> a;
86-
void xxx(void) {
87-
a b;
88-
}
85+
void xxx(void) { a b; }

0 commit comments

Comments
 (0)