[lld] 34d15ea - [lld-macho][nfc] Sanity check on template type

Vy Nguyen via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 16 17:05:01 PST 2021


Author: Vy Nguyen
Date: 2021-11-16T20:04:49-05:00
New Revision: 34d15eaced9db0a9769a7cdb1899ffa534b6ed44

URL: https://github.com/llvm/llvm-project/commit/34d15eaced9db0a9769a7cdb1899ffa534b6ed44
DIFF: https://github.com/llvm/llvm-project/commit/34d15eaced9db0a9769a7cdb1899ffa534b6ed44.diff

LOG: [lld-macho][nfc] Sanity check on template type

Differential Revision: https://reviews.llvm.org/D114044

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 9fb6cd3bf265..7bc432296024 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -70,6 +70,8 @@
 #include "llvm/TextAPI/Architecture.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 
+#include <type_traits>
+
 using namespace llvm;
 using namespace llvm::MachO;
 using namespace llvm::support::endian;
@@ -358,6 +360,9 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
 template <class T>
 static InputSection *findContainingSubsection(Subsections &subsections,
                                               T *offset) {
+  static_assert(std::is_same<uint64_t, T>::value ||
+                    std::is_same<uint32_t, T>::value,
+                "unexpected type for offset");
   auto it = std::prev(llvm::upper_bound(
       subsections, *offset,
       [](uint64_t value, Subsection subsec) { return value < subsec.offset; }));


        


More information about the llvm-commits mailing list