ealcdan created this revision. Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun. Herald added a reviewer: njames93. Herald added a project: All. ealcdan requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Some options take the maximum unsigned integer value as default, but they are being dumped to a string as integers. This makes -dump-config write invalid '-1' values for these options. This change fixes this issue by using utostr if the option is unsigned. Change-Id: I22d481047330a89984d6eb27bb02f85c71d42bdb Fixes: #60217 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157869 Files: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp clang-tools-extra/clang-tidy/ClangTidyCheck.h Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyCheck.h +++ clang-tools-extra/clang-tidy/ClangTidyCheck.h @@ -350,12 +350,21 @@ /// Stores an option with the check-local name \p LocalName with /// integer value \p Value to \p Options. template <typename T> - std::enable_if_t<std::is_integral<T>::value> + std::enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value> store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) const { storeInt(Options, LocalName, Value); } + /// Stores an option with the check-local name \p LocalName with + /// unsigned integer value \p Value to \p Options. + template <typename T> + std::enable_if_t<std::is_unsigned<T>::value> + store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, + T Value) const { + storeUnsigned(Options, LocalName, Value); + } + /// Stores an option with the check-local name \p LocalName as the string /// representation of the Enum \p Value to \p Options. /// @@ -398,7 +407,8 @@ void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName, int64_t Value) const; - + void storeUnsigned(ClangTidyOptions::OptionMap &Options, + StringRef LocalName, uint64_t Value) const; std::string NamePrefix; const ClangTidyOptions::OptionMap &CheckOptions; Index: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -138,6 +138,12 @@ store(Options, LocalName, llvm::itostr(Value)); } +void ClangTidyCheck::OptionsView::storeUnsigned( + ClangTidyOptions::OptionMap &Options, StringRef LocalName, + uint64_t Value) const { + store(Options, LocalName, llvm::utostr(Value)); +} + template <> void ClangTidyCheck::OptionsView::store<bool>( ClangTidyOptions::OptionMap &Options, StringRef LocalName,
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyCheck.h +++ clang-tools-extra/clang-tidy/ClangTidyCheck.h @@ -350,12 +350,21 @@ /// Stores an option with the check-local name \p LocalName with /// integer value \p Value to \p Options. template <typename T> - std::enable_if_t<std::is_integral<T>::value> + std::enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value> store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) const { storeInt(Options, LocalName, Value); } + /// Stores an option with the check-local name \p LocalName with + /// unsigned integer value \p Value to \p Options. + template <typename T> + std::enable_if_t<std::is_unsigned<T>::value> + store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, + T Value) const { + storeUnsigned(Options, LocalName, Value); + } + /// Stores an option with the check-local name \p LocalName as the string /// representation of the Enum \p Value to \p Options. /// @@ -398,7 +407,8 @@ void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName, int64_t Value) const; - + void storeUnsigned(ClangTidyOptions::OptionMap &Options, + StringRef LocalName, uint64_t Value) const; std::string NamePrefix; const ClangTidyOptions::OptionMap &CheckOptions; Index: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -138,6 +138,12 @@ store(Options, LocalName, llvm::itostr(Value)); } +void ClangTidyCheck::OptionsView::storeUnsigned( + ClangTidyOptions::OptionMap &Options, StringRef LocalName, + uint64_t Value) const { + store(Options, LocalName, llvm::utostr(Value)); +} + template <> void ClangTidyCheck::OptionsView::store<bool>( ClangTidyOptions::OptionMap &Options, StringRef LocalName,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits