[clang] add support for VarTemplateSpecializationDecl

Summary:
This was added in C++14. Was investigating how SIOF dealt with this but
it turns out it already does the right thing as the translation unit of
global variable templates shows up as the place they are instantiated
(not the one where they are declared), which works well for SIOF
checking.

Reviewed By: da319

Differential Revision: D27500998

fbshipit-source-id: b8b9b9c48
master
Jules Villard 4 years ago committed by Facebook GitHub Bot
parent d198cb855d
commit a5b4992873

@ -876,7 +876,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
enum_constant_trans trans_state decl_ref
| `Function, _ ->
function_deref_trans trans_state decl_ref
| (`Var | `ImplicitParam | `ParmVar), _ ->
| (`Var | `VarTemplateSpecialization | `ImplicitParam | `ParmVar), _ ->
var_deref_trans trans_state stmt_info decl_ref
| (`Field | `ObjCIvar), MemberOrIvar pre_trans_result ->
(* a field outside of constructor initialization is probably a pointer to member, which we

@ -84,7 +84,8 @@ let sil_var_of_decl context var_decl procname =
let trans_unit_ctx = context.CContext.translation_unit_context in
let open Clang_ast_t in
match var_decl with
| VarDecl (decl_info, name_info, qual_type, var_decl_info) ->
| VarDecl (decl_info, name_info, qual_type, var_decl_info)
| VarTemplateSpecializationDecl (decl_info, name_info, qual_type, var_decl_info) ->
let shoud_be_mangled = not (is_custom_var_pointer decl_info.Clang_ast_t.di_pointer) in
let var_decl_details = Some (decl_info, qual_type, var_decl_info, shoud_be_mangled) in
mk_sil_var trans_unit_ctx name_info var_decl_details procname outer_procname

@ -6,7 +6,7 @@
TESTS_DIR = ../../..
# see explanations in cpp/biabduction/Makefile for the custom isystem
CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(CLANG_INCLUDES)/c++/v1/ -c
CLANG_OPTIONS = -x c++ -std=c++14 -nostdinc++ -isystem$(CLANG_INCLUDES)/c++/v1/ -c
INFER_OPTIONS = --siof-only --siof-check-iostreams --debug-exceptions --project-root $(TESTS_DIR)
INFERPRINT_OPTIONS = --issues-tests

@ -16,11 +16,16 @@ struct SomeOtherTemplatedNonPODObject {
SomeOtherTemplatedNonPODObject() {
global_template_object.some_method(); // OK, same translation unit
extern_global_object.some_method(); // bad, different translation unit
};
}
SomeOtherTemplatedNonPODObject(int i) {
global_template_object.some_method(); // OK, same translation unit
};
}
SomeOtherTemplatedNonPODObject(int i, int j) {
// OK: declared in another file but instantiated in this translation unit
someTemplatedStatic<int>.some_method();
}
};
SomeOtherTemplatedNonPODObject<bool> another_templated_global_object_bad;
@ -29,3 +34,4 @@ SomeOtherTemplatedNonPODObject<bool> another_templated_global_object2_bad(
SomeOtherTemplatedNonPODObject<bool> another_templated_global_object3_bad(
access_to_templated_non_pod());
SomeOtherTemplatedNonPODObject<bool> another_templated_global_object4_good(42);
SomeOtherTemplatedNonPODObject<bool> access_variable_template_ok(32, 52);

@ -37,6 +37,11 @@ struct SomeTemplatedNonPODObject {
}
};
// C++14 template variables are initialized where they are used so do not
// participate in SIOF
template <typename T>
SomeTemplatedNonPODObject<T> someTemplatedStatic = {};
template <typename T>
class SomeTemplatedConstexprObject {
public:

Loading…
Cancel
Save