Skip to content

Commit d4ff345

Browse files
[release/9.0-staging] Add flags when the clang's major version is > 20.0 (#121151)
## 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 PR #120775. .NET 10: #121124 .NET 8: #121150 ## Regression - [ ] Yes - [x] No Build with the new clang-21 compiler will cause the runtime to crash. ## 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 has zero impact on our production build since we specifically target clang-18. This is only valid for those partners that are using clang-20+.
1 parent e9313ed commit d4ff345

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

eng/native/configurecompiler.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,21 @@ if (CLR_CMAKE_HOST_UNIX)
526526
# Disable frame pointer optimizations so profilers can get better call stacks
527527
add_compile_options(-fno-omit-frame-pointer)
528528

529-
# Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
530-
# using twos-complement representation (this is normally undefined according to the C++ spec).
531-
add_compile_options(-fwrapv)
529+
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 20.0) OR
530+
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20.0))
531+
# Make signed overflow well-defined. Implies the following flags in clang-20 and above.
532+
# -fwrapv - Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
533+
# using twos-complement representation (this is normally undefined according to the C++ spec).
534+
# -fwrapv-pointer - The same as -fwrapv but for pointers.
535+
add_compile_options(-fno-strict-overflow)
536+
537+
# Suppress C++ strict aliasing rules. This matches our use of MSVC.
538+
add_compile_options(-fno-strict-aliasing)
539+
else()
540+
# Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
541+
# using twos-complement representation (this is normally undefined according to the C++ spec).
542+
add_compile_options(-fwrapv)
543+
endif()
532544

533545
if(CLR_CMAKE_HOST_APPLE)
534546
# 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
@@ -6404,8 +6404,8 @@ class CordbThread : public CordbBase, public ICorDebugThread,
64046404
// Lazily initialized.
64056405
EXCEPTION_RECORD * m_pExceptionRecord;
64066406

6407-
static const CorDebugUserState kInvalidUserState = CorDebugUserState(-1);
6408-
CorDebugUserState m_userState; // This is the current state of the
6407+
static const int kInvalidUserState = -1;
6408+
int m_userState; // This is the current state of the
64096409
// thread, at the time that the
64106410
// left side synchronized
64116411

src/coreclr/debug/di/rsthread.cpp

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

786-
return m_userState;
786+
return (CorDebugUserState)m_userState;
787787
}
788788

789789

@@ -887,7 +887,7 @@ HRESULT CordbThread::CreateStepper(ICorDebugStepper ** ppStepper)
887887
//Returns true if current user state of a thread is USER_WAIT_SLEEP_JOIN
888888
bool CordbThread::IsThreadWaitingOrSleeping()
889889
{
890-
CorDebugUserState userState = m_userState;
890+
int userState = m_userState;
891891
if (userState == kInvalidUserState)
892892
{
893893
//If m_userState is not ready, we'll read from DAC only part of it which
@@ -3721,14 +3721,14 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
37213721
LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: hijackCtx started as:\n"));
37223722
LogContext(GetHijackCtx());
37233723

3724-
// Save the thread's full context for all platforms except for x86 because we need the
3724+
// Save the thread's full context for all platforms except for x86 because we need the
37253725
// DT_CONTEXT_EXTENDED_REGISTERS to avoid getting incomplete information and corrupt the thread context
37263726
DT_CONTEXT context;
3727-
#ifdef TARGET_X86
3727+
#ifdef TARGET_X86
37283728
context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
37293729
#else
37303730
context.ContextFlags = DT_CONTEXT_FULL;
3731-
#endif
3731+
#endif
37323732

37333733
BOOL succ = DbiGetThreadContext(m_handle, &context);
37343734
_ASSERTE(succ);
@@ -3739,7 +3739,7 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
37393739
LOG((LF_CORDB, LL_ERROR, "CUT::SFCHFS: DbiGetThreadContext error=0x%x\n", error));
37403740
}
37413741

3742-
#ifdef TARGET_X86
3742+
#ifdef TARGET_X86
37433743
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
37443744
#else
37453745
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL;

0 commit comments

Comments
 (0)