[siof] do not generate dummy derefs in initializer code

Summary:
This confuses the SIOF checker and causes false positives. This dummy deref is
generated for constructors of classes that are modeled as being pointer types
instead of the actual class in infer, typically for smart pointers. I do not
understand how this works.

The biabduction also analyses this code, so might now get confused itself.

Reviewed By: jberdine

Differential Revision: D6221817

fbshipit-source-id: 050c5a9
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 0f1bdf664d
commit 525a94e470

@ -812,7 +812,7 @@ module Issue = struct
( if Config.developer_mode then
let num_pruned_issues = List.length issues - List.length issues' in
if num_pruned_issues > 0 then
L.user_warning "Note: pruned %d duplicate issues" num_pruned_issues ) ;
L.user_warning "Note: pruned %d duplicate issues@\n" num_pruned_issues ) ;
issues'
end

@ -1121,11 +1121,19 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
There is no LValueToRvalue cast in the AST afterwards since clang doesn't know
that class type is translated as pointer type. It gets added here instead. *)
let extra_res_trans =
match class_type.desc with
| Typ.Tptr _ ->
dereference_value_from_result sil_loc tmp_res_trans ~strip_pointer:false
| _ ->
tmp_res_trans
let do_extra_deref =
match class_type.desc with
| Typ.Tptr _ ->
(* do not inject the extra dereference for procedures generated to record the
initialization code of globals *)
Procdesc.get_proc_name trans_state.context.procdesc
|> Typ.Procname.get_global_name_of_initializer |> Option.is_none
| _ ->
false
in
if do_extra_deref then
dereference_value_from_result sil_loc tmp_res_trans ~strip_pointer:false
else tmp_res_trans
in
let res_trans_callee =
decl_ref_trans trans_state this_res_trans si decl_ref ~is_constructor_init:false

@ -25,8 +25,10 @@ SOURCES = \
siof/siof_templated.cpp \
siof/siof_different_tu.cpp \
siof/std_ios_base_init.cpp \
siof/smart_pointer1.cpp \
siof/smart_pointer2.cpp \
HEADERS = siof/siof_types.h
HEADERS = siof/siof_types.h siof/smart_pointer1.h
include $(TESTS_DIR)/clang.make

@ -0,0 +1,11 @@
/*
* Copyright (c) 2017 - 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.
*/
#include "smart_pointer1.h"
std::unique_ptr<int> InitWithConstexprStaticOK::foo_smart_pointer_;

@ -0,0 +1,26 @@
/*
* Copyright (c) 2017 - 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.
*/
#pragma once
// Some funkiness in infer's models of smart pointers make it add extra
// instructions after calls to the constructors, which trips SIOF. This tests
// the custom SIOF logic that unhacks the hack.
#include <memory>
class InitWithConstexprStaticOK {
public:
InitWithConstexprStaticOK() {
if (foo_smart_pointer_) {
}
}
private:
static std::unique_ptr<int> foo_smart_pointer_;
};

@ -0,0 +1,11 @@
/*
* Copyright (c) 2017 - 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.
*/
#include "smart_pointer1.h"
InitWithConstexprStaticOK initWithConstexprStaticOk;
Loading…
Cancel
Save