llvm.org GIT mirror llvm / 638ba5a
Fix ODR violations due to abuse of LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR This is a short-term fix for PR33650 aimed to get the modules build bots green again. Remove all the places where we use the LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR macros to try to locally specialize a global template for a global type. That's not how C++ works. Instead, we now centrally define how to format vectors of fundamental types and of string (std::string and StringRef). We use flow formatting for the former cases, since that's the obvious right thing to do; in the latter case, it's less clear what the right choice is, but flow formatting is really bad for some cases (due to very long strings), so we pick block formatting. (Many of the cases that were using flow formatting for strings are improved by this change.) Other than the flow -> block formatting change for some vectors of strings, this should result in no functionality change. Differential Revision: https://reviews.llvm.org/D34907 Corresponding updates to clang, clang-tools-extra, and lld to follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306878 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Smith 3 years ago
15 changed file(s) with 112 addition(s) and 78 deletion(s). Raw diff Collapse all Expand all
139139 } // End yaml namespace
140140 } // End llvm namespace
141141
142 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint64_t)
143
144142 namespace llvm {
145143 namespace yaml {
146144
187185
188186 LLVM_YAML_IS_STRING_MAP(TypeIdSummary)
189187 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml)
190 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string)
191188
192189 namespace llvm {
193190 namespace yaml {
160160 } // namespace llvm::DWARFYAML
161161 } // namespace llvm
162162
163 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint8_t)
164163 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
165 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
166164 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
167165 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
168166 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
139139
140140 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
141141 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section)
142 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int64_t)
143142 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
144143 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
145144 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::ExportEntry)
279279 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
280280 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
281281 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
282 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
283282
284283 namespace llvm {
285284 namespace yaml {
179179 /// to/from a YAML sequence. For example:
180180 ///
181181 /// template<>
182 /// struct SequenceTraits< std::vector> {
183 /// static size_t size(IO &io, std::vector &seq) {
182 /// struct SequenceTraits {
183 /// static size_t size(IO &io, MyContainer &seq) {
184184 /// return seq.size();
185185 /// }
186 /// static MyType& element(IO &, std::vector &seq, size_t index) {
186 /// static MyType& element(IO &, MyContainer &seq, size_t index) {
187187 /// if ( index >= seq.size() )
188188 /// seq.resize(index+1);
189189 /// return seq[index];
190190 /// }
191191 /// };
192 template>
192 template, typename EnableIf = void>
193193 struct SequenceTraits {
194194 // Must provide:
195195 // static size_t size(IO &io, T &seq);
198198 // The following is option and will cause generated YAML to use
199199 // a flow sequence (e.g. [a,b,c]).
200200 // static const bool flow = true;
201 };
202
203 /// This class should be specialized by any type for which vectors of that
204 /// type need to be converted to/from a YAML sequence.
205 template
206 struct SequenceElementTraits {
207 // Must provide:
208 // static const bool flow;
201209 };
202210
203211 /// This class should be specialized by any type that needs to be converted
15411549 return yout;
15421550 }
15431551
1544 template struct SequenceTraitsImpl {
1545 using _type = typename T::value_type;
1546
1552 template struct IsFlowSequenceBase {};
1553 template <> struct IsFlowSequenceBase { static const bool flow = true; };
1554
1555 template
1556 struct SequenceTraitsImpl : IsFlowSequenceBase {
1557 private:
1558 using type = typename T::value_type;
1559
1560 public:
15471561 static size_t size(IO &io, T &seq) { return seq.size(); }
15481562
1549 static _type &element(IO &io, T &seq, size_t index) {
1563 static type &element(IO &io, T &seq, size_t index) {
15501564 if (index >= seq.size())
15511565 seq.resize(index + 1);
15521566 return seq[index];
15531567 }
15541568 };
15551569
1570 // Simple helper to check an expression can be used as a bool-valued template
1571 // argument.
1572 template struct CheckIsBool { static const bool value = true; };
1573
1574 // If T has SequenceElementTraits, then vector and SmallVector have
1575 // SequenceTraits that do the obvious thing.
1576 template
1577 struct SequenceTraits,
1578 typename std::enable_if
1579 SequenceElementTraits::flow>::value>::type>
1580 : SequenceTraitsImpl, SequenceElementTraits::flow> {};
1581 template
1582 struct SequenceTraits,
1583 typename std::enable_if
1584 SequenceElementTraits::flow>::value>::type>
1585 : SequenceTraitsImpl, SequenceElementTraits::flow> {};
1586
1587 // Sequences of fundamental types use flow formatting.
1588 template
1589 struct SequenceElementTraits<
1590 T, typename std::enable_if::value>::type> {
1591 static const bool flow = true;
1592 };
1593
1594 // Sequences of strings use block formatting.
1595 template<> struct SequenceElementTraits {
1596 static const bool flow = false;
1597 };
1598 template<> struct SequenceElementTraits {
1599 static const bool flow = false;
1600 };
1601 template<> struct SequenceElementTraits> {
1602 static const bool flow = false;
1603 };
1604
15561605 /// Implementation of CustomMappingTraits for std::map.
15571606 template struct StdMapStringCustomMappingTraitsImpl {
15581607 using map_type = std::map;
15701619 } // end namespace yaml
15711620 } // end namespace llvm
15721621
1622 #define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
1623 namespace llvm { \
1624 namespace yaml { \
1625 static_assert( \
1626 !std::is_fundamental::value && \
1627 !std::is_same::value && \
1628 !std::is_same::value, \
1629 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
1630 template <> struct SequenceElementTraits { \
1631 static const bool flow = FLOW; \
1632 }; \
1633 } \
1634 }
1635
15731636 /// Utility for declaring that a std::vector of a particular type
15741637 /// should be considered a YAML sequence.
1575 #define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \
1576 namespace llvm { \
1577 namespace yaml { \
1578 template <> \
1579 struct SequenceTraits> \
1580 : public SequenceTraitsImpl> {}; \
1581 template \
1582 struct SequenceTraits> \
1583 : public SequenceTraitsImpl> {}; \
1584 } \
1585 }
1638 #define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
1639 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
15861640
15871641 /// Utility for declaring that a std::vector of a particular type
15881642 /// should be considered a YAML flow sequence.
1589 /// We need to do a partial specialization on the vector version, not a full.
1590 /// If this is a full specialization, the compiler is a bit too "smart" and
1591 /// decides to warn on -Wunused-const-variable. This workaround can be
1592 /// removed and we can do a full specialization on std::vector once
1593 /// PR28878 is fixed.
1594 #define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \
1595 namespace llvm { \
1596 namespace yaml { \
1597 template \
1598 struct SequenceTraits> \
1599 : public SequenceTraitsImpl> { \
1600 static const bool flow = true; \
1601 }; \
1602 template \
1603 struct SequenceTraits> \
1604 : public SequenceTraitsImpl> { \
1605 static const bool flow = true; \
1606 }; \
1607 } \
1608 }
1643 #define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
1644 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
16091645
16101646 #define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
16111647 namespace llvm { \
16521688 namespace yaml { \
16531689 template \
16541690 struct DocumentListTraits> \
1655 : public SequenceTraitsImpl> {}; \
1691 : public SequenceTraitsImpl, false> {}; \
16561692 template <> \
16571693 struct DocumentListTraits> \
1658 : public SequenceTraitsImpl> {}; \
1694 : public SequenceTraitsImpl, false> {}; \
16591695 } \
16601696 }
16611697
4747 LLVM_YAML_IS_SEQUENCE_VECTOR(InlineeInfo)
4848 LLVM_YAML_IS_SEQUENCE_VECTOR(CrossModuleExport)
4949 LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLCrossModuleImport)
50 LLVM_YAML_IS_SEQUENCE_VECTOR(StringRef)
5150 LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLFrameData)
52 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
5351
5452 LLVM_YAML_DECLARE_SCALAR_TRAITS(HexFormattedString, false)
5553 LLVM_YAML_DECLARE_ENUM_TRAITS(DebugSubsectionKind)
2626 using namespace llvm::CodeViewYAML::detail;
2727 using namespace llvm::yaml;
2828
29 LLVM_YAML_IS_SEQUENCE_VECTOR(StringRef)
3029 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex)
3130
3231 // We only need to declare these, the definitions are in CodeViewYAMLTypes.cpp
2828 using namespace llvm::yaml;
2929
3030 LLVM_YAML_IS_SEQUENCE_VECTOR(OneMethodRecord)
31 LLVM_YAML_IS_SEQUENCE_VECTOR(StringRef)
3231 LLVM_YAML_IS_SEQUENCE_VECTOR(VFTableSlotKind)
3332 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex)
3433
1919 using namespace llvm::AMDGPU;
2020 using namespace llvm::AMDGPU::CodeObject;
2121
22 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
23 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string)
2422 LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Arg::Metadata)
2523 LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Metadata)
2624
1515
1616 ; CHECK: ---
1717 ; CHECK: Version: [ 1, 0 ]
18 ; CHECK: Printf: [ '1:1:4:%d\n', '2:1:8:%g\n' ]
18 ; CHECK: Printf:
19 ; CHECK: - '1:1:4:%d\n'
20 ; CHECK: - '2:1:8:%g\n'
1921 ; CHECK: Kernels:
2022
2123 ; CHECK: - Name: test_char
12521254 ; NOTES-NEXT: Owner Data size Description
12531255 ; NOTES-NEXT: AMD 0x00000008 Unknown note type: (0x00000001)
12541256 ; NOTES-NEXT: AMD 0x0000001b Unknown note type: (0x00000003)
1255 ; GFX700: AMD 0x00008b06 Unknown note type: (0x0000000a)
1256 ; GFX800: AMD 0x00008e6a Unknown note type: (0x0000000a)
1257 ; GFX900: AMD 0x00008b06 Unknown note type: (0x0000000a)
1257 ; GFX700: AMD 0x00008b0a Unknown note type: (0x0000000a)
1258 ; GFX800: AMD 0x00008e6e Unknown note type: (0x0000000a)
1259 ; GFX900: AMD 0x00008b0a Unknown note type: (0x0000000a)
12581260
12591261 ; PARSER: AMDGPU Code Object Metadata Parser Test: PASS
33
44 // CHECK: .amdgpu_code_object_metadata
55 // CHECK: Version: [ 1, 0 ]
6 // CHECK: Printf: [ '1:1:4:%d\n', '2:1:8:%g\n' ]
6 // CHECK: Printf:
7 // CHECK: - '1:1:4:%d\n'
8 // CHECK: - '2:1:8:%g\n'
79 // CHECK: Kernels:
810 // CHECK: - Name: test_kernel
911 // CHECK: Language: OpenCL C
33
44 // CHECK: .amdgpu_code_object_metadata
55 // CHECK: Version: [ 1, 0 ]
6 // CHECK: Printf: [ '1:1:4:%d\n', '2:1:8:%g\n' ]
6 // CHECK: Printf:
7 // CHECK: - '1:1:4:%d\n'
8 // CHECK: - '2:1:8:%g\n'
79 // CHECK: Kernels:
810 // CHECK: - Name: test_kernel
911 // CHECK: Language: OpenCL C
5959 ; SUMMARY-NEXT: SizeM1BitWidth: 0
6060 ; SUMMARY-NEXT: WPDRes:
6161
62 ; SUMMARY: CfiFunctionDefs: [ f, g, h ]
63 ; SUMMARY-NEXT: CfiFunctionDecls: [ external, external_weak ]
62 ; SUMMARY: CfiFunctionDefs:
63 ; SUMMARY-NEXT: - f
64 ; SUMMARY-NEXT: - g
65 ; SUMMARY-NEXT: - h
66 ; SUMMARY-NEXT: CfiFunctionDecls:
67 ; SUMMARY-NEXT: - external
68 ; SUMMARY-NEXT: - external_weak
6469 ; SUMMARY-NEXT: ...
2929 using namespace llvm::pdb::yaml;
3030 using namespace llvm::yaml;
3131
32 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
33 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
3432 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::NamedStreamMapping)
3533 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbDbiModuleInfo)
3634 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::StreamBlockList)
10281028
10291029 LLVM_YAML_STRONG_TYPEDEF(int, MyNumber)
10301030 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyNumber)
1031 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::StringRef)
1031 LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, MyString)
1032 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyString)
10321033
10331034 namespace llvm {
10341035 namespace yaml {
10481049
10491050 static bool mustQuote(StringRef) { return false; }
10501051 };
1052
1053 template <> struct ScalarTraits {
1054 using Impl = ScalarTraits;
1055 static void output(const MyString &V, void *Ctx, raw_ostream &OS) {
1056 Impl::output(V, Ctx, OS);
1057 }
1058 static StringRef input(StringRef S, void *Ctx, MyString &V) {
1059 return Impl::input(S, Ctx, V.value);
1060 }
1061 static bool mustQuote(StringRef S) { return Impl::mustQuote(S); }
1062 };
10511063 }
10521064 }
10531065
10541066 struct NameAndNumbers {
10551067 llvm::StringRef name;
1056 std::vector<llvm::StringRef> strings;
1068 std::vector<MyString> strings;
10571069 std::vector single;
10581070 std::vector numbers;
10591071 };
11271139 EXPECT_FALSE(yin.error());
11281140 EXPECT_TRUE(map2.name.equals("hello"));
11291141 EXPECT_EQ(map2.strings.size(), 2UL);
1130 EXPECT_TRUE(map2.strings[0].equals("one"));
1131 EXPECT_TRUE(map2.strings[1].equals("two"));
1142 EXPECT_TRUE(map2.strings[0].value.equals("one"));
1143 EXPECT_TRUE(map2.strings[1].value.equals("two"));
11321144 EXPECT_EQ(map2.single.size(), 1UL);
11331145 EXPECT_EQ(1, map2.single[0]);
11341146 EXPECT_EQ(map2.numbers.size(), 3UL);
17381750 //
17391751 // Test error handling reading built-in uint8_t type
17401752 //
1741 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint8_t)
17421753 TEST(YAMLIO, TestReadBuiltInTypesUint8Error) {
17431754 std::vector seq;
17441755 Input yin("---\n"
17571768 //
17581769 // Test error handling reading built-in uint16_t type
17591770 //
1760 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint16_t)
17611771 TEST(YAMLIO, TestReadBuiltInTypesUint16Error) {
17621772 std::vector seq;
17631773 Input yin("---\n"
17761786 //
17771787 // Test error handling reading built-in uint32_t type
17781788 //
1779 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
17801789 TEST(YAMLIO, TestReadBuiltInTypesUint32Error) {
17811790 std::vector seq;
17821791 Input yin("---\n"
17951804 //
17961805 // Test error handling reading built-in uint64_t type
17971806 //
1798 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint64_t)
17991807 TEST(YAMLIO, TestReadBuiltInTypesUint64Error) {
18001808 std::vector seq;
18011809 Input yin("---\n"
18141822 //
18151823 // Test error handling reading built-in int8_t type
18161824 //
1817 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int8_t)
18181825 TEST(YAMLIO, TestReadBuiltInTypesint8OverError) {
18191826 std::vector seq;
18201827 Input yin("---\n"
18521859 //
18531860 // Test error handling reading built-in int16_t type
18541861 //
1855 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int16_t)
18561862 TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) {
18571863 std::vector seq;
18581864 Input yin("---\n"
18911897 //
18921898 // Test error handling reading built-in int32_t type
18931899 //
1894 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int32_t)
18951900 TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) {
18961901 std::vector seq;
18971902 Input yin("---\n"
19291934 //
19301935 // Test error handling reading built-in int64_t type
19311936 //
1932 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int64_t)
19331937 TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) {
19341938 std::vector seq;
19351939 Input yin("---\n"
19661970 //
19671971 // Test error handling reading built-in float type
19681972 //
1969 LLVM_YAML_IS_SEQUENCE_VECTOR(float)
19701973 TEST(YAMLIO, TestReadBuiltInTypesFloatError) {
19711974 std::vector seq;
19721975 Input yin("---\n"
19851988 //
19861989 // Test error handling reading built-in float type
19871990 //
1988 LLVM_YAML_IS_SEQUENCE_VECTOR(double)
19891991 TEST(YAMLIO, TestReadBuiltInTypesDoubleError) {
19901992 std::vector seq;
19911993 Input yin("---\n"