Summary: This diff fixes two issues in the backend that were causing Bad_footprint errors when abducing pointsto facts for expressions that start in an array access and follow up with another structured access, eg `x[0].some_field`: 1. array accesses were assumed to come last in these expressions 2. the type of the root exp passed to the function that walks down the list of offsets to apply to it was wrong in the case of arrays: it was always the type of the whole expression instead of the root expr (eg the type of `x[0].some_field` instead of the type of `x`). Reviewed By: sblackshear, jeremydubreil Differential Revision: D3800566 fbshipit-source-id: 0511604master
parent
41e51bc28c
commit
4fe1615434
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 - 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct { int f1; } a_struct;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int f1;
|
||||||
|
a_struct array[10];
|
||||||
|
} b_struct;
|
||||||
|
|
||||||
|
void init_static() { static const b_struct x[] = {{1}}; }
|
||||||
|
|
||||||
|
int array_of_struct(b_struct x[]) {
|
||||||
|
int j = x[0].array[5].f1;
|
||||||
|
int i = x[0].f1;
|
||||||
|
b_struct y = x[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int pointer_of_struct(b_struct* x) {
|
||||||
|
int i = (*x).f1;
|
||||||
|
b_struct y = *x;
|
||||||
|
int j = y.f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int array_of_array_of_struct(b_struct x[][100]) {
|
||||||
|
int i = x[32][52].f1;
|
||||||
|
b_struct* y = x[32];
|
||||||
|
b_struct z = x[32][52];
|
||||||
|
int j = z.f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pointer_of_array_of_struct(b_struct* x[], int n) {
|
||||||
|
int i = (*x)[n].f1;
|
||||||
|
b_struct y = (*x)[n];
|
||||||
|
int j = y.f1;
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 - 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.c.infer;
|
||||||
|
|
||||||
|
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 ArrayOfStructsAbductionTest {
|
||||||
|
|
||||||
|
public static final String source_file =
|
||||||
|
"infer/tests/codetoanalyze/c/errors/initialization/abduce_structured_types.c";
|
||||||
|
|
||||||
|
private static ImmutableList<String> inferCmd;
|
||||||
|
|
||||||
|
public static final String BAD_FOOTPRINT = "Bad_footprint";
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void runInfer() throws InterruptedException, IOException {
|
||||||
|
ImmutableList<String> extraOptions =
|
||||||
|
new ImmutableList.Builder<String>()
|
||||||
|
.add("--developer-mode")
|
||||||
|
.build();
|
||||||
|
inferCmd = InferRunner.createCInferCommand(folder, source_file, extraOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenInferRunsOnAssertExampleThenNPENotFound()
|
||||||
|
throws InterruptedException, IOException, InferException {
|
||||||
|
InferResults inferResults = InferRunner.runInferC(inferCmd);
|
||||||
|
String[] no_procedures = {};
|
||||||
|
|
||||||
|
assertThat("Results should not contain a bad footprint error",
|
||||||
|
inferResults,
|
||||||
|
containsExactly(BAD_FOOTPRINT,
|
||||||
|
source_file,
|
||||||
|
no_procedures));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue