aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--comparison.cc31
-rw-r--r--comparison.h31
-rw-r--r--equality.h15
-rw-r--r--fidelity.cc13
-rw-r--r--fingerprint.cc17
-rw-r--r--graph.h53
-rw-r--r--naming.cc14
-rw-r--r--naming.h4
-rw-r--r--proto_reader.cc19
-rw-r--r--proto_writer.cc27
-rw-r--r--stable_hash.cc17
-rw-r--r--stable_hash.h4
-rw-r--r--stg.proto31
-rw-r--r--substitution.h11
-rw-r--r--test_cases/abigail_reader/array/multidimensional_c.xml (renamed from test_cases/abigail_reader/array/multidimensional.c.xml)0
-rw-r--r--test_cases/abigail_reader/array/multidimensional_cc.xml (renamed from test_cases/abigail_reader/array/multidimensional.cc.xml)0
-rw-r--r--test_cases/abigail_reader/array/simple_array_c.xml (renamed from test_cases/abigail_reader/array/simple_array.c.xml)0
-rw-r--r--test_cases/abigail_reader/array/simple_array_cc.xml (renamed from test_cases/abigail_reader/array/simple_array.cc.xml)0
-rw-r--r--test_cases/abigail_reader/array/unknown_size_c.xml (renamed from test_cases/abigail_reader/array/unknown_size.c.xml)0
-rw-r--r--test_cases/abigail_reader/array/unknown_size_extern_c.xml (renamed from test_cases/abigail_reader/array/unknown_size_extern.c.xml)0
-rw-r--r--test_cases/abigail_reader/array/variable_length_c.xml (renamed from test_cases/abigail_reader/array/variable_length.c.xml)0
-rw-r--r--test_cases/abigail_reader/composite/abstract_base_class_cc.xml (renamed from test_cases/abigail_reader/composite/abstract_base_class.cc.xml)0
-rw-r--r--test_cases/abigail_reader/composite/anonymous_cc.xml (renamed from test_cases/abigail_reader/composite/anonymous.cc.xml)0
-rw-r--r--test_cases/abigail_reader/composite/anonymous_member_c.xml (renamed from test_cases/abigail_reader/composite/anonymous_member.c.xml)0
-rw-r--r--test_cases/abigail_reader/composite/anonymous_member_chain_c.xml (renamed from test_cases/abigail_reader/composite/anonymous_member_chain.c.xml)0
-rw-r--r--test_cases/abigail_reader/composite/base_class_order_cc.xml (renamed from test_cases/abigail_reader/composite/base_class_order.cc.xml)0
-rw-r--r--test_cases/abigail_reader/composite/base_class_size_cc.xml (renamed from test_cases/abigail_reader/composite/base_class_size.cc.xml)0
-rw-r--r--test_cases/abigail_reader/composite/forward_c.xml (renamed from test_cases/abigail_reader/composite/forward.c.xml)0
-rw-r--r--test_cases/abigail_reader/composite/kind_cc.xml (renamed from test_cases/abigail_reader/composite/kind.cc.xml)0
-rw-r--r--test_cases/abigail_reader/composite/virtual_inheritance_cc.xml (renamed from test_cases/abigail_reader/composite/virtual_inheritance.cc.xml)0
-rw-r--r--test_cases/abigail_reader/composite/virtual_only_base_class_cc.xml (renamed from test_cases/abigail_reader/composite/virtual_only_base_class.cc.xml)0
-rw-r--r--test_cases/abigail_reader/enum/anonymous_c.xml (renamed from test_cases/abigail_reader/enum/anonymous.c.xml)0
-rw-r--r--test_cases/abigail_reader/enum/declaration_only_c.xml (renamed from test_cases/abigail_reader/enum/declaration_only.c.xml)0
-rw-r--r--test_cases/abigail_reader/enum/fixed_underlying_type_cc.xml (renamed from test_cases/abigail_reader/enum/fixed_underlying_type.cc.xml)0
-rw-r--r--test_cases/abigail_reader/enum/limits_c.xml (renamed from test_cases/abigail_reader/enum/limits.c.xml)0
-rw-r--r--test_cases/abigail_reader/enum/simple_c.xml (renamed from test_cases/abigail_reader/enum/simple.c.xml)0
-rw-r--r--test_cases/abigail_reader/function/array_parameter_c.xml (renamed from test_cases/abigail_reader/function/array_parameter.c.xml)0
-rw-r--r--test_cases/abigail_reader/function/methods_cc.xml (renamed from test_cases/abigail_reader/function/methods.cc.xml)0
-rw-r--r--test_cases/abigail_reader/function/parameters_c.xml (renamed from test_cases/abigail_reader/function/parameters.c.xml)0
-rw-r--r--test_cases/abigail_reader/function/parameters_cc.xml (renamed from test_cases/abigail_reader/function/parameters.cc.xml)0
-rw-r--r--test_cases/abigail_reader/function/static_method_cc.xml (renamed from test_cases/abigail_reader/function/static_method.cc.xml)0
-rw-r--r--test_cases/abigail_reader/function/variadic_parameter_cc.xml (renamed from test_cases/abigail_reader/function/variadic_parameter.cc.xml)0
-rw-r--r--test_cases/abigail_reader/function/virtual_method_cc.xml (renamed from test_cases/abigail_reader/function/virtual_method.cc.xml)0
-rw-r--r--test_cases/abigail_reader/member/member_types_cc.xml (renamed from test_cases/abigail_reader/member/member_types.cc.xml)0
-rw-r--r--test_cases/abigail_reader/member/pointer_to_member_cc.xml (renamed from test_cases/abigail_reader/member/pointer_to_member.cc.xml)0
-rw-r--r--test_cases/abigail_reader/misc/enum_c.xml (renamed from test_cases/abigail_reader/misc/enum.c.xml)0
-rw-r--r--test_cases/abigail_reader/misc/enum_cc.xml (renamed from test_cases/abigail_reader/misc/enum.cc.xml)0
-rw-r--r--test_cases/abigail_reader/misc/enum_const_c.xml (renamed from test_cases/abigail_reader/misc/enum_const.c.xml)0
-rw-r--r--test_cases/abigail_reader/namespace/nested_anonymous_types_cc.xml (renamed from test_cases/abigail_reader/namespace/nested_anonymous_types.cc.xml)0
-rw-r--r--test_cases/abigail_reader/namespace/nested_cc.xml (renamed from test_cases/abigail_reader/namespace/nested.cc.xml)0
-rw-r--r--test_cases/abigail_reader/namespace/simple_cc.xml (renamed from test_cases/abigail_reader/namespace/simple.cc.xml)0
-rw-r--r--test_cases/abigail_reader/namespace/using_namespace_in_function_cc.xml (renamed from test_cases/abigail_reader/namespace/using_namespace_in_function.cc.xml)0
-rw-r--r--test_cases/abigail_reader/primitive/all_c99_types_c.xml (renamed from test_cases/abigail_reader/primitive/all_c99_types.c.xml)0
-rw-r--r--test_cases/abigail_reader/primitive/long_c.xml (renamed from test_cases/abigail_reader/primitive/long.c.xml)0
-rw-r--r--test_cases/abigail_reader/qualified/const_long_c.xml (renamed from test_cases/abigail_reader/qualified/const_long.c.xml)0
-rw-r--r--test_cases/abigail_reader/qualified/int_c.xml (renamed from test_cases/abigail_reader/qualified/int.c.xml)0
-rw-r--r--test_cases/abigail_reader/qualified/pointers_c.xml (renamed from test_cases/abigail_reader/qualified/pointers.c.xml)0
-rw-r--r--test_cases/abigail_reader/qualified/useless_c.xml (renamed from test_cases/abigail_reader/qualified/useless.c.xml)0
-rw-r--r--test_cases/abigail_reader/reference/type_cc.xml (renamed from test_cases/abigail_reader/reference/type.cc.xml)0
-rw-r--r--test_cases/abigail_reader/scc/same_c.xml (renamed from test_cases/abigail_reader/scc/same.c.xml)0
-rw-r--r--test_cases/abigail_reader/scc/simple_c.xml (renamed from test_cases/abigail_reader/scc/simple.c.xml)0
-rw-r--r--test_cases/abigail_reader/static/simple_cc.xml (renamed from test_cases/abigail_reader/static/simple.cc.xml)0
-rw-r--r--test_cases/abigail_reader/struct/anonymous_c.xml (renamed from test_cases/abigail_reader/struct/anonymous.c.xml)0
-rw-r--r--test_cases/abigail_reader/struct/bit_field_c.xml (renamed from test_cases/abigail_reader/struct/bit_field.c.xml)0
-rw-r--r--test_cases/abigail_reader/struct/declaration_only_c.xml (renamed from test_cases/abigail_reader/struct/declaration_only.c.xml)0
-rw-r--r--test_cases/abigail_reader/struct/nested_c.xml (renamed from test_cases/abigail_reader/struct/nested.c.xml)0
-rw-r--r--test_cases/abigail_reader/struct/nested_cc.xml (renamed from test_cases/abigail_reader/struct/nested.cc.xml)0
-rw-r--r--test_cases/abigail_reader/struct/struct_union_c.xml (renamed from test_cases/abigail_reader/struct/struct_union.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/absolute_object_c.xml (renamed from test_cases/abigail_reader/symbol/absolute_object.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/alias_c.xml (renamed from test_cases/abigail_reader/symbol/alias.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/ifunc_c.xml (renamed from test_cases/abigail_reader/symbol/ifunc.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/tls_c.xml (renamed from test_cases/abigail_reader/symbol/tls.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/tls_cc.xml (renamed from test_cases/abigail_reader/symbol/tls.cc.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/version_definition_c.xml (renamed from test_cases/abigail_reader/symbol/version_definition.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/version_need_c.xml (renamed from test_cases/abigail_reader/symbol/version_need.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/visibility_c.xml (renamed from test_cases/abigail_reader/symbol/visibility.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/visibility_cc.xml (renamed from test_cases/abigail_reader/symbol/visibility.cc.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/weak_c.xml (renamed from test_cases/abigail_reader/symbol/weak.c.xml)0
-rw-r--r--test_cases/abigail_reader/symbol/weak_cc.xml (renamed from test_cases/abigail_reader/symbol/weak.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/template_class_cc.xml (renamed from test_cases/abigail_reader/template/template_class.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/template_function_cc.xml (renamed from test_cases/abigail_reader/template/template_function.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/template_member_function_cc.xml (renamed from test_cases/abigail_reader/template/template_member_function.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/template_typedef_cc.xml (renamed from test_cases/abigail_reader/template/template_typedef.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/variadic_template_alias_cc.xml (renamed from test_cases/abigail_reader/template/variadic_template_alias.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/variadic_template_class_cc.xml (renamed from test_cases/abigail_reader/template/variadic_template_class.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/variadic_template_function_cc.xml (renamed from test_cases/abigail_reader/template/variadic_template_function.cc.xml)0
-rw-r--r--test_cases/abigail_reader/template/variadic_template_variable_cc.xml (renamed from test_cases/abigail_reader/template/variadic_template_variable.cc.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/chain_c.xml (renamed from test_cases/abigail_reader/typedef/chain.c.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/nullptr_cc.xml (renamed from test_cases/abigail_reader/typedef/nullptr.cc.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/scoped_composite_nested_struct_cc.xml (renamed from test_cases/abigail_reader/typedef/scoped_composite_nested_struct.cc.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/simple_c.xml (renamed from test_cases/abigail_reader/typedef/simple.c.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/simple_cc.xml (renamed from test_cases/abigail_reader/typedef/simple.cc.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/using_and_typedef_cc.xml (renamed from test_cases/abigail_reader/typedef/using_and_typedef.cc.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/using_in_function_cc.xml (renamed from test_cases/abigail_reader/typedef/using_in_function.cc.xml)0
-rw-r--r--test_cases/abigail_reader/typedef/void_typedef_c.xml (renamed from test_cases/abigail_reader/typedef/void_typedef.c.xml)0
-rw-r--r--test_cases/abigail_reader/types/char_c.xml (renamed from test_cases/abigail_reader/types/char.c.xml)0
-rw-r--r--test_cases/abigail_reader/types/pointer_c.xml (renamed from test_cases/abigail_reader/types/pointer.c.xml)0
-rw-r--r--test_cases/abigail_reader/types/pointer_reference_cc.xml (renamed from test_cases/abigail_reader/types/pointer_reference.cc.xml)0
-rw-r--r--test_cases/info_tests/enum/expected/methods_rs.elf_stg53
-rw-r--r--test_cases/info_tests/enum/methods.rs14
-rw-r--r--test_cases/info_tests/variant/expected/simple_rs.elf_stg33
-rw-r--r--test_cases/info_tests/variant/simple.rs14
-rw-r--r--type_normalisation.cc11
-rw-r--r--type_resolution.cc16
-rw-r--r--unification.cc17
106 files changed, 410 insertions, 39 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9587c6a..38bb294 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -117,11 +117,11 @@ endforeach()
# Testing
-find_package(Catch2 QUIET)
+find_package(Catch2 2 QUIET)
if(NOT Catch2_FOUND)
- message(NOTICE "Catch2 testing framework not found. Disabling tests.")
+ message(NOTICE "Catch2 v2 testing framework not found. Disabling tests.")
else()
enable_testing()
diff --git a/comparison.cc b/comparison.cc
index ca821f9..8e0dacb 100644
--- a/comparison.cc
+++ b/comparison.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2020-2022 Google LLC
+// Copyright 2020-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -454,6 +454,14 @@ Result Compare::operator()(const Member& x1, const Member& x2) {
return result;
}
+Result Compare::operator()(const VariantMember& x1, const VariantMember& x2) {
+ Result result;
+ result.MaybeAddNodeDiff("discriminant", x1.discriminant_value,
+ x2.discriminant_value);
+ result.MaybeAddEdgeDiff("", (*this)(x1.type_id, x2.type_id));
+ return result;
+}
+
Result Compare::operator()(const StructUnion& x1, const StructUnion& x2) {
Result result;
// Compare two anonymous types recursively, not holding diffs.
@@ -552,6 +560,23 @@ Result Compare::operator()(const Enumeration& x1, const Enumeration& x2) {
return result;
}
+Result Compare::operator()(const Variant& x1, const Variant& x2) {
+ Result result;
+ // Compare two identically named variants recursively, holding diffs.
+ // Everything else treated as distinct. No recursion.
+ if (x1.name != x2.name) {
+ return result.MarkIncomparable();
+ }
+ result.diff_.holds_changes = true; // Anonymous variants are not allowed.
+
+ result.MaybeAddNodeDiff("bytesize", x1.bytesize, x2.bytesize);
+ const auto type_diff =
+ (*this)(x1.discriminant_type_id, x2.discriminant_type_id);
+ result.MaybeAddEdgeDiff("discriminant", type_diff);
+ CompareNodes(result, *this, x1.members, x2.members);
+ return result;
+}
+
Result Compare::operator()(const Function& x1, const Function& x2) {
Result result;
const auto type_diff = (*this)(x1.return_type_id, x2.return_type_id);
@@ -751,6 +776,10 @@ std::string MatchingKey::operator()(const Member& x) {
return (*this)(x.type_id);
}
+std::string MatchingKey::operator()(const VariantMember& x) {
+ return x.name;
+}
+
std::string MatchingKey::operator()(const StructUnion& x) {
if (!x.name.empty()) {
return x.name;
diff --git a/comparison.h b/comparison.h
index 693c55a..81eccf5 100644
--- a/comparison.h
+++ b/comparison.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2020-2023 Google LLC
+// Copyright 2020-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -23,6 +23,7 @@
#define STG_COMPARISON_H_
#include <cstddef>
+#include <cstdint>
#include <functional>
#include <map>
#include <memory>
@@ -32,7 +33,6 @@
#include <sstream>
#include <string>
#include <string_view>
-#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -46,19 +46,19 @@ namespace stg {
struct Ignore {
enum Value {
// noise reduction
- SYMBOL_TYPE_PRESENCE = 1<<0,
- TYPE_DECLARATION_STATUS = 1<<1,
- PRIMITIVE_TYPE_ENCODING = 1<<2,
- MEMBER_SIZE = 1<<3,
- ENUM_UNDERLYING_TYPE = 1<<4,
- QUALIFIER = 1<<5,
- SYMBOL_CRC = 1<<6,
+ SYMBOL_TYPE_PRESENCE,
+ TYPE_DECLARATION_STATUS,
+ PRIMITIVE_TYPE_ENCODING,
+ MEMBER_SIZE,
+ ENUM_UNDERLYING_TYPE,
+ QUALIFIER,
+ SYMBOL_CRC,
// ABI compatibility testing
- INTERFACE_ADDITION = 1<<7,
- TYPE_DEFINITION_ADDITION = 1<<8,
+ INTERFACE_ADDITION,
+ TYPE_DEFINITION_ADDITION,
};
- using Bitset = std::underlying_type_t<Value>;
+ using Bitset = uint16_t;
Ignore() = default;
template <typename... Values>
@@ -69,10 +69,10 @@ struct Ignore {
}
void Set(Value other) {
- bitset |= static_cast<Bitset>(other);
+ bitset = bitset | (1 << other);
}
bool Test(Value other) const {
- return bitset & static_cast<Bitset>(other);
+ return bitset & (1 << other);
}
Bitset bitset = 0;
@@ -214,6 +214,7 @@ struct MatchingKey {
std::string operator()(const BaseClass&);
std::string operator()(const Method&);
std::string operator()(const Member&);
+ std::string operator()(const VariantMember&);
std::string operator()(const StructUnion&);
template <typename Node>
std::string operator()(const Node&);
@@ -284,8 +285,10 @@ struct Compare {
Result operator()(const BaseClass&, const BaseClass&);
Result operator()(const Method&, const Method&);
Result operator()(const Member&, const Member&);
+ Result operator()(const VariantMember&, const VariantMember&);
Result operator()(const StructUnion&, const StructUnion&);
Result operator()(const Enumeration&, const Enumeration&);
+ Result operator()(const Variant&, const Variant&);
Result operator()(const Function&, const Function&);
Result operator()(const ElfSymbol&, const ElfSymbol&);
Result operator()(const Interface&, const Interface&);
diff --git a/equality.h b/equality.h
index 77cd1a4..eb47db9 100644
--- a/equality.h
+++ b/equality.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -160,6 +160,12 @@ struct Equals {
&& (*this)(x1.type_id, x2.type_id);
}
+ bool operator()(const VariantMember& x1, const VariantMember& x2) {
+ return x1.name == x2.name
+ && x1.discriminant_value == x2.discriminant_value
+ && (*this)(x1.type_id, x2.type_id);
+ }
+
bool operator()(const StructUnion& x1, const StructUnion& x2) {
const auto& definition1 = x1.definition;
const auto& definition2 = x2.definition;
@@ -188,6 +194,13 @@ struct Equals {
return result;
}
+ bool operator()(const Variant& x1, const Variant& x2) {
+ return x1.name == x2.name
+ && x1.bytesize == x2.bytesize
+ && (*this)(x1.discriminant_type_id, x2.discriminant_type_id)
+ && (*this)(x1.members, x2.members);
+ }
+
bool operator()(const Function& x1, const Function& x2) {
return (*this)(x1.parameters, x2.parameters)
&& (*this)(x1.return_type_id, x2.return_type_id);
diff --git a/fidelity.cc b/fidelity.cc
index 89c3c8c..66ab9d2 100644
--- a/fidelity.cc
+++ b/fidelity.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2023 Google LLC
+// Copyright 2023-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -53,8 +53,10 @@ struct Fidelity {
void operator()(const BaseClass&, Id);
void operator()(const Method&, Id);
void operator()(const Member&, Id);
+ void operator()(const VariantMember&, Id);
void operator()(const StructUnion&, Id);
void operator()(const Enumeration&, Id);
+ void operator()(const Variant&, Id);
void operator()(const Function&, Id);
void operator()(const ElfSymbol&, Id);
void operator()(const Interface&, Id);
@@ -121,6 +123,10 @@ void Fidelity::operator()(const Member& x, Id) {
(*this)(x.type_id);
}
+void Fidelity::operator()(const VariantMember& x, Id) {
+ (*this)(x.type_id);
+}
+
void Fidelity::operator()(const StructUnion& x, Id id) {
if (!x.name.empty()) {
auto [it, _] =
@@ -146,6 +152,11 @@ void Fidelity::operator()(const Enumeration& x, Id id) {
}
}
+void Fidelity::operator()(const Variant& x, Id id) {
+ types.emplace(describe(id).ToString(), TypeFidelity::FULLY_DEFINED);
+ (*this)(x.members);
+}
+
void Fidelity::operator()(const Function& x, Id) {
(*this)(x.return_type_id);
(*this)(x.parameters);
diff --git a/fingerprint.cc b/fingerprint.cc
index b97b2ff..05a4cdc 100644
--- a/fingerprint.cc
+++ b/fingerprint.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -16,6 +16,7 @@
// limitations under the License.
//
// Author: Giuliano Procida
+// Author: Siddharth Nayyar
#include "fingerprint.h"
@@ -92,6 +93,14 @@ struct Hasher {
return hash('D', x.name, x.offset, (*this)(x.type_id));
}
+ HashValue operator()(const VariantMember& x) {
+ auto h = hash('m', x.name, (*this)(x.type_id));
+ if (x.discriminant_value) {
+ h = hash(h, *x.discriminant_value);
+ }
+ return h;
+ }
+
HashValue operator()(const StructUnion& x) {
auto h = hash('U', static_cast<uint32_t>(x.kind), x.name);
if (x.definition.has_value()) {
@@ -129,6 +138,12 @@ struct Hasher {
return h;
}
+ HashValue operator()(const Variant& x) {
+ auto h = hash('v', x.name, x.bytesize, (*this)(x.discriminant_type_id));
+ ToDo(x.members);
+ return h;
+ }
+
HashValue operator()(const Function& x) {
auto h = hash('F', (*this)(x.return_type_id));
for (const auto& parameter : x.parameters) {
diff --git a/graph.h b/graph.h
index 5f3cd73..f75173a 100644
--- a/graph.h
+++ b/graph.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2020-2023 Google LLC
+// Copyright 2020-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -200,6 +200,16 @@ struct Member {
uint64_t bitsize;
};
+struct VariantMember {
+ VariantMember(const std::string& name,
+ std::optional<int64_t> discriminant_value, Id type_id)
+ : name(name), discriminant_value(discriminant_value), type_id(type_id) {}
+
+ std::string name;
+ std::optional<int64_t> discriminant_value;
+ Id type_id;
+};
+
struct StructUnion {
enum class Kind { STRUCT, UNION };
struct Definition {
@@ -238,6 +248,20 @@ struct Enumeration {
std::optional<Definition> definition;
};
+struct Variant {
+ Variant(const std::string& name, uint64_t bytesize, Id discriminant_type_id,
+ const std::vector<Id>& members)
+ : name(name),
+ bytesize(bytesize),
+ discriminant_type_id(discriminant_type_id),
+ members(members) {}
+
+ std::string name;
+ uint64_t bytesize;
+ Id discriminant_type_id;
+ std::vector<Id> members;
+};
+
struct Function {
Function(Id return_type_id, const std::vector<Id>& parameters)
: return_type_id(return_type_id), parameters(parameters) {}
@@ -377,12 +401,18 @@ class Graph {
} else if constexpr (std::is_same_v<Node, Member>) {
reference = {Which::MEMBER, member_.size()};
member_.emplace_back(std::forward<Args>(args)...);
+ } else if constexpr (std::is_same_v<Node, VariantMember>) {
+ reference = {Which::VARIANT_MEMBER, variant_member_.size()};
+ variant_member_.emplace_back(std::forward<Args>(args)...);
} else if constexpr (std::is_same_v<Node, StructUnion>) {
reference = {Which::STRUCT_UNION, struct_union_.size()};
struct_union_.emplace_back(std::forward<Args>(args)...);
} else if constexpr (std::is_same_v<Node, Enumeration>) {
reference = {Which::ENUMERATION, enumeration_.size()};
enumeration_.emplace_back(std::forward<Args>(args)...);
+ } else if constexpr (std::is_same_v<Node, Variant>) {
+ reference = {Which::VARIANT, variant_.size()};
+ variant_.emplace_back(std::forward<Args>(args)...);
} else if constexpr (std::is_same_v<Node, Function>) {
reference = {Which::FUNCTION, function_.size()};
function_.emplace_back(std::forward<Args>(args)...);
@@ -454,8 +484,10 @@ class Graph {
BASE_CLASS,
METHOD,
MEMBER,
+ VARIANT_MEMBER,
STRUCT_UNION,
ENUMERATION,
+ VARIANT,
FUNCTION,
ELF_SYMBOL,
INTERFACE,
@@ -473,8 +505,10 @@ class Graph {
std::vector<BaseClass> base_class_;
std::vector<Method> method_;
std::vector<Member> member_;
+ std::vector<VariantMember> variant_member_;
std::vector<StructUnion> struct_union_;
std::vector<Enumeration> enumeration_;
+ std::vector<Variant> variant_;
std::vector<Function> function_;
std::vector<ElfSymbol> elf_symbol_;
std::vector<Interface> interface_;
@@ -506,10 +540,14 @@ Result Graph::Apply(FunctionObject& function, Id id, Args&&... args) const {
return function(method_[ix], std::forward<Args>(args)...);
case Which::MEMBER:
return function(member_[ix], std::forward<Args>(args)...);
+ case Which::VARIANT_MEMBER:
+ return function(variant_member_[ix], std::forward<Args>(args)...);
case Which::STRUCT_UNION:
return function(struct_union_[ix], std::forward<Args>(args)...);
case Which::ENUMERATION:
return function(enumeration_[ix], std::forward<Args>(args)...);
+ case Which::VARIANT:
+ return function(variant_[ix], std::forward<Args>(args)...);
case Which::FUNCTION:
return function(function_[ix], std::forward<Args>(args)...);
case Which::ELF_SYMBOL:
@@ -560,12 +598,18 @@ Result Graph::Apply2(
case Which::MEMBER:
return function(member_[ix1], member_[ix2],
std::forward<Args>(args)...);
+ case Which::VARIANT_MEMBER:
+ return function(variant_member_[ix1], variant_member_[ix2],
+ std::forward<Args>(args)...);
case Which::STRUCT_UNION:
return function(struct_union_[ix1], struct_union_[ix2],
std::forward<Args>(args)...);
case Which::ENUMERATION:
return function(enumeration_[ix1], enumeration_[ix2],
std::forward<Args>(args)...);
+ case Which::VARIANT:
+ return function(variant_[ix1], variant_[ix2],
+ std::forward<Args>(args)...);
case Which::FUNCTION:
return function(function_[ix1], function_[ix2],
std::forward<Args>(args)...);
@@ -622,6 +666,13 @@ struct InterfaceKey {
return "enum " + x.name;
}
+ std::string operator()(const stg::Variant& x) const {
+ if (x.name.empty()) {
+ Die() << "anonymous variant interface type";
+ }
+ return "variant " + x.name;
+ }
+
std::string operator()(const stg::ElfSymbol& x) const {
return VersionedSymbolName(x);
}
diff --git a/naming.cc b/naming.cc
index f386dce..77548c1 100644
--- a/naming.cc
+++ b/naming.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2020-2022 Google LLC
+// Copyright 2020-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -189,6 +189,12 @@ Name Describe::operator()(const Member& x) {
return description;
}
+Name Describe::operator()(const VariantMember& x) {
+ auto description = (*this)(x.type_id);
+ description = description.Add(Side::LEFT, Precedence::ATOMIC, x.name);
+ return description;
+}
+
Name Describe::operator()(const StructUnion& x) {
std::ostringstream os;
os << x.kind << ' ';
@@ -219,6 +225,12 @@ Name Describe::operator()(const Enumeration& x) {
return Name{os.str()};
}
+Name Describe::operator()(const Variant& x) {
+ std::ostringstream os;
+ os << "variant " << x.name;
+ return Name{os.str()};
+}
+
Name Describe::operator()(const Function& x) {
std::ostringstream os;
os << '(';
diff --git a/naming.h b/naming.h
index 163627f..87496b3 100644
--- a/naming.h
+++ b/naming.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2020-2022 Google LLC
+// Copyright 2020-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -68,8 +68,10 @@ struct Describe {
Name operator()(const BaseClass&);
Name operator()(const Method&);
Name operator()(const Member&);
+ Name operator()(const VariantMember&);
Name operator()(const StructUnion&);
Name operator()(const Enumeration&);
+ Name operator()(const Variant&);
Name operator()(const Function&);
Name operator()(const ElfSymbol&);
Name operator()(const Interface&);
diff --git a/proto_reader.cc b/proto_reader.cc
index c7eacb7..f2683ef 100644
--- a/proto_reader.cc
+++ b/proto_reader.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -65,8 +65,10 @@ struct Transformer {
void AddNode(const BaseClass&);
void AddNode(const Method&);
void AddNode(const Member&);
+ void AddNode(const Variant&);
void AddNode(const StructUnion&);
void AddNode(const Enumeration&);
+ void AddNode(const VariantMember&);
void AddNode(const Function&);
void AddNode(const ElfSymbol&);
void AddNode(const Symbols&);
@@ -111,8 +113,10 @@ Id Transformer::Transform(const proto::STG& x) {
AddNodes(x.base_class());
AddNodes(x.method());
AddNodes(x.member());
+ AddNodes(x.variant_member());
AddNodes(x.struct_union());
AddNodes(x.enumeration());
+ AddNodes(x.variant());
AddNodes(x.function());
AddNodes(x.elf_symbol());
AddNodes(x.symbols());
@@ -192,6 +196,14 @@ void Transformer::AddNode(const Member& x) {
x.bitsize());
}
+void Transformer::AddNode(const VariantMember& x) {
+ const auto& discr_value = x.has_discriminant_value()
+ ? std::make_optional(x.discriminant_value())
+ : std::nullopt;
+ AddNode<stg::VariantMember>(GetId(x.id()), x.name(), discr_value,
+ GetId(x.type_id()));
+}
+
void Transformer::AddNode(const StructUnion& x) {
if (x.has_definition()) {
AddNode<stg::StructUnion>(
@@ -214,6 +226,11 @@ void Transformer::AddNode(const Enumeration& x) {
}
}
+void Transformer::AddNode(const Variant& x) {
+ AddNode<stg::Variant>(GetId(x.id()), x.name(), x.bytesize(),
+ GetId(x.discriminant_type_id()), x.member_id());
+}
+
void Transformer::AddNode(const Function& x) {
AddNode<stg::Function>(GetId(x.id()), GetId(x.return_type_id()),
x.parameter_id());
diff --git a/proto_writer.cc b/proto_writer.cc
index 694d65e..919c5e8 100644
--- a/proto_writer.cc
+++ b/proto_writer.cc
@@ -74,8 +74,10 @@ struct Transform {
void operator()(const stg::BaseClass&, uint32_t);
void operator()(const stg::Method&, uint32_t);
void operator()(const stg::Member&, uint32_t);
+ void operator()(const stg::VariantMember&, uint32_t);
void operator()(const stg::StructUnion&, uint32_t);
void operator()(const stg::Enumeration&, uint32_t);
+ void operator()(const stg::Variant&, uint32_t);
void operator()(const stg::Function&, uint32_t);
void operator()(const stg::ElfSymbol&, uint32_t);
void operator()(const stg::Interface&, uint32_t);
@@ -92,7 +94,7 @@ struct Transform {
std::unordered_map<uint32_t, Id> GetInternalIdByExternalIdMap() {
std::unordered_map<uint32_t, Id> internal_id_map;
- for (const auto [id, ext_id] : external_id_by_internal_id) {
+ for (const auto& [id, ext_id] : external_id_by_internal_id) {
internal_id_map.emplace(ext_id, id);
}
return internal_id_map;
@@ -213,6 +215,17 @@ void Transform<MapId>::operator()(const stg::Member& x, uint32_t id) {
}
template <typename MapId>
+void Transform<MapId>::operator()(const stg::VariantMember& x, uint32_t id) {
+ auto& variant_member = *stg.add_variant_member();
+ variant_member.set_id(id);
+ variant_member.set_name(x.name);
+ if (x.discriminant_value) {
+ variant_member.set_discriminant_value(*x.discriminant_value);
+ }
+ variant_member.set_type_id((*this)(x.type_id));
+}
+
+template <typename MapId>
void Transform<MapId>::operator()(const stg::StructUnion& x, uint32_t id) {
auto& struct_union = *stg.add_struct_union();
struct_union.set_id(id);
@@ -251,6 +264,18 @@ void Transform<MapId>::operator()(const stg::Enumeration& x, uint32_t id) {
}
template <typename MapId>
+void Transform<MapId>::operator()(const stg::Variant& x, uint32_t id) {
+ auto& variant = *stg.add_variant();
+ variant.set_id(id);
+ variant.set_name(x.name);
+ variant.set_bytesize(x.bytesize);
+ variant.set_discriminant_type_id((*this)(x.discriminant_type_id));
+ for (const auto id : x.members) {
+ variant.add_member_id((*this)(id));
+ }
+}
+
+template <typename MapId>
void Transform<MapId>::operator()(const stg::Function& x, uint32_t id) {
auto& function = *stg.add_function();
function.set_id(id);
diff --git a/stable_hash.cc b/stable_hash.cc
index 8621aed..a8f9366 100644
--- a/stable_hash.cc
+++ b/stable_hash.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -126,6 +126,14 @@ HashValue StableHash::operator()(const Member& x) {
}
}
+HashValue StableHash::operator()(const VariantMember& x) {
+ HashValue hash = hash_('v', x.name);
+ hash = DecayHashCombine<8>(hash, (*this)(x.type_id));
+ return x.discriminant_value
+ ? DecayHashCombine<20>(hash, hash_(*x.discriminant_value))
+ : hash;
+}
+
HashValue StableHash::operator()(const StructUnion& x) {
HashValue hash = hash_('S', static_cast<uint32_t>(x.kind), x.name,
static_cast<bool>(x.definition));
@@ -151,6 +159,13 @@ HashValue StableHash::operator()(const Enumeration& x) {
hash, DecayHashCombineInReverse<8>(x.definition->enumerators, hash_enum));
}
+HashValue StableHash::operator()(const Variant& x) {
+ HashValue hash = hash_('V', x.name, x.bytesize);
+ hash = DecayHashCombine<8>(hash, (*this)(x.discriminant_type_id));
+ return DecayHashCombine<2>(hash,
+ DecayHashCombineInReverse<8>(x.members, *this));
+}
+
HashValue StableHash::operator()(const Function& x) {
return DecayHashCombine<2>(hash_('f', (*this)(x.return_type_id)),
DecayHashCombineInReverse<4>(x.parameters, *this));
diff --git a/stable_hash.h b/stable_hash.h
index 1732610..b0b9265 100644
--- a/stable_hash.h
+++ b/stable_hash.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -45,8 +45,10 @@ class StableHash {
HashValue operator()(const BaseClass&);
HashValue operator()(const Method&);
HashValue operator()(const Member&);
+ HashValue operator()(const VariantMember&);
HashValue operator()(const StructUnion&);
HashValue operator()(const Enumeration&);
+ HashValue operator()(const Variant&);
HashValue operator()(const Function&);
HashValue operator()(const ElfSymbol&);
HashValue operator()(const Interface&);
diff --git a/stg.proto b/stg.proto
index 6f5ce91..7703b79 100644
--- a/stg.proto
+++ b/stg.proto
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: protobuffer -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -158,6 +158,13 @@ message Member {
uint64 bitsize = 5;
}
+message VariantMember {
+ fixed32 id = 1;
+ string name = 2;
+ optional int64 discriminant_value = 3;
+ fixed32 type_id = 4;
+}
+
message StructUnion {
enum Kind {
KIND_UNSPECIFIED = 0;
@@ -194,6 +201,14 @@ message Enumeration {
optional Definition definition = 3;
}
+message Variant {
+ fixed32 id = 1;
+ string name = 2;
+ uint64 bytesize = 3;
+ fixed32 discriminant_type_id = 4;
+ repeated fixed32 member_id = 5;
+}
+
message Function {
fixed32 id = 1;
fixed32 return_type_id = 2;
@@ -268,10 +283,12 @@ message STG {
repeated BaseClass base_class = 12;
repeated Method method = 13;
repeated Member member = 14;
- repeated StructUnion struct_union = 15;
- repeated Enumeration enumeration = 16;
- repeated Function function = 17;
- repeated ElfSymbol elf_symbol = 18;
- repeated Symbols symbols = 19;
- repeated Interface interface = 20;
+ repeated VariantMember variant_member = 15;
+ repeated StructUnion struct_union = 16;
+ repeated Enumeration enumeration = 17;
+ repeated Variant variant = 18;
+ repeated Function function = 19;
+ repeated ElfSymbol elf_symbol = 20;
+ repeated Symbols symbols = 21;
+ repeated Interface interface = 22;
}
diff --git a/substitution.h b/substitution.h
index 67f74b4..863115f 100644
--- a/substitution.h
+++ b/substitution.h
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -99,6 +99,10 @@ struct Substitute {
Update(x.type_id);
}
+ void operator()(VariantMember& x) {
+ Update(x.type_id);
+ }
+
void operator()(StructUnion& x) {
if (x.definition.has_value()) {
auto& definition = x.definition.value();
@@ -115,6 +119,11 @@ struct Substitute {
}
}
+ void operator()(Variant& x) {
+ Update(x.discriminant_type_id);
+ Update(x.members);
+ }
+
void operator()(Function& x) {
Update(x.parameters);
Update(x.return_type_id);
diff --git a/test_cases/abigail_reader/array/multidimensional.c.xml b/test_cases/abigail_reader/array/multidimensional_c.xml
index 531c49b..531c49b 100644
--- a/test_cases/abigail_reader/array/multidimensional.c.xml
+++ b/test_cases/abigail_reader/array/multidimensional_c.xml
diff --git a/test_cases/abigail_reader/array/multidimensional.cc.xml b/test_cases/abigail_reader/array/multidimensional_cc.xml
index 71ad057..71ad057 100644
--- a/test_cases/abigail_reader/array/multidimensional.cc.xml
+++ b/test_cases/abigail_reader/array/multidimensional_cc.xml
diff --git a/test_cases/abigail_reader/array/simple_array.c.xml b/test_cases/abigail_reader/array/simple_array_c.xml
index 5316876..5316876 100644
--- a/test_cases/abigail_reader/array/simple_array.c.xml
+++ b/test_cases/abigail_reader/array/simple_array_c.xml
diff --git a/test_cases/abigail_reader/array/simple_array.cc.xml b/test_cases/abigail_reader/array/simple_array_cc.xml
index 3e60e91..3e60e91 100644
--- a/test_cases/abigail_reader/array/simple_array.cc.xml
+++ b/test_cases/abigail_reader/array/simple_array_cc.xml
diff --git a/test_cases/abigail_reader/array/unknown_size.c.xml b/test_cases/abigail_reader/array/unknown_size_c.xml
index d622d60..d622d60 100644
--- a/test_cases/abigail_reader/array/unknown_size.c.xml
+++ b/test_cases/abigail_reader/array/unknown_size_c.xml
diff --git a/test_cases/abigail_reader/array/unknown_size_extern.c.xml b/test_cases/abigail_reader/array/unknown_size_extern_c.xml
index 94116a0..94116a0 100644
--- a/test_cases/abigail_reader/array/unknown_size_extern.c.xml
+++ b/test_cases/abigail_reader/array/unknown_size_extern_c.xml
diff --git a/test_cases/abigail_reader/array/variable_length.c.xml b/test_cases/abigail_reader/array/variable_length_c.xml
index f50e0c1..f50e0c1 100644
--- a/test_cases/abigail_reader/array/variable_length.c.xml
+++ b/test_cases/abigail_reader/array/variable_length_c.xml
diff --git a/test_cases/abigail_reader/composite/abstract_base_class.cc.xml b/test_cases/abigail_reader/composite/abstract_base_class_cc.xml
index 33f4047..33f4047 100644
--- a/test_cases/abigail_reader/composite/abstract_base_class.cc.xml
+++ b/test_cases/abigail_reader/composite/abstract_base_class_cc.xml
diff --git a/test_cases/abigail_reader/composite/anonymous.cc.xml b/test_cases/abigail_reader/composite/anonymous_cc.xml
index 44ca297..44ca297 100644
--- a/test_cases/abigail_reader/composite/anonymous.cc.xml
+++ b/test_cases/abigail_reader/composite/anonymous_cc.xml
diff --git a/test_cases/abigail_reader/composite/anonymous_member.c.xml b/test_cases/abigail_reader/composite/anonymous_member_c.xml
index c795a51..c795a51 100644
--- a/test_cases/abigail_reader/composite/anonymous_member.c.xml
+++ b/test_cases/abigail_reader/composite/anonymous_member_c.xml
diff --git a/test_cases/abigail_reader/composite/anonymous_member_chain.c.xml b/test_cases/abigail_reader/composite/anonymous_member_chain_c.xml
index fdf5219..fdf5219 100644
--- a/test_cases/abigail_reader/composite/anonymous_member_chain.c.xml
+++ b/test_cases/abigail_reader/composite/anonymous_member_chain_c.xml
diff --git a/test_cases/abigail_reader/composite/base_class_order.cc.xml b/test_cases/abigail_reader/composite/base_class_order_cc.xml
index 2dcaf43..2dcaf43 100644
--- a/test_cases/abigail_reader/composite/base_class_order.cc.xml
+++ b/test_cases/abigail_reader/composite/base_class_order_cc.xml
diff --git a/test_cases/abigail_reader/composite/base_class_size.cc.xml b/test_cases/abigail_reader/composite/base_class_size_cc.xml
index 3fe7dd3..3fe7dd3 100644
--- a/test_cases/abigail_reader/composite/base_class_size.cc.xml
+++ b/test_cases/abigail_reader/composite/base_class_size_cc.xml
diff --git a/test_cases/abigail_reader/composite/forward.c.xml b/test_cases/abigail_reader/composite/forward_c.xml
index ee761d1..ee761d1 100644
--- a/test_cases/abigail_reader/composite/forward.c.xml
+++ b/test_cases/abigail_reader/composite/forward_c.xml
diff --git a/test_cases/abigail_reader/composite/kind.cc.xml b/test_cases/abigail_reader/composite/kind_cc.xml
index 452f861..452f861 100644
--- a/test_cases/abigail_reader/composite/kind.cc.xml
+++ b/test_cases/abigail_reader/composite/kind_cc.xml
diff --git a/test_cases/abigail_reader/composite/virtual_inheritance.cc.xml b/test_cases/abigail_reader/composite/virtual_inheritance_cc.xml
index 0b4a8a5..0b4a8a5 100644
--- a/test_cases/abigail_reader/composite/virtual_inheritance.cc.xml
+++ b/test_cases/abigail_reader/composite/virtual_inheritance_cc.xml
diff --git a/test_cases/abigail_reader/composite/virtual_only_base_class.cc.xml b/test_cases/abigail_reader/composite/virtual_only_base_class_cc.xml
index 26745f5..26745f5 100644
--- a/test_cases/abigail_reader/composite/virtual_only_base_class.cc.xml
+++ b/test_cases/abigail_reader/composite/virtual_only_base_class_cc.xml
diff --git a/test_cases/abigail_reader/enum/anonymous.c.xml b/test_cases/abigail_reader/enum/anonymous_c.xml
index 61fc625..61fc625 100644
--- a/test_cases/abigail_reader/enum/anonymous.c.xml
+++ b/test_cases/abigail_reader/enum/anonymous_c.xml
diff --git a/test_cases/abigail_reader/enum/declaration_only.c.xml b/test_cases/abigail_reader/enum/declaration_only_c.xml
index e267713..e267713 100644
--- a/test_cases/abigail_reader/enum/declaration_only.c.xml
+++ b/test_cases/abigail_reader/enum/declaration_only_c.xml
diff --git a/test_cases/abigail_reader/enum/fixed_underlying_type.cc.xml b/test_cases/abigail_reader/enum/fixed_underlying_type_cc.xml
index e834e2f..e834e2f 100644
--- a/test_cases/abigail_reader/enum/fixed_underlying_type.cc.xml
+++ b/test_cases/abigail_reader/enum/fixed_underlying_type_cc.xml
diff --git a/test_cases/abigail_reader/enum/limits.c.xml b/test_cases/abigail_reader/enum/limits_c.xml
index f02c77b..f02c77b 100644
--- a/test_cases/abigail_reader/enum/limits.c.xml
+++ b/test_cases/abigail_reader/enum/limits_c.xml
diff --git a/test_cases/abigail_reader/enum/simple.c.xml b/test_cases/abigail_reader/enum/simple_c.xml
index e03901f..e03901f 100644
--- a/test_cases/abigail_reader/enum/simple.c.xml
+++ b/test_cases/abigail_reader/enum/simple_c.xml
diff --git a/test_cases/abigail_reader/function/array_parameter.c.xml b/test_cases/abigail_reader/function/array_parameter_c.xml
index 4820b5c..4820b5c 100644
--- a/test_cases/abigail_reader/function/array_parameter.c.xml
+++ b/test_cases/abigail_reader/function/array_parameter_c.xml
diff --git a/test_cases/abigail_reader/function/methods.cc.xml b/test_cases/abigail_reader/function/methods_cc.xml
index 9c5fbf9..9c5fbf9 100644
--- a/test_cases/abigail_reader/function/methods.cc.xml
+++ b/test_cases/abigail_reader/function/methods_cc.xml
diff --git a/test_cases/abigail_reader/function/parameters.c.xml b/test_cases/abigail_reader/function/parameters_c.xml
index 6e901d8..6e901d8 100644
--- a/test_cases/abigail_reader/function/parameters.c.xml
+++ b/test_cases/abigail_reader/function/parameters_c.xml
diff --git a/test_cases/abigail_reader/function/parameters.cc.xml b/test_cases/abigail_reader/function/parameters_cc.xml
index e288bbd..e288bbd 100644
--- a/test_cases/abigail_reader/function/parameters.cc.xml
+++ b/test_cases/abigail_reader/function/parameters_cc.xml
diff --git a/test_cases/abigail_reader/function/static_method.cc.xml b/test_cases/abigail_reader/function/static_method_cc.xml
index c42f164..c42f164 100644
--- a/test_cases/abigail_reader/function/static_method.cc.xml
+++ b/test_cases/abigail_reader/function/static_method_cc.xml
diff --git a/test_cases/abigail_reader/function/variadic_parameter.cc.xml b/test_cases/abigail_reader/function/variadic_parameter_cc.xml
index cb3ff91..cb3ff91 100644
--- a/test_cases/abigail_reader/function/variadic_parameter.cc.xml
+++ b/test_cases/abigail_reader/function/variadic_parameter_cc.xml
diff --git a/test_cases/abigail_reader/function/virtual_method.cc.xml b/test_cases/abigail_reader/function/virtual_method_cc.xml
index 7f43b7d..7f43b7d 100644
--- a/test_cases/abigail_reader/function/virtual_method.cc.xml
+++ b/test_cases/abigail_reader/function/virtual_method_cc.xml
diff --git a/test_cases/abigail_reader/member/member_types.cc.xml b/test_cases/abigail_reader/member/member_types_cc.xml
index e2578df..e2578df 100644
--- a/test_cases/abigail_reader/member/member_types.cc.xml
+++ b/test_cases/abigail_reader/member/member_types_cc.xml
diff --git a/test_cases/abigail_reader/member/pointer_to_member.cc.xml b/test_cases/abigail_reader/member/pointer_to_member_cc.xml
index bd821a3..bd821a3 100644
--- a/test_cases/abigail_reader/member/pointer_to_member.cc.xml
+++ b/test_cases/abigail_reader/member/pointer_to_member_cc.xml
diff --git a/test_cases/abigail_reader/misc/enum.c.xml b/test_cases/abigail_reader/misc/enum_c.xml
index 9351c14..9351c14 100644
--- a/test_cases/abigail_reader/misc/enum.c.xml
+++ b/test_cases/abigail_reader/misc/enum_c.xml
diff --git a/test_cases/abigail_reader/misc/enum.cc.xml b/test_cases/abigail_reader/misc/enum_cc.xml
index 6bed093..6bed093 100644
--- a/test_cases/abigail_reader/misc/enum.cc.xml
+++ b/test_cases/abigail_reader/misc/enum_cc.xml
diff --git a/test_cases/abigail_reader/misc/enum_const.c.xml b/test_cases/abigail_reader/misc/enum_const_c.xml
index 8a7e26c..8a7e26c 100644
--- a/test_cases/abigail_reader/misc/enum_const.c.xml
+++ b/test_cases/abigail_reader/misc/enum_const_c.xml
diff --git a/test_cases/abigail_reader/namespace/nested_anonymous_types.cc.xml b/test_cases/abigail_reader/namespace/nested_anonymous_types_cc.xml
index 4df142c..4df142c 100644
--- a/test_cases/abigail_reader/namespace/nested_anonymous_types.cc.xml
+++ b/test_cases/abigail_reader/namespace/nested_anonymous_types_cc.xml
diff --git a/test_cases/abigail_reader/namespace/nested.cc.xml b/test_cases/abigail_reader/namespace/nested_cc.xml
index 2b7db2c..2b7db2c 100644
--- a/test_cases/abigail_reader/namespace/nested.cc.xml
+++ b/test_cases/abigail_reader/namespace/nested_cc.xml
diff --git a/test_cases/abigail_reader/namespace/simple.cc.xml b/test_cases/abigail_reader/namespace/simple_cc.xml
index 8cecf42..8cecf42 100644
--- a/test_cases/abigail_reader/namespace/simple.cc.xml
+++ b/test_cases/abigail_reader/namespace/simple_cc.xml
diff --git a/test_cases/abigail_reader/namespace/using_namespace_in_function.cc.xml b/test_cases/abigail_reader/namespace/using_namespace_in_function_cc.xml
index 3352210..3352210 100644
--- a/test_cases/abigail_reader/namespace/using_namespace_in_function.cc.xml
+++ b/test_cases/abigail_reader/namespace/using_namespace_in_function_cc.xml
diff --git a/test_cases/abigail_reader/primitive/all_c99_types.c.xml b/test_cases/abigail_reader/primitive/all_c99_types_c.xml
index ae0f6c4..ae0f6c4 100644
--- a/test_cases/abigail_reader/primitive/all_c99_types.c.xml
+++ b/test_cases/abigail_reader/primitive/all_c99_types_c.xml
diff --git a/test_cases/abigail_reader/primitive/long.c.xml b/test_cases/abigail_reader/primitive/long_c.xml
index c17119a..c17119a 100644
--- a/test_cases/abigail_reader/primitive/long.c.xml
+++ b/test_cases/abigail_reader/primitive/long_c.xml
diff --git a/test_cases/abigail_reader/qualified/const_long.c.xml b/test_cases/abigail_reader/qualified/const_long_c.xml
index 3bf8a25..3bf8a25 100644
--- a/test_cases/abigail_reader/qualified/const_long.c.xml
+++ b/test_cases/abigail_reader/qualified/const_long_c.xml
diff --git a/test_cases/abigail_reader/qualified/int.c.xml b/test_cases/abigail_reader/qualified/int_c.xml
index 8807a9a..8807a9a 100644
--- a/test_cases/abigail_reader/qualified/int.c.xml
+++ b/test_cases/abigail_reader/qualified/int_c.xml
diff --git a/test_cases/abigail_reader/qualified/pointers.c.xml b/test_cases/abigail_reader/qualified/pointers_c.xml
index a5fff88..a5fff88 100644
--- a/test_cases/abigail_reader/qualified/pointers.c.xml
+++ b/test_cases/abigail_reader/qualified/pointers_c.xml
diff --git a/test_cases/abigail_reader/qualified/useless.c.xml b/test_cases/abigail_reader/qualified/useless_c.xml
index 663a657..663a657 100644
--- a/test_cases/abigail_reader/qualified/useless.c.xml
+++ b/test_cases/abigail_reader/qualified/useless_c.xml
diff --git a/test_cases/abigail_reader/reference/type.cc.xml b/test_cases/abigail_reader/reference/type_cc.xml
index 9b620a3..9b620a3 100644
--- a/test_cases/abigail_reader/reference/type.cc.xml
+++ b/test_cases/abigail_reader/reference/type_cc.xml
diff --git a/test_cases/abigail_reader/scc/same.c.xml b/test_cases/abigail_reader/scc/same_c.xml
index 4b9c1f6..4b9c1f6 100644
--- a/test_cases/abigail_reader/scc/same.c.xml
+++ b/test_cases/abigail_reader/scc/same_c.xml
diff --git a/test_cases/abigail_reader/scc/simple.c.xml b/test_cases/abigail_reader/scc/simple_c.xml
index 22237df..22237df 100644
--- a/test_cases/abigail_reader/scc/simple.c.xml
+++ b/test_cases/abigail_reader/scc/simple_c.xml
diff --git a/test_cases/abigail_reader/static/simple.cc.xml b/test_cases/abigail_reader/static/simple_cc.xml
index 5e1efd3..5e1efd3 100644
--- a/test_cases/abigail_reader/static/simple.cc.xml
+++ b/test_cases/abigail_reader/static/simple_cc.xml
diff --git a/test_cases/abigail_reader/struct/anonymous.c.xml b/test_cases/abigail_reader/struct/anonymous_c.xml
index bd6cef0..bd6cef0 100644
--- a/test_cases/abigail_reader/struct/anonymous.c.xml
+++ b/test_cases/abigail_reader/struct/anonymous_c.xml
diff --git a/test_cases/abigail_reader/struct/bit_field.c.xml b/test_cases/abigail_reader/struct/bit_field_c.xml
index e3b1eb0..e3b1eb0 100644
--- a/test_cases/abigail_reader/struct/bit_field.c.xml
+++ b/test_cases/abigail_reader/struct/bit_field_c.xml
diff --git a/test_cases/abigail_reader/struct/declaration_only.c.xml b/test_cases/abigail_reader/struct/declaration_only_c.xml
index 4a20056..4a20056 100644
--- a/test_cases/abigail_reader/struct/declaration_only.c.xml
+++ b/test_cases/abigail_reader/struct/declaration_only_c.xml
diff --git a/test_cases/abigail_reader/struct/nested.c.xml b/test_cases/abigail_reader/struct/nested_c.xml
index 21b8d2b..21b8d2b 100644
--- a/test_cases/abigail_reader/struct/nested.c.xml
+++ b/test_cases/abigail_reader/struct/nested_c.xml
diff --git a/test_cases/abigail_reader/struct/nested.cc.xml b/test_cases/abigail_reader/struct/nested_cc.xml
index 1a710d8..1a710d8 100644
--- a/test_cases/abigail_reader/struct/nested.cc.xml
+++ b/test_cases/abigail_reader/struct/nested_cc.xml
diff --git a/test_cases/abigail_reader/struct/struct_union.c.xml b/test_cases/abigail_reader/struct/struct_union_c.xml
index 31cc776..31cc776 100644
--- a/test_cases/abigail_reader/struct/struct_union.c.xml
+++ b/test_cases/abigail_reader/struct/struct_union_c.xml
diff --git a/test_cases/abigail_reader/symbol/absolute_object.c.xml b/test_cases/abigail_reader/symbol/absolute_object_c.xml
index 7aa88a7..7aa88a7 100644
--- a/test_cases/abigail_reader/symbol/absolute_object.c.xml
+++ b/test_cases/abigail_reader/symbol/absolute_object_c.xml
diff --git a/test_cases/abigail_reader/symbol/alias.c.xml b/test_cases/abigail_reader/symbol/alias_c.xml
index 6408afe..6408afe 100644
--- a/test_cases/abigail_reader/symbol/alias.c.xml
+++ b/test_cases/abigail_reader/symbol/alias_c.xml
diff --git a/test_cases/abigail_reader/symbol/ifunc.c.xml b/test_cases/abigail_reader/symbol/ifunc_c.xml
index 585bcb8..585bcb8 100644
--- a/test_cases/abigail_reader/symbol/ifunc.c.xml
+++ b/test_cases/abigail_reader/symbol/ifunc_c.xml
diff --git a/test_cases/abigail_reader/symbol/tls.c.xml b/test_cases/abigail_reader/symbol/tls_c.xml
index d5f6b10..d5f6b10 100644
--- a/test_cases/abigail_reader/symbol/tls.c.xml
+++ b/test_cases/abigail_reader/symbol/tls_c.xml
diff --git a/test_cases/abigail_reader/symbol/tls.cc.xml b/test_cases/abigail_reader/symbol/tls_cc.xml
index aa64858..aa64858 100644
--- a/test_cases/abigail_reader/symbol/tls.cc.xml
+++ b/test_cases/abigail_reader/symbol/tls_cc.xml
diff --git a/test_cases/abigail_reader/symbol/version_definition.c.xml b/test_cases/abigail_reader/symbol/version_definition_c.xml
index 8f16c20..8f16c20 100644
--- a/test_cases/abigail_reader/symbol/version_definition.c.xml
+++ b/test_cases/abigail_reader/symbol/version_definition_c.xml
diff --git a/test_cases/abigail_reader/symbol/version_need.c.xml b/test_cases/abigail_reader/symbol/version_need_c.xml
index 6ad7e74..6ad7e74 100644
--- a/test_cases/abigail_reader/symbol/version_need.c.xml
+++ b/test_cases/abigail_reader/symbol/version_need_c.xml
diff --git a/test_cases/abigail_reader/symbol/visibility.c.xml b/test_cases/abigail_reader/symbol/visibility_c.xml
index b5aca34..b5aca34 100644
--- a/test_cases/abigail_reader/symbol/visibility.c.xml
+++ b/test_cases/abigail_reader/symbol/visibility_c.xml
diff --git a/test_cases/abigail_reader/symbol/visibility.cc.xml b/test_cases/abigail_reader/symbol/visibility_cc.xml
index dedae35..dedae35 100644
--- a/test_cases/abigail_reader/symbol/visibility.cc.xml
+++ b/test_cases/abigail_reader/symbol/visibility_cc.xml
diff --git a/test_cases/abigail_reader/symbol/weak.c.xml b/test_cases/abigail_reader/symbol/weak_c.xml
index 734ba74..734ba74 100644
--- a/test_cases/abigail_reader/symbol/weak.c.xml
+++ b/test_cases/abigail_reader/symbol/weak_c.xml
diff --git a/test_cases/abigail_reader/symbol/weak.cc.xml b/test_cases/abigail_reader/symbol/weak_cc.xml
index b737529..b737529 100644
--- a/test_cases/abigail_reader/symbol/weak.cc.xml
+++ b/test_cases/abigail_reader/symbol/weak_cc.xml
diff --git a/test_cases/abigail_reader/template/template_class.cc.xml b/test_cases/abigail_reader/template/template_class_cc.xml
index 0a21cb8..0a21cb8 100644
--- a/test_cases/abigail_reader/template/template_class.cc.xml
+++ b/test_cases/abigail_reader/template/template_class_cc.xml
diff --git a/test_cases/abigail_reader/template/template_function.cc.xml b/test_cases/abigail_reader/template/template_function_cc.xml
index 81214ff..81214ff 100644
--- a/test_cases/abigail_reader/template/template_function.cc.xml
+++ b/test_cases/abigail_reader/template/template_function_cc.xml
diff --git a/test_cases/abigail_reader/template/template_member_function.cc.xml b/test_cases/abigail_reader/template/template_member_function_cc.xml
index b59a65d..b59a65d 100644
--- a/test_cases/abigail_reader/template/template_member_function.cc.xml
+++ b/test_cases/abigail_reader/template/template_member_function_cc.xml
diff --git a/test_cases/abigail_reader/template/template_typedef.cc.xml b/test_cases/abigail_reader/template/template_typedef_cc.xml
index 21a0da1..21a0da1 100644
--- a/test_cases/abigail_reader/template/template_typedef.cc.xml
+++ b/test_cases/abigail_reader/template/template_typedef_cc.xml
diff --git a/test_cases/abigail_reader/template/variadic_template_alias.cc.xml b/test_cases/abigail_reader/template/variadic_template_alias_cc.xml
index 7984c15..7984c15 100644
--- a/test_cases/abigail_reader/template/variadic_template_alias.cc.xml
+++ b/test_cases/abigail_reader/template/variadic_template_alias_cc.xml
diff --git a/test_cases/abigail_reader/template/variadic_template_class.cc.xml b/test_cases/abigail_reader/template/variadic_template_class_cc.xml
index fce7d0b..fce7d0b 100644
--- a/test_cases/abigail_reader/template/variadic_template_class.cc.xml
+++ b/test_cases/abigail_reader/template/variadic_template_class_cc.xml
diff --git a/test_cases/abigail_reader/template/variadic_template_function.cc.xml b/test_cases/abigail_reader/template/variadic_template_function_cc.xml
index db5665e..db5665e 100644
--- a/test_cases/abigail_reader/template/variadic_template_function.cc.xml
+++ b/test_cases/abigail_reader/template/variadic_template_function_cc.xml
diff --git a/test_cases/abigail_reader/template/variadic_template_variable.cc.xml b/test_cases/abigail_reader/template/variadic_template_variable_cc.xml
index 929f612..929f612 100644
--- a/test_cases/abigail_reader/template/variadic_template_variable.cc.xml
+++ b/test_cases/abigail_reader/template/variadic_template_variable_cc.xml
diff --git a/test_cases/abigail_reader/typedef/chain.c.xml b/test_cases/abigail_reader/typedef/chain_c.xml
index 514f42f..514f42f 100644
--- a/test_cases/abigail_reader/typedef/chain.c.xml
+++ b/test_cases/abigail_reader/typedef/chain_c.xml
diff --git a/test_cases/abigail_reader/typedef/nullptr.cc.xml b/test_cases/abigail_reader/typedef/nullptr_cc.xml
index 7c69285..7c69285 100644
--- a/test_cases/abigail_reader/typedef/nullptr.cc.xml
+++ b/test_cases/abigail_reader/typedef/nullptr_cc.xml
diff --git a/test_cases/abigail_reader/typedef/scoped_composite_nested_struct.cc.xml b/test_cases/abigail_reader/typedef/scoped_composite_nested_struct_cc.xml
index 9cfed9c..9cfed9c 100644
--- a/test_cases/abigail_reader/typedef/scoped_composite_nested_struct.cc.xml
+++ b/test_cases/abigail_reader/typedef/scoped_composite_nested_struct_cc.xml
diff --git a/test_cases/abigail_reader/typedef/simple.c.xml b/test_cases/abigail_reader/typedef/simple_c.xml
index 871875e..871875e 100644
--- a/test_cases/abigail_reader/typedef/simple.c.xml
+++ b/test_cases/abigail_reader/typedef/simple_c.xml
diff --git a/test_cases/abigail_reader/typedef/simple.cc.xml b/test_cases/abigail_reader/typedef/simple_cc.xml
index 47c9b23..47c9b23 100644
--- a/test_cases/abigail_reader/typedef/simple.cc.xml
+++ b/test_cases/abigail_reader/typedef/simple_cc.xml
diff --git a/test_cases/abigail_reader/typedef/using_and_typedef.cc.xml b/test_cases/abigail_reader/typedef/using_and_typedef_cc.xml
index f86e85e..f86e85e 100644
--- a/test_cases/abigail_reader/typedef/using_and_typedef.cc.xml
+++ b/test_cases/abigail_reader/typedef/using_and_typedef_cc.xml
diff --git a/test_cases/abigail_reader/typedef/using_in_function.cc.xml b/test_cases/abigail_reader/typedef/using_in_function_cc.xml
index 5a89783..5a89783 100644
--- a/test_cases/abigail_reader/typedef/using_in_function.cc.xml
+++ b/test_cases/abigail_reader/typedef/using_in_function_cc.xml
diff --git a/test_cases/abigail_reader/typedef/void_typedef.c.xml b/test_cases/abigail_reader/typedef/void_typedef_c.xml
index e3362e0..e3362e0 100644
--- a/test_cases/abigail_reader/typedef/void_typedef.c.xml
+++ b/test_cases/abigail_reader/typedef/void_typedef_c.xml
diff --git a/test_cases/abigail_reader/types/char.c.xml b/test_cases/abigail_reader/types/char_c.xml
index 5f74833..5f74833 100644
--- a/test_cases/abigail_reader/types/char.c.xml
+++ b/test_cases/abigail_reader/types/char_c.xml
diff --git a/test_cases/abigail_reader/types/pointer.c.xml b/test_cases/abigail_reader/types/pointer_c.xml
index 2950398..2950398 100644
--- a/test_cases/abigail_reader/types/pointer.c.xml
+++ b/test_cases/abigail_reader/types/pointer_c.xml
diff --git a/test_cases/abigail_reader/types/pointer_reference.cc.xml b/test_cases/abigail_reader/types/pointer_reference_cc.xml
index 48374d5..48374d5 100644
--- a/test_cases/abigail_reader/types/pointer_reference.cc.xml
+++ b/test_cases/abigail_reader/types/pointer_reference_cc.xml
diff --git a/test_cases/info_tests/enum/expected/methods_rs.elf_stg b/test_cases/info_tests/enum/expected/methods_rs.elf_stg
new file mode 100644
index 0000000..855c592
--- /dev/null
+++ b/test_cases/info_tests/enum/expected/methods_rs.elf_stg
@@ -0,0 +1,53 @@
+version: 0x00000002
+root_id: 0x84ea5130 # interface
+primitive {
+ id: 0x2d2f93e0
+ name: "u8"
+ encoding: UNSIGNED_INTEGER
+ bytesize: 0x00000001
+}
+primitive {
+ id: 0xd4bacb77
+ name: "u32"
+ encoding: UNSIGNED_INTEGER
+ bytesize: 0x00000004
+}
+enumeration {
+ id: 0x96f0eeaf
+ name: "methods::Foo"
+ definition {
+ underlying_type_id: 0x2d2f93e0 # u8
+ enumerator {
+ name: "Zero"
+ }
+ enumerator {
+ name: "One"
+ value: 1
+ }
+ enumerator {
+ name: "Two"
+ value: 2
+ }
+ enumerator {
+ name: "Three"
+ value: 3
+ }
+ }
+}
+function {
+ id: 0x8d8230ce
+ return_type_id: 0xd4bacb77 # u32
+ parameter_id: 0x96f0eeaf # enum methods::Foo
+}
+elf_symbol {
+ id: 0x14be2940
+ name: "Foo__to_u32"
+ is_defined: true
+ symbol_type: FUNCTION
+ type_id: 0x8d8230ce # u32(enum methods::Foo)
+ full_name: "methods::to_u32"
+}
+interface {
+ id: 0x84ea5130
+ symbol_id: 0x14be2940 # u32 methods::to_u32(enum methods::Foo)
+}
diff --git a/test_cases/info_tests/enum/methods.rs b/test_cases/info_tests/enum/methods.rs
new file mode 100644
index 0000000..6f6ff89
--- /dev/null
+++ b/test_cases/info_tests/enum/methods.rs
@@ -0,0 +1,14 @@
+pub enum Foo {
+ Zero = 0,
+ One,
+ Two,
+ Three,
+}
+
+impl Foo {
+ // avoid issues with hash in mangled name
+ #[export_name = "Foo__to_u32"]
+ pub fn to_u32(self) -> u32 {
+ self as u32
+ }
+}
diff --git a/test_cases/info_tests/variant/expected/simple_rs.elf_stg b/test_cases/info_tests/variant/expected/simple_rs.elf_stg
new file mode 100644
index 0000000..4621cf8
--- /dev/null
+++ b/test_cases/info_tests/variant/expected/simple_rs.elf_stg
@@ -0,0 +1,33 @@
+version: 0x00000002
+root_id: 0x84ea5130 # interface
+primitive {
+ id: 0x62aebfd4
+ name: "bool"
+ encoding: BOOLEAN
+ bytesize: 0x00000001
+}
+struct_union {
+ id: 0x176387ba
+ kind: STRUCT
+ name: "simple::Foo"
+ definition {
+ bytesize: 12
+ }
+}
+function {
+ id: 0xbb888a50
+ return_type_id: 0x62aebfd4 # bool
+ parameter_id: 0x176387ba # struct simple::Foo
+}
+elf_symbol {
+ id: 0x4e2f2fc8
+ name: "is_unit"
+ is_defined: true
+ symbol_type: FUNCTION
+ type_id: 0xbb888a50 # bool(struct simple::Foo)
+ full_name: "simple::is_unit"
+}
+interface {
+ id: 0x84ea5130
+ symbol_id: 0x4e2f2fc8 # bool simple::is_unit(struct simple::Foo)
+}
diff --git a/test_cases/info_tests/variant/simple.rs b/test_cases/info_tests/variant/simple.rs
new file mode 100644
index 0000000..5f080ec
--- /dev/null
+++ b/test_cases/info_tests/variant/simple.rs
@@ -0,0 +1,14 @@
+#[repr(u8)]
+pub enum Foo {
+ Unit,
+ TwoU32s(u32, u32),
+ ThreeI16s { x: i16, y: i16, z: i16 },
+}
+
+#[no_mangle]
+pub fn is_unit(foo: Foo) -> bool {
+ match foo {
+ Foo::Unit => true,
+ _ => false,
+ }
+}
diff --git a/type_normalisation.cc b/type_normalisation.cc
index 377198f..aeac699 100644
--- a/type_normalisation.cc
+++ b/type_normalisation.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2023 Google LLC
+// Copyright 2023-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -126,6 +126,10 @@ struct FindQualifiedTypesAndFunctions {
(*this)(x.type_id);
}
+ void operator()(const VariantMember& x, Id) {
+ (*this)(x.type_id);
+ }
+
void operator()(const StructUnion& x, Id) {
if (x.definition.has_value()) {
auto& definition = x.definition.value();
@@ -141,6 +145,11 @@ struct FindQualifiedTypesAndFunctions {
}
}
+ void operator()(const Variant& x, Id) {
+ (*this)(x.discriminant_type_id);
+ (*this)(x.members);
+ }
+
void operator()(const Function& x, Id node_id) {
functions.emplace(node_id);
for (auto& id : x.parameters) {
diff --git a/type_resolution.cc b/type_resolution.cc
index 928332c..c9fe51d 100644
--- a/type_resolution.cc
+++ b/type_resolution.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022-2023 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -45,7 +45,7 @@ struct NamedTypes {
seen.Reserve(graph.Limit());
}
- enum class Tag { STRUCT, UNION, ENUM, TYPEDEF };
+ enum class Tag { STRUCT, UNION, ENUM, TYPEDEF, VARIANT };
using Type = std::pair<Tag, std::string>;
struct Info {
std::vector<Id> definitions;
@@ -121,6 +121,10 @@ struct NamedTypes {
(*this)(x.type_id);
}
+ void operator()(const VariantMember& x, Id) {
+ (*this)(x.type_id);
+ }
+
void operator()(const StructUnion& x, Id id) {
auto tag = x.kind == StructUnion::Kind::STRUCT ? Tag::STRUCT : Tag::UNION;
const auto& name = x.name;
@@ -156,6 +160,14 @@ struct NamedTypes {
}
}
+ void operator()(const Variant& x, Id id) {
+ const auto& name = x.name;
+ auto& info = GetInfo(Tag::VARIANT, name);
+ info.definitions.push_back(id);
+ ++definitions;
+ (*this)(x.members);
+ }
+
void operator()(const Function& x, Id) {
(*this)(x.return_type_id);
(*this)(x.parameters);
diff --git a/unification.cc b/unification.cc
index b48c2ee..0d77012 100644
--- a/unification.cc
+++ b/unification.cc
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- mode: C++ -*-
//
-// Copyright 2022-2023 Google LLC
+// Copyright 2022-2024 Google LLC
//
// Licensed under the Apache License v2.0 with LLVM Exceptions (the
// "License"); you may not use this file except in compliance with the
@@ -170,6 +170,13 @@ struct Unifier {
? Right : Neither;
}
+ Winner operator()(const VariantMember& x1, const VariantMember& x2) {
+ return x1.name == x2.name
+ && x1.discriminant_value == x2.discriminant_value
+ && (*this)(x1.type_id, x2.type_id)
+ ? Right : Neither;
+ }
+
Winner operator()(const StructUnion& x1, const StructUnion& x2) {
const auto& definition1 = x1.definition;
const auto& definition2 = x2.definition;
@@ -198,6 +205,14 @@ struct Unifier {
return result ? definition2.has_value() ? Right : Left : Neither;
}
+ Winner operator()(const Variant& x1, const Variant& x2) {
+ return x1.name == x2.name
+ && x1.bytesize == x2.bytesize
+ && (*this)(x1.discriminant_type_id, x2.discriminant_type_id)
+ && (*this)(x1.members, x2.members)
+ ? Right : Neither;
+ }
+
Winner operator()(const Function& x1, const Function& x2) {
return (*this)(x1.parameters, x2.parameters)
&& (*this)(x1.return_type_id, x2.return_type_id)