Skip to content

Commit 1557b21

Browse files
authored
Merge pull request #188 from plum-umd/iss182
Fix for issue 182 (prototype for nullary functions)
2 parents 072b906 + a33906d commit 1557b21

File tree

234 files changed

+6061
-11132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+6061
-11132
lines changed

clang/lib/CConv/RewriteUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ bool TypeRewritingVisitor::VisitFunctionDecl(FunctionDecl *FD) {
675675
s = s + ")";
676676
} else {
677677
s = s + "void)";
678+
if (!FD->getType()->isFunctionProtoType())
679+
DidAny = true;
678680
}
679681

680682
if (EndStuff.size() > 0)

clang/test/CheckedCRewriter/arrboth.c

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// RUN: cconv-standalone -alltypes %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL" %s
2-
//RUN: cconv-standalone %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL" %s
3-
//RUN: cconv-standalone -output-postfix=checkedNOALL %s
4-
//RUN: %clang -c %S/arrboth.checkedNOALL.c
5-
//RUN: rm %S/arrboth.checkedNOALL.c
1+
// RUN: cconv-standalone -alltypes %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
2+
//RUN: cconv-standalone %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
3+
// RUN: cconv-standalone %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
4+
65

76

87
/*********************************************************************************/
@@ -16,7 +15,7 @@ through invalid pointer arithmetic, an unsafe cast, etc.*/
1615
/*********************************************************************************/
1716

1817

19-
#define size_t int
18+
typedef unsigned long size_t;
2019
#define NULL 0
2120
extern _Itype_for_any(T) void *calloc(size_t nmemb, size_t size) : itype(_Array_ptr<T>) byte_count(nmemb * size);
2221
extern _Itype_for_any(T) void free(void *pointer : itype(_Array_ptr<T>) byte_count(0));
@@ -28,58 +27,41 @@ extern _Unchecked char *strcpy(char * restrict dest, const char * restrict src :
2827
struct general {
2928
int data;
3029
struct general *next;
30+
//CHECK: _Ptr<struct general> next;
3131
};
32-
//CHECK_NOALL: _Ptr<struct general> next;
33-
34-
//CHECK_ALL: _Ptr<struct general> next;
35-
3632

3733
struct warr {
3834
int data1[5];
35+
//CHECK_NOALL: int data1[5];
36+
//CHECK_ALL: int data1 _Checked[5];
3937
char *name;
38+
//CHECK: _Ptr<char> name;
4039
};
41-
//CHECK_NOALL: int data1[5];
42-
//CHECK_NOALL: _Ptr<char> name;
43-
44-
//CHECK_ALL: int data1 _Checked[5];
45-
//CHECK_ALL: _Ptr<char> name;
46-
4740

4841
struct fptrarr {
4942
int *values;
43+
//CHECK: _Ptr<int> values;
5044
char *name;
45+
//CHECK: _Ptr<char> name;
5146
int (*mapper)(int);
47+
//CHECK: _Ptr<int (int )> mapper;
5248
};
53-
//CHECK_NOALL: _Ptr<int> values;
54-
//CHECK_NOALL: _Ptr<char> name;
55-
//CHECK_NOALL: _Ptr<int (int )> mapper;
56-
57-
//CHECK_ALL: _Ptr<int> values;
58-
//CHECK_ALL: _Ptr<char> name;
59-
//CHECK_ALL: _Ptr<int (int )> mapper;
60-
6149

6250
struct fptr {
6351
int *value;
52+
//CHECK: _Ptr<int> value;
6453
int (*func)(int);
54+
//CHECK: _Ptr<int (int )> func;
6555
};
66-
//CHECK_NOALL: _Ptr<int> value;
67-
//CHECK_NOALL: _Ptr<int (int )> func;
68-
69-
//CHECK_ALL: _Ptr<int> value;
70-
//CHECK_ALL: _Ptr<int (int )> func;
71-
7256

7357
struct arrfptr {
7458
int args[5];
59+
//CHECK_NOALL: int args[5];
60+
//CHECK_ALL: int args _Checked[5];
7561
int (*funcs[5]) (int);
62+
//CHECK_NOALL: int (*funcs[5]) (int);
63+
//CHECK_ALL: _Ptr<int (int )> funcs _Checked[5];
7664
};
77-
//CHECK_NOALL: int args[5];
78-
//CHECK_NOALL: int (*funcs[5]) (int);
79-
80-
//CHECK_ALL: int args _Checked[5];
81-
//CHECK_ALL: _Ptr<int (int )> funcs _Checked[5];
82-
8365

8466
int add1(int x) {
8567
return x+1;
@@ -107,54 +89,49 @@ int zerohuh(int n) {
10789
}
10890

10991
int *mul2(int *x) {
92+
//CHECK: _Ptr<int> mul2(_Ptr<int> x) {
11093
*x *= 2;
11194
return x;
11295
}
11396

114-
//CHECK_NOALL: _Ptr<int> mul2(_Ptr<int> x) {
115-
116-
//CHECK_ALL: _Ptr<int> mul2(_Ptr<int> x) {
117-
11897
int * sus(int * x, int * y) {
98+
//CHECK_NOALL: int * sus(int *x, _Ptr<int> y) {
99+
//CHECK_ALL: _Nt_array_ptr<int> sus(int *x, _Ptr<int> y) {
119100
x = (int *) 5;
101+
//CHECK: x = (int *) 5;
120102
int *z = calloc(5, sizeof(int));
121-
int i, *p, fac;
103+
//CHECK_NOALL: int *z = calloc<int>(5, sizeof(int));
104+
//CHECK_ALL: _Nt_array_ptr<int> z : count(5) = calloc<int>(5, sizeof(int));
105+
int i, fac;
106+
int *p;
107+
//CHECK_NOALL: int *p;
108+
//CHECK_ALL: _Array_ptr<int> p : count(5) = ((void *)0);
122109
for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i)
123110
{ *p = fac; }
124111
z += 2;
125112
return z; }
126-
//CHECK_NOALL: int * sus(int *x, _Ptr<int> y) {
127-
//CHECK_NOALL: int *z = calloc<int>(5, sizeof(int));
128-
//CHECK_NOALL: int i, *p, fac;
129-
//CHECK_ALL: _Nt_array_ptr<int> sus(int *x, _Ptr<int> y) {
130-
//CHECK_ALL: _Nt_array_ptr<int> z : count(5) = calloc<int>(5, sizeof(int));
131-
//CHECK_ALL: _Array_ptr<int> p : count(5) = ((void *)0);
132113

133114
int * foo() {
115+
//CHECK_NOALL: int * foo(void) {
116+
//CHECK_ALL: _Nt_array_ptr<int> foo(void) {
134117
int * x = malloc(sizeof(int));
118+
//CHECK: int * x = malloc<int>(sizeof(int));
135119
int * y = malloc(sizeof(int));
120+
//CHECK: _Ptr<int> y = malloc<int>(sizeof(int));
136121
int * z = sus(x, y);
122+
//CHECK_NOALL: int * z = sus(x, y);
123+
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);
137124
return z; }
138-
//CHECK_NOALL: int * foo() {
139-
//CHECK_NOALL: int * x = malloc<int>(sizeof(int));
140-
//CHECK_NOALL: _Ptr<int> y = malloc<int>(sizeof(int));
141-
//CHECK_NOALL: int * z = sus(x, y);
142-
//CHECK_ALL: _Nt_array_ptr<int> foo(void) {
143-
//CHECK_ALL: int * x = malloc<int>(sizeof(int));
144-
//CHECK_ALL: _Ptr<int> y = malloc<int>(sizeof(int));
145-
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);
146125

147126
int * bar() {
127+
//CHECK_NOALL: int * bar(void) {
128+
//CHECK_ALL: _Nt_array_ptr<int> bar(void) {
148129
int * x = malloc(sizeof(int));
130+
//CHECK: int * x = malloc<int>(sizeof(int));
149131
int * y = malloc(sizeof(int));
132+
//CHECK: _Ptr<int> y = malloc<int>(sizeof(int));
150133
int * z = sus(x, y);
134+
//CHECK_NOALL: int * z = sus(x, y);
135+
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);
151136
z += 2;
152137
return z; }
153-
//CHECK_NOALL: int * bar() {
154-
//CHECK_NOALL: int * x = malloc<int>(sizeof(int));
155-
//CHECK_NOALL: _Ptr<int> y = malloc<int>(sizeof(int));
156-
//CHECK_NOALL: int * z = sus(x, y);
157-
//CHECK_ALL: _Nt_array_ptr<int> bar(void) {
158-
//CHECK_ALL: int * x = malloc<int>(sizeof(int));
159-
//CHECK_ALL: _Ptr<int> y = malloc<int>(sizeof(int));
160-
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);

clang/test/CheckedCRewriter/arrbothmulti1.c

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ through invalid pointer arithmetic, an unsafe cast, etc.*/
2121
/*********************************************************************************/
2222

2323

24-
#define size_t int
24+
typedef unsigned long size_t;
2525
#define NULL 0
2626
extern _Itype_for_any(T) void *calloc(size_t nmemb, size_t size) : itype(_Array_ptr<T>) byte_count(nmemb * size);
2727
extern _Itype_for_any(T) void free(void *pointer : itype(_Array_ptr<T>) byte_count(0));
@@ -33,58 +33,41 @@ extern _Unchecked char *strcpy(char * restrict dest, const char * restrict src :
3333
struct general {
3434
int data;
3535
struct general *next;
36+
//CHECK: _Ptr<struct general> next;
3637
};
37-
//CHECK_NOALL: _Ptr<struct general> next;
38-
39-
//CHECK_ALL: _Ptr<struct general> next;
40-
4138

4239
struct warr {
4340
int data1[5];
41+
//CHECK_NOALL: int data1[5];
42+
//CHECK_ALL: int data1 _Checked[5];
4443
char *name;
44+
//CHECK: _Ptr<char> name;
4545
};
46-
//CHECK_NOALL: int data1[5];
47-
//CHECK_NOALL: _Ptr<char> name;
48-
49-
//CHECK_ALL: int data1 _Checked[5];
50-
//CHECK_ALL: _Ptr<char> name;
51-
5246

5347
struct fptrarr {
5448
int *values;
49+
//CHECK: _Ptr<int> values;
5550
char *name;
51+
//CHECK: _Ptr<char> name;
5652
int (*mapper)(int);
53+
//CHECK: _Ptr<int (int )> mapper;
5754
};
58-
//CHECK_NOALL: _Ptr<int> values;
59-
//CHECK_NOALL: _Ptr<char> name;
60-
//CHECK_NOALL: _Ptr<int (int )> mapper;
61-
62-
//CHECK_ALL: _Ptr<int> values;
63-
//CHECK_ALL: _Ptr<char> name;
64-
//CHECK_ALL: _Ptr<int (int )> mapper;
65-
6655

6756
struct fptr {
6857
int *value;
58+
//CHECK: _Ptr<int> value;
6959
int (*func)(int);
60+
//CHECK: _Ptr<int (int )> func;
7061
};
71-
//CHECK_NOALL: _Ptr<int> value;
72-
//CHECK_NOALL: _Ptr<int (int )> func;
73-
74-
//CHECK_ALL: _Ptr<int> value;
75-
//CHECK_ALL: _Ptr<int (int )> func;
76-
7762

7863
struct arrfptr {
7964
int args[5];
65+
//CHECK_NOALL: int args[5];
66+
//CHECK_ALL: int args _Checked[5];
8067
int (*funcs[5]) (int);
68+
//CHECK_NOALL: int (*funcs[5]) (int);
69+
//CHECK_ALL: _Ptr<int (int )> funcs _Checked[5];
8170
};
82-
//CHECK_NOALL: int args[5];
83-
//CHECK_NOALL: int (*funcs[5]) (int);
84-
85-
//CHECK_ALL: int args _Checked[5];
86-
//CHECK_ALL: _Ptr<int (int )> funcs _Checked[5];
87-
8871

8972
int add1(int x) {
9073
return x+1;
@@ -112,43 +95,36 @@ int zerohuh(int n) {
11295
}
11396

11497
int *mul2(int *x) {
98+
//CHECK: _Ptr<int> mul2(_Ptr<int> x) {
11599
*x *= 2;
116100
return x;
117101
}
118102

119-
//CHECK_NOALL: _Ptr<int> mul2(_Ptr<int> x) {
120-
121-
//CHECK_ALL: _Ptr<int> mul2(_Ptr<int> x) {
122-
123103
int * sus(int *, int *);
124-
//CHECK_NOALL: int * sus(int *, _Ptr<int> y);
125-
//CHECK_ALL: _Nt_array_ptr<int> sus(int *, _Ptr<int> y);
104+
//CHECK_NOALL: int * sus(int *, _Ptr<int> y);
105+
//CHECK_ALL: _Nt_array_ptr<int> sus(int *, _Ptr<int> y);
126106

127107
int * foo() {
108+
//CHECK_NOALL: int * foo(void) {
109+
//CHECK_ALL: _Nt_array_ptr<int> foo(void) {
128110
int * x = malloc(sizeof(int));
111+
//CHECK: int * x = malloc<int>(sizeof(int));
129112
int * y = malloc(sizeof(int));
113+
//CHECK: _Ptr<int> y = malloc<int>(sizeof(int));
130114
int * z = sus(x, y);
115+
//CHECK_NOALL: int * z = sus(x, y);
116+
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);
131117
return z; }
132-
//CHECK_NOALL: int * foo() {
133-
//CHECK_NOALL: int * x = malloc<int>(sizeof(int));
134-
//CHECK_NOALL: _Ptr<int> y = malloc<int>(sizeof(int));
135-
//CHECK_NOALL: int * z = sus(x, y);
136-
//CHECK_ALL: _Nt_array_ptr<int> foo(void) {
137-
//CHECK_ALL: int * x = malloc<int>(sizeof(int));
138-
//CHECK_ALL: _Ptr<int> y = malloc<int>(sizeof(int));
139-
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);
140118

141119
int * bar() {
120+
//CHECK_NOALL: int * bar(void) {
121+
//CHECK_ALL: _Nt_array_ptr<int> bar(void) {
142122
int * x = malloc(sizeof(int));
123+
//CHECK: int * x = malloc<int>(sizeof(int));
143124
int * y = malloc(sizeof(int));
125+
//CHECK: _Ptr<int> y = malloc<int>(sizeof(int));
144126
int * z = sus(x, y);
127+
//CHECK_NOALL: int * z = sus(x, y);
128+
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);
145129
z += 2;
146130
return z; }
147-
//CHECK_NOALL: int * bar() {
148-
//CHECK_NOALL: int * x = malloc<int>(sizeof(int));
149-
//CHECK_NOALL: _Ptr<int> y = malloc<int>(sizeof(int));
150-
//CHECK_NOALL: int * z = sus(x, y);
151-
//CHECK_ALL: _Nt_array_ptr<int> bar(void) {
152-
//CHECK_ALL: int * x = malloc<int>(sizeof(int));
153-
//CHECK_ALL: _Ptr<int> y = malloc<int>(sizeof(int));
154-
//CHECK_ALL: _Nt_array_ptr<int> z = sus(x, y);

0 commit comments

Comments
 (0)