From f959821c16b824b06fb40e954a3605b5f844e8ae Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 30 Aug 2025 16:19:39 +0800 Subject: [PATCH 01/28] Use HOST_64BIT --- src/coreclr/nativeaot/Runtime/CommonMacros.h | 28 +++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index 13d065c303eb25..5980907c44c7de 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -97,39 +97,17 @@ inline bool IS_ALIGNED(T* val, uintptr_t alignment); //------------------------------------------------------------------------------------------------- // Platform-specific defines -#if defined(HOST_AMD64) - -#define LOG2_PTRSIZE 3 -#define POINTER_SIZE 8 - -#elif defined(HOST_X86) - -#define LOG2_PTRSIZE 2 -#define POINTER_SIZE 4 - -#elif defined(HOST_ARM) - -#define LOG2_PTRSIZE 2 -#define POINTER_SIZE 4 - -#elif defined(HOST_ARM64) +#ifdef HOST_64BIT #define LOG2_PTRSIZE 3 #define POINTER_SIZE 8 -#elif defined (HOST_WASM) +#else // HOST_64BIT #define LOG2_PTRSIZE 2 #define POINTER_SIZE 4 -#elif defined(HOST_LOONGARCH64) || defined (HOST_RISCV64) - -#define LOG2_PTRSIZE 3 -#define POINTER_SIZE 8 - -#else -#error Unsupported target architecture -#endif +#endif // HOST_64BIT #ifndef __GCENV_BASE_INCLUDED__ From a93479dcdfc9c80a0e71306957ed5917f9e3b560 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 31 Aug 2025 21:33:07 +0800 Subject: [PATCH 02/28] Cleanup __int64 definition --- src/coreclr/nativeaot/Runtime/CommonMacros.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index 5980907c44c7de..54c69163ef20e3 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -41,14 +41,6 @@ #define offsetof(s,m) (uintptr_t)( (intptr_t)&reinterpret_cast((((s *)0)->m)) ) #endif // offsetof -#ifdef __GNUC__ -#ifdef HOST_64BIT -#define __int64 long -#else // HOST_64BIT -#define __int64 long long -#endif // HOST_64BIT -#endif // __GNUC__ - #ifndef FORCEINLINE #define FORCEINLINE __forceinline #endif From 41c3a609ab205c900f0e94150f5817e4d44ae910 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 1 Sep 2025 23:36:51 +0800 Subject: [PATCH 03/28] _tfopen --- src/coreclr/gc/env/gcenv.base.h | 6 ------ src/coreclr/vm/gcenv.h | 4 ---- 2 files changed, 10 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index 2bcf98bd4e3a77..6f727a4e2c11da 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -103,12 +103,6 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x) snprintf(string, sizeInBytes, format, ## __VA_ARGS__) #endif -#ifdef UNICODE -#define _tfopen _wfopen -#else -#define _tfopen fopen -#endif - #define WINAPI __stdcall typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter); diff --git a/src/coreclr/vm/gcenv.h b/src/coreclr/vm/gcenv.h index 35bf026c5d4525..79c52e5eee9c28 100644 --- a/src/coreclr/vm/gcenv.h +++ b/src/coreclr/vm/gcenv.h @@ -61,8 +61,4 @@ namespace ETW } GC_ROOT_KIND; }; -#ifdef TARGET_UNIX -#define _tfopen _wfopen -#endif - #endif // GCENV_H_ From 14ba0d9abe90d227f00c15fc4f769491528115d5 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 1 Sep 2025 23:45:06 +0800 Subject: [PATCH 04/28] Consolidate NOINLINE definitions --- src/coreclr/gc/env/gcenv.base.h | 4 ---- src/coreclr/gc/vxsort/defs.h | 5 ++--- src/coreclr/inc/cor.h | 10 ---------- src/coreclr/inc/palclr.h | 10 ++-------- src/coreclr/nativeaot/Runtime/CommonMacros.h | 8 -------- src/native/minipal/utils.h | 6 ++++++ 6 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index 6f727a4e2c11da..837ae7af3e97f2 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -26,10 +26,6 @@ #else // __GNUC__ #define __forceinline inline #endif // __GNUC__ -// [LOCALGC TODO] is there a better place for this? -#define NOINLINE __attribute__((noinline)) -#else // !_MSC_VER -#define NOINLINE __declspec(noinline) #endif // _MSC_VER #ifdef _MSC_VER diff --git a/src/coreclr/gc/vxsort/defs.h b/src/coreclr/gc/vxsort/defs.h index d6373a21ad2699..31e3a0a590983b 100644 --- a/src/coreclr/gc/vxsort/defs.h +++ b/src/coreclr/gc/vxsort/defs.h @@ -4,6 +4,8 @@ #ifndef VXSORT_DEFS_H #define VXSORT_DEFS_H +#include + #if _MSC_VER #ifdef _M_X86 #define ARCH_X86 @@ -30,19 +32,16 @@ #ifdef __clang__ #define mess_up_cmov() #define INLINE __attribute__((always_inline)) -#define NOINLINE __attribute__((noinline)) #else // MSVC #include #define mess_up_cmov() _ReadBarrier(); #define INLINE __forceinline -#define NOINLINE __declspec(noinline) #endif #else // GCC + Clang #define mess_up_cmov() #define INLINE __attribute__((always_inline)) -#define NOINLINE __attribute__((noinline)) #endif using std::max; diff --git a/src/coreclr/inc/cor.h b/src/coreclr/inc/cor.h index d4fe6b0275a0d2..3f8eca1df3ac1d 100644 --- a/src/coreclr/inc/cor.h +++ b/src/coreclr/inc/cor.h @@ -1676,16 +1676,6 @@ typedef enum #endif #endif -#ifndef NOINLINE -#ifdef _MSC_VER -#define NOINLINE __declspec(noinline) -#elif defined __GNUC__ -#define NOINLINE __attribute__ ((noinline)) -#else -#define NOINLINE -#endif -#endif // !NOINLINE - // return true if it is a primitive type, i.e. only need to store CorElementType FORCEINLINE int CorIsPrimitiveType(CorElementType elementtype) { diff --git a/src/coreclr/inc/palclr.h b/src/coreclr/inc/palclr.h index 6985ced7f39dd5..94947f88fa83b1 100644 --- a/src/coreclr/inc/palclr.h +++ b/src/coreclr/inc/palclr.h @@ -11,6 +11,8 @@ #ifndef __PALCLR_H__ #define __PALCLR_H__ +#include + #if defined(HOST_WINDOWS) // This macro is used to standardize the wide character string literals between UNIX and Windows. @@ -39,14 +41,6 @@ #endif // !_MSC_VER #endif // !NOTHROW_DECL -#ifndef NOINLINE -#ifdef _MSC_VER -#define NOINLINE __declspec(noinline) -#else -#define NOINLINE __attribute__((noinline)) -#endif // !_MSC_VER -#endif // !NOINLINE - #ifdef _MSC_VER #define EMPTY_BASES_DECL __declspec(empty_bases) #else diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index 54c69163ef20e3..0f410b80e58e44 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -49,14 +49,6 @@ #define __forceinline __attribute__((always_inline)) inline #endif // __GNUC__ -#ifndef NOINLINE -#ifdef _MSC_VER -#define NOINLINE __declspec(noinline) -#else -#define NOINLINE __attribute__((noinline)) -#endif -#endif - #ifndef __GCENV_BASE_INCLUDED__ #include diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index 23a6a643601d1e..3537c04398ed72 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -38,6 +38,12 @@ # define FALLTHROUGH #endif +#if defined(_MSC_VER) +#define NOINLINE __declspec(noinline) +#else +#define NOINLINE __attribute__((noinline)) +#endif + #if defined(_MSC_VER) #define LIBC_CALLBACK __cdecl #else From bf4caa7a06a589885b8101ac0bd883816d11de43 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 1 Sep 2025 23:56:40 +0800 Subject: [PATCH 05/28] FORCEINLINE --- src/coreclr/gc/env/gcenv.base.h | 1 - src/coreclr/inc/cor.h | 8 -------- src/coreclr/inc/utilcode.h | 7 ------- src/coreclr/nativeaot/Runtime/CommonMacros.h | 4 ---- src/coreclr/pal/inc/pal.h | 8 -------- src/native/minipal/utils.h | 2 ++ 6 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index 837ae7af3e97f2..0444b55796bed7 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -84,7 +84,6 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x) #define FALSE false #define CALLBACK __stdcall -#define FORCEINLINE __forceinline #define INFINITE 0xFFFFFFFF diff --git a/src/coreclr/inc/cor.h b/src/coreclr/inc/cor.h index 3f8eca1df3ac1d..74dceb2a4107e5 100644 --- a/src/coreclr/inc/cor.h +++ b/src/coreclr/inc/cor.h @@ -1657,14 +1657,6 @@ typedef enum //***************************************************************************** //***************************************************************************** -#ifndef FORCEINLINE - #if _MSC_VER < 1200 - #define FORCEINLINE inline - #else - #define FORCEINLINE __forceinline - #endif -#endif - // We need a version that is FORCEINLINE on retail and NOINLINE on debug diff --git a/src/coreclr/inc/utilcode.h b/src/coreclr/inc/utilcode.h index 0ed568eedbb527..8ec93ff9bba782 100644 --- a/src/coreclr/inc/utilcode.h +++ b/src/coreclr/inc/utilcode.h @@ -142,13 +142,6 @@ typedef LPSTR LPUTF8; #include "stdmacros.h" //********** Macros. ********************************************************** -#ifndef FORCEINLINE - #if _MSC_VER < 1200 - #define FORCEINLINE inline - #else - #define FORCEINLINE __forceinline - #endif -#endif #ifndef DEBUG_NOINLINE #if defined(_DEBUG) diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index 0f410b80e58e44..f0be79917ff481 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -41,10 +41,6 @@ #define offsetof(s,m) (uintptr_t)( (intptr_t)&reinterpret_cast((((s *)0)->m)) ) #endif // offsetof -#ifndef FORCEINLINE -#define FORCEINLINE __forceinline -#endif - #ifdef __GNUC__ #define __forceinline __attribute__((always_inline)) inline #endif // __GNUC__ diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 766d4cdc9f7c8c..e7e06be149a60d 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -143,14 +143,6 @@ extern bool g_arm64_atomics_present; #define UNALIGNED -#ifndef FORCEINLINE -#if _MSC_VER < 1200 -#define FORCEINLINE inline -#else -#define FORCEINLINE __forceinline -#endif -#endif - #ifndef NOOPT_ATTRIBUTE #if defined(__llvm__) #define NOOPT_ATTRIBUTE optnone diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index 3537c04398ed72..b2d47cad87a37f 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -40,8 +40,10 @@ #if defined(_MSC_VER) #define NOINLINE __declspec(noinline) +#define FORCEINLINE __forceinline #else #define NOINLINE __attribute__((noinline)) +#define FORCEINLINE __attribute__((always_inline)) inline #endif #if defined(_MSC_VER) From 210d0ee137f9f500cfa98e2eb33a9711515cb5e4 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 2 Sep 2025 21:22:25 +0800 Subject: [PATCH 06/28] Cleanup __forceinline usages --- src/coreclr/gc/env/gcenv.base.h | 5 ---- src/coreclr/gc/env/gcenv.interlocked.inl | 30 +++++++++---------- src/coreclr/gc/env/gcenv.unix.inl | 2 +- src/coreclr/gc/env/gcenv.windows.inl | 2 +- src/coreclr/gc/gceventstatus.h | 2 +- src/coreclr/gc/vxsort/defs.h | 5 ++-- src/coreclr/ilasm/method.hpp | 2 +- src/coreclr/inc/gcinfodecoder.h | 12 ++++---- src/coreclr/jit/codegen.h | 2 +- src/coreclr/jit/compiler.hpp | 4 +-- src/coreclr/jit/hashbv.h | 2 +- src/coreclr/nativeaot/Runtime/CommonMacros.h | 4 --- .../nativeaot/Runtime/inc/MethodTable.inl | 2 +- src/coreclr/pal/inc/pal_mstypes.h | 4 +-- src/coreclr/utilcode/stresslog.cpp | 2 +- src/coreclr/vm/gc_unwind_x86.inl | 4 +-- src/coreclr/vm/methodtable.h | 28 ++++++++--------- src/coreclr/vm/object.inl | 6 ++-- 18 files changed, 53 insertions(+), 65 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index 0444b55796bed7..f3dfd8a30e16b8 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -21,11 +21,6 @@ #ifndef _MSC_VER #define __stdcall -#ifdef __GNUC__ -#define __forceinline __attribute__((always_inline)) inline -#else // __GNUC__ -#define __forceinline inline -#endif // __GNUC__ #endif // _MSC_VER #ifdef _MSC_VER diff --git a/src/coreclr/gc/env/gcenv.interlocked.inl b/src/coreclr/gc/env/gcenv.interlocked.inl index 3e4d761bca0d02..89222c90a664f9 100644 --- a/src/coreclr/gc/env/gcenv.interlocked.inl +++ b/src/coreclr/gc/env/gcenv.interlocked.inl @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// __forceinline implementation of the Interlocked class methods +// FORCEINLINE implementation of the Interlocked class methods // #ifndef __GCENV_INTERLOCKED_INL__ @@ -11,7 +11,7 @@ #endif // _MSC_VER #ifndef _MSC_VER -__forceinline void Interlocked::InterlockedOperationBarrier() +FORCEINLINE void Interlocked::InterlockedOperationBarrier() { #if defined(HOST_ARM64) || defined(HOST_LOONGARCH64) || defined(HOST_RISCV64) // See PAL_InterlockedOperationBarrier() in the PAL @@ -26,7 +26,7 @@ __forceinline void Interlocked::InterlockedOperationBarrier() // Return: // The resulting incremented value template -__forceinline T Interlocked::Increment(T volatile *addend) +FORCEINLINE T Interlocked::Increment(T volatile *addend) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -44,7 +44,7 @@ __forceinline T Interlocked::Increment(T volatile *addend) // Return: // The resulting decremented value template -__forceinline T Interlocked::Decrement(T volatile *addend) +FORCEINLINE T Interlocked::Decrement(T volatile *addend) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -63,7 +63,7 @@ __forceinline T Interlocked::Decrement(T volatile *addend) // Return: // The previous value of the destination template -__forceinline T Interlocked::Exchange(T volatile *destination, T value) +FORCEINLINE T Interlocked::Exchange(T volatile *destination, T value) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -84,7 +84,7 @@ __forceinline T Interlocked::Exchange(T volatile *destination, T value) // Return: // The original value of the destination template -__forceinline T Interlocked::CompareExchange(T volatile *destination, T exchange, T comparand) +FORCEINLINE T Interlocked::CompareExchange(T volatile *destination, T exchange, T comparand) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -103,7 +103,7 @@ __forceinline T Interlocked::CompareExchange(T volatile *destination, T exchange // Return: // The previous value of the addend template -__forceinline T Interlocked::ExchangeAdd(T volatile *addend, T value) +FORCEINLINE T Interlocked::ExchangeAdd(T volatile *addend, T value) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -116,7 +116,7 @@ __forceinline T Interlocked::ExchangeAdd(T volatile *addend, T value) } template -__forceinline T Interlocked::ExchangeAdd64(T volatile* addend, T value) +FORCEINLINE T Interlocked::ExchangeAdd64(T volatile* addend, T value) { #ifdef _MSC_VER static_assert(sizeof(int64_t) == sizeof(T), "Size of LONGLONG must be the same as size of T"); @@ -129,7 +129,7 @@ __forceinline T Interlocked::ExchangeAdd64(T volatile* addend, T value) } template -__forceinline T Interlocked::ExchangeAddPtr(T volatile* addend, T value) +FORCEINLINE T Interlocked::ExchangeAddPtr(T volatile* addend, T value) { #ifdef _MSC_VER #ifdef HOST_64BIT @@ -151,7 +151,7 @@ __forceinline T Interlocked::ExchangeAddPtr(T volatile* addend, T value) // destination - the first operand and the destination // value - second operand template -__forceinline void Interlocked::And(T volatile *destination, T value) +FORCEINLINE void Interlocked::And(T volatile *destination, T value) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -167,7 +167,7 @@ __forceinline void Interlocked::And(T volatile *destination, T value) // destination - the first operand and the destination // value - second operand template -__forceinline void Interlocked::Or(T volatile *destination, T value) +FORCEINLINE void Interlocked::Or(T volatile *destination, T value) { #ifdef _MSC_VER static_assert(sizeof(long) == sizeof(T), "Size of long must be the same as size of T"); @@ -185,7 +185,7 @@ __forceinline void Interlocked::Or(T volatile *destination, T value) // Return: // The previous value of the destination template -__forceinline T Interlocked::ExchangePointer(T volatile * destination, T value) +FORCEINLINE T Interlocked::ExchangePointer(T volatile * destination, T value) { #ifdef _MSC_VER #ifdef HOST_64BIT @@ -201,7 +201,7 @@ __forceinline T Interlocked::ExchangePointer(T volatile * destination, T value) } template -__forceinline T Interlocked::ExchangePointer(T volatile * destination, std::nullptr_t value) +FORCEINLINE T Interlocked::ExchangePointer(T volatile * destination, std::nullptr_t value) { #ifdef _MSC_VER #ifdef HOST_64BIT @@ -225,7 +225,7 @@ __forceinline T Interlocked::ExchangePointer(T volatile * destination, std::null // Return: // The original value of the destination template -__forceinline T Interlocked::CompareExchangePointer(T volatile *destination, T exchange, T comparand) +FORCEINLINE T Interlocked::CompareExchangePointer(T volatile *destination, T exchange, T comparand) { #ifdef _MSC_VER #ifdef HOST_64BIT @@ -241,7 +241,7 @@ __forceinline T Interlocked::CompareExchangePointer(T volatile *destination, T e } template -__forceinline T Interlocked::CompareExchangePointer(T volatile *destination, T exchange, std::nullptr_t comparand) +FORCEINLINE T Interlocked::CompareExchangePointer(T volatile *destination, T exchange, std::nullptr_t comparand) { #ifdef _MSC_VER #ifdef HOST_64BIT diff --git a/src/coreclr/gc/env/gcenv.unix.inl b/src/coreclr/gc/env/gcenv.unix.inl index d6e5ca796a1499..0e221e8a0a9596 100644 --- a/src/coreclr/gc/env/gcenv.unix.inl +++ b/src/coreclr/gc/env/gcenv.unix.inl @@ -11,7 +11,7 @@ extern uint32_t g_pageSizeUnixInl; #define OS_PAGE_SIZE GCToOSInterface::GetPageSize() #ifndef DACCESS_COMPILE -__forceinline size_t GCToOSInterface::GetPageSize() +FORCEINLINE size_t GCToOSInterface::GetPageSize() { return g_pageSizeUnixInl; } diff --git a/src/coreclr/gc/env/gcenv.windows.inl b/src/coreclr/gc/env/gcenv.windows.inl index df34e1aaa7c7ae..8ac51a19775076 100644 --- a/src/coreclr/gc/env/gcenv.windows.inl +++ b/src/coreclr/gc/env/gcenv.windows.inl @@ -9,7 +9,7 @@ #define OS_PAGE_SIZE GCToOSInterface::GetPageSize() -__forceinline size_t GCToOSInterface::GetPageSize() +FORCEINLINE size_t GCToOSInterface::GetPageSize() { return 0x1000; } diff --git a/src/coreclr/gc/gceventstatus.h b/src/coreclr/gc/gceventstatus.h index 9e689b008f8807..3c41d019e11725 100644 --- a/src/coreclr/gc/gceventstatus.h +++ b/src/coreclr/gc/gceventstatus.h @@ -60,7 +60,7 @@ class GCEventStatus * IsEnabled queries whether or not the given level and keyword are * enabled on the given provider, returning true if they are. */ - __forceinline static bool IsEnabled(GCEventProvider provider, GCEventKeyword keyword, GCEventLevel level) + FORCEINLINE static bool IsEnabled(GCEventProvider provider, GCEventKeyword keyword, GCEventLevel level) { assert(level >= GCEventLevel_None && level < GCEventLevel_Max); diff --git a/src/coreclr/gc/vxsort/defs.h b/src/coreclr/gc/vxsort/defs.h index 31e3a0a590983b..a2e0a7af152ae9 100644 --- a/src/coreclr/gc/vxsort/defs.h +++ b/src/coreclr/gc/vxsort/defs.h @@ -31,19 +31,18 @@ #ifdef _MSC_VER #ifdef __clang__ #define mess_up_cmov() -#define INLINE __attribute__((always_inline)) #else // MSVC #include #define mess_up_cmov() _ReadBarrier(); -#define INLINE __forceinline #endif #else // GCC + Clang #define mess_up_cmov() -#define INLINE __attribute__((always_inline)) #endif +#define INLINE FORCEINLINE + using std::max; using std::min; #endif // VXSORT_DEFS_H diff --git a/src/coreclr/ilasm/method.hpp b/src/coreclr/ilasm/method.hpp index 0f6fc2ccadc9a3..dfd22c1f79691f 100644 --- a/src/coreclr/ilasm/method.hpp +++ b/src/coreclr/ilasm/method.hpp @@ -56,7 +56,7 @@ struct ARG_NAME_LIST DWORD dwAttr; CustomDescrList CustDList; ARG_NAME_LIST *pNext; - __forceinline ARG_NAME_LIST(int i, LPCUTF8 sz, BinStr *pbSig, BinStr *pbMarsh, DWORD attr) + FORCEINLINE ARG_NAME_LIST(int i, LPCUTF8 sz, BinStr *pbSig, BinStr *pbMarsh, DWORD attr) { nNum = i; //dwName = (DWORD)strlen(sz); diff --git a/src/coreclr/inc/gcinfodecoder.h b/src/coreclr/inc/gcinfodecoder.h index 87693d89d25c9f..9e3c0974564577 100644 --- a/src/coreclr/inc/gcinfodecoder.h +++ b/src/coreclr/inc/gcinfodecoder.h @@ -300,7 +300,7 @@ class BitStreamReader } // NOTE: This routine is perf-critical - __forceinline size_t Read( int numBits ) + FORCEINLINE size_t Read( int numBits ) { SUPPORTS_DAC; @@ -325,7 +325,7 @@ class BitStreamReader // This version reads one bit // NOTE: This routine is perf-critical - __forceinline size_t ReadOneFast() + FORCEINLINE size_t ReadOneFast() { SUPPORTS_DAC; @@ -346,13 +346,13 @@ class BitStreamReader } - __forceinline size_t GetCurrentPos() + FORCEINLINE size_t GetCurrentPos() { SUPPORTS_DAC; return (size_t) ((m_pCurrent - m_pBuffer) * BITS_PER_SIZE_T + m_RelPos - m_InitialRelPos); } - __forceinline void SetCurrentPos( size_t pos ) + FORCEINLINE void SetCurrentPos( size_t pos ) { size_t adjPos = pos + m_InitialRelPos; m_pCurrent = m_pBuffer + adjPos / BITS_PER_SIZE_T; @@ -364,7 +364,7 @@ class BitStreamReader _ASSERTE(GetCurrentPos() == pos); } - __forceinline void Skip( SSIZE_T numBitsToSkip ) + FORCEINLINE void Skip( SSIZE_T numBitsToSkip ) { SUPPORTS_DAC; @@ -416,7 +416,7 @@ class BitStreamReader } } - __forceinline size_t DecodeVarLengthUnsigned(int base) + FORCEINLINE size_t DecodeVarLengthUnsigned(int base) { _ASSERTE((base > 0) && (base < (int)BITS_PER_SIZE_T)); diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index 6fadbfa9aede89..e47fe8ab57bbe6 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -1044,7 +1044,7 @@ class CodeGen final : public CodeGenInterface // // Return Value: // None. - __forceinline void genUpdateLifeStore(GenTree* tree, regNumber targetReg, LclVarDsc* varDsc) + FORCEINLINE void genUpdateLifeStore(GenTree* tree, regNumber targetReg, LclVarDsc* varDsc) { if (targetReg != REG_NA) { diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 1c1c9e0225033f..12280cde617228 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -3605,7 +3605,7 @@ inline regNumber genMapFloatRegArgNumToRegNum(unsigned argNum) #endif } -__forceinline regNumber genMapRegArgNumToRegNum(unsigned argNum, var_types type, CorInfoCallConvExtension callConv) +FORCEINLINE regNumber genMapRegArgNumToRegNum(unsigned argNum, var_types type, CorInfoCallConvExtension callConv) { if (varTypeUsesFloatArgReg(type)) { @@ -3642,7 +3642,7 @@ inline regMaskTP genMapFloatRegArgNumToRegMask(unsigned argNum) #endif } -__forceinline regMaskTP genMapArgNumToRegMask(unsigned argNum, var_types type) +FORCEINLINE regMaskTP genMapArgNumToRegMask(unsigned argNum, var_types type) { regMaskTP result; if (varTypeUsesFloatArgReg(type)) diff --git a/src/coreclr/jit/hashbv.h b/src/coreclr/jit/hashbv.h index 232c35d6394597..688718244659d5 100644 --- a/src/coreclr/jit/hashbv.h +++ b/src/coreclr/jit/hashbv.h @@ -194,7 +194,7 @@ class hashBv void dump(); void dumpFancy(); #endif // DEBUG - __forceinline int hashtable_size() const + FORCEINLINE int hashtable_size() const { return 1 << this->log2_hashSize; } diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index f0be79917ff481..0d5e5e3fd90b16 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -41,10 +41,6 @@ #define offsetof(s,m) (uintptr_t)( (intptr_t)&reinterpret_cast((((s *)0)->m)) ) #endif // offsetof -#ifdef __GNUC__ -#define __forceinline __attribute__((always_inline)) inline -#endif // __GNUC__ - #ifndef __GCENV_BASE_INCLUDED__ #include diff --git a/src/coreclr/nativeaot/Runtime/inc/MethodTable.inl b/src/coreclr/nativeaot/Runtime/inc/MethodTable.inl index 88d797deeec176..c2f92f169bc3cc 100644 --- a/src/coreclr/nativeaot/Runtime/inc/MethodTable.inl +++ b/src/coreclr/nativeaot/Runtime/inc/MethodTable.inl @@ -39,7 +39,7 @@ inline MethodTable* MethodTable::GetDynamicTemplateType() #endif // !defined(DACCESS_COMPILE) // Calculate the offset of a field of the MethodTable that has a variable offset. -__forceinline uint32_t MethodTable::GetFieldOffset(EETypeField eField) +FORCEINLINE uint32_t MethodTable::GetFieldOffset(EETypeField eField) { // First part of MethodTable consists of the fixed portion followed by the vtable. uint32_t cbOffset = offsetof(MethodTable, m_VTable) + (sizeof(UIntTarget) * m_usNumVtableSlots); diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index a0762726ba18e9..5441336e01ca33 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -78,9 +78,7 @@ extern "C" { #if defined(_VAC_) && defined(__cplusplus) #define __inline inline #endif - -#define __forceinline inline - + #define PALIMPORT #ifndef DLLEXPORT diff --git a/src/coreclr/utilcode/stresslog.cpp b/src/coreclr/utilcode/stresslog.cpp index 3fd772c41e92b5..c8d98427363a40 100644 --- a/src/coreclr/utilcode/stresslog.cpp +++ b/src/coreclr/utilcode/stresslog.cpp @@ -35,7 +35,7 @@ thread_local bool t_triedToCreateThreadStressLog; variable-speed CPUs (for power management), this is not accurate, but may be good enough. */ -__forceinline +FORCEINLINE #ifdef HOST_WINDOWS __declspec(naked) #else diff --git a/src/coreclr/vm/gc_unwind_x86.inl b/src/coreclr/vm/gc_unwind_x86.inl index 852cd40a024af6..0e240a1869409a 100644 --- a/src/coreclr/vm/gc_unwind_x86.inl +++ b/src/coreclr/vm/gc_unwind_x86.inl @@ -36,7 +36,7 @@ static bool trEnumGCRefs = false; static bool dspPtr = false; // prints the live ptrs as reported #endif -__forceinline unsigned decodeUnsigned(PTR_CBYTE& src) +FORCEINLINE unsigned decodeUnsigned(PTR_CBYTE& src) { LIMITED_METHOD_CONTRACT; SUPPORTS_DAC; @@ -67,7 +67,7 @@ __forceinline unsigned decodeUnsigned(PTR_CBYTE& src) return value; } -__forceinline int decodeSigned(PTR_CBYTE& src) +FORCEINLINE int decodeSigned(PTR_CBYTE& src) { LIMITED_METHOD_CONTRACT; SUPPORTS_DAC; diff --git a/src/coreclr/vm/methodtable.h b/src/coreclr/vm/methodtable.h index c8fbbb572be5a9..e8217fb2808a6e 100644 --- a/src/coreclr/vm/methodtable.h +++ b/src/coreclr/vm/methodtable.h @@ -3790,61 +3790,61 @@ public : enum_flag_TokenMask = 0xFFFFFF00, }; // enum WFLAGS2_ENUM - __forceinline void ClearFlag(WFLAGS_LOW_ENUM flag) + FORCEINLINE void ClearFlag(WFLAGS_LOW_ENUM flag) { _ASSERTE(!IsStringOrArray()); m_dwFlags &= ~flag; } - __forceinline void SetFlag(WFLAGS_LOW_ENUM flag) + FORCEINLINE void SetFlag(WFLAGS_LOW_ENUM flag) { _ASSERTE(!IsStringOrArray()); m_dwFlags |= flag; } - __forceinline DWORD GetFlag(WFLAGS_LOW_ENUM flag) const + FORCEINLINE DWORD GetFlag(WFLAGS_LOW_ENUM flag) const { SUPPORTS_DAC; return (IsStringOrArray() ? (enum_flag_StringArrayValues & flag) : (m_dwFlags & flag)); } - __forceinline BOOL TestFlagWithMask(WFLAGS_LOW_ENUM mask, WFLAGS_LOW_ENUM flag) const + FORCEINLINE BOOL TestFlagWithMask(WFLAGS_LOW_ENUM mask, WFLAGS_LOW_ENUM flag) const { LIMITED_METHOD_DAC_CONTRACT; return (IsStringOrArray() ? (((DWORD)enum_flag_StringArrayValues & (DWORD)mask) == (DWORD)flag) : ((m_dwFlags & (DWORD)mask) == (DWORD)flag)); } - __forceinline void ClearFlag(WFLAGS_HIGH_ENUM flag) + FORCEINLINE void ClearFlag(WFLAGS_HIGH_ENUM flag) { m_dwFlags &= ~flag; } - __forceinline void SetFlag(WFLAGS_HIGH_ENUM flag) + FORCEINLINE void SetFlag(WFLAGS_HIGH_ENUM flag) { m_dwFlags |= flag; } - __forceinline DWORD GetFlag(WFLAGS_HIGH_ENUM flag) const + FORCEINLINE DWORD GetFlag(WFLAGS_HIGH_ENUM flag) const { LIMITED_METHOD_DAC_CONTRACT; return m_dwFlags & flag; } - __forceinline BOOL TestFlagWithMask(WFLAGS_HIGH_ENUM mask, WFLAGS_HIGH_ENUM flag) const + FORCEINLINE BOOL TestFlagWithMask(WFLAGS_HIGH_ENUM mask, WFLAGS_HIGH_ENUM flag) const { LIMITED_METHOD_DAC_CONTRACT; return ((m_dwFlags & (DWORD)mask) == (DWORD)flag); } - __forceinline void ClearFlag(WFLAGS2_ENUM flag) + FORCEINLINE void ClearFlag(WFLAGS2_ENUM flag) { m_dwFlags2 &= ~flag; } - __forceinline void SetFlag(WFLAGS2_ENUM flag) + FORCEINLINE void SetFlag(WFLAGS2_ENUM flag) { m_dwFlags2 |= flag; } - __forceinline DWORD GetFlag(WFLAGS2_ENUM flag) const + FORCEINLINE DWORD GetFlag(WFLAGS2_ENUM flag) const { LIMITED_METHOD_DAC_CONTRACT; return m_dwFlags2 & flag; } - __forceinline BOOL TestFlagWithMask(WFLAGS2_ENUM mask, WFLAGS2_ENUM flag) const + FORCEINLINE BOOL TestFlagWithMask(WFLAGS2_ENUM mask, WFLAGS2_ENUM flag) const { return (m_dwFlags2 & (DWORD)mask) == (DWORD)flag; } @@ -3913,12 +3913,12 @@ public : TADDR m_pCanonMT; }; - __forceinline static LowBits union_getLowBits(TADDR pCanonMT) + FORCEINLINE static LowBits union_getLowBits(TADDR pCanonMT) { LIMITED_METHOD_DAC_CONTRACT; return LowBits(pCanonMT & UNION_MASK); } - __forceinline static TADDR union_getPointer(TADDR pCanonMT) + FORCEINLINE static TADDR union_getPointer(TADDR pCanonMT) { LIMITED_METHOD_DAC_CONTRACT; return (pCanonMT & ~UNION_MASK); diff --git a/src/coreclr/vm/object.inl b/src/coreclr/vm/object.inl index 467ec47a1b3be4..a1bedd6e9d9826 100644 --- a/src/coreclr/vm/object.inl +++ b/src/coreclr/vm/object.inl @@ -46,14 +46,14 @@ inline SIZE_T Object::GetSize() return s; } -__forceinline /*static*/ DWORD StringObject::GetBaseSize() +FORCEINLINE /*static*/ DWORD StringObject::GetBaseSize() { LIMITED_METHOD_DAC_CONTRACT; return OBJECT_BASESIZE + sizeof(DWORD) /* length */ + sizeof(WCHAR) /* null terminator */; } -__forceinline /*static*/ SIZE_T StringObject::GetSize(DWORD strLen) +FORCEINLINE /*static*/ SIZE_T StringObject::GetSize(DWORD strLen) { LIMITED_METHOD_DAC_CONTRACT; @@ -231,7 +231,7 @@ inline TypeHandle ArrayBase::GetArrayElementTypeHandle() const //=============================================================================== // Returns true if this pMT is Nullable for T is equivalent to paramMT -__forceinline BOOL Nullable::IsNullableForType(TypeHandle type, MethodTable* paramMT) +FORCEINLINE BOOL Nullable::IsNullableForType(TypeHandle type, MethodTable* paramMT) { if (type.IsTypeDesc()) return FALSE; From 34cb67cb4267dd1d390dba1e21fc6083e87e7d67 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 2 Sep 2025 22:42:56 +0800 Subject: [PATCH 07/28] __UNREACHABLE --- src/coreclr/debug/di/rsmain.cpp | 2 +- src/coreclr/gc/env/gcenv.base.h | 6 ------ src/coreclr/inc/check.h | 1 - src/coreclr/inc/corhlpr.h | 1 - src/coreclr/inc/unreachable.h | 18 ------------------ src/coreclr/nativeaot/Runtime/rhassert.h | 12 +++--------- src/coreclr/utilcode/opinfo.cpp | 2 +- src/native/minipal/utils.h | 6 ++++++ 8 files changed, 11 insertions(+), 37 deletions(-) delete mode 100644 src/coreclr/inc/unreachable.h diff --git a/src/coreclr/debug/di/rsmain.cpp b/src/coreclr/debug/di/rsmain.cpp index d34c84974a0bb7..9a2de7bf42009f 100644 --- a/src/coreclr/debug/di/rsmain.cpp +++ b/src/coreclr/debug/di/rsmain.cpp @@ -1646,7 +1646,7 @@ HRESULT Cordb::CreateProcessCommon(ICorDebugRemoteTarget * pRemoteTarget, break; default: - __assume(0); + UNREACHABLE(); } #endif // FEATURE_INTEROP_DEBUGGING diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index f3dfd8a30e16b8..bdced75491a90e 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -23,12 +23,6 @@ #define __stdcall #endif // _MSC_VER -#ifdef _MSC_VER -#define __UNREACHABLE() __assume(0) -#else -#define __UNREACHABLE() __builtin_unreachable() -#endif - #ifndef SIZE_T_MAX #define SIZE_T_MAX ((size_t)-1) #endif diff --git a/src/coreclr/inc/check.h b/src/coreclr/inc/check.h index d1f921b5663f9d..9597756c1ed346 100644 --- a/src/coreclr/inc/check.h +++ b/src/coreclr/inc/check.h @@ -12,7 +12,6 @@ #define CHECK_H_ #include "daccess.h" -#include "unreachable.h" // Use the C++ detection idiom (https://isocpp.org/blog/2017/09/detection-idiom-a-stopgap-for-concepts-simon-brand) template struct make_void { using type = void; }; diff --git a/src/coreclr/inc/corhlpr.h b/src/coreclr/inc/corhlpr.h index 0bd3b1e1dfe854..9f5189858b695d 100644 --- a/src/coreclr/inc/corhlpr.h +++ b/src/coreclr/inc/corhlpr.h @@ -21,7 +21,6 @@ #include "cor.h" #include "corhdr.h" #include "corerror.h" -#include "unreachable.h" #include using std::nothrow; diff --git a/src/coreclr/inc/unreachable.h b/src/coreclr/inc/unreachable.h deleted file mode 100644 index 7cb857a176efa6..00000000000000 --- a/src/coreclr/inc/unreachable.h +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// --------------------------------------------------------------------------- -// unreachable.h -// --------------------------------------------------------------------------- - - -#ifndef __UNREACHABLE_H__ -#define __UNREACHABLE_H__ - -#if defined(_MSC_VER) -#define __UNREACHABLE() __assume(0) -#else -#define __UNREACHABLE() __builtin_unreachable() -#endif - -#endif // __UNREACHABLE_H__ - diff --git a/src/coreclr/nativeaot/Runtime/rhassert.h b/src/coreclr/nativeaot/Runtime/rhassert.h index de725ae26bdafa..1c5e5b89276399 100644 --- a/src/coreclr/nativeaot/Runtime/rhassert.h +++ b/src/coreclr/nativeaot/Runtime/rhassert.h @@ -3,12 +3,6 @@ #ifndef __RHASSERT_H__ #define __RHASSERT_H__ -#ifdef _MSC_VER -#define ASSUME(expr) __assume(expr) -#else // _MSC_VER -#define ASSUME(expr) do { if (!(expr)) __builtin_unreachable(); } while (0) -#endif // _MSC_VER - #if defined(_DEBUG) && !defined(DACCESS_COMPILE) #define ASSERT(expr) \ @@ -50,15 +44,15 @@ void Assert(const char * expr, const char * file, unsigned int line_num, const c #define PORTABILITY_ASSERT(message) \ ASSERT_UNCONDITIONALLY(message); \ - ASSUME(0); \ + __UNREACHABLE(); \ #define UNREACHABLE() \ ASSERT_UNCONDITIONALLY("UNREACHABLE"); \ - ASSUME(0); \ + __UNREACHABLE(); \ #define UNREACHABLE_MSG(message) \ ASSERT_UNCONDITIONALLY(message); \ - ASSUME(0); \ + __UNREACHABLE(); \ #ifdef HOST_WINDOWS #define RhFailFast() ::RaiseFailFastException(NULL, NULL, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS) diff --git a/src/coreclr/utilcode/opinfo.cpp b/src/coreclr/utilcode/opinfo.cpp index 0dc1086b40908f..685a23abf8503d 100644 --- a/src/coreclr/utilcode/opinfo.cpp +++ b/src/coreclr/utilcode/opinfo.cpp @@ -112,7 +112,7 @@ const BYTE* OpInfo::fetch(const BYTE* instrPtr, OpArgsVal* args) { #ifdef _DEBUG _ASSERTE(!"BadType"); #else - __assume(0); // we are really certain the default case does not happen + UNREACHABLE(); // we are really certain the default case does not happen #endif break; } diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index b2d47cad87a37f..7205c04e3b89b2 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -38,6 +38,12 @@ # define FALLTHROUGH #endif +#ifdef _MSC_VER +#define __UNREACHABLE() __assume(0) +#else +#define __UNREACHABLE() __builtin_unreachable() +#endif + #if defined(_MSC_VER) #define NOINLINE __declspec(noinline) #define FORCEINLINE __forceinline From 72d12b05bdb7c9994c37ba071d4efd81156542a5 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 3 Sep 2025 23:30:55 +0800 Subject: [PATCH 08/28] Unused defines --- src/coreclr/gc/unix/gcenv.unix.cpp | 4 ---- src/coreclr/pal/inc/pal.h | 4 ---- src/coreclr/pal/inc/pal_mstypes.h | 15 --------------- 3 files changed, 23 deletions(-) diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index 682c6adac7807c..e67e8a8d818d4c 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -36,10 +36,6 @@ #undef min #undef max -#ifndef __has_cpp_attribute -#define __has_cpp_attribute(x) (0) -#endif - #include #if HAVE_SYS_TIME_H diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index e7e06be149a60d..14950a24d80a20 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -151,10 +151,6 @@ extern bool g_arm64_atomics_present; #endif #endif -#ifndef __has_cpp_attribute -#define __has_cpp_attribute(x) (0) -#endif - /******************* PAL-Specific Entrypoints *****************************/ #define DLL_PROCESS_ATTACH 1 diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index 5441336e01ca33..4be80bb4c677a2 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -71,10 +71,6 @@ extern "C" { #define CALLBACK __cdecl -#if !defined(_declspec) -#define _declspec(e) __declspec(e) -#endif - #if defined(_VAC_) && defined(__cplusplus) #define __inline inline #endif @@ -101,13 +97,6 @@ extern "C" { #define OPTIONAL #define FAR -#ifdef UNICODE -#define __TEXT(x) L##x -#else -#define __TEXT(x) x -#endif -#define TEXT(x) __TEXT(x) - //////////////////////////////////////////////////////////////////////// // Some special values //////////////////////////////////////////////////////////////////////// @@ -137,10 +126,6 @@ extern "C" { // Misc. types //////////////////////////////////////////////////////////////////////// -#if HOST_64BIT -typedef long double LONG_DOUBLE; -#endif - typedef void VOID; typedef int LONG; // NOTE: diff from windows.h, for LP64 compat From fcd8af907fcf36116a6faf9fdf83dd900741f59a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 3 Sep 2025 23:35:48 +0800 Subject: [PATCH 09/28] Number literal helpers --- src/coreclr/gc/env/gcenv.base.h | 1 - src/coreclr/inc/clrtypes.h | 61 +------------------- src/coreclr/inc/palclr.h | 40 ------------- src/coreclr/nativeaot/Runtime/CommonMacros.h | 29 ---------- src/coreclr/pal/inc/pal_mstypes.h | 13 ----- src/native/minipal/utils.h | 24 ++++++++ 6 files changed, 25 insertions(+), 143 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index bdced75491a90e..f547fd3ca5ae48 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -438,7 +438,6 @@ typedef DPTR(uint8_t) PTR_uint8_t; #define CONSISTENCY_CHECK(_expr) ASSERT(_expr) #define COMPILER_ASSUME(cond) ASSERT(cond) #define EEPOLICY_HANDLE_FATAL_ERROR(error) ASSERT(!"EEPOLICY_HANDLE_FATAL_ERROR") -#define UI64(_literal) _literal##ULL class ObjHeader; class MethodTable; diff --git a/src/coreclr/inc/clrtypes.h b/src/coreclr/inc/clrtypes.h index 6238201535dcd6..bba06f11a039ff 100644 --- a/src/coreclr/inc/clrtypes.h +++ b/src/coreclr/inc/clrtypes.h @@ -11,12 +11,7 @@ #ifndef CLRTYPES_H_ #define CLRTYPES_H_ -#if defined(_MSC_VER) && !defined(SOURCE_FORMATTING) - // Prefer intsafe.h when available, which defines many of the MAX/MIN - // values below (which is why they are in #ifndef blocks). - #include -#endif - +#include #include "crtwrap.h" #include "winwrap.h" #include "staticcontract.h" @@ -27,60 +22,6 @@ #define POINTER_BITS (32) #endif -// ================================================================================ -// Integral types - use these for all integral types -// These types are in ALL_CAPS. Each type has a _MIN and _MAX defined for it. -// ================================================================================ - -// -------------------------------------------------------------------------------- -// Use these types for fixed size integers: -// INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 -// -------------------------------------------------------------------------------- - -#ifndef INT8_MAX - typedef signed char INT8; - typedef unsigned char UINT8; - typedef short INT16; - typedef unsigned short UINT16; - typedef int INT32; - typedef unsigned int UINT32; - typedef __int64 INT64; - typedef unsigned __int64 UINT64; - - #ifdef _MSC_VER - /* These macros must exactly match those in the Windows SDK's intsafe.h */ - #define INT8_MIN (-127i8 - 1) - #define INT16_MIN (-32767i16 - 1) - #define INT32_MIN (-2147483647i32 - 1) - #define INT64_MIN (-9223372036854775807i64 - 1) - - #define INT8_MAX 127i8 - #define INT16_MAX 32767i16 - #define INT32_MAX 2147483647i32 - #define INT64_MAX 9223372036854775807i64 - - #define UINT8_MAX 0xffui8 - #define UINT16_MAX 0xffffui16 - #define UINT32_MAX 0xffffffffui32 - #define UINT64_MAX 0xffffffffffffffffui64 - #else - #define INT8_MIN ((INT8)0x80) - #define INT16_MIN ((INT16)0x8000) - #define INT32_MIN ((INT32)0x80000000) - #define INT64_MIN ((INT64) I64(0x8000000000000000)) - - #define INT8_MAX ((INT8)0x7f) - #define INT16_MAX ((INT16)0x7fff) - #define INT32_MAX ((INT32)0x7fffffff) - #define INT64_MAX ((INT64) I64(0x7fffffffffffffff)) - - #define UINT8_MAX ((UINT8)0xffU) - #define UINT16_MAX ((UINT16)0xffffU) - #define UINT32_MAX ((UINT32)0xffffffffU) - #define UINT64_MAX ((UINT64) UI64(0xffffffffffffffff)) - #endif -#endif // !INT8_MAX - // UINTX_MINs aren't defined in standard header files, // so definition must be separately predicated. #ifndef UINT8_MIN diff --git a/src/coreclr/inc/palclr.h b/src/coreclr/inc/palclr.h index 94947f88fa83b1..14a83103d1798f 100644 --- a/src/coreclr/inc/palclr.h +++ b/src/coreclr/inc/palclr.h @@ -173,46 +173,6 @@ #endif -// PAL Numbers -// Used to ensure cross-compiler compatibility when declaring large -// integer constants. 64-bit integer constants should be wrapped in the -// declarations listed here. -// -// Each of the #defines here is wrapped to avoid conflicts with pal.h. - -#if defined(_MSC_VER) - -// MSVC's way of declaring large integer constants -// If you define these in one step, without the _HELPER macros, you -// get extra whitespace when composing these with other concatenating macros. -#ifndef I64 -#define I64_HELPER(x) x ## i64 -#define I64(x) I64_HELPER(x) -#endif - -#ifndef UI64 -#define UI64_HELPER(x) x ## ui64 -#define UI64(x) UI64_HELPER(x) -#endif - -#else - -// GCC's way of declaring large integer constants -// If you define these in one step, without the _HELPER macros, you -// get extra whitespace when composing these with other concatenating macros. -#ifndef I64 -#define I64_HELPER(x) x ## LL -#define I64(x) I64_HELPER(x) -#endif - -#ifndef UI64 -#define UI64_HELPER(x) x ## ULL -#define UI64(x) UI64_HELPER(x) -#endif - -#endif - - // PAL SEH // Macros for portable exception handling. The Win32 SEH is emulated using // these macros and setjmp/longjmp on Unix diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index 0d5e5e3fd90b16..ac50d2c934dafa 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -285,33 +285,4 @@ extern uint64_t g_startupTimelineEvents[NUM_STARTUP_TIMELINE_EVENTS]; #define STARTUP_TIMELINE_EVENT(eventid) #endif // PROFILE_STARTUP -// PAL Numbers -// Used to ensure cross-compiler compatibility when declaring large -// integer constants. 64-bit integer constants should be wrapped in the -// declarations listed here. -// -// Each of the #defines here is wrapped to avoid conflicts with pal.h. - -#if defined(_MSC_VER) - -// MSVC's way of declaring large integer constants -// If you define these in one step, without the _HELPER macros, you -// get extra whitespace when composing these with other concatenating macros. -#ifndef I64 -#define I64_HELPER(x) x ## i64 -#define I64(x) I64_HELPER(x) -#endif - -#else - -// GCC's way of declaring large integer constants -// If you define these in one step, without the _HELPER macros, you -// get extra whitespace when composing these with other concatenating macros. -#ifndef I64 -#define I64_HELPER(x) x ## LL -#define I64(x) I64_HELPER(x) -#endif - -#endif - #endif // __COMMONMACROS_H__ diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index 4be80bb4c677a2..dfe35053474e6f 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -109,19 +109,6 @@ extern "C" { #define FALSE 0 #endif -//////////////////////////////////////////////////////////////////////// -// Misc. type helpers -//////////////////////////////////////////////////////////////////////// - -// GCC's way of declaring large integer constants -// If you define these in one step, without the _HELPER macros, you -// get extra whitespace when composing these with other concatenating macros. -#define I64_HELPER(x) x ## LL -#define I64(x) I64_HELPER(x) - -#define UI64_HELPER(x) x ## ULL -#define UI64(x) UI64_HELPER(x) - //////////////////////////////////////////////////////////////////////// // Misc. types //////////////////////////////////////////////////////////////////////// diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index 7205c04e3b89b2..fb5a8a3d272915 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -52,6 +52,30 @@ #define FORCEINLINE __attribute__((always_inline)) inline #endif +#if defined(_MSC_VER) + +// MSVC's way of declaring large integer constants +// If you define these in one step, without the _HELPER macros, you +// get extra whitespace when composing these with other concatenating macros. +#define I64_HELPER(x) x ## i64 +#define I64(x) I64_HELPER(x) + +#define UI64_HELPER(x) x ## ui64 +#define UI64(x) UI64_HELPER(x) + +#else + +// GCC's way of declaring large integer constants +// If you define these in one step, without the _HELPER macros, you +// get extra whitespace when composing these with other concatenating macros. +#define I64_HELPER(x) x ## LL +#define I64(x) I64_HELPER(x) + +#define UI64_HELPER(x) x ## ULL +#define UI64(x) UI64_HELPER(x) + +#endif + #if defined(_MSC_VER) #define LIBC_CALLBACK __cdecl #else From d12d0e2ecfe6350645d8d00b5bc7181f50dba81b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 4 Sep 2025 17:57:42 +0800 Subject: [PATCH 10/28] DECLSPEC_ALIGN --- src/coreclr/gc/env/gcenv.base.h | 6 ------ src/coreclr/nativeaot/Runtime/PalLimitedContext.h | 9 +-------- src/coreclr/pal/inc/pal.h | 6 ------ src/native/minipal/utils.h | 6 ++++++ 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index f547fd3ca5ae48..de2436b44f4bc7 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -426,12 +426,6 @@ typedef DPTR(uint8_t) PTR_uint8_t; #define DATA_ALIGNMENT sizeof(uintptr_t) #define RAW_KEYWORD(x) x -#ifdef _MSC_VER -#define DECLSPEC_ALIGN(x) __declspec(align(x)) -#else -#define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) -#endif - #ifndef _ASSERTE #define _ASSERTE(_expr) ASSERT(_expr) #endif diff --git a/src/coreclr/nativeaot/Runtime/PalLimitedContext.h b/src/coreclr/nativeaot/Runtime/PalLimitedContext.h index c5e36453687aef..cf8e442b126b9e 100644 --- a/src/coreclr/nativeaot/Runtime/PalLimitedContext.h +++ b/src/coreclr/nativeaot/Runtime/PalLimitedContext.h @@ -6,14 +6,7 @@ #define PAL_LIMITED_CONTEXT_INCLUDED #include "rhassert.h" - -#ifndef DECLSPEC_ALIGN -#ifdef _MSC_VER -#define DECLSPEC_ALIGN(x) __declspec(align(x)) -#else -#define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) -#endif -#endif // DECLSPEC_ALIGN +#include #ifdef HOST_AMD64 #define AMD64_ALIGN_16 DECLSPEC_ALIGN(16) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 14950a24d80a20..3fe98fc44393a7 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -121,12 +121,6 @@ extern bool g_arm64_atomics_present; #define LANG_ENGLISH 0x09 /******************* Compiler-specific glue *******************************/ -#if defined(_MSC_VER) -#define DECLSPEC_ALIGN(x) __declspec(align(x)) -#else -#define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x))) -#endif - #define DECLSPEC_NORETURN PAL_NORETURN #define EMPTY_BASES_DECL diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index fb5a8a3d272915..cf1f07ef36976b 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -76,6 +76,12 @@ #endif +#ifdef _MSC_VER +#define DECLSPEC_ALIGN(x) __declspec(align(x)) +#else +#define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) +#endif + #if defined(_MSC_VER) #define LIBC_CALLBACK __cdecl #else From 9ed376a4d2ac528535dcf24b43decd802e3906eb Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 19:40:11 +0800 Subject: [PATCH 11/28] Unused --- src/coreclr/pal/inc/pal.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 3fe98fc44393a7..54639bb76623f8 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -409,15 +409,6 @@ PAL_PerfJitDump_Finish(); #define IDABORT 3 #define IDRETRY 4 -// From win32.h -#ifndef _CRTIMP -#ifdef __GNUC__ -#define _CRTIMP -#else // __GNUC__ -#define _CRTIMP __declspec(dllimport) -#endif // __GNUC__ -#endif // _CRTIMP - /******************* winbase.h Entrypoints and defines ************************/ typedef struct _SECURITY_ATTRIBUTES { DWORD nLength; From 0187c4521bc1a78aacb50d71651f88eb580e5bb9 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 22:25:20 +0800 Subject: [PATCH 12/28] Use offsetof from stddef --- src/coreclr/nativeaot/Runtime/CommonMacros.h | 4 +--- src/coreclr/pal/inc/rt/palrt.h | 4 ---- src/coreclr/pal/src/include/pal/palinternal.h | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/CommonMacros.h b/src/coreclr/nativeaot/Runtime/CommonMacros.h index ac50d2c934dafa..e2bea3c2af5fcf 100644 --- a/src/coreclr/nativeaot/Runtime/CommonMacros.h +++ b/src/coreclr/nativeaot/Runtime/CommonMacros.h @@ -37,9 +37,7 @@ #endif // _MSC_VER -#ifndef offsetof -#define offsetof(s,m) (uintptr_t)( (intptr_t)&reinterpret_cast((((s *)0)->m)) ) -#endif // offsetof +#include #ifndef __GCENV_BASE_INCLUDED__ diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index 45ed97d670f7ee..ee35d6dbd4126d 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -129,10 +129,6 @@ typedef enum tagEFaultRepRetVal #define _WINNT_ -#ifndef offsetof -#define offsetof(type, field) __builtin_offsetof(type, field) -#endif - #define CONTAINING_RECORD(address, type, field) \ ((type *)((LONG_PTR)(address) - offsetof(type, field))) diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 603ea73b008270..45c2345450bcbc 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -219,7 +219,7 @@ function_name() to call the system's implementation #define INFTIM -1 #endif // !HAVE_INFTIM -#define OffsetOf(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) +#include #undef assert #define assert (Use__ASSERTE_instead_of_assert) assert From 163dbb38e71ea37ec2b13519fc49c10a8c73df1b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 22:36:11 +0800 Subject: [PATCH 13/28] Macros from palrt --- src/coreclr/pal/inc/rt/palrt.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index ee35d6dbd4126d..c81d4b458147b1 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -135,12 +135,6 @@ typedef enum tagEFaultRepRetVal #define ARGUMENT_PRESENT(ArgumentPointer) (\ (CHAR *)(ArgumentPointer) != (CHAR *)(NULL) ) -#if defined(HOST_64BIT) -#define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG) -#else -#define MAX_NATURAL_ALIGNMENT sizeof(ULONG) -#endif - #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name #ifndef COM_NO_WINDOWS_H @@ -316,11 +310,6 @@ typedef struct tagDEC { #define DECIMAL_SETZERO(dec) {DECIMAL_LO32(dec) = 0; DECIMAL_MID32(dec) = 0; DECIMAL_HI32(dec) = 0; DECIMAL_SIGNSCALE(dec) = 0;} -typedef struct tagBLOB { - ULONG cbSize; - BYTE *pBlobData; -} BLOB, *LPBLOB; - interface IStream; interface IRecordInfo; @@ -1021,8 +1010,6 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD EXCEPTION_REGISTRATION_RECORD; typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD; typedef LPVOID HKEY; -typedef LPVOID PACL; -typedef LPVOID LPBC; typedef LPVOID PSECURITY_DESCRIPTOR; typedef struct _EXCEPTION_RECORD64 { From 74eac86ce0757458b54d9add14d1bafb80e11a8d Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 22:36:18 +0800 Subject: [PATCH 14/28] HWND --- src/coreclr/debug/ee/debuggermessagebox.cpp | 2 ++ src/coreclr/pal/inc/pal_mstypes.h | 1 - src/coreclr/pal/inc/rt/palrt.h | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/debug/ee/debuggermessagebox.cpp b/src/coreclr/debug/ee/debuggermessagebox.cpp index 5814d17d11b295..b34554090a55a2 100644 --- a/src/coreclr/debug/ee/debuggermessagebox.cpp +++ b/src/coreclr/debug/ee/debuggermessagebox.cpp @@ -34,10 +34,12 @@ static void DbgPrintf(const LPCSTR szFormat, ...) } } +#ifndef HOST_UNIX typedef int (*MessageBoxWFnPtr)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType); +#endif // !HOST_UNIX static int MessageBoxImpl( LPCWSTR title, // Dialog box title diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index dfe35053474e6f..b9cfad1f8374e7 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -258,7 +258,6 @@ typedef CONST TCHAR *LPCTSTR; #define HIBYTE(w) ((BYTE)((DWORD_PTR)(w) >> 8)) typedef VOID *HANDLE; -typedef HANDLE HWND; typedef struct __PAL_RemoteHandle__ { HANDLE h; } *RHANDLE; typedef HANDLE *PHANDLE; typedef HANDLE *LPHANDLE; diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index c81d4b458147b1..c6bb7289b32068 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -665,8 +665,6 @@ typename std::remove_reference::type&& move( T&& t ); #define __RPC__inout #define __RPC__deref_out_ecount_full_opt(x) -typedef HANDLE HWND; - typedef struct _LIST_ENTRY { struct _LIST_ENTRY *Flink; struct _LIST_ENTRY *Blink; From d363579aa9757729b3cff902eed9153c56c01942 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 22:42:24 +0800 Subject: [PATCH 15/28] MsgBox --- src/coreclr/debug/ee/debugger.cpp | 4 ++++ src/coreclr/debug/ee/debuggermessagebox.cpp | 2 ++ src/coreclr/pal/inc/pal.h | 9 --------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/coreclr/debug/ee/debugger.cpp b/src/coreclr/debug/ee/debugger.cpp index e797008279411d..757e250ff15f17 100644 --- a/src/coreclr/debug/ee/debugger.cpp +++ b/src/coreclr/debug/ee/debugger.cpp @@ -8631,12 +8631,16 @@ int Debugger::NotifyUserOfFault(bool userBreakpoint, DebuggerLaunchSetting dls) if (userBreakpoint) { msg = "Application has encountered a user-defined breakpoint.\n\nProcess ID=0x%x (%d), Thread ID=0x%x (%d).\n\nClick ABORT to terminate the application.\nClick RETRY to debug the application.\nClick IGNORE to ignore the breakpoint."; +#ifdef HOST_WINDOWS flags |= MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION; +#endif } else { msg = "Application has generated an exception that could not be handled.\n\nProcess ID=0x%x (%d), Thread ID=0x%x (%d).\n\nClick OK to terminate the application.\nClick CANCEL to debug the application."; +#ifdef HOST_WINDOWS flags |= MB_OKCANCEL | MB_ICONEXCLAMATION; +#endif } // Format message string using optional parameters diff --git a/src/coreclr/debug/ee/debuggermessagebox.cpp b/src/coreclr/debug/ee/debuggermessagebox.cpp index b34554090a55a2..af86529d3c5499 100644 --- a/src/coreclr/debug/ee/debuggermessagebox.cpp +++ b/src/coreclr/debug/ee/debuggermessagebox.cpp @@ -159,10 +159,12 @@ int NotifyUserOfFaultMessageBox( int result = IDCANCEL; +#ifdef HOST_WINDOWS // Add the MB_TASKMODAL style to indicate that the dialog should be displayed on top of the windows // owned by the current thread and should prevent interaction with them until dismissed. // Include in the MB_DEFAULT_DESKTOP_ONLY style. uType |= (MB_TASKMODAL | MB_DEFAULT_DESKTOP_ONLY); +#endif EX_TRY { diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 54639bb76623f8..d37d37410f6432 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -395,15 +395,6 @@ PAL_PerfJitDump_Finish(); /******************* winuser.h Entrypoints *******************************/ -#define MB_OKCANCEL 0x00000001L -#define MB_ABORTRETRYIGNORE 0x00000002L - -#define MB_ICONEXCLAMATION 0x00000030L - -#define MB_TASKMODAL 0x00002000L - -#define MB_DEFAULT_DESKTOP_ONLY 0x00020000L - #define IDOK 1 #define IDCANCEL 2 #define IDABORT 3 From b6c703b14aa57f436c73bf7ee92f2accc8d20def Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 22:47:09 +0800 Subject: [PATCH 16/28] Misc unused --- src/coreclr/pal/inc/pal.h | 2 -- src/coreclr/pal/inc/pal_mstypes.h | 3 --- src/coreclr/pal/inc/rt/palrt.h | 11 ----------- 3 files changed, 16 deletions(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index d37d37410f6432..e902003fd7dccf 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -407,8 +407,6 @@ typedef struct _SECURITY_ATTRIBUTES { BOOL bInheritHandle; } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; -#define _SH_DENYWR 0x20 /* deny write mode */ - #define FILE_READ_DATA ( 0x0001 ) // file & pipe #define FILE_APPEND_DATA ( 0x0004 ) // file diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index b9cfad1f8374e7..ace5142f005b5d 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -266,9 +266,6 @@ typedef HANDLE *LPHANDLE; #define INVALID_FILE_ATTRIBUTES ((DWORD) -1) typedef HANDLE HMODULE; typedef HANDLE HINSTANCE; -typedef HANDLE HGLOBAL; -typedef HANDLE HLOCAL; -typedef HANDLE HRSRC; typedef LONG HRESULT; typedef LONG NTSTATUS; diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index c6bb7289b32068..746f219a57c4b0 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -643,17 +643,6 @@ inline errno_t __cdecl _fopen_unsafe(FILE * *ff, const char *fileName, const cha /******************* misc ***************************************/ -#ifdef __cplusplus -namespace std -{ - typedef decltype(nullptr) nullptr_t; -} - -extern "C++" -template< class T > -typename std::remove_reference::type&& move( T&& t ); -#endif // __cplusplus - #define __RPC__out #define __RPC__in #define __RPC__deref_out_opt From ad03c60fb773b26aa3d1ea043dddccde983b8a9d Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 6 Sep 2025 23:11:38 +0800 Subject: [PATCH 17/28] Fix build --- src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp | 1 + src/coreclr/utilcode/opinfo.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp index 7f2d17b3f4376c..8ead6c24ba94df 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp @@ -4,6 +4,7 @@ #include "common.h" #include "daccess.h" #include "rhassert.h" +#include #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 diff --git a/src/coreclr/utilcode/opinfo.cpp b/src/coreclr/utilcode/opinfo.cpp index 685a23abf8503d..ac040c2d22427d 100644 --- a/src/coreclr/utilcode/opinfo.cpp +++ b/src/coreclr/utilcode/opinfo.cpp @@ -112,7 +112,7 @@ const BYTE* OpInfo::fetch(const BYTE* instrPtr, OpArgsVal* args) { #ifdef _DEBUG _ASSERTE(!"BadType"); #else - UNREACHABLE(); // we are really certain the default case does not happen + __UNREACHABLE(); // we are really certain the default case does not happen #endif break; } From ebcd6576fa980a60dc853c8fb8cdb7df97de38f8 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 7 Sep 2025 01:03:20 +0800 Subject: [PATCH 18/28] Use standard alignas --- src/coreclr/debug/ee/debugger.h | 4 ++-- src/coreclr/debug/inc/dbgtargetcontext.h | 10 +++++----- src/coreclr/gc/gc.cpp | 8 ++++---- src/coreclr/gc/gcpriv.h | 2 +- src/coreclr/inc/crosscomp.h | 8 ++++---- src/coreclr/inc/sarray.h | 4 ++-- src/coreclr/inc/sbuffer.h | 4 ++-- .../nativeaot/Runtime/PalLimitedContext.h | 2 +- .../Runtime/UniversalTransitionHelpers.cpp | 4 ++-- src/coreclr/pal/inc/pal.h | 20 +++++++++---------- src/coreclr/vm/appdomain.cpp | 2 +- src/coreclr/vm/callhelpers.h | 2 +- src/native/minipal/utils.h | 6 ------ 13 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/coreclr/debug/ee/debugger.h b/src/coreclr/debug/ee/debugger.h index 403add11227084..225ca3da646357 100644 --- a/src/coreclr/debug/ee/debugger.h +++ b/src/coreclr/debug/ee/debugger.h @@ -1136,7 +1136,7 @@ struct DebuggerHeapExecutableMemoryPage; // for the page, and the remaining ones are DataChunks and are handed out // by the allocator when it allocates memory. // ------------------------------------------------------------------------ */ -union DECLSPEC_ALIGN(EXPECTED_CHUNKSIZE) DebuggerHeapExecutableMemoryChunk { +union alignas(EXPECTED_CHUNKSIZE) DebuggerHeapExecutableMemoryChunk { struct DataChunk { @@ -1172,7 +1172,7 @@ static_assert(sizeof(DebuggerHeapExecutableMemoryChunk) == EXPECTED_CHUNKSIZE, " // about which of the other chunks are used/free as well as a pointer to // the next page. // ------------------------------------------------------------------------ */ -struct DECLSPEC_ALIGN(DEBUGGERHEAP_PAGESIZE) DebuggerHeapExecutableMemoryPage +struct alignas(DEBUGGERHEAP_PAGESIZE) DebuggerHeapExecutableMemoryPage { inline DebuggerHeapExecutableMemoryPage* GetNextPage() { diff --git a/src/coreclr/debug/inc/dbgtargetcontext.h b/src/coreclr/debug/inc/dbgtargetcontext.h index 606e4954b35272..eb656c89a61a53 100644 --- a/src/coreclr/debug/inc/dbgtargetcontext.h +++ b/src/coreclr/debug/inc/dbgtargetcontext.h @@ -212,7 +212,7 @@ typedef struct { BYTE Reserved4[96]; } DT_XMM_SAVE_AREA32; -typedef struct DECLSPEC_ALIGN(16) { +typedef struct alignas(16) { DWORD64 P1Home; DWORD64 P2Home; @@ -319,7 +319,7 @@ typedef struct { LONGLONG High; } DT_NEON128; -typedef DECLSPEC_ALIGN(8) struct { +typedef alignas(8) struct { // // Control flags. @@ -401,7 +401,7 @@ typedef struct { LONGLONG High; } DT_NEON128; -typedef DECLSPEC_ALIGN(16) struct { +typedef alignas(16) struct { // // Control flags. // @@ -494,7 +494,7 @@ static_assert(sizeof(DT_CONTEXT) == sizeof(T_CONTEXT), "DT_CONTEXT size must equ #define DT_LOONGARCH64_MAX_BREAKPOINTS 8 #define DT_LOONGARCH64_MAX_WATCHPOINTS 2 -typedef struct DECLSPEC_ALIGN(16) { +typedef struct alignas(16) { // // Control flags. // @@ -563,7 +563,7 @@ static_assert(sizeof(DT_CONTEXT) == sizeof(T_CONTEXT), "DT_CONTEXT size must equ #define DT_RISCV64_MAX_BREAKPOINTS 8 #define DT_RISCV64_MAX_WATCHPOINTS 2 -typedef struct DECLSPEC_ALIGN(16) { +typedef struct alignas(16) { // // Control flags. // diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index bdf67f7374dfaf..0bd4449a27fa21 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -693,21 +693,21 @@ enum gc_join_flavor #define first_thread_arrived 2 #pragma warning(push) -#pragma warning(disable:4324) // don't complain if DECLSPEC_ALIGN actually pads -struct DECLSPEC_ALIGN(HS_CACHE_LINE_SIZE) join_structure +#pragma warning(disable:4324) // don't complain if alignas actually pads +struct alignas(HS_CACHE_LINE_SIZE) join_structure { // Shared non volatile keep on separate line to prevent eviction int n_threads; // Keep polling/wait structures on separate line write once per join - DECLSPEC_ALIGN(HS_CACHE_LINE_SIZE) + alignas(HS_CACHE_LINE_SIZE) GCEvent joined_event[3]; // the last event in the array is only used for first_thread_arrived. Volatile lock_color; VOLATILE(BOOL) wait_done; VOLATILE(BOOL) joined_p; // Keep volatile counted locks on separate cache line write many per join - DECLSPEC_ALIGN(HS_CACHE_LINE_SIZE) + alignas(HS_CACHE_LINE_SIZE) VOLATILE(int) join_lock; VOLATILE(int) r_join_lock; diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 0247a4e5a96de6..edb25ba442c188 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -6140,7 +6140,7 @@ struct gap_reloc_pair #define min_pre_pin_obj_size (sizeof (gap_reloc_pair) + min_obj_size) -struct DECLSPEC_ALIGN(8) aligned_plug_and_gap +struct alignas(8) aligned_plug_and_gap { size_t additional_pad; plug_and_gap plugandgap; diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index 4c30eb01ba8ae9..9d817db7d422e6 100644 --- a/src/coreclr/inc/crosscomp.h +++ b/src/coreclr/inc/crosscomp.h @@ -66,7 +66,7 @@ typedef struct _NEON128 { } NEON128, *PNEON128; #endif // !defined(HOST_ARM64) -typedef struct DECLSPEC_ALIGN(8) _T_CONTEXT { +typedef struct alignas(8) _T_CONTEXT { // // Control flags. // @@ -223,7 +223,7 @@ typedef union _NEON128 { BYTE B[16]; } NEON128, *PNEON128; -typedef struct DECLSPEC_ALIGN(16) _T_CONTEXT { +typedef struct alignas(16) _T_CONTEXT { // // Control flags. @@ -415,7 +415,7 @@ enum #define CONTEXT_UNWOUND_TO_CALL 0x20000000 -typedef struct DECLSPEC_ALIGN(16) _T_CONTEXT { +typedef struct alignas(16) _T_CONTEXT { // // Control flags. @@ -548,7 +548,7 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #define CONTEXT_UNWOUND_TO_CALL 0x20000000 -typedef struct DECLSPEC_ALIGN(16) _T_CONTEXT { +typedef struct alignas(16) _T_CONTEXT { // // Control flags. diff --git a/src/coreclr/inc/sarray.h b/src/coreclr/inc/sarray.h index 4c5e7ef86c1b6d..28277292f7d401 100644 --- a/src/coreclr/inc/sarray.h +++ b/src/coreclr/inc/sarray.h @@ -190,8 +190,8 @@ class EMPTY_BASES_DECL InlineSArray : public SArray #ifdef TARGET_WINDOWS #pragma warning(push) #pragma warning(disable:4200) // zero sized array -#pragma warning(disable:4324) // don't complain if DECLSPEC_ALIGN actually pads - DECLSPEC_ALIGN(BUFFER_ALIGNMENT) BYTE m_prealloc[SIZE*sizeof(ELEMENT)]; +#pragma warning(disable:4324) // don't complain if alignas actually pads + alignas(BUFFER_ALIGNMENT) BYTE m_prealloc[SIZE*sizeof(ELEMENT)]; #pragma warning(pop) #else // use UINT64 to get maximum alignment of the memory diff --git a/src/coreclr/inc/sbuffer.h b/src/coreclr/inc/sbuffer.h index aa743695895b2f..40c5cafec94e10 100644 --- a/src/coreclr/inc/sbuffer.h +++ b/src/coreclr/inc/sbuffer.h @@ -534,8 +534,8 @@ class EMPTY_BASES_DECL InlineSBuffer : public SBuffer #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4200) // zero sized array -#pragma warning(disable:4324) // don't complain if DECLSPEC_ALIGN actually pads - DECLSPEC_ALIGN(BUFFER_ALIGNMENT) BYTE m_prealloc[size]; +#pragma warning(disable:4324) // don't complain if alignas actually pads + alignas(BUFFER_ALIGNMENT) BYTE m_prealloc[size]; #pragma warning(pop) #else // use UINT64 to get maximum alignment of the memory diff --git a/src/coreclr/nativeaot/Runtime/PalLimitedContext.h b/src/coreclr/nativeaot/Runtime/PalLimitedContext.h index cf8e442b126b9e..cf82cd7b028046 100644 --- a/src/coreclr/nativeaot/Runtime/PalLimitedContext.h +++ b/src/coreclr/nativeaot/Runtime/PalLimitedContext.h @@ -9,7 +9,7 @@ #include #ifdef HOST_AMD64 -#define AMD64_ALIGN_16 DECLSPEC_ALIGN(16) +#define AMD64_ALIGN_16 alignas(16) #else // HOST_AMD64 #define AMD64_ALIGN_16 #endif // HOST_AMD64 diff --git a/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp b/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp index aabf45392313ae..53635bf199a48c 100644 --- a/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp @@ -35,7 +35,7 @@ #define TRASH_VALUE_ALIGNMENT 16 EXTERN_C -DECLSPEC_ALIGN(TRASH_VALUE_ALIGNMENT) +alignas(TRASH_VALUE_ALIGNMENT) const uint32_t RhpIntegerTrashValues[] = { // Lo32 Hi32 Lo32 Hi32 Hi32:Lo32 // ----------- ----------- --------- --------- ------------------ @@ -50,7 +50,7 @@ const uint32_t RhpIntegerTrashValues[] = { }; EXTERN_C -DECLSPEC_ALIGN(TRASH_VALUE_ALIGNMENT) +alignas(TRASH_VALUE_ALIGNMENT) const uint32_t RhpFpTrashValues[] = { // Lo32 Hi32 Lo32 Hi32 Hi32:Lo32 // ----------- ----------- ------------------- ------------------- ------------------- diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index e902003fd7dccf..f1d98aad32863d 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -1190,17 +1190,17 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { (UI64(1) << (XSTATE_AVX512_ZMM))) #define XSTATE_MASK_APX (UI64(1) << (XSTATE_APX)) -typedef struct DECLSPEC_ALIGN(16) _M128A { +typedef struct alignas(16) _M128A { ULONGLONG Low; LONGLONG High; } M128A, *PM128A; -typedef struct DECLSPEC_ALIGN(16) _M256 { +typedef struct alignas(16) _M256 { M128A Low; M128A High; } M256, *PM256; -typedef struct DECLSPEC_ALIGN(16) _M512 { +typedef struct alignas(16) _M512 { M256 Low; M256 High; } M512, *PM512; @@ -1224,7 +1224,7 @@ typedef struct _XMM_SAVE_AREA32 { BYTE Reserved4[96]; } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32; -typedef struct DECLSPEC_ALIGN(16) _CONTEXT { +typedef struct alignas(16) _CONTEXT { _CONTEXT() = default; _CONTEXT(const _CONTEXT& ctx) @@ -1542,7 +1542,7 @@ typedef struct _NEON128 { LONGLONG High; } NEON128, *PNEON128; -typedef struct DECLSPEC_ALIGN(8) _CONTEXT { +typedef struct alignas(8) _CONTEXT { // // Control flags. @@ -1704,7 +1704,7 @@ typedef struct _NEON128 { LONGLONG High; } NEON128, *PNEON128; -typedef struct DECLSPEC_ALIGN(16) _CONTEXT { +typedef struct alignas(16) _CONTEXT { // // Control flags. @@ -1886,7 +1886,7 @@ typedef union IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_XDATA { #define LOONGARCH64_MAX_BREAKPOINTS 8 #define LOONGARCH64_MAX_WATCHPOINTS 2 -typedef struct DECLSPEC_ALIGN(16) _CONTEXT { +typedef struct alignas(16) _CONTEXT { // // Control flags. @@ -2006,7 +2006,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { #define RISCV64_MAX_BREAKPOINTS 8 #define RISCV64_MAX_WATCHPOINTS 2 -typedef struct DECLSPEC_ALIGN(16) _CONTEXT { +typedef struct alignas(16) _CONTEXT { // // Control flags. @@ -2114,7 +2114,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { #define CONTEXT_EXCEPTION_REQUEST 0x40000000 #define CONTEXT_EXCEPTION_REPORTING 0x80000000 -typedef struct DECLSPEC_ALIGN(8) _CONTEXT { +typedef struct alignas(8) _CONTEXT { // // Control flags. @@ -2220,7 +2220,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { #define CONTEXT_EXCEPTION_REQUEST 0x40000000 #define CONTEXT_EXCEPTION_REPORTING 0x80000000 -typedef struct DECLSPEC_ALIGN(16) _CONTEXT { +typedef struct alignas(16) _CONTEXT { // // Control flags. diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 7b247b2b8bfd02..e21d1b75d31534 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -93,7 +93,7 @@ SPTR_IMPL(SystemDomain, SystemDomain, m_pSystemDomain); GlobalStringLiteralMap* SystemDomain::m_pGlobalStringLiteralMap = NULL; FrozenObjectHeapManager* SystemDomain::m_FrozenObjectHeapManager = NULL; -DECLSPEC_ALIGN(16) +alignas(16) static BYTE g_pSystemDomainMemory[sizeof(SystemDomain)]; CrstStatic SystemDomain::m_SystemDomainCrst; diff --git a/src/coreclr/vm/callhelpers.h b/src/coreclr/vm/callhelpers.h index 0527dbe0d8076c..e1153a2afff6f0 100644 --- a/src/coreclr/vm/callhelpers.h +++ b/src/coreclr/vm/callhelpers.h @@ -44,7 +44,7 @@ struct CallDescrData #ifdef ENREGISTERED_RETURNTYPE_MAXSIZE #ifdef TARGET_ARM64 // Use NEON128 to ensure proper alignment for vectors. - DECLSPEC_ALIGN(16) NEON128 returnValue[ENREGISTERED_RETURNTYPE_MAXSIZE / sizeof(NEON128)]; + alignas(16) NEON128 returnValue[ENREGISTERED_RETURNTYPE_MAXSIZE / sizeof(NEON128)]; #else // Use UINT64 to ensure proper alignment UINT64 returnValue[ENREGISTERED_RETURNTYPE_MAXSIZE / sizeof(UINT64)]; diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index cf1f07ef36976b..fb5a8a3d272915 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -76,12 +76,6 @@ #endif -#ifdef _MSC_VER -#define DECLSPEC_ALIGN(x) __declspec(align(x)) -#else -#define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) -#endif - #if defined(_MSC_VER) #define LIBC_CALLBACK __cdecl #else From eb9c8af90c15d9860b8e2c37eb0bd1c898d68ba0 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 7 Sep 2025 01:31:30 +0800 Subject: [PATCH 19/28] Revert "Use standard alignas" This reverts commit ebcd6576fa980a60dc853c8fb8cdb7df97de38f8. --- src/coreclr/debug/ee/debugger.h | 4 ++-- src/coreclr/debug/inc/dbgtargetcontext.h | 10 +++++----- src/coreclr/gc/gc.cpp | 8 ++++---- src/coreclr/gc/gcpriv.h | 2 +- src/coreclr/inc/crosscomp.h | 8 ++++---- src/coreclr/inc/sarray.h | 4 ++-- src/coreclr/inc/sbuffer.h | 4 ++-- .../nativeaot/Runtime/PalLimitedContext.h | 2 +- .../Runtime/UniversalTransitionHelpers.cpp | 4 ++-- src/coreclr/pal/inc/pal.h | 20 +++++++++---------- src/coreclr/vm/appdomain.cpp | 2 +- src/coreclr/vm/callhelpers.h | 2 +- src/native/minipal/utils.h | 6 ++++++ 13 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/coreclr/debug/ee/debugger.h b/src/coreclr/debug/ee/debugger.h index 225ca3da646357..403add11227084 100644 --- a/src/coreclr/debug/ee/debugger.h +++ b/src/coreclr/debug/ee/debugger.h @@ -1136,7 +1136,7 @@ struct DebuggerHeapExecutableMemoryPage; // for the page, and the remaining ones are DataChunks and are handed out // by the allocator when it allocates memory. // ------------------------------------------------------------------------ */ -union alignas(EXPECTED_CHUNKSIZE) DebuggerHeapExecutableMemoryChunk { +union DECLSPEC_ALIGN(EXPECTED_CHUNKSIZE) DebuggerHeapExecutableMemoryChunk { struct DataChunk { @@ -1172,7 +1172,7 @@ static_assert(sizeof(DebuggerHeapExecutableMemoryChunk) == EXPECTED_CHUNKSIZE, " // about which of the other chunks are used/free as well as a pointer to // the next page. // ------------------------------------------------------------------------ */ -struct alignas(DEBUGGERHEAP_PAGESIZE) DebuggerHeapExecutableMemoryPage +struct DECLSPEC_ALIGN(DEBUGGERHEAP_PAGESIZE) DebuggerHeapExecutableMemoryPage { inline DebuggerHeapExecutableMemoryPage* GetNextPage() { diff --git a/src/coreclr/debug/inc/dbgtargetcontext.h b/src/coreclr/debug/inc/dbgtargetcontext.h index eb656c89a61a53..606e4954b35272 100644 --- a/src/coreclr/debug/inc/dbgtargetcontext.h +++ b/src/coreclr/debug/inc/dbgtargetcontext.h @@ -212,7 +212,7 @@ typedef struct { BYTE Reserved4[96]; } DT_XMM_SAVE_AREA32; -typedef struct alignas(16) { +typedef struct DECLSPEC_ALIGN(16) { DWORD64 P1Home; DWORD64 P2Home; @@ -319,7 +319,7 @@ typedef struct { LONGLONG High; } DT_NEON128; -typedef alignas(8) struct { +typedef DECLSPEC_ALIGN(8) struct { // // Control flags. @@ -401,7 +401,7 @@ typedef struct { LONGLONG High; } DT_NEON128; -typedef alignas(16) struct { +typedef DECLSPEC_ALIGN(16) struct { // // Control flags. // @@ -494,7 +494,7 @@ static_assert(sizeof(DT_CONTEXT) == sizeof(T_CONTEXT), "DT_CONTEXT size must equ #define DT_LOONGARCH64_MAX_BREAKPOINTS 8 #define DT_LOONGARCH64_MAX_WATCHPOINTS 2 -typedef struct alignas(16) { +typedef struct DECLSPEC_ALIGN(16) { // // Control flags. // @@ -563,7 +563,7 @@ static_assert(sizeof(DT_CONTEXT) == sizeof(T_CONTEXT), "DT_CONTEXT size must equ #define DT_RISCV64_MAX_BREAKPOINTS 8 #define DT_RISCV64_MAX_WATCHPOINTS 2 -typedef struct alignas(16) { +typedef struct DECLSPEC_ALIGN(16) { // // Control flags. // diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 0bd4449a27fa21..bdf67f7374dfaf 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -693,21 +693,21 @@ enum gc_join_flavor #define first_thread_arrived 2 #pragma warning(push) -#pragma warning(disable:4324) // don't complain if alignas actually pads -struct alignas(HS_CACHE_LINE_SIZE) join_structure +#pragma warning(disable:4324) // don't complain if DECLSPEC_ALIGN actually pads +struct DECLSPEC_ALIGN(HS_CACHE_LINE_SIZE) join_structure { // Shared non volatile keep on separate line to prevent eviction int n_threads; // Keep polling/wait structures on separate line write once per join - alignas(HS_CACHE_LINE_SIZE) + DECLSPEC_ALIGN(HS_CACHE_LINE_SIZE) GCEvent joined_event[3]; // the last event in the array is only used for first_thread_arrived. Volatile lock_color; VOLATILE(BOOL) wait_done; VOLATILE(BOOL) joined_p; // Keep volatile counted locks on separate cache line write many per join - alignas(HS_CACHE_LINE_SIZE) + DECLSPEC_ALIGN(HS_CACHE_LINE_SIZE) VOLATILE(int) join_lock; VOLATILE(int) r_join_lock; diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index edb25ba442c188..0247a4e5a96de6 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -6140,7 +6140,7 @@ struct gap_reloc_pair #define min_pre_pin_obj_size (sizeof (gap_reloc_pair) + min_obj_size) -struct alignas(8) aligned_plug_and_gap +struct DECLSPEC_ALIGN(8) aligned_plug_and_gap { size_t additional_pad; plug_and_gap plugandgap; diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index 9d817db7d422e6..4c30eb01ba8ae9 100644 --- a/src/coreclr/inc/crosscomp.h +++ b/src/coreclr/inc/crosscomp.h @@ -66,7 +66,7 @@ typedef struct _NEON128 { } NEON128, *PNEON128; #endif // !defined(HOST_ARM64) -typedef struct alignas(8) _T_CONTEXT { +typedef struct DECLSPEC_ALIGN(8) _T_CONTEXT { // // Control flags. // @@ -223,7 +223,7 @@ typedef union _NEON128 { BYTE B[16]; } NEON128, *PNEON128; -typedef struct alignas(16) _T_CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _T_CONTEXT { // // Control flags. @@ -415,7 +415,7 @@ enum #define CONTEXT_UNWOUND_TO_CALL 0x20000000 -typedef struct alignas(16) _T_CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _T_CONTEXT { // // Control flags. @@ -548,7 +548,7 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #define CONTEXT_UNWOUND_TO_CALL 0x20000000 -typedef struct alignas(16) _T_CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _T_CONTEXT { // // Control flags. diff --git a/src/coreclr/inc/sarray.h b/src/coreclr/inc/sarray.h index 28277292f7d401..4c5e7ef86c1b6d 100644 --- a/src/coreclr/inc/sarray.h +++ b/src/coreclr/inc/sarray.h @@ -190,8 +190,8 @@ class EMPTY_BASES_DECL InlineSArray : public SArray #ifdef TARGET_WINDOWS #pragma warning(push) #pragma warning(disable:4200) // zero sized array -#pragma warning(disable:4324) // don't complain if alignas actually pads - alignas(BUFFER_ALIGNMENT) BYTE m_prealloc[SIZE*sizeof(ELEMENT)]; +#pragma warning(disable:4324) // don't complain if DECLSPEC_ALIGN actually pads + DECLSPEC_ALIGN(BUFFER_ALIGNMENT) BYTE m_prealloc[SIZE*sizeof(ELEMENT)]; #pragma warning(pop) #else // use UINT64 to get maximum alignment of the memory diff --git a/src/coreclr/inc/sbuffer.h b/src/coreclr/inc/sbuffer.h index 40c5cafec94e10..aa743695895b2f 100644 --- a/src/coreclr/inc/sbuffer.h +++ b/src/coreclr/inc/sbuffer.h @@ -534,8 +534,8 @@ class EMPTY_BASES_DECL InlineSBuffer : public SBuffer #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4200) // zero sized array -#pragma warning(disable:4324) // don't complain if alignas actually pads - alignas(BUFFER_ALIGNMENT) BYTE m_prealloc[size]; +#pragma warning(disable:4324) // don't complain if DECLSPEC_ALIGN actually pads + DECLSPEC_ALIGN(BUFFER_ALIGNMENT) BYTE m_prealloc[size]; #pragma warning(pop) #else // use UINT64 to get maximum alignment of the memory diff --git a/src/coreclr/nativeaot/Runtime/PalLimitedContext.h b/src/coreclr/nativeaot/Runtime/PalLimitedContext.h index cf82cd7b028046..cf8e442b126b9e 100644 --- a/src/coreclr/nativeaot/Runtime/PalLimitedContext.h +++ b/src/coreclr/nativeaot/Runtime/PalLimitedContext.h @@ -9,7 +9,7 @@ #include #ifdef HOST_AMD64 -#define AMD64_ALIGN_16 alignas(16) +#define AMD64_ALIGN_16 DECLSPEC_ALIGN(16) #else // HOST_AMD64 #define AMD64_ALIGN_16 #endif // HOST_AMD64 diff --git a/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp b/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp index 53635bf199a48c..aabf45392313ae 100644 --- a/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp @@ -35,7 +35,7 @@ #define TRASH_VALUE_ALIGNMENT 16 EXTERN_C -alignas(TRASH_VALUE_ALIGNMENT) +DECLSPEC_ALIGN(TRASH_VALUE_ALIGNMENT) const uint32_t RhpIntegerTrashValues[] = { // Lo32 Hi32 Lo32 Hi32 Hi32:Lo32 // ----------- ----------- --------- --------- ------------------ @@ -50,7 +50,7 @@ const uint32_t RhpIntegerTrashValues[] = { }; EXTERN_C -alignas(TRASH_VALUE_ALIGNMENT) +DECLSPEC_ALIGN(TRASH_VALUE_ALIGNMENT) const uint32_t RhpFpTrashValues[] = { // Lo32 Hi32 Lo32 Hi32 Hi32:Lo32 // ----------- ----------- ------------------- ------------------- ------------------- diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index f1d98aad32863d..e902003fd7dccf 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -1190,17 +1190,17 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { (UI64(1) << (XSTATE_AVX512_ZMM))) #define XSTATE_MASK_APX (UI64(1) << (XSTATE_APX)) -typedef struct alignas(16) _M128A { +typedef struct DECLSPEC_ALIGN(16) _M128A { ULONGLONG Low; LONGLONG High; } M128A, *PM128A; -typedef struct alignas(16) _M256 { +typedef struct DECLSPEC_ALIGN(16) _M256 { M128A Low; M128A High; } M256, *PM256; -typedef struct alignas(16) _M512 { +typedef struct DECLSPEC_ALIGN(16) _M512 { M256 Low; M256 High; } M512, *PM512; @@ -1224,7 +1224,7 @@ typedef struct _XMM_SAVE_AREA32 { BYTE Reserved4[96]; } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32; -typedef struct alignas(16) _CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _CONTEXT { _CONTEXT() = default; _CONTEXT(const _CONTEXT& ctx) @@ -1542,7 +1542,7 @@ typedef struct _NEON128 { LONGLONG High; } NEON128, *PNEON128; -typedef struct alignas(8) _CONTEXT { +typedef struct DECLSPEC_ALIGN(8) _CONTEXT { // // Control flags. @@ -1704,7 +1704,7 @@ typedef struct _NEON128 { LONGLONG High; } NEON128, *PNEON128; -typedef struct alignas(16) _CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _CONTEXT { // // Control flags. @@ -1886,7 +1886,7 @@ typedef union IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_XDATA { #define LOONGARCH64_MAX_BREAKPOINTS 8 #define LOONGARCH64_MAX_WATCHPOINTS 2 -typedef struct alignas(16) _CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _CONTEXT { // // Control flags. @@ -2006,7 +2006,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { #define RISCV64_MAX_BREAKPOINTS 8 #define RISCV64_MAX_WATCHPOINTS 2 -typedef struct alignas(16) _CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _CONTEXT { // // Control flags. @@ -2114,7 +2114,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { #define CONTEXT_EXCEPTION_REQUEST 0x40000000 #define CONTEXT_EXCEPTION_REPORTING 0x80000000 -typedef struct alignas(8) _CONTEXT { +typedef struct DECLSPEC_ALIGN(8) _CONTEXT { // // Control flags. @@ -2220,7 +2220,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { #define CONTEXT_EXCEPTION_REQUEST 0x40000000 #define CONTEXT_EXCEPTION_REPORTING 0x80000000 -typedef struct alignas(16) _CONTEXT { +typedef struct DECLSPEC_ALIGN(16) _CONTEXT { // // Control flags. diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index e21d1b75d31534..7b247b2b8bfd02 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -93,7 +93,7 @@ SPTR_IMPL(SystemDomain, SystemDomain, m_pSystemDomain); GlobalStringLiteralMap* SystemDomain::m_pGlobalStringLiteralMap = NULL; FrozenObjectHeapManager* SystemDomain::m_FrozenObjectHeapManager = NULL; -alignas(16) +DECLSPEC_ALIGN(16) static BYTE g_pSystemDomainMemory[sizeof(SystemDomain)]; CrstStatic SystemDomain::m_SystemDomainCrst; diff --git a/src/coreclr/vm/callhelpers.h b/src/coreclr/vm/callhelpers.h index e1153a2afff6f0..0527dbe0d8076c 100644 --- a/src/coreclr/vm/callhelpers.h +++ b/src/coreclr/vm/callhelpers.h @@ -44,7 +44,7 @@ struct CallDescrData #ifdef ENREGISTERED_RETURNTYPE_MAXSIZE #ifdef TARGET_ARM64 // Use NEON128 to ensure proper alignment for vectors. - alignas(16) NEON128 returnValue[ENREGISTERED_RETURNTYPE_MAXSIZE / sizeof(NEON128)]; + DECLSPEC_ALIGN(16) NEON128 returnValue[ENREGISTERED_RETURNTYPE_MAXSIZE / sizeof(NEON128)]; #else // Use UINT64 to ensure proper alignment UINT64 returnValue[ENREGISTERED_RETURNTYPE_MAXSIZE / sizeof(UINT64)]; diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index fb5a8a3d272915..cf1f07ef36976b 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -76,6 +76,12 @@ #endif +#ifdef _MSC_VER +#define DECLSPEC_ALIGN(x) __declspec(align(x)) +#else +#define DECLSPEC_ALIGN(x) __attribute__((aligned(x))) +#endif + #if defined(_MSC_VER) #define LIBC_CALLBACK __cdecl #else From a418cd624f126c13d1a015244a7fec92b2a9b1c2 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 7 Sep 2025 14:21:20 +0800 Subject: [PATCH 20/28] Unify LL numeric suffix --- src/coreclr/gc/handletablecore.cpp | 4 ++-- src/coreclr/gcinfo/gcinfodumper.cpp | 2 +- src/coreclr/ilasm/grammar_after.cpp | 4 ++-- src/coreclr/ilasm/writer.cpp | 2 +- src/coreclr/ildasm/dasm.cpp | 4 ++-- src/coreclr/inc/ceefilegenwriter.h | 4 ++-- src/coreclr/inc/clrtypes.h | 4 ++-- src/coreclr/inc/sbuffer.inl | 2 +- src/coreclr/md/inc/metamodel.h | 2 +- src/coreclr/pal/inc/pal.h | 12 +++++----- src/coreclr/pal/src/arch/arm64/asmconstants.h | 2 +- .../c_runtime/sscanf_s/test4/test4.cpp | 2 +- .../c_runtime/sscanf_s/test5/test5.cpp | 2 +- .../c_runtime/sscanf_s/test6/test6.cpp | 2 +- .../c_runtime/sscanf_s/test7/test7.cpp | 2 +- .../c_runtime/sscanf_s/test8/test8.cpp | 2 +- src/coreclr/vm/comdatetime.cpp | 2 +- src/coreclr/vm/common.h | 2 +- src/coreclr/vm/contractimpl.h | 18 +++++++------- src/coreclr/vm/hash.h | 2 +- src/coreclr/vm/vars.hpp | 2 +- src/native/minipal/utils.h | 24 ------------------- 22 files changed, 39 insertions(+), 63 deletions(-) diff --git a/src/coreclr/gc/handletablecore.cpp b/src/coreclr/gc/handletablecore.cpp index 76046964b4ef3d..2a5b36200b312e 100644 --- a/src/coreclr/gc/handletablecore.cpp +++ b/src/coreclr/gc/handletablecore.cpp @@ -685,7 +685,7 @@ void SegmentRemoveFreeBlocks(TableSegment *pSegment, uint32_t uType, BOOL *pfSca #ifdef HANDLE_OPTIMIZE_FOR_64_HANDLE_BLOCKS // determine whether this block is empty - if (((uint64_t*)pSegment->rgFreeMask)[uBlock] == UI64(0xFFFFFFFFFFFFFFFF)) + if (((uint64_t*)pSegment->rgFreeMask)[uBlock] == 0xFFFFFFFFFFFFFFFFULL) #else // assume this block is empty until we know otherwise BOOL fEmpty = TRUE; @@ -1039,7 +1039,7 @@ void SegmentResortChains(TableSegment *pSegment) { #ifdef HANDLE_OPTIMIZE_FOR_64_HANDLE_BLOCKS // determine whether this block is empty - if (((uint64_t*)pSegment->rgFreeMask)[uBlock] == UI64(0xFFFFFFFFFFFFFFFF)) + if (((uint64_t*)pSegment->rgFreeMask)[uBlock] == 0xFFFFFFFFFFFFFFFFULL) #else // assume this block is empty until we know otherwise BOOL fEmpty = TRUE; diff --git a/src/coreclr/gcinfo/gcinfodumper.cpp b/src/coreclr/gcinfo/gcinfodumper.cpp index c22850c2b0f10c..4f0591528dc820 100644 --- a/src/coreclr/gcinfo/gcinfodumper.cpp +++ b/src/coreclr/gcinfo/gcinfodumper.cpp @@ -17,7 +17,7 @@ #ifdef HOST_64BIT // All stack offsets are INT32's, so this guarantees a disjoint range of // addresses for each register. -#define ADDRESS_SPACING UI64(0x100000000) +#define ADDRESS_SPACING 0x100000000ULL #elif defined(TARGET_ARM) #define ADDRESS_SPACING 0x100000 #else diff --git a/src/coreclr/ilasm/grammar_after.cpp b/src/coreclr/ilasm/grammar_after.cpp index ac43bd8faace16..79637ea1332db5 100644 --- a/src/coreclr/ilasm/grammar_after.cpp +++ b/src/coreclr/ilasm/grammar_after.cpp @@ -1200,8 +1200,8 @@ int yylex() begNum = curPos; { uint64_t i64 = str2uint64(begNum, const_cast(&curPos), radix); - uint64_t mask64 = neg ? UI64(0xFFFFFFFF80000000) : UI64(0xFFFFFFFF00000000); - uint64_t largestNegVal32 = UI64(0x0000000080000000); + uint64_t mask64 = neg ? 0xFFFFFFFF80000000ULL : 0xFFFFFFFF00000000ULL; + uint64_t largestNegVal32 = 0x0000000080000000ULL; if ((i64 & mask64) && (i64 != largestNegVal32)) { yylval.int64 = new int64_t(i64); diff --git a/src/coreclr/ilasm/writer.cpp b/src/coreclr/ilasm/writer.cpp index e718839a8664e9..cab91df8cb4c32 100644 --- a/src/coreclr/ilasm/writer.cpp +++ b/src/coreclr/ilasm/writer.cpp @@ -1238,7 +1238,7 @@ HRESULT Assembler::CreatePEFile(_In_ __nullterminated WCHAR *pwzOutputFilename) if(m_dwCeeFileFlags & ICEE_CREATE_FILE_PE64) { ULONGLONG *pdw = new ULONGLONG[N]; - for(i=0; i Date: Sun, 7 Sep 2025 14:30:02 +0800 Subject: [PATCH 21/28] More unused mstypes --- src/coreclr/pal/inc/pal_mstypes.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/coreclr/pal/inc/pal_mstypes.h b/src/coreclr/pal/inc/pal_mstypes.h index ace5142f005b5d..631c416ce45924 100644 --- a/src/coreclr/pal/inc/pal_mstypes.h +++ b/src/coreclr/pal/inc/pal_mstypes.h @@ -132,11 +132,9 @@ typedef unsigned short USHORT; typedef USHORT *PUSHORT; typedef unsigned char UCHAR; typedef UCHAR *PUCHAR; -typedef char *PSZ; typedef ULONGLONG DWORDLONG; typedef unsigned int DWORD; // NOTE: diff from windows.h, for LP64 compat -typedef unsigned int DWORD32, *PDWORD32; typedef int BOOL; typedef unsigned char BYTE; @@ -218,10 +216,6 @@ typedef LONG_PTR LPARAM; typedef char16_t WCHAR; typedef DWORD LCID; -typedef PDWORD PLCID; -typedef WORD LANGID; - -typedef DWORD LCTYPE; typedef WCHAR *PWCHAR; typedef WCHAR *LPWCH, *PWCH; @@ -258,7 +252,6 @@ typedef CONST TCHAR *LPCTSTR; #define HIBYTE(w) ((BYTE)((DWORD_PTR)(w) >> 8)) typedef VOID *HANDLE; -typedef struct __PAL_RemoteHandle__ { HANDLE h; } *RHANDLE; typedef HANDLE *PHANDLE; typedef HANDLE *LPHANDLE; #define INVALID_HANDLE_VALUE ((VOID *)(-1)) From bdace49b105f515ba8221c52f7b4c9b96e76858e Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 22 Sep 2025 13:26:21 +0800 Subject: [PATCH 22/28] Title-case OffsetOf is unused --- src/coreclr/pal/src/include/pal/palinternal.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 45c2345450bcbc..8c610758a998d5 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -219,8 +219,6 @@ function_name() to call the system's implementation #define INFTIM -1 #endif // !HAVE_INFTIM -#include - #undef assert #define assert (Use__ASSERTE_instead_of_assert) assert From 92e2f6e48fc30be7ac70e2a3c648d828a50696bf Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 23 Sep 2025 15:57:52 +0800 Subject: [PATCH 23/28] Cleanup raw __UNREACHABLE --- src/coreclr/gc/env/gcenv.base.h | 4 ++++ src/coreclr/gc/gc.cpp | 6 +++--- src/coreclr/utilcode/opinfo.cpp | 7 ++----- src/coreclr/vm/nativelibrary.cpp | 2 +- src/coreclr/vm/threadsuspend.cpp | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index de2436b44f4bc7..4737f6dde5dce0 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -23,6 +23,10 @@ #define __stdcall #endif // _MSC_VER +#ifndef UNREACHABLE +#define UNREACHABLE __UNREACHABLE +#endif + #ifndef SIZE_T_MAX #define SIZE_T_MAX ((size_t)-1) #endif diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index d5a017b7fac992..c9a050dabf8335 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -5306,7 +5306,7 @@ struct initial_memory_details case 0: return block_size_normal; case 1: return block_size_large; case 2: return block_size_pinned; - default: __UNREACHABLE(); + default: UNREACHABLE(); } }; @@ -5319,7 +5319,7 @@ struct initial_memory_details case soh_gen2: return initial_normal_heap[h_number].memory_base; case loh_generation: return initial_large_heap[h_number].memory_base; case poh_generation: return initial_pinned_heap[h_number].memory_base; - default: __UNREACHABLE(); + default: UNREACHABLE(); } }; @@ -5332,7 +5332,7 @@ struct initial_memory_details case soh_gen2: return block_size_normal; case loh_generation: return block_size_large; case poh_generation: return block_size_pinned; - default: __UNREACHABLE(); + default: UNREACHABLE(); } }; diff --git a/src/coreclr/utilcode/opinfo.cpp b/src/coreclr/utilcode/opinfo.cpp index ac040c2d22427d..55d4aea1e80da6 100644 --- a/src/coreclr/utilcode/opinfo.cpp +++ b/src/coreclr/utilcode/opinfo.cpp @@ -9,6 +9,7 @@ #include // for debugMacros.h #include "debugmacros.h" // for ASSERTE #include "opinfo.h" +#include "check.h" OpInfo::OpInfoData OpInfo::table[] = { @@ -109,11 +110,7 @@ const BYTE* OpInfo::fetch(const BYTE* instrPtr, OpArgsVal* args) { args->phi.vars = (unsigned short*) instrPtr; instrPtr += (2 * args->phi.count); break; default: -#ifdef _DEBUG - _ASSERTE(!"BadType"); -#else - __UNREACHABLE(); // we are really certain the default case does not happen -#endif + UNREACHABLE(); // we are really certain the default case does not happen break; } return(instrPtr); diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index 534e25db221cc1..dec0e92964cd8f 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -123,7 +123,7 @@ namespace } #endif // TARGET_UNIX - __UNREACHABLE(); + UNREACHABLE(); } private: diff --git a/src/coreclr/vm/threadsuspend.cpp b/src/coreclr/vm/threadsuspend.cpp index 538d1f4b57783b..d296e58aa1f346 100644 --- a/src/coreclr/vm/threadsuspend.cpp +++ b/src/coreclr/vm/threadsuspend.cpp @@ -2728,7 +2728,7 @@ void __stdcall Thread::RedirectedHandledJITCase(RedirectReason reason) RestoreContextSimulated(pThread, pCtx, &frame, dwLastError); // we never return to the caller. - __UNREACHABLE(); + UNREACHABLE(); } #endif // TARGET_X86 @@ -2774,7 +2774,7 @@ void __stdcall Thread::RedirectedHandledJITCase(RedirectReason reason) #endif // we never return to the caller. - __UNREACHABLE(); + UNREACHABLE(); } //**************************************************************************************** From 63b9410690e48f1c5de5761312aeb96e3d145792 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 24 Sep 2025 16:07:35 +0800 Subject: [PATCH 24/28] Unify unreachable with assert --- src/coreclr/gc/env/gcenv.base.h | 4 ---- src/coreclr/inc/check.h | 20 -------------------- src/coreclr/nativeaot/Runtime/rhassert.h | 8 ++------ src/native/minipal/utils.h | 15 +++++++++++++-- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index 4737f6dde5dce0..de2436b44f4bc7 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -23,10 +23,6 @@ #define __stdcall #endif // _MSC_VER -#ifndef UNREACHABLE -#define UNREACHABLE __UNREACHABLE -#endif - #ifndef SIZE_T_MAX #define SIZE_T_MAX ((size_t)-1) #endif diff --git a/src/coreclr/inc/check.h b/src/coreclr/inc/check.h index 9597756c1ed346..b020f5f3b6f067 100644 --- a/src/coreclr/inc/check.h +++ b/src/coreclr/inc/check.h @@ -542,9 +542,6 @@ CHECK CheckValue(TYPENAME &val) // to make sure it is always true. //-------------------------------------------------------------------------------- -#define UNREACHABLE() \ - UNREACHABLE_MSG("") - #define UNREACHABLE_RET() \ do { \ UNREACHABLE(); \ @@ -557,23 +554,6 @@ CHECK CheckValue(TYPENAME &val) return 0; \ } while (0) -#ifdef _DEBUG_IMPL - -// Note that the "do { } while (0)" syntax trick here doesn't work, as the compiler -// gives an error that the while(0) is unreachable code -#define UNREACHABLE_MSG(_message) \ -{ \ - CHECK _check; \ - _check.Setup(_message, "", __FILE__, __LINE__); \ - _check.Trigger("Reached the \"unreachable\""); \ -} __UNREACHABLE() - -#else - -#define UNREACHABLE_MSG(_message) __UNREACHABLE() - -#endif - //-------------------------------------------------------------------------------- // STRESS_CHECK represents a check which is included in a free build // @todo: behavior on trigger diff --git a/src/coreclr/nativeaot/Runtime/rhassert.h b/src/coreclr/nativeaot/Runtime/rhassert.h index 1c5e5b89276399..3b1890e667aa14 100644 --- a/src/coreclr/nativeaot/Runtime/rhassert.h +++ b/src/coreclr/nativeaot/Runtime/rhassert.h @@ -44,15 +44,11 @@ void Assert(const char * expr, const char * file, unsigned int line_num, const c #define PORTABILITY_ASSERT(message) \ ASSERT_UNCONDITIONALLY(message); \ - __UNREACHABLE(); \ - -#define UNREACHABLE() \ - ASSERT_UNCONDITIONALLY("UNREACHABLE"); \ - __UNREACHABLE(); \ + UNREACHABLE(); \ #define UNREACHABLE_MSG(message) \ ASSERT_UNCONDITIONALLY(message); \ - __UNREACHABLE(); \ + UNREACHABLE(); \ #ifdef HOST_WINDOWS #define RhFailFast() ::RaiseFailFastException(NULL, NULL, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS) diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index a6fe9bdfc078c3..7c2e377b6887a8 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -4,6 +4,8 @@ #ifndef HAVE_MINIPAL_UTILS_H #define HAVE_MINIPAL_UTILS_H +#include + #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) // Number of characters in a string literal. Excludes terminating NULL. @@ -39,10 +41,19 @@ #endif #ifdef _MSC_VER -#define __UNREACHABLE() __assume(0) +#define UNREACHABLE_MSG(message) \ + do { \ + assert((void)message, 0); \ + __assume(0); \ + } while (0) #else -#define __UNREACHABLE() __builtin_unreachable() +#define UNREACHABLE_MSG(message) \ + do { \ + assert((void)message, 0); \ + __builtin_unreachable(); \ + } while (0) #endif +#define UNREACHABLE() UNREACHABLE_MSG("Unreachable reached") #if defined(_MSC_VER) #define NOINLINE __declspec(noinline) From abc33626dbfc573823c7df0105f7c3daaa7c0e89 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 25 Sep 2025 23:59:38 +0800 Subject: [PATCH 25/28] Apply suggestion from code review Co-authored-by: Jan Kotas --- src/native/minipal/utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index 7c2e377b6887a8..804e71fe63370f 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -43,13 +43,13 @@ #ifdef _MSC_VER #define UNREACHABLE_MSG(message) \ do { \ - assert((void)message, 0); \ + assert(!#message); \ __assume(0); \ } while (0) #else #define UNREACHABLE_MSG(message) \ do { \ - assert((void)message, 0); \ + assert(!#message); \ __builtin_unreachable(); \ } while (0) #endif From 32785f25133d5c02f7869c9128395d5514c76872 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 26 Sep 2025 10:23:17 +0800 Subject: [PATCH 26/28] Remove duplicated definition --- src/coreclr/nativeaot/Runtime/rhassert.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/rhassert.h b/src/coreclr/nativeaot/Runtime/rhassert.h index 3b1890e667aa14..c603790d90c617 100644 --- a/src/coreclr/nativeaot/Runtime/rhassert.h +++ b/src/coreclr/nativeaot/Runtime/rhassert.h @@ -46,10 +46,6 @@ void Assert(const char * expr, const char * file, unsigned int line_num, const c ASSERT_UNCONDITIONALLY(message); \ UNREACHABLE(); \ -#define UNREACHABLE_MSG(message) \ - ASSERT_UNCONDITIONALLY(message); \ - UNREACHABLE(); \ - #ifdef HOST_WINDOWS #define RhFailFast() ::RaiseFailFastException(NULL, NULL, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS) #else From 478483319702d085427d424f3e150d384661c77f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 26 Sep 2025 10:43:57 +0800 Subject: [PATCH 27/28] Update assert redefining --- src/coreclr/nativeaot/Runtime/rhassert.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreclr/nativeaot/Runtime/rhassert.h b/src/coreclr/nativeaot/Runtime/rhassert.h index c603790d90c617..268f36551acde4 100644 --- a/src/coreclr/nativeaot/Runtime/rhassert.h +++ b/src/coreclr/nativeaot/Runtime/rhassert.h @@ -3,6 +3,8 @@ #ifndef __RHASSERT_H__ #define __RHASSERT_H__ +#include + #if defined(_DEBUG) && !defined(DACCESS_COMPILE) #define ASSERT(expr) \ @@ -46,6 +48,11 @@ void Assert(const char * expr, const char * file, unsigned int line_num, const c ASSERT_UNCONDITIONALLY(message); \ UNREACHABLE(); \ +#ifdef assert +#undef assert +#define assert(_expr) ASSERT(_expr) +#endif + #ifdef HOST_WINDOWS #define RhFailFast() ::RaiseFailFastException(NULL, NULL, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS) #else From 27109eafb935ff8ebd57c1ddac7b0537084fcb32 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 30 Sep 2025 20:15:16 +0800 Subject: [PATCH 28/28] Handle assert conflict --- src/mono/mono/utils/dlmalloc.c | 1 + src/native/minipal/utils.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/mono/mono/utils/dlmalloc.c b/src/mono/mono/utils/dlmalloc.c index 53fbd2adf2bf85..972c7a61af4ed7 100644 --- a/src/mono/mono/utils/dlmalloc.c +++ b/src/mono/mono/utils/dlmalloc.c @@ -1169,6 +1169,7 @@ int mspace_mallopt(int, int); #ifndef LACKS_STDLIB_H #include /* for abort() */ #endif /* LACKS_STDLIB_H */ +#undef assert #ifdef DEBUG #if ABORT_ON_ASSERT_FAILURE #define assert(x) if(!(x)) ABORT diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index 804e71fe63370f..97758ffcf0f8a8 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -4,7 +4,9 @@ #ifndef HAVE_MINIPAL_UTILS_H #define HAVE_MINIPAL_UTILS_H +#ifndef assert #include +#endif #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))