From db289c1a1a70f6dc2a818aa1dd69d89c9c2b4b99 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Wed, 31 Jan 2024 17:13:43 +0000 Subject: [PATCH] tbv2: use std::decay_t with smart pointers CodeGen v2 permits template parameters to be qualified. This means that if we call `make_field` with a template parameter it will be qualified. However, we don't qualify the types when generating meta functions such as `NameProvider` and `TypeHandler`. This means these qualified types don't match up with the expected type. Use `std::decay_t` when forwarding the type to `NameProvider` and `TypeHandler` so they're always the base type that they were generated with. Most of this is covered by `make_field`, but there are direct references to `TypeHandler` in a lot of `TypeHandler::type` fields. Fix the problematic types manually for now, there may need to be a better solution with meta functions for this in the future. Test Plan: - CI - Added a test for `std::unique_ptr` to exercise this. Failed before, passes after. - Added a test for `std::unique_ptr>` to test a non-primitive type. Failed before, passes after. --- oi/FuncGen.cpp | 8 +-- test/integration/std_smart_ptr.toml | 97 +++++++++++++++++++++++++++++ types/shrd_ptr_type.toml | 2 +- types/uniq_ptr_type.toml | 2 +- 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/oi/FuncGen.cpp b/oi/FuncGen.cpp index fbe6658..11298ca 100644 --- a/oi/FuncGen.cpp +++ b/oi/FuncGen.cpp @@ -625,11 +625,11 @@ template constexpr inst::Field make_field(std::string_view name) { return inst::Field{ sizeof(T), - ExclusiveSizeProvider::size, + ExclusiveSizeProvider>::size, name, - NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, + NameProvider>::names, + TypeHandler>::fields, + TypeHandler>::processors, std::is_fundamental_v, }; } diff --git a/test/integration/std_smart_ptr.toml b/test/integration/std_smart_ptr.toml index c9ab383..d0bddb6 100644 --- a/test/integration/std_smart_ptr.toml +++ b/test/integration/std_smart_ptr.toml @@ -32,6 +32,31 @@ definitions = ''' } ] ''' + [cases.unique_ptr_const_uint64_empty] + param_types = ["std::unique_ptr&"] + setup = "return {nullptr};" + expect_json = ''' + [ + { + "staticSize": 8, + "dynamicSize": 0, + "exclusiveSize": 8, + "length": 0, + "capacity": 1, + "elementStaticSize": 8 + } + ] + ''' + expect_json_v2 = ''' + [ + { + "staticSize": 8, + "exclusiveSize": 8, + "length": 0, + "capacity": 1 + } + ] + ''' [cases.unique_ptr_uint64_present] param_types = ["std::unique_ptr&"] setup = "return {std::make_unique(64)};" @@ -82,6 +107,30 @@ definitions = ''' } ] ''' + [cases.unique_ptr_const_vector_empty] + param_types = ["std::unique_ptr>&"] + setup = "return {nullptr};" + expect_json = ''' + [ + { + "staticSize": 8, + "dynamicSize": 0, + "length": 0, + "capacity": 1, + "elementStaticSize": 24 + } + ] + ''' + expect_json_v2 = ''' + [ + { + "staticSize": 8, + "exclusiveSize": 8, + "length": 0, + "capacity": 1 + } + ] + ''' [cases.unique_ptr_vector_present] param_types = ["std::unique_ptr>&"] setup = "return {std::make_unique>(std::initializer_list({1,2,3,4,5}))};" @@ -188,6 +237,30 @@ definitions = ''' } ] ''' + [cases.shared_ptr_const_uint64_empty] + param_types = ["std::shared_ptr&"] + setup = "return {nullptr};" + expect_json = ''' + [ + { + "staticSize": 16, + "dynamicSize": 0, + "length": 0, + "capacity": 1, + "elementStaticSize": 8 + } + ] + ''' + expect_json_v2 = ''' + [ + { + "staticSize": 16, + "exclusiveSize": 16, + "length": 0, + "capacity": 1 + } + ] + ''' [cases.shared_ptr_uint64_present] param_types = ["std::shared_ptr&"] setup = "return std::make_shared(64);" @@ -241,6 +314,30 @@ definitions = ''' } ] ''' + [cases.shared_ptr_const_vector_empty] + param_types = ["std::shared_ptr>&"] + setup = "return {nullptr};" + expect_json = ''' + [ + { + "staticSize": 16, + "dynamicSize": 0, + "length": 0, + "capacity": 1, + "elementStaticSize": 24 + } + ] + ''' + expect_json_v2 = ''' + [ + { + "staticSize": 16, + "exclusiveSize": 16, + "length": 0, + "capacity": 1 + } + ] + ''' [cases.shared_ptr_vector_present] param_types = ["std::shared_ptr>&"] setup = "return std::make_shared>(std::initializer_list({1,2,3,4,5}));" diff --git a/types/shrd_ptr_type.toml b/types/shrd_ptr_type.toml index 3439bf3..ab42eef 100644 --- a/types/shrd_ptr_type.toml +++ b/types/shrd_ptr_type.toml @@ -60,7 +60,7 @@ el.pointer = std::get(d.val).value; type = """ types::st::Sum, - typename TypeHandler::type> + typename TypeHandler>::type> """ func = """ #ifdef __GLIBCXX__ diff --git a/types/uniq_ptr_type.toml b/types/uniq_ptr_type.toml index f71cff4..90663a4 100644 --- a/types/uniq_ptr_type.toml +++ b/types/uniq_ptr_type.toml @@ -61,7 +61,7 @@ el.pointer = std::get(d.val).value; type = """ types::st::Sum, - typename TypeHandler::type> + typename TypeHandler>::type> """ func = """ auto sum = std::get(d.val);