Skip to content

Commit dea4915

Browse files
author
Aaron Eline
committed
CheckedRegions understnad ret types
1 parent 531e239 commit dea4915

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

clang/lib/3C/CheckedRegions.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,19 @@ CheckedRegionAdder::findParentCompound(const ast_type_traits::DynTypedNode &N,
9292
return *Min;
9393
}
9494

95-
bool CheckedRegionAdder::isFunctionBody(CompoundStmt *S) {
95+
96+
bool isTopLevel(ASTContext *Context, CompoundStmt *S) {
9697
const auto &Parents = Context->getParents(*S);
9798
if (Parents.empty()) {
9899
return false;
99100
}
100101
return Parents[0].get<FunctionDecl>();
101102
}
102103

104+
bool CheckedRegionAdder::isFunctionBody(CompoundStmt *S) {
105+
return isTopLevel(Context, S);
106+
}
107+
103108
bool CheckedRegionAdder::isParentChecked(
104109
const ast_type_traits::DynTypedNode &DTN) {
105110
if (const auto *Parent = findParentCompound(DTN).first) {
@@ -154,13 +159,26 @@ bool CheckedRegionFinder::VisitDoStmt(DoStmt *S) {
154159

155160
bool CheckedRegionFinder::VisitCompoundStmt(CompoundStmt *S) {
156161
// Visit all subblocks, find all unchecked types
157-
bool Localwild = 0;
162+
bool Localwild = false;
158163
for (const auto &SubStmt : S->children()) {
159164
CheckedRegionFinder Sub(Context, Writer, Info, Seen, Map, EmitWarnings);
160165
Sub.TraverseStmt(SubStmt);
161166
Localwild |= Sub.Wild;
162167
}
163168

169+
// If we are a function def, need to check return type
170+
if (isTopLevel(Context, S)) {
171+
const auto &Parents = Context->getParents(*S);
172+
assert(!Parents.empty());
173+
FunctionDecl* Parent = const_cast<FunctionDecl*>(Parents[0].get<FunctionDecl>());
174+
assert(Parent != NULL);
175+
auto retType = Parent->getReturnType().getTypePtr();
176+
if (retType->isPointerType()) {
177+
CVarOption CV = Info.getVariable(Parent, Context);
178+
Localwild |= isWild(CV) || containsUncheckedPtr(Parent->getReturnType());
179+
}
180+
}
181+
164182
markChecked(S, Localwild);
165183

166184
Wild = false;

clang/test/3C/checkedregions.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ void baz(void) {
8080
bad();
8181
}
8282
}
83+
84+
int* g() {
85+
//CHECK: int* g(void) {
86+
return 1;
87+
}
88+
89+

clang/test/3C/fn_sets.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ void foo1(int *z) {
5151
/* Testing Something with a larger set of functions */
5252

5353
int *a() {
54-
//CHECK: int *a(void) _Checked {
54+
//CHECK: int *a(void) {
5555
return 0;
5656
}
5757
int *b() {
58-
//CHECK: int *b(void) _Checked {
58+
//CHECK: int *b(void) {
5959
return 0;
6060
}
6161
int *c() {
62-
//CHECK: int *c(void) _Checked {
62+
//CHECK: int *c(void) {
6363
return 0;
6464
}
6565
int *d() {
66-
//CHECK: int *d(void) _Checked {
66+
//CHECK: int *d(void) {
6767
return 0;
6868
}
6969
int *e() {
@@ -72,7 +72,7 @@ int *e() {
7272
//CHECK: return (int*) 1;
7373
}
7474
int *i() {
75-
//CHECK: _Ptr<int> i(void) _Checked {
75+
//CHECK: _Ptr<int> i(void) _Checked {
7676
return 0;
7777
}
7878

0 commit comments

Comments
 (0)