https://github.com/AdityaSinha149 created 
https://github.com/llvm/llvm-project/pull/238231

This is an NFC PR. It changes the if else chain in the `CreateFileHandler` 
function to use a `StringSwitch`. It makes the code more readable and more 
convenient for future additions. 

>From 9579df04600e5c3c7b82fdebeeca731ac19e4400 Mon Sep 17 00:00:00 2001
From: AdityaSinha149 <[email protected]>
Date: Tue, 3 Nov 2026 12:28:30 +0530
Subject: [PATCH] [NFC][clang][Driver] Changed if-else to a StringSwitch in
 CreateFileHandler

---
 clang/lib/Driver/OffloadBundler.cpp | 41 +++++++++++------------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index 2d0c326ab6f406..521b2889141634 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -913,33 +913,24 @@ static Expected<std::unique_ptr<FileHandler>>
 CreateFileHandler(MemoryBuffer &FirstInput,
                   const OffloadBundlerConfig &BundlerConfig) {
   std::string FilesType = BundlerConfig.FilesType;
-
-  if (FilesType == "i")
-    return std::make_unique<TextFileHandler>(/*Comment=*/"//");
-  if (FilesType == "ii")
-    return std::make_unique<TextFileHandler>(/*Comment=*/"//");
-  if (FilesType == "cui")
-    return std::make_unique<TextFileHandler>(/*Comment=*/"//");
-  if (FilesType == "hipi")
-    return std::make_unique<TextFileHandler>(/*Comment=*/"//");
   // TODO: `.d` should be eventually removed once `-M` and its variants are
   // handled properly in offload compilation.
-  if (FilesType == "d")
-    return std::make_unique<TextFileHandler>(/*Comment=*/"#");
-  if (FilesType == "ll")
-    return std::make_unique<TextFileHandler>(/*Comment=*/";");
-  if (FilesType == "bc")
-    return std::make_unique<BinaryFileHandler>(BundlerConfig);
-  if (FilesType == "s")
-    return std::make_unique<TextFileHandler>(/*Comment=*/"#");
-  if (FilesType == "o")
-    return CreateObjectFileHandler(FirstInput, BundlerConfig);
-  if (FilesType == "a")
-    return CreateObjectFileHandler(FirstInput, BundlerConfig);
-  if (FilesType == "gch")
-    return std::make_unique<BinaryFileHandler>(BundlerConfig);
-  if (FilesType == "ast")
-    return std::make_unique<BinaryFileHandler>(BundlerConfig);
+  enum class Kind { SlashText, HashText, SemiText, Binary, Object, Unknown };
+  Kind K = StringSwitch<Kind>(FilesType)
+                .Cases({"i", "ii", "cui", "hipi"}, Kind::SlashText)
+                .Cases({"d", "s"}, Kind::HashText)
+                .Case("ll", Kind::SemiText)
+                .Cases({"bc", "gch", "ast"}, Kind::Binary)
+                .Cases({"o", "a"}, Kind::Object)
+                .Default(Kind::Unknown);
+  switch (K) {
+  case Kind::SlashText: return std::make_unique<TextFileHandler>("//");
+  case Kind::HashText:  return std::make_unique<TextFileHandler>("#");
+  case Kind::SemiText:  return std::make_unique<TextFileHandler>(";");
+  case Kind::Binary:    return 
std::make_unique<BinaryFileHandler>(BundlerConfig);
+  case Kind::Object:    return CreateObjectFileHandler(FirstInput, 
BundlerConfig);
+  case Kind::Unknown:   break;
+  }
 
   return createStringError(errc::invalid_argument,
                            "'" + FilesType + "': invalid file type specified");

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to