-
Notifications
You must be signed in to change notification settings - Fork 5
CheckedRegions understand return types, fixes #263 #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,18 @@ | |
using namespace llvm; | ||
using namespace clang; | ||
|
||
|
||
// Check if the compound statement is a function body | ||
// Used in both visitors so abstracted to a function | ||
bool isTopLevel(ASTContext *Context, CompoundStmt *S) { | ||
const auto &Parents = Context->getParents(*S); | ||
if (Parents.empty()) { | ||
return false; | ||
} | ||
// Ensure that our parent is a functiondecl | ||
return Parents[0].get<FunctionDecl>() != nullptr; | ||
} | ||
|
||
// CheckedRegionAdder | ||
|
||
bool CheckedRegionAdder::VisitCompoundStmt(CompoundStmt *S) { | ||
|
@@ -92,12 +104,10 @@ CheckedRegionAdder::findParentCompound(const ast_type_traits::DynTypedNode &N, | |
return *Min; | ||
} | ||
|
||
|
||
|
||
bool CheckedRegionAdder::isFunctionBody(CompoundStmt *S) { | ||
const auto &Parents = Context->getParents(*S); | ||
if (Parents.empty()) { | ||
return false; | ||
} | ||
return Parents[0].get<FunctionDecl>(); | ||
return isTopLevel(Context, S); | ||
} | ||
|
||
bool CheckedRegionAdder::isParentChecked( | ||
|
@@ -154,13 +164,26 @@ bool CheckedRegionFinder::VisitDoStmt(DoStmt *S) { | |
|
||
bool CheckedRegionFinder::VisitCompoundStmt(CompoundStmt *S) { | ||
// Visit all subblocks, find all unchecked types | ||
bool Localwild = 0; | ||
bool Localwild = false; | ||
for (const auto &SubStmt : S->children()) { | ||
CheckedRegionFinder Sub(Context, Writer, Info, Seen, Map, EmitWarnings); | ||
Sub.TraverseStmt(SubStmt); | ||
Localwild |= Sub.Wild; | ||
} | ||
|
||
// If we are a function def, need to check return type | ||
if (isTopLevel(Context, S)) { | ||
const auto &Parents = Context->getParents(*S); | ||
assert(!Parents.empty()); | ||
FunctionDecl* Parent = const_cast<FunctionDecl*>(Parents[0].get<FunctionDecl>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we might be able to make the parameter of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm happy to go through and try to make that change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, per the status meeting: Let's just do this as a separate PR; leave the |
||
assert(Parent != nullptr); | ||
auto retType = Parent->getReturnType().getTypePtr(); | ||
if (retType->isPointerType()) { | ||
CVarOption CV = Info.getVariable(Parent, Context); | ||
Localwild |= isWild(CV) || containsUncheckedPtr(Parent->getReturnType()); | ||
} | ||
} | ||
|
||
markChecked(S, Localwild); | ||
|
||
Wild = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,3 +80,10 @@ void baz(void) { | |
bad(); | ||
} | ||
} | ||
|
||
int* g() { | ||
//CHECK: int* g(void) { | ||
return 1; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.