TypeGraph: Create dummy containers

These represent types which don't store any interesting data for us to
measure, but which are required by a real container so can not be
replaced with our own generated class types.

std::allocator often has bad DWARF, so it must be replaced after the
DWARF is fixed up in Flattener. The others could be replaced earlier in
the transformation process if desired, but I've left them all together
for simplicity for now.

This fixes the folly::fbstring tests.
This commit is contained in:
Alastair Robertson 2023-06-26 11:00:51 -07:00 committed by Alastair Robertson
parent 4dc9007166
commit 04715e2015
8 changed files with 36 additions and 21 deletions

View File

@ -20,7 +20,7 @@ workflows:
- build-gcc
oid_test_args: "-ftype-graph"
tests_regex: "OidIntegration\\..*"
exclude_regex: ".*inheritance_polymorphic.*|.*fbstring.*"
exclude_regex: ".*inheritance_polymorphic.*"
- coverage:
requires:
- test-gcc
@ -41,6 +41,7 @@ workflows:
- build-clang
oid_test_args: "-ftype-graph"
tests_regex: "OidIntegration\\..*"
# Tests disabled due to bad DWARF generated by the old clang compiler in CI
exclude_regex: ".*inheritance_polymorphic.*|.*fbstring.*|.*std_string_*|.*multi_arg_tb_.*|.*ignored_a"
executors:

View File

@ -46,5 +46,4 @@ containers = [
"PWD/types/std_variant.toml",
"PWD/types/thrift_isset_type.toml",
"PWD/types/weak_ptr_type.toml",
"PWD/types/std_char_traits.toml",
]

View File

@ -273,5 +273,6 @@ ContainerInfo::ContainerInfo(std::string typeName_,
: typeName(std::move(typeName_)),
matcher(getMatcher(typeName)),
ctype(ctype_),
header(std::move(header_)) {
header(std::move(header_)),
codegen(Codegen{"// DummyDecl %1%\n", "// DummyFunc %1%\n"}) {
}

View File

@ -15,6 +15,7 @@ add_library(type_graph
)
add_dependencies(type_graph libdrgn)
target_link_libraries(type_graph
container_info
symbol_service
"-L${DRGN_PATH}/.libs"

View File

@ -20,6 +20,15 @@
namespace type_graph {
// TODO:
// - read these from a TOML file
// - don't require specifying ctype and header
const std::array<ContainerInfo, 3> TypeIdentifier::dummyContainers_ = {
ContainerInfo{"std::allocator", DUMMY_TYPE, "memory"},
ContainerInfo{"std::char_traits", DUMMY_TYPE, "string"},
ContainerInfo{"folly::fbstring_core", DUMMY_TYPE, "folly/FBString.h"},
};
Pass TypeIdentifier::createPass() {
auto fn = [](TypeGraph& typeGraph) {
TypeIdentifier typeId{typeGraph};
@ -67,6 +76,24 @@ void TypeIdentifier::visit(Container& c) {
continue;
}
if (Class* paramClass = dynamic_cast<Class*>(param.type)) {
bool replaced = false;
for (const auto& info : dummyContainers_) {
if (std::regex_search(paramClass->fqName(), info.matcher)) {
// Create dummy containers
auto* dummy =
typeGraph_.make_type<Container>(info, param.type->size());
dummy->templateParams = paramClass->templateParams;
c.templateParams[i] = dummy;
replaced = true;
}
}
if (replaced) {
continue;
}
}
if (std::find(stubParams.begin(), stubParams.end(), i) !=
stubParams.end()) {
size_t size = param.type->size();

View File

@ -15,11 +15,13 @@
*/
#pragma once
#include <array>
#include <unordered_set>
#include "PassManager.h"
#include "Types.h"
#include "Visitor.h"
#include "oi/ContainerInfo.h"
namespace type_graph {
@ -46,6 +48,8 @@ class TypeIdentifier : public RecursiveVisitor {
private:
std::unordered_set<Type*> visited_;
TypeGraph& typeGraph_;
static const std::array<ContainerInfo, 3> dummyContainers_;
};
} // namespace type_graph

View File

@ -42,7 +42,6 @@ containers = [
"../types/std_variant.toml",
"../types/thrift_isset_type.toml",
"../types/weak_ptr_type.toml",
"../types/std_char_traits.toml",
]
[headers]

View File

@ -1,17 +0,0 @@
[info]
type_name = "std::char_traits"
ctype = "DUMMY_TYPE"
header = "string"
# Old:
typeName = "std::char_traits<"
ns = ["namespace std"]
numTemplateParams = 1
[codegen]
decl = """
// DummyDecl %1%
"""
func = """
// DummyFunc %1%
"""