[libc-commits] [PATCH] D115028: [libc] More resilient arch dependent include selection

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Dec 3 01:08:50 PST 2021


gchatelet created this revision.
gchatelet added a reviewer: gchatelet.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added a project: libc-project.
gchatelet requested review of this revision.

I intend to use this approach for arch dependant include selection, it is more resilient to file movement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115028

Files:
  libc/src/string/memory_utils/elements.h
  libc/src/string/memory_utils/elements_aarch64.h
  libc/src/string/memory_utils/elements_x86.h


Index: libc/src/string/memory_utils/elements_x86.h
===================================================================
--- libc/src/string/memory_utils/elements_x86.h
+++ libc/src/string/memory_utils/elements_x86.h
@@ -9,9 +9,11 @@
 #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
 
-#include "src/__support/architectures.h"
+#if !defined(LLVM_LIBC_ARCH_X86)
+#error "Invalid include"
+#endif
 
-#if defined(LLVM_LIBC_ARCH_X86)
+#include "src/__support/architectures.h"
 
 #include <stddef.h> // size_t
 #include <stdint.h> // uint8_t, uint16_t, uint32_t, uint64_t
@@ -177,6 +179,4 @@
 } // namespace x86
 } // namespace __llvm_libc
 
-#endif // defined(LLVM_LIBC_ARCH_X86)
-
 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
Index: libc/src/string/memory_utils/elements_aarch64.h
===================================================================
--- libc/src/string/memory_utils/elements_aarch64.h
+++ libc/src/string/memory_utils/elements_aarch64.h
@@ -11,7 +11,9 @@
 
 #include "src/__support/architectures.h"
 
-#if defined(LLVM_LIBC_ARCH_AARCH64)
+#if !defined(LLVM_LIBC_ARCH_AARCH64)
+#error "Invalid include"
+#endif
 
 #include <src/string/memory_utils/elements.h>
 #include <stddef.h> // size_t
@@ -119,6 +121,4 @@
 } // namespace aarch64
 } // namespace __llvm_libc
 
-#endif // defined(LLVM_LIBC_ARCH_AARCH64)
-
 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_AARCH64_H
Index: libc/src/string/memory_utils/elements.h
===================================================================
--- libc/src/string/memory_utils/elements.h
+++ libc/src/string/memory_utils/elements.h
@@ -657,7 +657,10 @@
 } // namespace scalar
 } // namespace __llvm_libc
 
+#if defined(LLVM_LIBC_ARCH_AARCH64)
 #include <src/string/memory_utils/elements_aarch64.h>
+#elif defined(LLVM_LIBC_ARCH_X86)
 #include <src/string/memory_utils/elements_x86.h>
+#endif
 
 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115028.391575.patch
Type: text/x-patch
Size: 1987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20211203/c508df28/attachment.bin>


More information about the libc-commits mailing list