[lld] [lld] check the format of libary and skip the wrong one (PR #78874)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 20 19:49:47 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff bb6564a1b59eaaafbce46b519a45fc9d9e4f8f8a 3f67e78f52433dbaeb8005815fc05314779601b4 -- lld/ELF/Config.h lld/ELF/Driver.cpp lld/ELF/DriverUtils.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 3f0502bf04..dea2741e59 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1221,7 +1221,7 @@ static void readConfigs(opt::InputArgList &args) {
       args.hasArg(OPT_visual_studio_diagnostics_format, false);
 
   config->CheckFormat =
-    args.hasFlag(OPT_check_format, OPT_no_check_format, true);
+      args.hasFlag(OPT_check_format, OPT_no_check_format, true);
 
   config->allowMultipleDefinition =
       args.hasFlag(OPT_allow_multiple_definition,
@@ -3098,55 +3098,56 @@ bool LinkerDriver::checkFile(StringRef path) {
     return true;
 
   Optional<MemoryBufferRef> buffer = readFile(path);
-  if(!buffer)
+  if (!buffer)
     return false;
 
   MemoryBufferRef mbref = *buffer;
 
-  switch(identify_magic(mbref.getBuffer())){
-    case file_magic::unknown:
-      return true;
-    case file_magic::archive: {
-      auto members = getArchiveMembers(mbref);
-      if(inWholeArchive){
-        for (const auto &p : members) {
-          bool SingleFile=isBitcode(p.first)?
-            checkFileFormat(make<BitcodeFile>(p.first, path, p.second, false)):
-            checkFileFormat(createObjFile(p.first, path));
-          return SingleFile;
-        }
-      }
-      for (const auto &p : members){
-        switch(identify_magic(p.first.getBuffer())){
-          case file_magic::elf_relocatable:
-            if(!checkFileFormat(createObjFile(p.first, path, true)))
-              return false;
-            break;
-          case file_magic::bitcode:
-            if(!checkFileFormat(make<BitcodeFile>(p.first, path, p.second, true)))
-              return false;
-            break;
-          default:{
-            warn(path + ": archive member '" + p.first.getBufferIdentifier() +
-                 "' is neither ET_REL nor LLVM bitcode");
-          }
-        }
+  switch (identify_magic(mbref.getBuffer())) {
+  case file_magic::unknown:
+    return true;
+  case file_magic::archive: {
+    auto members = getArchiveMembers(mbref);
+    if (inWholeArchive) {
+      for (const auto &p : members) {
+        bool SingleFile = isBitcode(p.first)
+                              ? checkFileFormat(make<BitcodeFile>(
+                                    p.first, path, p.second, false))
+                              : checkFileFormat(createObjFile(p.first, path));
+        return SingleFile;
       }
-      return true;
     }
-    case file_magic::elf_shared_object:
-      if (config->isStatic || config->relocatable) {
-        warn("attempted static link of dynamic object " + path);
-        return false;
+    for (const auto &p : members) {
+      switch (identify_magic(p.first.getBuffer())) {
+      case file_magic::elf_relocatable:
+        if (!checkFileFormat(createObjFile(p.first, path, true)))
+          return false;
+        break;
+      case file_magic::bitcode:
+        if (!checkFileFormat(make<BitcodeFile>(p.first, path, p.second, true)))
+          return false;
+        break;
+      default: {
+        warn(path + ": archive member '" + p.first.getBufferIdentifier() +
+             "' is neither ET_REL nor LLVM bitcode");
+      }
       }
-      path = mbref.getBufferIdentifier();
-      return checkFileFormat(make<SharedFile>(mbref, path));
-    case file_magic::bitcode:
-      return checkFileFormat(make<BitcodeFile>(mbref, "", 0, inLib));
-    case file_magic::elf_relocatable:
-      return checkFileFormat(createObjFile(mbref, "", inLib));
-    default:
-      warn(path + ": unknown file type");
+    }
+    return true;
+  }
+  case file_magic::elf_shared_object:
+    if (config->isStatic || config->relocatable) {
+      warn("attempted static link of dynamic object " + path);
       return false;
+    }
+    path = mbref.getBufferIdentifier();
+    return checkFileFormat(make<SharedFile>(mbref, path));
+  case file_magic::bitcode:
+    return checkFileFormat(make<BitcodeFile>(mbref, "", 0, inLib));
+  case file_magic::elf_relocatable:
+    return checkFileFormat(createObjFile(mbref, "", inLib));
+  default:
+    warn(path + ": unknown file type");
+    return false;
   }
 }
\ No newline at end of file

``````````

</details>


https://github.com/llvm/llvm-project/pull/78874


More information about the llvm-commits mailing list