Skip to content

Commit 03f86af

Browse files
committed
initial fix and test consolidation
1 parent ce04a57 commit 03f86af

File tree

7 files changed

+108
-119
lines changed

7 files changed

+108
-119
lines changed

clang/lib/CConv/ConstraintBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ void processRecordDecl(RecordDecl *Declaration, ProgramInfo &Info,
3636
// We only want to re-write a record if it contains
3737
// any pointer types, to include array types.
3838
for (const auto &D : Definition->fields()) {
39-
bool mark_wild = ((D->getType()->isPointerType() || D->getType()->isArrayType()) &&
39+
bool mark_wild = ((D->getType()->isPointerType()
40+
|| D->getType()->isArrayType()) &&
4041
(FL.isInSystemHeader() || Definition->isUnion()));
4142
if (!mark_wild && inFunc) {
4243
Decl *D = Declaration->getNextDeclInContext();
4344
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
44-
if (!VD->getType()->isPointerType() && !VD->getType()->isArrayType()) {
45+
if (!VD->getType()->isPointerType()
46+
&& !VD->getType()->isArrayType() && !VD->hasInit()) {
4547
unsigned int BeginLoc = VD->getBeginLoc().getRawEncoding();
4648
unsigned int EndLoc = VD->getEndLoc().getRawEncoding();
4749
mark_wild = (lastRecordLocation >= BeginLoc &&

clang/test/CheckedCRewriter/anonstruct.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

clang/test/CheckedCRewriter/arrinlinestruct.c

Lines changed: 0 additions & 20 deletions
This file was deleted.

clang/test/CheckedCRewriter/complexinlinestruct.c

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// RUN: cconv-standalone -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
2+
// RUN: cconv-standalone -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
3+
// RUN: cconv-standalone -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
4+
// RUN: cconv-standalone -output-postfix=checked -alltypes %s
5+
// RUN: cconv-standalone -alltypes %S/inline_anon_structs.checked.c -- | count 0
6+
// RUN: rm %S/inline_anon_structs.checked.c
7+
8+
9+
/*This code ensures conversion happens as expected when
10+
an inlinestruct and its associated VarDecl have different locations*/
11+
int valuable;
12+
13+
static struct foo
14+
{
15+
const char* name;
16+
//CHECK_NOALL: const char* name;
17+
//CHECK_ALL: _Ptr<const char> name;
18+
int* p_valuable;
19+
//CHECK: _Ptr<int> p_valuable;
20+
}
21+
array[] =
22+
{
23+
{ "mystery", &valuable }
24+
};
25+
26+
/*This code is a series of more complex tests for inline structs*/
27+
/* a, b, c below all stay as WILD pointers; d can be a _Ptr<...>*/
28+
29+
/* one decl; x rewrites to _Ptr<int> */
30+
struct foo1 { int *x; } *a;
31+
//CHECK: struct foo1 { _Ptr<int> x; } *a;
32+
33+
struct baz { int *z; };
34+
//CHECK: struct baz { _Ptr<int> z; };
35+
struct baz *d;
36+
//CHECK: _Ptr<struct baz> d = ((void *)0);
37+
38+
struct bad { int* y; } *b, *c;
39+
//CHECK: struct bad { int* y; } *b, *c;
40+
41+
/* two decls, y should be converted */
42+
struct bar { int* y; } *e, *f;
43+
//CHECK: struct bar { _Ptr<int> y; } *e, *f;
44+
45+
46+
void foo(void) {
47+
a->x = (void*)0;
48+
b->y = (int *) 5;
49+
d->z = (void*)0;
50+
}
51+
52+
/*This code tests anonymous structs */
53+
struct {
54+
/*the fields of the anonymous struct are free to be marked checked*/
55+
int *data;
56+
//CHECK_NOALL: int *data;
57+
//CHECK_ALL: _Array_ptr<int> data : count(4);
58+
59+
/* but the actual pointer can't be */
60+
} *x;
61+
62+
/*ensure trivial conversion*/
63+
void foo1(int *w) {
64+
//CHECK: void foo1(_Ptr<int> w) {
65+
x->data = malloc(sizeof(int)*4);
66+
x->data[1] = 4;
67+
}
68+
69+
70+
/*This code tests more complex variable declarations*/
71+
struct alpha {
72+
int *data;
73+
//CHECK: _Ptr<int> data;
74+
};
75+
struct alpha *al[4];
76+
//CHECK_NOALL: struct alpha *al[4];
77+
//CHECK_ALL: _Ptr<struct alpha> al _Checked[4];
78+
79+
/*be should be made wild, whereas a should be converted*/
80+
struct {
81+
int *a;
82+
//CHECK: _Ptr<int> a;
83+
} *be[4];
84+
85+
/*this code checks inline structs withiin functions*/
86+
void foo2(int *x) {
87+
//CHECK: void foo2(_Ptr<int> x) {
88+
struct bar { int *x; } *y = 0;
89+
//CHECK: struct bar { _Ptr<int> x; } *y = 0;
90+
91+
/*A non-pointer struct without an init will be marked wild*/
92+
struct something { int *x; } z;
93+
//CHECK: struct something { int *x; } z;
94+
95+
/*so will ones that are anonymous*/
96+
struct { int *x; } a;
97+
//CHECK: struct { int *x; } a;
98+
99+
/*if it have an initializer, the rewriter won't have trouble*/
100+
struct { int * c; } b = {};
101+
//CHECK: struct { _Ptr<int> c; } b = {};
102+
}
103+
104+

clang/test/CheckedCRewriter/inlinestruct_difflocs.c

Lines changed: 0 additions & 22 deletions
This file was deleted.

clang/test/CheckedCRewriter/inlinestructinfunc.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)