Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
9a5fb2c3
Commit
9a5fb2c3
authored
Dec 01, 2023
by
Paul
Browse files
Format
parent
f583f039
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
17 deletions
+25
-17
tools/cppcheck/migraphx.py
tools/cppcheck/migraphx.py
+25
-17
No files found.
tools/cppcheck/migraphx.py
View file @
9a5fb2c3
import
cppcheck
,
itertools
import
cppcheck
,
itertools
from
cppcheckdata
import
simpleMatch
,
match
#patterns, bind_split
from
cppcheckdata
import
simpleMatch
,
match
#patterns, bind_split
def
skipTokenMatches
(
tokens
,
skip
=
None
):
def
skipTokenMatches
(
tokens
,
skip
=
None
):
...
@@ -37,6 +37,7 @@ def getVariableDecl(var):
...
@@ -37,6 +37,7 @@ def getVariableDecl(var):
end
=
end
.
next
end
=
end
.
next
return
var
.
typeStartToken
.
forward
(
end
)
return
var
.
typeStartToken
.
forward
(
end
)
def
isFunctionCall
(
token
):
def
isFunctionCall
(
token
):
if
not
token
:
if
not
token
:
return
False
return
False
...
@@ -48,6 +49,7 @@ def isFunctionCall(token):
...
@@ -48,6 +49,7 @@ def isFunctionCall(token):
return
False
return
False
return
True
return
True
# def isplit(source, sep=' '):
# def isplit(source, sep=' '):
# sepsize = len(sep)
# sepsize = len(sep)
# start = 0
# start = 0
...
@@ -127,6 +129,7 @@ def isFunctionCall(token):
...
@@ -127,6 +129,7 @@ def isFunctionCall(token):
# bindings['end'] = end
# bindings['end'] = end
# return MatchResult(True, bindings=bindings)
# return MatchResult(True, bindings=bindings)
@
cppcheck
.
checker
@
cppcheck
.
checker
def
AvoidBranchingStatementAsLastInLoop
(
cfg
,
data
):
def
AvoidBranchingStatementAsLastInLoop
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
...
@@ -159,7 +162,7 @@ def AvoidBranchingStatementAsLastInLoop(cfg, data):
...
@@ -159,7 +162,7 @@ def AvoidBranchingStatementAsLastInLoop(cfg, data):
def
ConditionalAssert
(
cfg
,
data
):
def
ConditionalAssert
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'if':
# if token.str != 'if':
# continue
# continue
if
not
match
(
token
,
"if (*) { assert (*) ; }"
):
if
not
match
(
token
,
"if (*) { assert (*) ; }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
cppcheck
.
reportError
(
token
,
"style"
,
...
@@ -170,7 +173,7 @@ def ConditionalAssert(cfg, data):
...
@@ -170,7 +173,7 @@ def ConditionalAssert(cfg, data):
def
EmptyCatchStatement
(
cfg
,
data
):
def
EmptyCatchStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'catch':
# if token.str != 'catch':
# continue
# continue
if
not
match
(
token
,
"catch (*) { }"
):
if
not
match
(
token
,
"catch (*) { }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
"An empty catch statement."
)
cppcheck
.
reportError
(
token
,
"style"
,
"An empty catch statement."
)
...
@@ -180,7 +183,7 @@ def EmptyCatchStatement(cfg, data):
...
@@ -180,7 +183,7 @@ def EmptyCatchStatement(cfg, data):
def
EmptyDoWhileStatement
(
cfg
,
data
):
def
EmptyDoWhileStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'do':
# if token.str != 'do':
# continue
# continue
if
not
simpleMatch
(
token
,
"do { } while ("
):
if
not
simpleMatch
(
token
,
"do { } while ("
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty do-while."
)
cppcheck
.
reportError
(
token
,
"style"
,
"Empty do-while."
)
...
@@ -190,7 +193,7 @@ def EmptyDoWhileStatement(cfg, data):
...
@@ -190,7 +193,7 @@ def EmptyDoWhileStatement(cfg, data):
def
EmptyElseBlock
(
cfg
,
data
):
def
EmptyElseBlock
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'else':
# if token.str != 'else':
# continue
# continue
if
not
simpleMatch
(
token
,
"else { }"
):
if
not
simpleMatch
(
token
,
"else { }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
cppcheck
.
reportError
(
token
,
"style"
,
...
@@ -201,7 +204,7 @@ def EmptyElseBlock(cfg, data):
...
@@ -201,7 +204,7 @@ def EmptyElseBlock(cfg, data):
def
EmptyForStatement
(
cfg
,
data
):
def
EmptyForStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'for':
# if token.str != 'for':
# continue
# continue
if
not
match
(
token
,
"for (*) { }"
):
if
not
match
(
token
,
"for (*) { }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty for statement."
)
cppcheck
.
reportError
(
token
,
"style"
,
"Empty for statement."
)
...
@@ -211,7 +214,7 @@ def EmptyForStatement(cfg, data):
...
@@ -211,7 +214,7 @@ def EmptyForStatement(cfg, data):
def
EmptyIfStatement
(
cfg
,
data
):
def
EmptyIfStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'if':
# if token.str != 'if':
# continue
# continue
if
not
match
(
token
,
"if (*) { }"
):
if
not
match
(
token
,
"if (*) { }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty if statement."
)
cppcheck
.
reportError
(
token
,
"style"
,
"Empty if statement."
)
...
@@ -221,7 +224,7 @@ def EmptyIfStatement(cfg, data):
...
@@ -221,7 +224,7 @@ def EmptyIfStatement(cfg, data):
def
EmptySwitchStatement
(
cfg
,
data
):
def
EmptySwitchStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'switch':
# if token.str != 'switch':
# continue
# continue
if
not
match
(
token
,
"switch (*) { }"
):
if
not
match
(
token
,
"switch (*) { }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty switch statement."
)
cppcheck
.
reportError
(
token
,
"style"
,
"Empty switch statement."
)
...
@@ -231,7 +234,7 @@ def EmptySwitchStatement(cfg, data):
...
@@ -231,7 +234,7 @@ def EmptySwitchStatement(cfg, data):
def
EmptyWhileStatement
(
cfg
,
data
):
def
EmptyWhileStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'while':
# if token.str != 'while':
# continue
# continue
if
not
match
(
token
,
"while (*) { }"
):
if
not
match
(
token
,
"while (*) { }"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty while statement."
)
cppcheck
.
reportError
(
token
,
"style"
,
"Empty while statement."
)
...
@@ -241,7 +244,7 @@ def EmptyWhileStatement(cfg, data):
...
@@ -241,7 +244,7 @@ def EmptyWhileStatement(cfg, data):
def
ForLoopShouldBeWhileLoop
(
cfg
,
data
):
def
ForLoopShouldBeWhileLoop
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'for':
# if token.str != 'for':
# continue
# continue
if
not
match
(
token
,
"for ( ; !!;"
):
if
not
match
(
token
,
"for ( ; !!;"
):
continue
continue
# Skip empty for loops
# Skip empty for loops
...
@@ -279,7 +282,7 @@ def GotoStatement(cfg, data):
...
@@ -279,7 +282,7 @@ def GotoStatement(cfg, data):
def
LambdaAttribute
(
cfg
,
data
):
def
LambdaAttribute
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != ']':
# if token.str != ']':
# continue
# continue
if
not
match
(
token
,
"] __device__|__host__ {|("
):
if
not
match
(
token
,
"] __device__|__host__ {|("
):
continue
continue
cppcheck
.
reportError
(
cppcheck
.
reportError
(
...
@@ -306,7 +309,7 @@ def MultipleUnaryOperator(cfg, data):
...
@@ -306,7 +309,7 @@ def MultipleUnaryOperator(cfg, data):
def
MutableVariable
(
cfg
,
data
):
def
MutableVariable
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'mutable':
# if token.str != 'mutable':
# continue
# continue
if
not
match
(
token
,
"mutable %var%"
):
if
not
match
(
token
,
"mutable %var%"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
cppcheck
.
reportError
(
token
,
"style"
,
...
@@ -349,7 +352,7 @@ def RedundantCast(cfg, data):
...
@@ -349,7 +352,7 @@ def RedundantCast(cfg, data):
def
RedundantConditionalOperator
(
cfg
,
data
):
def
RedundantConditionalOperator
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != '?':
# if token.str != '?':
# continue
# continue
if
not
match
(
token
,
"? true|false : true|false"
):
if
not
match
(
token
,
"? true|false : true|false"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
cppcheck
.
reportError
(
token
,
"style"
,
...
@@ -360,7 +363,7 @@ def RedundantConditionalOperator(cfg, data):
...
@@ -360,7 +363,7 @@ def RedundantConditionalOperator(cfg, data):
def
RedundantIfStatement
(
cfg
,
data
):
def
RedundantIfStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'if':
# if token.str != 'if':
# continue
# continue
if
not
match
(
if
not
match
(
token
,
token
,
"if (*) { return true|false ; } else { return true|false ; }"
):
"if (*) { return true|false ; } else { return true|false ; }"
):
...
@@ -407,7 +410,7 @@ def RedundantLocalVariable(cfg, data):
...
@@ -407,7 +410,7 @@ def RedundantLocalVariable(cfg, data):
def
UnnecessaryEmptyCondition
(
cfg
,
data
):
def
UnnecessaryEmptyCondition
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'if':
# if token.str != 'if':
# continue
# continue
m
=
match
(
token
,
"if (*)@if_cond { for (*)@for_cond {*} }"
)
m
=
match
(
token
,
"if (*)@if_cond { for (*)@for_cond {*} }"
)
if
not
m
:
if
not
m
:
continue
continue
...
@@ -439,7 +442,12 @@ def UseDeviceLaunch(cfg, data):
...
@@ -439,7 +442,12 @@ def UseDeviceLaunch(cfg, data):
@
cppcheck
.
checker
@
cppcheck
.
checker
def
UseManagePointer
(
cfg
,
data
):
def
UseManagePointer
(
cfg
,
data
):
functions
=
{
"fclose"
,
"free"
,
"hipFree"
,
"hipHostFree"
,
"hipFreeArray"
,
"hipMemFree"
,
"hipStreamDestroy"
,
"hipEventDestroy"
,
"hipArrayDestroy"
,
"hipCtxDestroy"
,
"hipDestroyTextureObject"
,
"hipDestroySurfaceObject"
,
"miirDestroyHandle"
}
functions
=
{
"fclose"
,
"free"
,
"hipFree"
,
"hipHostFree"
,
"hipFreeArray"
,
"hipMemFree"
,
"hipStreamDestroy"
,
"hipEventDestroy"
,
"hipArrayDestroy"
,
"hipCtxDestroy"
,
"hipDestroyTextureObject"
,
"hipDestroySurfaceObject"
,
"miirDestroyHandle"
}
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
if
not
isFunctionCall
(
token
):
if
not
isFunctionCall
(
token
):
continue
continue
...
@@ -453,7 +461,7 @@ def UseManagePointer(cfg, data):
...
@@ -453,7 +461,7 @@ def UseManagePointer(cfg, data):
def
UseSmartPointer
(
cfg
,
data
):
def
UseSmartPointer
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
for
token
in
cfg
.
tokenlist
:
# if token.str != 'new':
# if token.str != 'new':
# continue
# continue
if
not
match
(
token
,
"new %name%"
):
if
not
match
(
token
,
"new %name%"
):
continue
continue
cppcheck
.
reportError
(
token
,
"style"
,
cppcheck
.
reportError
(
token
,
"style"
,
...
...
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