[llvm-branch-commits] [compiler-rt] release/19.x: [compiler-rt] Fix definition of `usize` on 32-bit Windows (PR #106303)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Sep 1 01:11:56 PDT 2024


https://github.com/tru updated https://github.com/llvm/llvm-project/pull/106303

>From 32927ca57e805681fa93ed913c0f0d3c075563b7 Mon Sep 17 00:00:00 2001
From: Alexander Richardson <alexrichardson at google.com>
Date: Tue, 27 Aug 2024 15:37:24 -0700
Subject: [PATCH] [compiler-rt] Fix definition of `usize` on 32-bit Windows

32-bit Windows uses `unsigned int` for uintptr_t and size_t.
Commit 18e06e3e2f3d47433e1ed323b8725c76035fc1ac changed uptr to
unsigned long, so it no longer matches the real size_t/uintptr_t and
therefore the current definition of usize result in:
`error C2821: first formal parameter to 'operator new' must be 'size_t'`

However, the real problem is that uptr is wrong to work around the fact
that we have local SIZE_T and SSIZE_T typedefs that trample on the
basetsd.h definitions of the same name and therefore need to match
exactly. Unlike size_t/ssize_t the uppercase ones always use unsigned
long (even on 32-bit).

This commit works around the build breakage by keeping the existing
definitions of uptr/sptr and just changing usize. A follow-up change
will attempt to fix this properly.

Fixes: https://github.com/llvm/llvm-project/issues/101998

Reviewed By: mstorsjo

Pull Request: https://github.com/llvm/llvm-project/pull/106151

(cherry picked from commit bb27dd853a713866c025a94ead8f03a1e25d1b6e)
---
 .../lib/sanitizer_common/sanitizer_internal_defs.h       | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index 294e330c4d5611..eebfb00aad7acd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -194,7 +194,16 @@ typedef u64  OFF64_T;
 #ifdef __SIZE_TYPE__
 typedef __SIZE_TYPE__ usize;
 #else
+// Since we use this for operator new, usize must match the real size_t, but on
+// 32-bit Windows the definition of uptr does not actually match uintptr_t or
+// size_t because we are working around typedef mismatches for the (S)SIZE_T
+// types used in interception.h.
+// Until the definition of uptr has been fixed we have to special case Win32.
+#  if SANITIZER_WINDOWS && SANITIZER_WORDSIZE == 32
+typedef unsigned int usize;
+#  else
 typedef uptr usize;
+#  endif
 #endif
 
 typedef u64 tid_t;



More information about the llvm-branch-commits mailing list