[clang] Translate everything coming from <X>.h files when translating <X>.cpp source

Summary:
Implement heuristic to capture more of the user code:
In C++ there is a lot of interesting code in header files. On the other hand,
that code gets included in multiple places and we don't want to capture it by default (for performance reasons).
Right now we capture everything from source file + all symbols from headers that source file needs.

New heuristic will extend "capturing everything" to  matching header files (ie. capture everything in X.h if source file is X.cpp)

Reviewed By: jberdine

Differential Revision: D4238008

fbshipit-source-id: 0528250
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 6192cb98b4
commit 9d6a6510e8

@ -54,6 +54,11 @@ let should_translate trans_unit_ctx (loc_start, loc_end) decl_trans_context ~tra
which uses same logic to produce both files *)
let equal_current_source = DB.source_file_equal trans_unit_ctx.CFrontend_config.source_file
in
let equal_header_of_current_source maybe_header =
(* DB.source_file_of_header will cache calls to filesystem *)
let source_of_header_opt = DB.source_file_of_header maybe_header in
Option.map_default equal_current_source false source_of_header_opt
in
let file_in_project = map_file_of source_file_in_project loc_end
|| map_file_of source_file_in_project loc_start in
let translate_on_demand = translate_when_used || file_in_project || Config.models_mode in
@ -62,6 +67,7 @@ let should_translate trans_unit_ctx (loc_start, loc_end) decl_trans_context ~tra
map_file_of equal_current_source loc_end
|| map_file_of equal_current_source loc_start
|| file_in_models
|| (Config.cxx_experimental && map_file_of equal_header_of_current_source loc_start)
|| (Config.cxx_experimental && decl_trans_context = `Translation && translate_on_demand
&& not Config.testing_mode)

@ -9,8 +9,8 @@
#include <memory>
#include <string>
#include "main.h"
#include "project_lib.h"
#include "external/external_lib.h"
#include "exclude_dir/lib.h"

@ -60,6 +60,32 @@ digraph iCFG {
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_7" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" [label="3: Return Stmt \n n$0=*&a:int [line 19]\n *&return:int=n$0 [line 19]\n " shape="box"]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" [label="2: Exit internal::used_in_main_header \n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" [label="1: Start internal::used_in_main_header\nFormals: a:int\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" [label="4: DeclStmt \n n$2=_fun_internal::used_in_main_header(0:int) [line 17]\n *&x:int=n$2 [line 17]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" [label="3: Return Stmt \n n$0=*&a:int* [line 18]\n n$1=*n$0:int [line 18]\n *&return:int=n$1 [line 18]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" [label="2: Exit unused_deref_in_header \n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" [label="1: Start unused_deref_in_header\nFormals: a:int*\nLocals: x:int \n DECLARE_LOCALS(&return,&x); [line 16]\n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" ;
"std::__1::shared_ptr<int>_reset<int,_void>(_ZNSt3__110shared_ptrIiE5resetIivEEvPT_).29e462552cba695192437aa4bfbf146e_3" [label="3: Call _fun_std::__1::shared_ptr<int>_model_set \n n$0=*&this:int** [line 223]\n n$1=*&p:int* [line 223]\n _fun_std::__1::shared_ptr<int>_model_set(n$0:void**,n$1:void*) [line 223]\n " shape="box"]

@ -0,0 +1,19 @@
/*
* 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.
*/
#pragma once
#include "project_lib.h"
// even though it's unused, it should be translated if compiled source is
// main.cpp (or a symbolic link pointing to it)
int unused_deref_in_header(int* a) {
int x = internal::used_in_main_header(0);
return *a;
}

@ -60,6 +60,32 @@ digraph iCFG {
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_7" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" [label="3: Return Stmt \n n$0=*&a:int [line 19]\n *&return:int=n$0 [line 19]\n " shape="box"]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" [label="2: Exit internal::used_in_main_header \n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" [label="1: Start internal::used_in_main_header\nFormals: a:int\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" [label="4: DeclStmt \n n$2=_fun_internal::used_in_main_header(0:int) [line 17]\n *&x:int=n$2 [line 17]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" [label="3: Return Stmt \n n$0=*&a:int* [line 18]\n n$1=*n$0:int [line 18]\n *&return:int=n$1 [line 18]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" [label="2: Exit unused_deref_in_header \n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" [label="1: Start unused_deref_in_header\nFormals: a:int*\nLocals: x:int \n DECLARE_LOCALS(&return,&x); [line 16]\n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" ;
"std::__1::shared_ptr<int>_reset<int,_void>(_ZNSt3__110shared_ptrIiE5resetIivEEvPT_).29e462552cba695192437aa4bfbf146e_3" [label="3: Call _fun_std::__1::shared_ptr<int>_model_set \n n$0=*&this:int** [line 223]\n n$1=*&p:int* [line 223]\n _fun_std::__1::shared_ptr<int>_model_set(n$0:void**,n$1:void*) [line 223]\n " shape="box"]

@ -60,6 +60,32 @@ digraph iCFG {
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_7" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" [label="3: Return Stmt \n n$0=*&a:int [line 19]\n *&return:int=n$0 [line 19]\n " shape="box"]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" [label="2: Exit internal::used_in_main_header \n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" [label="1: Start internal::used_in_main_header\nFormals: a:int\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" [label="4: DeclStmt \n n$2=_fun_internal::used_in_main_header(0:int) [line 17]\n *&x:int=n$2 [line 17]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" [label="3: Return Stmt \n n$0=*&a:int* [line 18]\n n$1=*n$0:int [line 18]\n *&return:int=n$1 [line 18]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" [label="2: Exit unused_deref_in_header \n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" [label="1: Start unused_deref_in_header\nFormals: a:int*\nLocals: x:int \n DECLARE_LOCALS(&return,&x); [line 16]\n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" ;
"std::__1::shared_ptr<int>_reset<int,_void>(_ZNSt3__110shared_ptrIiE5resetIivEEvPT_).29e462552cba695192437aa4bfbf146e_3" [label="3: Call _fun_std::__1::shared_ptr<int>_model_set \n n$0=*&this:int** [line 223]\n n$1=*&p:int* [line 223]\n _fun_std::__1::shared_ptr<int>_model_set(n$0:void**,n$1:void*) [line 223]\n " shape="box"]

@ -60,6 +60,32 @@ digraph iCFG {
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_7" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" [label="3: Return Stmt \n n$0=*&a:int [line 19]\n *&return:int=n$0 [line 19]\n " shape="box"]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" ;
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_2" [label="2: Exit internal::used_in_main_header \n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" [label="1: Start internal::used_in_main_header\nFormals: a:int\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
"internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_1" -> "internal::used_in_main_header{d41d8cd98f00b204e9800998ecf8427e_ZN8internal19used_in_main_headerEi}.09c1faf931b185e882c0654aa991822d_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" [label="4: DeclStmt \n n$2=_fun_internal::used_in_main_header(0:int) [line 17]\n *&x:int=n$2 [line 17]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" [label="3: Return Stmt \n n$0=*&a:int* [line 18]\n n$1=*n$0:int [line 18]\n *&return:int=n$1 [line 18]\n " shape="box"]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_3" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" ;
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_2" [label="2: Exit unused_deref_in_header \n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" [label="1: Start unused_deref_in_header\nFormals: a:int*\nLocals: x:int \n DECLARE_LOCALS(&return,&x); [line 16]\n " color=yellow style=filled]
"unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_1" -> "unused_deref_in_header{d41d8cd98f00b204e9800998ecf8427e_Z22unused_deref_in_headerPi}.78f023ac84a54d52e15a570dccffee2c_4" ;
"std::__1::shared_ptr<int>_reset<int,_void>(_ZNSt3__110shared_ptrIiE5resetIivEEvPT_).29e462552cba695192437aa4bfbf146e_3" [label="3: Call _fun_std::__1::shared_ptr<int>_model_set \n n$0=*&this:int** [line 223]\n n$1=*&p:int* [line 223]\n _fun_std::__1::shared_ptr<int>_model_set(n$0:void**,n$1:void*) [line 223]\n " shape="box"]

@ -13,4 +13,8 @@ int fun(int a) { return a; }
// function shouldn't be translated if it's not used in source file
int unused(int a) { return a; }
// function should be translated because it's used in header corresponding
// to source file
int used_in_main_header(int a) { return a; }
}

Loading…
Cancel
Save