Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
06c281c2
Kaydet (Commit)
06c281c2
authored
Ara 15, 2017
tarafından
Noel Grandin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
loplugin:unusedindex fix false+ in nested loops
Change-Id: I31acbf104e49a4d1f077817a68d0b116fd2e0a30
üst
ca6d205e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
11 deletions
+28
-11
unusedindex.cxx
compilerplugins/clang/test/unusedindex.cxx
+16
-0
unusedindex.cxx
compilerplugins/clang/unusedindex.cxx
+12
-11
No files found.
compilerplugins/clang/test/unusedindex.cxx
Dosyayı görüntüle @
06c281c2
...
...
@@ -18,6 +18,22 @@ void func1()
n
+=
1
;
for
(
int
i
=
0
;
i
<
10
;
++
i
)
n
+=
i
;
for
(
int
i
=
0
;
i
<
10
;
++
i
)
// expected-error {{loop variable not used [loplugin:unusedindex]}}
{
for
(
int
j
=
0
;
j
<
10
;
++
j
)
{
n
+=
j
;
}
}
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
for
(
int
j
=
0
;
j
<
10
;
++
j
)
{
n
+=
j
;
n
+=
i
;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
compilerplugins/clang/unusedindex.cxx
Dosyayı görüntüle @
06c281c2
...
...
@@ -38,7 +38,7 @@ public:
bool
VisitDeclRefExpr
(
DeclRefExpr
const
*
stmt
);
private
:
VarDecl
const
*
mLoopVarDecl
=
nullptr
;
std
::
vector
<
VarDecl
const
*>
mLoopVarDecls
;
std
::
unordered_set
<
VarDecl
const
*>
mFoundSet
;
};
...
...
@@ -46,27 +46,28 @@ bool UnusedIndex::TraverseForStmt(ForStmt* stmt)
{
if
(
ignoreLocation
(
stmt
))
return
true
;
auto
savedCopy
=
mLoopVarDecl
;
mL
oopVarDecl
=
nullptr
;
VarDecl
const
*
l
oopVarDecl
=
nullptr
;
if
(
stmt
->
getInit
())
{
auto
declStmt
=
dyn_cast
<
DeclStmt
>
(
stmt
->
getInit
());
if
(
declStmt
&&
declStmt
->
isSingleDecl
())
{
auto
varDecl
=
dyn_cast
<
VarDecl
>
(
declStmt
->
getSingleDecl
());
if
(
varDecl
)
mLoopVarDecl
=
varDecl
;
loopVarDecl
=
dyn_cast
<
VarDecl
>
(
declStmt
->
getSingleDecl
());
}
}
if
(
loopVarDecl
)
mLoopVarDecls
.
push_back
(
loopVarDecl
);
// deliberately ignore the other parts of the for stmt, except for the body
auto
ret
=
RecursiveASTVisitor
::
TraverseStmt
(
stmt
->
getBody
());
if
(
mLoopVarDecl
&&
mFoundSet
.
erase
(
mLoopVarDecl
)
==
0
)
report
(
DiagnosticsEngine
::
Warning
,
"loop variable not used"
,
mLoopVarDecl
->
getLocStart
())
<<
mLoopVarDecl
->
getSourceRange
();
mLoopVarDecl
=
savedCopy
;
if
(
loopVarDecl
&&
mFoundSet
.
erase
(
loopVarDecl
)
==
0
)
report
(
DiagnosticsEngine
::
Warning
,
"loop variable not used"
,
loopVarDecl
->
getLocStart
())
<<
loopVarDecl
->
getSourceRange
();
if
(
loopVarDecl
)
mLoopVarDecls
.
pop_back
();
return
ret
;
}
...
...
@@ -75,7 +76,7 @@ bool UnusedIndex::VisitDeclRefExpr(DeclRefExpr const* stmt)
auto
varDecl
=
dyn_cast
<
VarDecl
>
(
stmt
->
getDecl
());
if
(
!
varDecl
)
return
true
;
if
(
mLoopVarDecl
&&
mLoopVarDecl
==
varDecl
)
if
(
std
::
find
(
mLoopVarDecls
.
begin
(),
mLoopVarDecls
.
end
(),
varDecl
)
!=
mLoopVarDecls
.
end
()
)
mFoundSet
.
insert
(
varDecl
);
return
true
;
}
...
...
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