[compiler-rt] [sanitizer_common] Add AIX specific platform support to sanitizer_common (PR #131866)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 18 10:37:54 PDT 2025


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 8e6fa15bc3e8a41553ffdc7fbd3d00285a250962 d8273ed5690fe55276f842e738edf4c6e801a56a --extensions inc,cpp,h -- compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno.h compiler-rt/lib/sanitizer_common/sanitizer_flags.inc compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
``````````

</details>

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

``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
index db4805468c..b357345ec7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
@@ -17,13 +17,13 @@
 // Helper to suppress warnings related to 8-byte atomic accesses when the target
 // is 32-bit AIX (where such accesses use libatomic).
 #if defined(_AIX) && !defined(__powerpc64__) && defined(__clang__)
-#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN                                \
-  _Pragma("clang diagnostic push")                                             \
-      _Pragma("clang diagnostic ignored \"-Watomic-alignment\"")
-#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END _Pragma("clang diagnostic pop")
+#  define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN \
+    _Pragma("clang diagnostic push")              \
+        _Pragma("clang diagnostic ignored \"-Watomic-alignment\"")
+#  define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END _Pragma("clang diagnostic pop")
 #else
-#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN
-#define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END
+#  define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_BEGIN
+#  define SANITIZER_IGNORE_ATOMIC_ALIGNMENT_END
 #endif
 
 namespace __sanitizer {
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
index a770c8cf65..aa30fd9b5d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
@@ -170,10 +170,10 @@ void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name,
     Report(
         "ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. "
         "Perhaps you're using ulimit -v "
-#if SANITIZER_AIX && SANITIZER_WORDSIZE == 32
+#  if SANITIZER_AIX && SANITIZER_WORDSIZE == 32
         "or using large address-space model for 32-bit XCOFF by using ldedit "
         "or setting LDR_CNTRL=MAXDATA or compiling the binary with -bmaxdata "
-#endif
+#  endif
         "\n",
         size);
     Die();
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index 214d286589..9de8c8aed0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -142,7 +142,7 @@
 #  define SANITIZER_MUSL 0
 #endif
 
-#define SANITIZER_POSIX                                     \
+#define SANITIZER_POSIX                                       \
   (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_APPLE || \
    SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_AIX)
 
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index 09a2fce1d8..6d23831f50 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -61,11 +61,11 @@
 #endif
 
 #if !SANITIZER_ANDROID
-#if !SANITIZER_AIX
-#include <sys/mount.h>
-#endif
-#include <sys/timeb.h>
-#include <utmpx.h>
+#    if !SANITIZER_AIX
+#      include <sys/mount.h>
+#    endif
+#    include <sys/timeb.h>
+#    include <utmpx.h>
 #endif
 
 #if SANITIZER_LINUX
@@ -112,13 +112,13 @@ typedef struct user_fpregs elf_fpregset_t;
 #endif
 
 #if !SANITIZER_ANDROID
-#if !SANITIZER_AIX
-#include <ifaddrs.h>
-#else
-#include <netinet/in.h>
-#endif
-#include <sys/ucontext.h>
-#include <wordexp.h>
+#    if !SANITIZER_AIX
+#      include <ifaddrs.h>
+#    else
+#      include <netinet/in.h>
+#    endif
+#    include <sys/ucontext.h>
+#    include <wordexp.h>
 #endif
 
 #if SANITIZER_LINUX
@@ -179,16 +179,16 @@ typedef struct user_fpregs elf_fpregset_t;
 #include <sys/sockio.h>
 #endif
 
-#if SANITIZER_AIX
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <stropts.h>
-#include <sys/statfs.h>
-#include <netinet/ip_mroute.h>
-#if HAVE_RPC_XDR_H
-#include <tirpc/rpc/xdr.h>
-#endif
-#endif
+#  if SANITIZER_AIX
+#    include <netinet/ip_mroute.h>
+#    include <stropts.h>
+#    include <sys/ioctl.h>
+#    include <sys/statfs.h>
+#    include <unistd.h>
+#    if HAVE_RPC_XDR_H
+#      include <tirpc/rpc/xdr.h>
+#    endif
+#  endif
 
 // Include these after system headers to avoid name clashes and ambiguities.
 #  include "sanitizer_common.h"
@@ -569,7 +569,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   const unsigned IOCTL_NOT_PRESENT = 0;
 
   // On AIX, some variables are unsigned long types.
-#if SANITIZER_AIX
+#  if SANITIZER_AIX
   uptr IOCTL_FIOASYNC = FIOASYNC;
   uptr IOCTL_FIONBIO = FIONBIO;
   uptr IOCTL_FIOSETOWN = FIOSETOWN;
@@ -583,7 +583,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   uptr IOCTL_TIOCSPGRP = TIOCSPGRP;
   uptr IOCTL_TIOCSTI = TIOCSTI;
   uptr IOCTL_TIOCSWINSZ = TIOCSWINSZ;
-#else
+#  else
   unsigned IOCTL_FIOASYNC = FIOASYNC;
   unsigned IOCTL_FIONBIO = FIONBIO;
   unsigned IOCTL_FIOSETOWN = FIOSETOWN;
@@ -597,7 +597,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned IOCTL_TIOCSPGRP = TIOCSPGRP;
   unsigned IOCTL_TIOCSTI = TIOCSTI;
   unsigned IOCTL_TIOCSWINSZ = TIOCSWINSZ;
-#endif
+#  endif
   unsigned IOCTL_FIOCLEX = FIOCLEX;
   unsigned IOCTL_FIOGETOWN = FIOGETOWN;
   unsigned IOCTL_FIONCLEX = FIONCLEX;
@@ -628,10 +628,10 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned IOCTL_TIOCNOTTY = TIOCNOTTY;
   unsigned IOCTL_TIOCNXCL = TIOCNXCL;
   unsigned IOCTL_TIOCOUTQ = TIOCOUTQ;
-#if !SANITIZER_AIX
+#  if !SANITIZER_AIX
   unsigned IOCTL_TIOCSCTTY = TIOCSCTTY;
-#endif
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  endif
+#  if SANITIZER_LINUX && !SANITIZER_ANDROID
   unsigned IOCTL_SIOCGETSGCNT = SIOCGETSGCNT;
   unsigned IOCTL_SIOCGETVIFCNT = SIOCGETVIFCNT;
 #endif
@@ -1139,13 +1139,13 @@ COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
 CHECK_SIZE_AND_OFFSET(dirent, d_ino);
 #if SANITIZER_APPLE
 CHECK_SIZE_AND_OFFSET(dirent, d_seekoff);
-#elif SANITIZER_AIX
+#  elif SANITIZER_AIX
 CHECK_SIZE_AND_OFFSET(dirent, d_offset);
-#elif SANITIZER_FREEBSD
+#  elif SANITIZER_FREEBSD
 // There is no 'd_off' field on FreeBSD.
-#else
+#  else
 CHECK_SIZE_AND_OFFSET(dirent, d_off);
-#endif
+#  endif
 CHECK_SIZE_AND_OFFSET(dirent, d_reclen);
 
 #if SANITIZER_GLIBC
@@ -1229,12 +1229,12 @@ CHECK_SIZE_AND_OFFSET(tm, tm_year);
 CHECK_SIZE_AND_OFFSET(tm, tm_wday);
 CHECK_SIZE_AND_OFFSET(tm, tm_yday);
 CHECK_SIZE_AND_OFFSET(tm, tm_isdst);
-#if !SANITIZER_AIX
+#  if !SANITIZER_AIX
 CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff);
 CHECK_SIZE_AND_OFFSET(tm, tm_zone);
-#endif
+#  endif
 
-#if SANITIZER_LINUX
+#  if SANITIZER_LINUX
 CHECK_TYPE_SIZE(mntent);
 CHECK_SIZE_AND_OFFSET(mntent, mnt_fsname);
 CHECK_SIZE_AND_OFFSET(mntent, mnt_dir);
@@ -1282,7 +1282,7 @@ CHECK_TYPE_SIZE(clock_t);
 CHECK_TYPE_SIZE(clockid_t);
 #endif
 
-#if !SANITIZER_ANDROID && !SANITIZER_AIX
+#  if !SANITIZER_ANDROID && !SANITIZER_AIX
 CHECK_TYPE_SIZE(ifaddrs);
 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 4f5022a75d..4b78944517 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -16,25 +16,25 @@
 
 #if SANITIZER_LINUX || SANITIZER_APPLE || SANITIZER_AIX
 
-#include "sanitizer_internal_defs.h"
-#include "sanitizer_platform.h"
-#include "sanitizer_mallinfo.h"
-
-#if SANITIZER_APPLE
-#include <sys/cdefs.h>
-#if !__DARWIN_ONLY_64_BIT_INO_T
-#define SANITIZER_HAS_STAT64 1
-#define SANITIZER_HAS_STATFS64 1
-#else
-#define SANITIZER_HAS_STAT64 0
-#define SANITIZER_HAS_STATFS64 0
-#endif
-#elif SANITIZER_GLIBC || SANITIZER_ANDROID || SANITIZER_AIX
-#define SANITIZER_HAS_STAT64 1
-#define SANITIZER_HAS_STATFS64 1
-#endif
+#  include "sanitizer_internal_defs.h"
+#  include "sanitizer_platform.h"
+#  include "sanitizer_mallinfo.h"
+
+#  if SANITIZER_APPLE
+#    include <sys/cdefs.h>
+#    if !__DARWIN_ONLY_64_BIT_INO_T
+#      define SANITIZER_HAS_STAT64 1
+#      define SANITIZER_HAS_STATFS64 1
+#    else
+#      define SANITIZER_HAS_STAT64 0
+#      define SANITIZER_HAS_STATFS64 0
+#    endif
+#  elif SANITIZER_GLIBC || SANITIZER_ANDROID || SANITIZER_AIX
+#    define SANITIZER_HAS_STAT64 1
+#    define SANITIZER_HAS_STATFS64 1
+#  endif
 
-#if defined(__sparc__)
+#  if defined(__sparc__)
 // FIXME: This can't be included from tsan which does not support sparc yet.
 #include "sanitizer_glibc_version.h"
 #endif
@@ -319,7 +319,7 @@ struct __sanitizer_iovec {
   usize iov_len;
 };
 
-#if !SANITIZER_ANDROID && !SANITIZER_AIX
+#  if !SANITIZER_ANDROID && !SANITIZER_AIX
 struct __sanitizer_ifaddrs {
   struct __sanitizer_ifaddrs *ifa_next;
   char *ifa_name;
@@ -341,7 +341,7 @@ typedef unsigned long __sanitizer_pthread_key_t;
 typedef unsigned __sanitizer_pthread_key_t;
 #endif
 
-#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_AIX
+#  if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_AIX
 
 struct __sanitizer_XDR {
   int x_op;
@@ -433,10 +433,10 @@ struct __sanitizer_tm {
   int tm_wday;
   int tm_yday;
   int tm_isdst;
-#if !SANITIZER_AIX
+#  if !SANITIZER_AIX
   long int tm_gmtoff;
   const char *tm_zone;
-#endif
+#  endif
 };
 
 #if SANITIZER_LINUX
@@ -480,19 +480,19 @@ struct __sanitizer_msghdr {
   struct __sanitizer_iovec *msg_iov;
   uptr msg_iovlen;
   void *msg_control;
-#if !SANITIZER_AIX
+#    if !SANITIZER_AIX
   uptr msg_controllen;
-#else
+#    else
   unsigned msg_controllen;
-#endif
+#    endif
   int msg_flags;
 };
 struct __sanitizer_cmsghdr {
-#if !SANITIZER_AIX
+#    if !SANITIZER_AIX
   uptr cmsg_len;
-#else
+#    else
   unsigned cmsg_len;
-#endif
+#    endif
   int cmsg_level;
   int cmsg_type;
 };
@@ -522,13 +522,13 @@ struct __sanitizer_dirent {
 };
 #  else
 struct __sanitizer_dirent {
-#if SANITIZER_AIX
+#    if SANITIZER_AIX
   uptr d_offset;
   uptr d_ino;
-#else
+#    else
   uptr d_ino;
   uptr d_off;
-#endif
+#    endif
   unsigned short d_reclen;
   // more fields that we don't care about
 };
@@ -544,16 +544,16 @@ struct __sanitizer_dirent64 {
 extern unsigned struct_sock_fprog_sz;
 #endif
 
-#if SANITIZER_AIX
+#  if SANITIZER_AIX
 typedef int __sanitizer_clock_t;
 typedef int __sanitizer_clockid_t;
-#elif defined(__x86_64__) && !defined(_LP64)
+#  elif defined(__x86_64__) && !defined(_LP64)
 typedef long long __sanitizer_clock_t;
-#else
+#  else
 typedef long __sanitizer_clock_t;
-#endif
+#  endif
 
-#if SANITIZER_LINUX
+#  if SANITIZER_LINUX
 typedef int __sanitizer_clockid_t;
 typedef unsigned long long __sanitizer_eventfd_t;
 #endif
@@ -607,15 +607,15 @@ struct __sanitizer_sigset_t {
   // The size is determined by looking at sizeof of real sigset_t on linux.
   uptr val[128 / sizeof(uptr)];
 };
-#elif SANITIZER_AIX
+#  elif SANITIZER_AIX
 struct __sanitizer_sigset_t {
-#if SANITIZER_WORDSIZE == 64
+#    if SANITIZER_WORDSIZE == 64
   uptr val[4];
-#else
+#    else
   uptr val[2];
-#endif
+#    endif
 };
-#endif
+#  endif
 
 struct __sanitizer_siginfo_pad {
 #if SANITIZER_X32
@@ -805,12 +805,12 @@ struct __sanitizer_addrinfo {
   int ai_family;
   int ai_socktype;
   int ai_protocol;
-#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX
-#if SANITIZER_AIX // AIX ai_addrlen type is size_t
+#  if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX
+#    if SANITIZER_AIX  // AIX ai_addrlen type is size_t
   uptr ai_addrlen;
-#else
+#    else
   unsigned ai_addrlen;
-#endif
+#    endif
   char *ai_canonname;
   void *ai_addr;
 #else // LINUX
@@ -819,9 +819,9 @@ struct __sanitizer_addrinfo {
   char *ai_canonname;
 #endif
   struct __sanitizer_addrinfo *ai_next;
-#if SANITIZER_AIX
+#  if SANITIZER_AIX
   int ai_eflags;
-#endif
+#  endif
 };
 
 struct __sanitizer_hostent {
@@ -838,7 +838,7 @@ struct __sanitizer_pollfd {
   short revents;
 };
 
-#if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX
+#  if SANITIZER_ANDROID || SANITIZER_APPLE || SANITIZER_AIX
 typedef unsigned __sanitizer_nfds_t;
 #else
 typedef unsigned long __sanitizer_nfds_t;
@@ -876,10 +876,10 @@ struct __sanitizer_wordexp_t {
   uptr we_wordc;
   char **we_wordv;
   uptr we_offs;
-#if SANITIZER_AIX
+#  if SANITIZER_AIX
   int we_sflags;
   uptr we_soffs;
-#endif
+#  endif
 };
 
 #if SANITIZER_LINUX && !SANITIZER_ANDROID
@@ -1139,7 +1139,7 @@ extern unsigned fpos_t_sz;
 // when it can not be determined without including any system headers.
 extern const unsigned IOCTL_NOT_PRESENT;
 
-#if SANITIZER_AIX
+#  if SANITIZER_AIX
 extern uptr IOCTL_FIOASYNC;
 extern uptr IOCTL_FIONBIO;
 extern uptr IOCTL_FIOSETOWN;
@@ -1153,7 +1153,7 @@ extern uptr IOCTL_TIOCSETD;
 extern uptr IOCTL_TIOCSPGRP;
 extern uptr IOCTL_TIOCSTI;
 extern uptr IOCTL_TIOCSWINSZ;
-#else
+#  else
 extern unsigned IOCTL_FIOASYNC;
 extern unsigned IOCTL_FIONBIO;
 extern unsigned IOCTL_FIOSETOWN;
@@ -1167,7 +1167,7 @@ extern unsigned IOCTL_TIOCSETD;
 extern unsigned IOCTL_TIOCSPGRP;
 extern unsigned IOCTL_TIOCSTI;
 extern unsigned IOCTL_TIOCSWINSZ;
-#endif
+#  endif
 
 extern unsigned IOCTL_FIOCLEX;
 extern unsigned IOCTL_FIOGETOWN;
@@ -1199,10 +1199,10 @@ extern unsigned IOCTL_TIOCMGET;
 extern unsigned IOCTL_TIOCNOTTY;
 extern unsigned IOCTL_TIOCNXCL;
 extern unsigned IOCTL_TIOCOUTQ;
-#if !SANITIZER_AIX
+#  if !SANITIZER_AIX
 extern unsigned IOCTL_TIOCSCTTY;
-#endif
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  endif
+#  if SANITIZER_LINUX && !SANITIZER_ANDROID
 extern unsigned IOCTL_SIOCGETSGCNT;
 extern unsigned IOCTL_SIOCGETVIFCNT;
 #endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
index 44c40036ba..b25ec8a66f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -27,7 +27,7 @@
 #include <signal.h>
 #include <sys/mman.h>
 
-#if SANITIZER_FREEBSD || SANITIZER_AIX
+#  if SANITIZER_FREEBSD || SANITIZER_AIX
 // The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before
 // that, it was never implemented.  So just define it to zero.
 #undef  MAP_NORESERVE

``````````

</details>


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


More information about the llvm-commits mailing list