Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
ae0738b4
Commit
ae0738b4
authored
Mar 10, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Format
parent
85ef47bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
25 deletions
+22
-25
plugins/refcount_checker/refcount_checker.cpp
plugins/refcount_checker/refcount_checker.cpp
+22
-25
No files found.
plugins/refcount_checker/refcount_checker.cpp
View file @
ae0738b4
...
@@ -74,7 +74,7 @@ static void dump(DeclContext* ctx) {
...
@@ -74,7 +74,7 @@ static void dump(DeclContext* ctx) {
class
RefcheckingVisitor
:
public
RecursiveASTVisitor
<
RefcheckingVisitor
>
{
class
RefcheckingVisitor
:
public
RecursiveASTVisitor
<
RefcheckingVisitor
>
{
private:
private:
ASTContext
*
Context
;
ASTContext
*
Context
;
enum
RefType
{
enum
RefType
{
UNKNOWN
,
UNKNOWN
,
...
@@ -118,7 +118,7 @@ private:
...
@@ -118,7 +118,7 @@ private:
}
}
BlockState
()
{}
BlockState
()
{}
BlockState
(
const
BlockState
&
rhs
)
{
BlockState
(
const
BlockState
&
rhs
)
{
states
=
rhs
.
states
;
states
=
rhs
.
states
;
for
(
auto
&&
p
:
rhs
.
vars
)
{
for
(
auto
&&
p
:
rhs
.
vars
)
{
auto
it
=
states
.
begin
();
auto
it
=
states
.
begin
();
...
@@ -167,7 +167,7 @@ private:
...
@@ -167,7 +167,7 @@ private:
}
}
}
}
for
(
auto
&&
bstate
:
{
state1
,
state2
})
{
for
(
auto
&&
bstate
:
{
state1
,
state2
})
{
for
(
auto
&&
state
:
state1
.
states
)
{
for
(
auto
&&
state
:
state1
.
states
)
{
if
(
state
.
num_refs
==
0
)
if
(
state
.
num_refs
==
0
)
continue
;
continue
;
...
@@ -358,9 +358,8 @@ private:
...
@@ -358,9 +358,8 @@ private:
if
(
auto
dostmt
=
dyn_cast
<
DoStmt
>
(
stmt
))
{
if
(
auto
dostmt
=
dyn_cast
<
DoStmt
>
(
stmt
))
{
Expr
*
cond
=
dostmt
->
getCond
();
Expr
*
cond
=
dostmt
->
getCond
();
auto
cond_casted
=
dyn_cast
<
CXXBoolLiteralExpr
>
(
cond
);
auto
cond_casted
=
dyn_cast
<
CXXBoolLiteralExpr
>
(
cond
);
RELEASE_ASSERT
(
RELEASE_ASSERT
(
cond_casted
&&
cond_casted
->
getValue
()
==
false
,
cond_casted
&&
cond_casted
->
getValue
()
==
false
,
"Only support `do {} while(false);` statements for now"
);
"Only support `do {} while(false);` statements for now"
);
handle
(
dostmt
->
getBody
(),
state
);
handle
(
dostmt
->
getBody
(),
state
);
return
;
return
;
}
}
...
@@ -369,8 +368,10 @@ private:
...
@@ -369,8 +368,10 @@ private:
handle
(
ifstmt
->
getCond
(),
state
);
handle
(
ifstmt
->
getCond
(),
state
);
BlockState
else_state
(
state
);
BlockState
else_state
(
state
);
if
(
ifstmt
->
getThen
())
handle
(
ifstmt
->
getThen
(),
state
);
if
(
ifstmt
->
getThen
())
if
(
ifstmt
->
getElse
())
handle
(
ifstmt
->
getElse
(),
else_state
);
handle
(
ifstmt
->
getThen
(),
state
);
if
(
ifstmt
->
getElse
())
handle
(
ifstmt
->
getElse
(),
else_state
);
checkSameAndMerge
(
state
,
else_state
);
checkSameAndMerge
(
state
,
else_state
);
return
;
return
;
}
}
...
@@ -443,11 +444,9 @@ private:
...
@@ -443,11 +444,9 @@ private:
}
}
public:
public:
explicit
RefcheckingVisitor
(
ASTContext
*
Context
)
:
Context
(
Context
)
{
explicit
RefcheckingVisitor
(
ASTContext
*
Context
)
:
Context
(
Context
)
{}
}
virtual
~
RefcheckingVisitor
()
{
virtual
~
RefcheckingVisitor
()
{}
}
virtual
bool
VisitFunctionDecl
(
FunctionDecl
*
func
)
{
virtual
bool
VisitFunctionDecl
(
FunctionDecl
*
func
)
{
if
(
!
func
->
hasBody
())
if
(
!
func
->
hasBody
())
...
@@ -467,10 +466,10 @@ public:
...
@@ -467,10 +466,10 @@ public:
if
(
filename
.
find
(
"lib/clang"
)
!=
StringRef
::
npos
)
if
(
filename
.
find
(
"lib/clang"
)
!=
StringRef
::
npos
)
return
true
;
return
true
;
//errs() << filename << '\n';
//
errs() << filename << '\n';
//if (func->getNameInfo().getAsString() != "firstlineno")
//
if (func->getNameInfo().getAsString() != "firstlineno")
//
return true;
//
return true;
checkFunction
(
func
);
checkFunction
(
func
);
...
@@ -483,25 +482,23 @@ private:
...
@@ -483,25 +482,23 @@ private:
RefcheckingVisitor
visitor
;
RefcheckingVisitor
visitor
;
public:
public:
explicit
RefcheckingASTConsumer
(
ASTContext
*
Context
)
:
visitor
(
Context
)
{
explicit
RefcheckingASTConsumer
(
ASTContext
*
Context
)
:
visitor
(
Context
)
{}
}
virtual
void
HandleTranslationUnit
(
ASTContext
&
Context
)
{
virtual
void
HandleTranslationUnit
(
ASTContext
&
Context
)
{
visitor
.
TraverseDecl
(
Context
.
getTranslationUnitDecl
());
visitor
.
TraverseDecl
(
Context
.
getTranslationUnitDecl
());
//dumper()->TraverseDecl(Context.getTranslationUnitDecl());
//
dumper()->TraverseDecl(Context.getTranslationUnitDecl());
}
}
};
};
class
RefcheckingFrontendAction
:
public
ASTFrontendAction
{
class
RefcheckingFrontendAction
:
public
ASTFrontendAction
{
public:
public:
virtual
std
::
unique_ptr
<
ASTConsumer
>
CreateASTConsumer
(
CompilerInstance
&
CI
,
StringRef
fname
)
{
virtual
std
::
unique_ptr
<
ASTConsumer
>
CreateASTConsumer
(
CompilerInstance
&
CI
,
StringRef
fname
)
{
return
std
::
unique_ptr
<
ASTConsumer
>
(
new
RefcheckingASTConsumer
(
&
CI
.
getASTContext
()));
return
std
::
unique_ptr
<
ASTConsumer
>
(
new
RefcheckingASTConsumer
(
&
CI
.
getASTContext
()));
}
}
};
};
int
main
(
int
argc
,
const
char
**
argv
)
{
int
main
(
int
argc
,
const
char
**
argv
)
{
CommonOptionsParser
OptionsParser
(
argc
,
argv
,
RefcheckingToolCategory
);
CommonOptionsParser
OptionsParser
(
argc
,
argv
,
RefcheckingToolCategory
);
ClangTool
Tool
(
OptionsParser
.
getCompilations
(),
ClangTool
Tool
(
OptionsParser
.
getCompilations
(),
OptionsParser
.
getSourcePathList
());
OptionsParser
.
getSourcePathList
());
return
Tool
.
run
(
newFrontendActionFactory
<
RefcheckingFrontendAction
>
().
get
());
return
Tool
.
run
(
newFrontendActionFactory
<
RefcheckingFrontendAction
>
().
get
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment