[PATCH 3/3] lint: Initial changes for clang-plugin

Tulio Magno Quites Machado Filho tuliom@ascii.art.br
Mon Apr 27 19:30:26 GMT 2026


From: Tulio Magno Quites Machado Filho <tuliom@redhat.com>

Start adapting clang-plugin's code based on the output from clang-tidy.
---
 clang-plugin/annobin.cpp | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang-plugin/annobin.cpp b/clang-plugin/annobin.cpp
index 1ba8b61..a739d43 100644
--- a/clang-plugin/annobin.cpp
+++ b/clang-plugin/annobin.cpp
@@ -29,6 +29,7 @@ using namespace llvm;
 
 #include "annobin-global.h"
 #include "annobin-common.h"
+#include <algorithm>
 #include <cstring>
 #include <cctype>
 #include <cstdarg>
@@ -130,7 +131,7 @@ private:
 #endif
 
       SourceManager & src = Context.getSourceManager ();
-      std::string filename = src.getFilename (src.getLocForStartOfFile (src.getMainFileID ())).str ().c_str ();
+      std::string filename = src.getFilename (src.getLocForStartOfFile (src.getMainFileID ())).str ();
 
       convert_to_valid_symbol_name (filename);
       verbose ("Generate start and end symbols based on: %s", filename.c_str());
@@ -197,7 +198,7 @@ private:
 
   private:
 
-    void
+    static void
     convert_to_valid_symbol_name (std::string& name)
     {
       for (auto & c : name)
@@ -214,7 +215,7 @@ private:
 	     append the time to the symbol name.  This will of course break
 	     the functionality of build-ids and reproducible builds.  That is
 	     why this option is off by default.  */
-	  struct timeval tv;
+	  struct timeval tv = {0, 0};
 
 	  if (gettimeofday (& tv, NULL))
 	    {
@@ -471,8 +472,7 @@ private:
       // The -cfguard option is Windows only - so we ignore it.
 
       val = CodeOpts.OptimizationLevel;
-      if (val > 3)
-	val = 3;
+      val = std::min(val, 3U);
       // The optimization level occupies bits 9..11 of the GOW value.
       val <<= 9;
       // FIXME: The value of Context.getDiagnostics().getEnableAllWarnings() does
@@ -586,8 +586,7 @@ private:
     {
       if (enabled)
 	return std::make_unique<AnnobinConsumer>(CI);
-      else
-	return std::make_unique<AnnobinDummyConsumer>(CI);
+      return std::make_unique<AnnobinDummyConsumer>(CI);
     }
 
     // Automatically run the plugin
@@ -664,8 +663,8 @@ private:
       // This allows command line options to override the environment.
       annobin_parse_env (parse_arg, (void *) "env");
 
-      for (unsigned i = 0, e = args.size(); i < e; ++i)
-	parse_arg (args[i].c_str (), "",  NULL);
+      for (const auto & i : args)
+	parse_arg (i.c_str (), "",  NULL);
 
       // This message has a secondary purpose.  It makes sure that the compiled
       // plugin includes a string which is specific to the installation directory.
-- 
2.50.1



More information about the Annobin mailing list