Fixing mangling of captured variables

Summary: public This diff fixes incorrect mangling of captured variables in blocks. Because they are formals,
they shouldn't be mangled, but this case was not taken into account. This caused an assert false in the
example infer/tests/codetoanalyze/objc/frontend/block/block.m which wasn't caught before because there
wasn't an endtoend test for it.

Reviewed By: akotulski

Differential Revision: D2560379

fb-gh-sync-id: db500b6
master
Dulma Rodriguez 9 years ago committed by facebook-github-bot-7
parent cf9c64acb3
commit bee713e557

@ -18,13 +18,20 @@ module L = Logging
let is_custom_var_pointer pointer = let is_custom_var_pointer pointer =
Utils.string_is_prefix CFrontend_config.pointer_prefix pointer Utils.string_is_prefix CFrontend_config.pointer_prefix pointer
let is_captured procdesc vname =
IList.exists
(fun (name, _) -> (Mangled.to_string name) = vname)
(Cfg.Procdesc.get_captured procdesc)
let sil_var_of_decl context var_decl procname = let sil_var_of_decl context var_decl procname =
let outer_procname = CContext.get_outer_procname context in let outer_procname = CContext.get_outer_procname context in
let procdesc = context.CContext.procdesc in
let open Clang_ast_t in let open Clang_ast_t in
match var_decl with match var_decl with
| VarDecl (decl_info, name_info, type_ptr, var_decl_info) -> | VarDecl (decl_info, name_info, type_ptr, var_decl_info) ->
let shoud_be_mangled = let shoud_be_mangled =
not (is_custom_var_pointer decl_info.Clang_ast_t.di_pointer) in not (is_custom_var_pointer decl_info.Clang_ast_t.di_pointer) &&
not (is_captured procdesc name_info.Clang_ast_t.ni_name) in
let var_decl_details = Some (decl_info, type_ptr, var_decl_info, shoud_be_mangled) in let var_decl_details = Some (decl_info, type_ptr, var_decl_info, shoud_be_mangled) in
General_utils.mk_sil_var name_info var_decl_details procname outer_procname General_utils.mk_sil_var name_info var_decl_details procname outer_procname
| ParmVarDecl (decl_info, name_info, type_ptr, var_decl_info) -> | ParmVarDecl (decl_info, name_info, type_ptr, var_decl_info) ->

@ -0,0 +1,63 @@
/*
* 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.ResultContainsErrorInMethod.contains;
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 BlockDivideByZeroTest {
public static final String FILE = "infer/tests/codetoanalyze/objc/frontend/block/block.m";
private static ImmutableList<String> inferCmd;
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCInferCommand(folder, FILE);
}
@Test
public void whenInferRunsOnMain1ThenDivideByZeroIsFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
String[] procedures = {
"main1",
};
assertThat(
"Results should contain the expected divide by zero",
inferResults,
containsExactly(
DIVIDE_BY_ZERO,
FILE,
procedures
)
);
}
}
Loading…
Cancel
Save