From 7e482f39762e0e5e4ccceab2205f7e4f515ad8bf Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Thu, 16 Jul 2026 14:40:33 -0700 Subject: [PATCH 1/2] Clean up redundant defines and warning suppressions in coreclr/vm/common.h Remove stale USE_COM_CONTEXT_DEF and _CRT_DEPENDENCY_ defines (no longer referenced) from vm/common.h and the debug/md/unwinder stdafx.h files, and drop the blanket MSVC #pragma warning(disable:...) block from vm/common.h since those suppressions are already applied globally in eng/native/configurecompiler.cmake. Fix the two call sites that relied on the removed C4238 (rvalue used as lvalue) suppression by introducing named locals: - AllocateObject in gchelpers.cpp - OleVariant::ExtractWrappedObjectsFromArray in olevariant.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 19deab6e-8bcd-404b-957a-092862dc4014 --- src/coreclr/debug/daccess/stdafx.h | 2 -- src/coreclr/debug/ee/stdafx.h | 2 -- src/coreclr/md/ceefilegen/stdafx.h | 1 - src/coreclr/unwinder/stdafx.h | 2 -- src/coreclr/vm/common.h | 35 ------------------------------ src/coreclr/vm/gchelpers.cpp | 3 ++- src/coreclr/vm/olevariant.cpp | 7 +++++- 7 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/coreclr/debug/daccess/stdafx.h b/src/coreclr/debug/daccess/stdafx.h index bff6a4f660379b..e439a01b9fe7e6 100644 --- a/src/coreclr/debug/daccess/stdafx.h +++ b/src/coreclr/debug/daccess/stdafx.h @@ -18,8 +18,6 @@ // and there's no reason why DAC should be forbidden from using it. #define DO_NOT_DISABLE_RAND -#define USE_COM_CONTEXT_DEF - #include #include #include diff --git a/src/coreclr/debug/ee/stdafx.h b/src/coreclr/debug/ee/stdafx.h index 4a07384047d0a7..5fecaecb9bc86d 100644 --- a/src/coreclr/debug/ee/stdafx.h +++ b/src/coreclr/debug/ee/stdafx.h @@ -7,8 +7,6 @@ // //***************************************************************************** -#define USE_COM_CONTEXT_DEF - #include #include #include diff --git a/src/coreclr/md/ceefilegen/stdafx.h b/src/coreclr/md/ceefilegen/stdafx.h index 4026a47f14107d..db15968905ac15 100644 --- a/src/coreclr/md/ceefilegen/stdafx.h +++ b/src/coreclr/md/ceefilegen/stdafx.h @@ -8,7 +8,6 @@ // Common include file for utility code. //***************************************************************************** -#define _CRT_DEPENDENCY_ //this code depends on the crt file functions #include #include #include diff --git a/src/coreclr/unwinder/stdafx.h b/src/coreclr/unwinder/stdafx.h index 8decdc68562bd4..4b9c1de9e5a6d8 100644 --- a/src/coreclr/unwinder/stdafx.h +++ b/src/coreclr/unwinder/stdafx.h @@ -8,8 +8,6 @@ // and there's no reason why DAC should be forbidden from using it. #define DO_NOT_DISABLE_RAND -#define USE_COM_CONTEXT_DEF - #include #include diff --git a/src/coreclr/vm/common.h b/src/coreclr/vm/common.h index 756ef7e0817fbb..54c17e3594bb3a 100644 --- a/src/coreclr/vm/common.h +++ b/src/coreclr/vm/common.h @@ -14,45 +14,10 @@ #define COMMON_TURNED_FPO_ON 1 #endif -#define USE_COM_CONTEXT_DEF - #if defined(_DEBUG) #define DEBUG_REGDISPLAY #endif -#ifdef _MSC_VER - - // These don't seem useful, so turning them off is no big deal -#pragma warning(disable:4201) // nameless struct/union -#pragma warning(disable:4512) // can't generate assignment constructor -#pragma warning(disable:4211) // nonstandard extension used (char name[0] in structs) -#pragma warning(disable:4268) // 'const' static/global data initialized with compiler generated default constructor fills the object with zeros -#pragma warning(disable:4238) // nonstandard extension used : class rvalue used as lvalue -#pragma warning(disable:4291) // no matching operator delete found -#pragma warning(disable:4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized - - // Depending on the code base, you may want to not disable these -#pragma warning(disable:4245) // assigning signed / unsigned -#pragma warning(disable:4127) // conditional expression is constant -#pragma warning(disable:4100) // unreferenced formal parameter - -#pragma warning(1:4189) // local variable initialized but not used - -#ifndef DEBUG -#pragma warning(disable:4505) // unreferenced local function has been removed -#pragma warning(disable:4313) // 'format specifier' in format string conflicts with argument %d of type 'type' -#endif // !DEBUG - - // CONSIDER put these back in -#pragma warning(disable:4063) // bad switch value for enum (only in Disasm.cpp) -#pragma warning(disable:4710) // function not inlined -#pragma warning(disable:4527) // user-defined destructor required -#pragma warning(disable:4513) // destructor could not be generated -#endif // _MSC_VER - -#define _CRT_DEPENDENCY_ //this code depends on the crt file functions - - #include #include #include diff --git a/src/coreclr/vm/gchelpers.cpp b/src/coreclr/vm/gchelpers.cpp index 7f9ab029d4c6f8..c961814b4966ac 100644 --- a/src/coreclr/vm/gchelpers.cpp +++ b/src/coreclr/vm/gchelpers.cpp @@ -1252,7 +1252,8 @@ OBJECTREF AllocateObject(MethodTable *pMT if (pMT == g_pBaseCOMObject) COMPlusThrow(kInvalidComObjectException, IDS_EE_NO_BACKING_CLASS_FACTORY); - oref = OBJECTREF_TO_UNCHECKED_OBJECTREF(AllocateComObject_ForManaged(pMT)); + OBJECTREF obj = AllocateComObject_ForManaged(pMT); + oref = OBJECTREF_TO_UNCHECKED_OBJECTREF(obj); } #endif // FEATURE_COMINTEROP_UNMANAGED_ACTIVATION #else // FEATURE_COMINTEROP diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index 90e847f3135c7b..2d8f48a26e4f7e 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -2513,9 +2513,14 @@ BASEARRAYREF OleVariant::ExtractWrappedObjectsFromArray(BASEARRAYREF *pArray) for (; pSrc < pSrcEnd; pSrc++, pDest++) { if (*pSrc != NULL) - memcpyNoGCRefs(pDest, &(*pSrc)->GetWrappedObject(), sizeof(DECIMAL)); + { + DECIMAL srcObj = (*pSrc)->GetWrappedObject(); + memcpyNoGCRefs(pDest, &srcObj, sizeof(DECIMAL)); + } else + { memset(pDest, 0, sizeof(DECIMAL)); + } } } else if (hndWrapperType == TypeHandle(CoreLibBinder::GetClass(CLASS__BSTR_WRAPPER))) From 17338c6fa459e4bcc3df71b913cbee5e85e978d5 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Thu, 16 Jul 2026 20:06:50 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Jan Kotas --- src/coreclr/vm/olevariant.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index 2d8f48a26e4f7e..c80e05d81bb6a7 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -2514,12 +2514,11 @@ BASEARRAYREF OleVariant::ExtractWrappedObjectsFromArray(BASEARRAYREF *pArray) { if (*pSrc != NULL) { - DECIMAL srcObj = (*pSrc)->GetWrappedObject(); - memcpyNoGCRefs(pDest, &srcObj, sizeof(DECIMAL)); + *pDest = (*pSrc)->GetWrappedObject(); } else { - memset(pDest, 0, sizeof(DECIMAL)); + *pDest = DECIMAL{}; } } }