Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
0e8e1fde
Commit
0e8e1fde
authored
15 years ago
by
Ted Kremenek
Browse files
Options
Downloads
Patches
Plain Diff
Fix: <
rdar://problem/7075531
> static analyzer wrongly detects unused ivars used in blocks
llvm-svn: 78409
parent
d0470d74
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
clang/lib/Analysis/CheckObjCUnusedIVars.cpp
+8
-2
8 additions, 2 deletions
clang/lib/Analysis/CheckObjCUnusedIVars.cpp
clang/test/Analysis/unused-ivars.m
+40
-5
40 additions, 5 deletions
clang/test/Analysis/unused-ivars.m
with
48 additions
and
7 deletions
clang/lib/Analysis/CheckObjCUnusedIVars.cpp
+
8
−
2
View file @
0e8e1fde
...
...
@@ -30,14 +30,20 @@ static void Scan(IvarUsageMap& M, const Stmt* S) {
if
(
!
S
)
return
;
if
(
const
ObjCIvarRefExpr
*
Ex
=
dyn_cast
<
ObjCIvarRefExpr
>
(
S
))
{
const
ObjCIvarDecl
*
D
=
Ex
->
getDecl
();
if
(
const
ObjCIvarRefExpr
*
Ex
=
dyn_cast
<
ObjCIvarRefExpr
>
(
S
))
{
const
ObjCIvarDecl
*
D
=
Ex
->
getDecl
();
IvarUsageMap
::
iterator
I
=
M
.
find
(
D
);
if
(
I
!=
M
.
end
())
I
->
second
=
Used
;
return
;
}
// Blocks can reference an instance variable of a class.
if
(
const
BlockExpr
*
BE
=
dyn_cast
<
BlockExpr
>
(
S
))
{
Scan
(
M
,
BE
->
getBody
());
return
;
}
for
(
Stmt
::
const_child_iterator
I
=
S
->
child_begin
(),
E
=
S
->
child_end
();
I
!=
E
;
++
I
)
Scan
(
M
,
*
I
);
}
...
...
This diff is collapsed.
Click to expand it.
clang/test/Analysis/unused-ivars.m
+
40
−
5
View file @
0e8e1fde
// RUN: clang-cc -analyze -warn-objc-unused-ivars %s -verify
// RUN: clang-cc
-triple x86_64-apple-darwin10
-analyze -warn-objc-unused-ivars %s -verify
@interface
A
{
@private
int
x
;
// expected-warning {{Instance variable 'x' in class 'A' is never used}}
//===--- BEGIN: Delta-debugging reduced headers. --------------------------===//
@protocol
NSObject
-
(
id
)
retain
;
-
(
oneway
void
)
release
;
@end
@interface
NSObject
<
NSObject
>
{}
-
(
id
)
init
;
+
(
id
)
alloc
;
@end
//===--- END: Delta-debugging reduced headers. ----------------------------===//
// This test case tests the basic functionality of the unused ivar test.
@interface
TestA
{
@private
int
x
;
// expected-warning {{Instance variable 'x' in class 'TestA' is never used}}
}
@end
@implementation
TestA
@end
@implementation
A
@end
// This test case tests whether the unused ivar check handles blocks that
// reference an instance variable. (<rdar://problem/7075531>)
@interface
TestB
:
NSObject
{
@private
id
_ivar
;
// no-warning
}
@property
(
readwrite
,
retain
)
id
ivar
;
@end
@implementation
TestB
-
(
id
)
ivar
{
__attribute__
((
__blocks__
(
byref
)))
id
value
=
((
void
*
)
0
);
void
(
^
b
)()
=
^
{
value
=
_ivar
;
};
b
();
return
value
;
}
-
(
void
)
setIvar
:(
id
)
newValue
{
void
(
^
b
)()
=
^
{
[
_ivar
release
];
_ivar
=
[
newValue
retain
];
};
b
();
}
@end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment