Reviewed By: dulmarod Differential Revision: D2699663 fb-gh-sync-id: c77957emaster
parent
12d21c73dd
commit
99c491e8c7
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
@interface B : NSObject
|
||||
|
||||
- (void) foo;
|
||||
|
||||
@end
|
||||
|
||||
@implementation B
|
||||
|
||||
-(void) foo {
|
||||
};
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface A : NSObject
|
||||
|
||||
@property (nonatomic) int *p;
|
||||
@property int *q; // atomic by default
|
||||
@property (atomic, assign) float f;
|
||||
|
||||
@property B *b;
|
||||
|
||||
- (void) write_p: (int)i;
|
||||
- (int) read_p;
|
||||
- (void) write_q: (int)i;
|
||||
- (int) read_q;
|
||||
- (void) write_f: (int)i;
|
||||
- (int) read_f;
|
||||
@end
|
||||
|
||||
|
||||
@implementation A
|
||||
|
||||
@synthesize b;
|
||||
|
||||
- (void) writeP: (int)i
|
||||
{
|
||||
_p = i; // Good access
|
||||
}
|
||||
|
||||
- (int) readP
|
||||
{
|
||||
return _p; // Good access
|
||||
}
|
||||
|
||||
- (void) writeQ: (int)i
|
||||
{
|
||||
_q = i; // Bad access
|
||||
}
|
||||
|
||||
- (int) readQ
|
||||
{
|
||||
return _q; // Bad access
|
||||
}
|
||||
|
||||
- (void) writeF: (float) j
|
||||
{
|
||||
self.f = j; // Good access
|
||||
}
|
||||
|
||||
- (int) readF
|
||||
{
|
||||
return self.f; // Good access
|
||||
}
|
||||
|
||||
- (void) bla
|
||||
{
|
||||
if (b) { // bad access
|
||||
[b foo]; //bad access
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package endtoend.objc;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.DebuggableTemporaryFolder;
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
import utils.InferRunner;
|
||||
|
||||
public class AtomicPropertyTest {
|
||||
|
||||
public static final String FILE =
|
||||
"infer/tests/codetoanalyze/objc/warnings/atomic_prop.m";
|
||||
|
||||
private static ImmutableList<String> inferCmd;
|
||||
|
||||
public static final String DIRECT_ATOMIC_PROPERTY_ACCESS = "DIRECT_ATOMIC_PROPERTY_ACCESS";
|
||||
|
||||
@ClassRule
|
||||
public static DebuggableTemporaryFolder folder =
|
||||
new DebuggableTemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferCmd = InferRunner.createObjCInferCommand(
|
||||
folder,
|
||||
FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInferRunsOnAtomicProperty()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
|
||||
assertThat(
|
||||
"Results should contain a direct atomic property access",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
DIRECT_ATOMIC_PROPERTY_ACCESS,
|
||||
FILE,
|
||||
new String[]{
|
||||
"writeQ:",
|
||||
"readQ",
|
||||
"bla"
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue