From acb33cba6d455dd96d82e2b746b2237f283a6416 Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Tue, 20 Oct 2020 17:50:29 -0700 Subject: [llvm] Fix ODRViolations for VersionTuple YAML specializations NFC It appears for Swift there was confusing errors when trying to parse APINotes, when libAPINotes and libInterfaceStub are linked, they both export symbol `__ZN4llvm4yaml7yamlizeINS_12VersionTupleEEENSt3__19enable_ifIXsr16has_ScalarTraitsIT_EE5valueEvE4typeERNS0_2IOERS5_bRNS0_12EmptyContextE`, and discovered same symbol defined within llvm-ifs. This consolidates the boilerplate into YAMLTraits and defers the specific validation in reading the whole input. fixes: rdar://problem/70450563 Reviewed By: phosek, dblaikie Differential Revision: https://reviews.llvm.org/D89764 --- llvm/tools/llvm-ifs/llvm-ifs.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'llvm/tools/llvm-ifs/llvm-ifs.cpp') diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp index eb18be2..8906300 100644 --- a/llvm/tools/llvm-ifs/llvm-ifs.cpp +++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp @@ -104,27 +104,6 @@ template <> struct ScalarEnumerationTraits { } }; -template <> struct ScalarTraits { - static void output(const VersionTuple &Value, void *, - llvm::raw_ostream &Out) { - Out << Value.getAsString(); - } - - static StringRef input(StringRef Scalar, void *, VersionTuple &Value) { - if (Value.tryParse(Scalar)) - return StringRef("Can't parse version: invalid version format."); - - if (Value > IFSVersionCurrent) - return StringRef("Unsupported IFS version."); - - // Returning empty StringRef indicates successful parse. - return StringRef(); - } - - // Don't place quotation marks around version value. - static QuotingType mustQuote(StringRef) { return QuotingType::None; } -}; - /// YAML traits for IFSSymbol. template <> struct MappingTraits { static void mapping(IO &IO, IFSSymbol &Symbol) { @@ -210,6 +189,11 @@ static Expected> readInputFile(StringRef FilePath) { if (std::error_code Err = YamlIn.error()) return createStringError(Err, "Failed reading Interface Stub File."); + if (Stub->IfsVersion > IFSVersionCurrent) + return make_error( + "IFS version " + Stub->IfsVersion.getAsString() + " is unsupported.", + std::make_error_code(std::errc::invalid_argument)); + return std::move(Stub); } -- cgit v1.1