[PATCH] D157869: [clang-tidy] Avoid overflow when dumping unsigned integer values

2023-08-14 Thread Daniel Alcaide Nombela via Phabricator via cfe-commits
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 
-std::enable_if_t::value>
+std::enable_if_t::value && std::is_signed::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 
+std::enable_if_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(
 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 
-std::enable_if_t::value>
+std::enable_if_t::value && std::is_signed::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 
+std::enable_if_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(
 ClangTidyOptions::OptionMap &Options, StringRef LocalName,
___
cfe-commits mailing list

[PATCH] D157869: [clang-tidy] Avoid overflow when dumping unsigned integer values

2023-08-14 Thread Daniel Alcaide Nombela via Phabricator via cfe-commits
ealcdan added a comment.

Thanks for the review. How should I procceed? Should I remove the "Fixes:" 
entry from the commit message?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157869/new/

https://reviews.llvm.org/D157869

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits