Skip to content

Commit e93e023

Browse files
[release/10.0] Apply changes for building with clang-21 (#121124)
## Customer Impact - [x] Customer reported - [ ] Found internally These issues were reported in #119706 as problems with clang-21 on Fedora 43. The investigation uncovered that clang introduced a potentially breaking change in clang-20 that we do not currently consume. These build changes impact VMR related builds when linux distrobutions performing source build adopt clang-21. clang-20 breaking change log - https://releases.llvm.org/20.1.0/tools/clang/docs/ReleaseNotes.html#potentially-breaking-changes. This PR contains the minimal changes needed to fix issues from the following PRs #120644 and #120775. ## Regression - [x] Yes - [ ] No Moving to the new clang-21 compiler will cause the runtime to crash. This is a regression from using .NET 10 and the default compiler of clang-19. ## Testing This has been validated using various legs and examples to demonstrate the usage of undefined behavior these flags convert into "defined" behavior in C/C++. ## Risk Low. This makes clang-21 more permissive and is limited to non official product builds. --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent d8c1745 commit e93e023

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

eng/native/configurecompiler.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,14 @@ if (CLR_CMAKE_HOST_UNIX)
540540
# Disable frame pointer optimizations so profilers can get better call stacks
541541
add_compile_options(-fno-omit-frame-pointer)
542542

543-
# Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
543+
# Make signed overflow well-defined. Implies the following flags in clang-20 and above.
544+
# -fwrapv - Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
544545
# using twos-complement representation (this is normally undefined according to the C++ spec).
545-
add_compile_options(-fwrapv)
546+
# -fwrapv-pointer - The same as -fwrapv but for pointers.
547+
add_compile_options(-fno-strict-overflow)
548+
549+
# Suppress C++ strict aliasing rules. This matches our use of MSVC.
550+
add_compile_options(-fno-strict-aliasing)
546551

547552
if(CLR_CMAKE_HOST_APPLE)
548553
# Clang will by default emit objc_msgSend stubs in Xcode 14, which ld from earlier Xcodes doesn't understand.

src/coreclr/debug/di/rspriv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6397,8 +6397,8 @@ class CordbThread : public CordbBase, public ICorDebugThread,
63976397
// Lazily initialized.
63986398
EXCEPTION_RECORD * m_pExceptionRecord;
63996399

6400-
static const CorDebugUserState kInvalidUserState = CorDebugUserState(-1);
6401-
CorDebugUserState m_userState; // This is the current state of the
6400+
static const int kInvalidUserState = -1;
6401+
int m_userState; // This is the current state of the
64026402
// thread, at the time that the
64036403
// left side synchronized
64046404

src/coreclr/debug/di/rsthread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ CorDebugUserState CordbThread::GetUserState()
782782
m_userState = pDAC->GetUserState(m_vmThreadToken);
783783
}
784784

785-
return m_userState;
785+
return (CorDebugUserState)m_userState;
786786
}
787787

788788

@@ -886,7 +886,7 @@ HRESULT CordbThread::CreateStepper(ICorDebugStepper ** ppStepper)
886886
//Returns true if current user state of a thread is USER_WAIT_SLEEP_JOIN
887887
bool CordbThread::IsThreadWaitingOrSleeping()
888888
{
889-
CorDebugUserState userState = m_userState;
889+
int userState = m_userState;
890890
if (userState == kInvalidUserState)
891891
{
892892
//If m_userState is not ready, we'll read from DAC only part of it which

src/mono/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,12 @@ if(GCC)
532532

533533
# The runtime code does not respect ANSI C strict aliasing rules
534534
append("-fno-strict-aliasing" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
535-
# We rely on signed overflow to behave
536-
append("-fwrapv" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
535+
536+
# Make signed overflow well-defined. Implies the following flags in clang-20 and above.
537+
# -fwrapv - Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
538+
# using twos-complement representation (this is normally undefined according to the C++ spec).
539+
# -fwrapv-pointer - The same as -fwrapv but for pointers.
540+
append("-fno-strict-overflow" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
537541

538542
set(WARNINGS "-Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes -Wno-format-zero-length -Wno-unused-function")
539543
set(WARNINGS_C "-Wmissing-prototypes -Wstrict-prototypes -Wnested-externs")

0 commit comments

Comments
 (0)