From: Aaron Robinson Date: Fri, 11 Mar 2022 04:59:21 +0000 (-0500) Subject: Update repo CMake configuration to target /W4 by default (#66474) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~10383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ce2b9f860f7a84c3059650bb67817d59d8f4953;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Update repo CMake configuration to target /W4 by default (#66474) * Update repo CMake configuration to target /W4 by default Disable all failing warnings. * Mono API tests only use W3 --- diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index b3ec614..ca92fe6 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -551,8 +551,10 @@ if (MSVC) # /W3 is added by default by CMake, so remove it string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - # set default warning level to 3 but allow targets to override it. - add_compile_options($<$:/W$>,$,3>>>) + + # [[! Microsoft.Security.SystemsADM.10086 !]] - SDL required warnings + # set default warning level to 4 but allow targets to override it. + add_compile_options($<$:/W$>,$,4>>>) add_compile_options($<$:/WX>) # treat warnings as errors add_compile_options($<$:/Oi>) # enable intrinsics add_compile_options($<$:/Oy->) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls @@ -579,19 +581,37 @@ if (MSVC) add_compile_options($<$:/wd4065>) # switch statement contains 'default' but no 'case' labels add_compile_options($<$:/wd4100>) # 'identifier' : unreferenced formal parameter add_compile_options($<$:/wd4127>) # conditional expression is constant + add_compile_options($<$:/wd4131>) # 'function' : uses old-style declarator add_compile_options($<$:/wd4189>) # local variable is initialized but not referenced add_compile_options($<$:/wd4200>) # nonstandard extension used : zero-sized array in struct/union add_compile_options($<$:/wd4201>) # nonstandard extension used : nameless struct/union + add_compile_options($<$:/wd4206>) # nonstandard extension used : translation unit is empty + add_compile_options($<$:/wd4239>) # nonstandard extension used : 'token' : conversion from 'type' to 'type' + add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data add_compile_options($<$:/wd4245>) # conversion from 'type1' to 'type2', signed/unsigned mismatch add_compile_options($<$:/wd4291>) # no matching operator delete found; memory will not be freed if initialization throws an exception + add_compile_options($<$:/wd4310>) # cast truncates constant value + add_compile_options($<$:/wd4324>) # 'struct_name' : structure was padded due to __declspec(align()) + add_compile_options($<$:/wd4366>) # The result of the unary 'operator' operator may be unaligned add_compile_options($<$:/wd4456>) # declaration of 'identifier' hides previous local declaration add_compile_options($<$:/wd4457>) # declaration of 'identifier' hides function parameter add_compile_options($<$:/wd4458>) # declaration of 'identifier' hides class member + add_compile_options($<$:/wd4459>) # declaration of 'identifier' hides global declaration + add_compile_options($<$:/wd4463>) # overflow; assigning value to bit-field that can only hold values from low_value to high_value + add_compile_options($<$:/wd4505>) # unreferenced function with internal linkage has been removed + add_compile_options($<$:/wd4611>) # interaction between 'function' and C++ object destruction is non-portable + add_compile_options($<$:/wd4701>) # potentially uninitialized local variable 'var' used + add_compile_options($<$:/wd4702>) # unreachable code + add_compile_options($<$:/wd4703>) # potentially uninitialized local pointer variable 'var' used + add_compile_options($<$:/wd4706>) # assignment within conditional expression add_compile_options($<$:/wd4733>) # Inline asm assigning to 'FS:0' : handler not registered as safe handler + add_compile_options($<$:/wd4815>) # 'var': zero-sized array in stack object will have no elements (unless the object is an aggregate that has been aggregate initialized) add_compile_options($<$:/wd4838>) # conversion from 'type_1' to 'type_2' requires a narrowing conversion + add_compile_options($<$:/wd4918>) # 'character' : invalid character in pragma optimization list add_compile_options($<$:/wd4960>) # 'function' is too big to be profiled add_compile_options($<$:/wd4961>) # No profile data was merged into '.pgd file', profile-guided optimizations disabled add_compile_options($<$:/wd5105>) # macro expansion producing 'defined' has undefined behavior + add_compile_options($<$:/wd5205>) # delete of an abstract class 'type-name' that has a non-virtual destructor results in undefined behavior # Treat Warnings as Errors: add_compile_options($<$:/we4007>) # 'main' : must be __cdecl. diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 4b3c07d..8c8ca43 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -5500,10 +5500,6 @@ gc_heap::compute_new_ephemeral_size() padding_size, (total_ephemeral_size - padding_size))); } -#ifdef _MSC_VER -#pragma warning(disable:4706) // "assignment within conditional expression" is intentional in this function. -#endif // _MSC_VER - heap_segment* gc_heap::soh_get_segment_to_expand() { @@ -5622,10 +5618,6 @@ gc_heap::soh_get_segment_to_expand() } #endif //!USE_REGIONS -#ifdef _MSC_VER -#pragma warning(default:4706) -#endif // _MSC_VER - //returns 0 in case of allocation failure heap_segment* gc_heap::get_segment (size_t size, gc_oh_num oh) @@ -12178,7 +12170,7 @@ void region_free_list::print (int hn, const char* msg, int* ages) } dprintf (3, ("[%s] h%2d age %d region %Ix (%Id)%s", - msg, hn, (int)heap_segment_age_in_free (region), + msg, hn, (int)heap_segment_age_in_free (region), heap_segment_mem (region), get_region_committed_size (region), ((heap_segment_committed (region) == heap_segment_reserved (region)) ? "(FC)" : ""))); } @@ -12331,7 +12323,7 @@ void gc_heap::distribute_free_regions() { num_decommit_regions_by_time++; size_decommit_regions_by_time += get_region_committed_size (region); - dprintf (REGIONS_LOG, ("h%2d region %Ix age %2d, decommit", + dprintf (REGIONS_LOG, ("h%2d region %Ix age %2d, decommit", i, heap_segment_mem (region), heap_segment_age_in_free (region))); region_free_list::unlink_region (region); region_free_list::add_region (region, global_regions_to_decommit); @@ -15834,10 +15826,6 @@ BOOL gc_heap::short_on_end_of_seg (heap_segment* seg) return !sufficient_p; } -#ifdef _MSC_VER -#pragma warning(disable:4706) // "assignment within conditional expression" is intentional in this function. -#endif // _MSC_VER - inline BOOL gc_heap::a_fit_free_list_p (int gen_number, size_t size, @@ -16114,10 +16102,6 @@ exit: return can_fit; } -#ifdef _MSC_VER -#pragma warning(default:4706) -#endif // _MSC_VER - BOOL gc_heap::a_fit_segment_end_p (int gen_number, heap_segment* seg, size_t size, @@ -20678,7 +20662,7 @@ void gc_heap::gc1() if (n < max_generation) { - int highest_gen_number = + int highest_gen_number = #ifdef USE_REGIONS max_generation; #else //USE_REGIONS @@ -22598,11 +22582,11 @@ void gc_heap::equalize_promoted_bytes() { dprintf (REGIONS_LOG, ("before equalize: gen: %d avg surv: %Id max_surv: %Id imbalance: %d", gen_idx, avg_surv_per_heap, max_surv_per_heap, max_surv_per_heap*100/avg_surv_per_heap)); } - // + // // step 2: // remove regions from surplus heaps until all heaps are <= average // put removed regions into surplus regions - // + // // step 3: // put regions into size classes by survivorship // put deficit heaps into size classes by deficit @@ -24992,7 +24976,7 @@ size_t gc_heap::committed_size() while (seg) { - uint8_t* start = + uint8_t* start = #ifdef USE_REGIONS get_region_start (seg); #else @@ -29553,7 +29537,7 @@ void gc_heap::plan_phase (int condemned_gen_number) #if defined(USE_REGIONS) && defined(BACKGROUND_GC) if (should_update_end_mark_size()) { - background_soh_size_end_mark += generation_end_seg_allocated (older_gen) - + background_soh_size_end_mark += generation_end_seg_allocated (older_gen) - r_older_gen_end_seg_allocated; } #endif //USE_REGIONS && BACKGROUND_GC @@ -30352,7 +30336,7 @@ void gc_heap::thread_final_regions (bool compact_p) while (max_gen_tail_region) { - background_soh_size_end_mark += heap_segment_allocated (max_gen_tail_region) - + background_soh_size_end_mark += heap_segment_allocated (max_gen_tail_region) - heap_segment_mem (max_gen_tail_region); max_gen_tail_region = heap_segment_next (max_gen_tail_region); @@ -30789,7 +30773,7 @@ void gc_heap::sweep_region_in_plan (heap_segment* region, int plan_gen_num = heap_segment_plan_gen_num (region); generation_allocation_size (generation_of (plan_gen_num)) += heap_segment_survived (region); - dprintf (REGIONS_LOG, ("sip: g%d alloc size is now %Id", plan_gen_num, + dprintf (REGIONS_LOG, ("sip: g%d alloc size is now %Id", plan_gen_num, generation_allocation_size (generation_of (plan_gen_num)))); } @@ -46043,7 +46027,7 @@ size_t GCHeap::ApproxTotalBytesInUse(BOOL small_heap_only) heap_segment* gen0_seg = generation_start_segment (gen); while (gen0_seg) { - uint8_t* end = in_range_for_segment (current_alloc_allocated, gen0_seg) ? + uint8_t* end = in_range_for_segment (current_alloc_allocated, gen0_seg) ? current_alloc_allocated : heap_segment_allocated (gen0_seg); gen0_size += end - heap_segment_mem (gen0_seg); @@ -46066,7 +46050,7 @@ size_t GCHeap::ApproxTotalBytesInUse(BOOL small_heap_only) if (gc_heap::current_c_gc_state == c_gc_state_planning) { // During BGC sweep since we can be deleting SOH segments, we avoid walking the segment - // list. + // list. generation* oldest_gen = pGenGCHeap->generation_of (max_generation); totsize = pGenGCHeap->background_soh_size_end_mark - generation_free_list_space (oldest_gen) - generation_free_obj_space (oldest_gen); stop_gen_index--; diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index 362a8b1..9a088b2 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -519,7 +519,6 @@ function(add_jit jitName) set_property(TARGET ${jitName} APPEND_STRING PROPERTY LINK_FLAGS ${JIT_EXPORTS_LINKER_OPTION}) set_property(TARGET ${jitName} APPEND_STRING PROPERTY LINK_DEPENDS ${JIT_EXPORTS_FILE}) - set_target_properties(${jitName} PROPERTIES MSVC_WARNING_LEVEL 4) target_link_libraries(${jitName} ${JIT_LINK_LIBRARIES} diff --git a/src/coreclr/vm/object.cpp b/src/coreclr/vm/object.cpp index dabc517..8071392 100644 --- a/src/coreclr/vm/object.cpp +++ b/src/coreclr/vm/object.cpp @@ -579,7 +579,7 @@ VOID Object::ValidateInner(BOOL bDeep, BOOL bVerifyNextHeader, BOOL bVerifySyncB #ifdef FEATURE_64BIT_ALIGNMENT if (pMT->RequiresAlign8()) { - CHECK_AND_TEAR_DOWN((((size_t)this) & 0x7) == (pMT->IsValueType()? 4:0)); + CHECK_AND_TEAR_DOWN((((size_t)this) & 0x7) == (size_t)(pMT->IsValueType()?4:0)); } lastTest = 9; #endif // FEATURE_64BIT_ALIGNMENT diff --git a/src/tests/Interop/COM/NativeClients/Dispatch/Client.cpp b/src/tests/Interop/COM/NativeClients/Dispatch/Client.cpp index a8c3ac3..10d48f7 100644 --- a/src/tests/Interop/COM/NativeClients/Dispatch/Client.cpp +++ b/src/tests/Interop/COM/NativeClients/Dispatch/Client.cpp @@ -364,7 +364,7 @@ void Validate_LCID_Marshaled() nullptr )); - THROW_FAIL_IF_FALSE(lcid == V_I4(&result)); + THROW_FAIL_IF_FALSE(lcid == (LCID)V_UI4(&result)); } namespace diff --git a/src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/CMakeLists.txt b/src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/CMakeLists.txt index 10e966b..eb1fb23 100644 --- a/src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/CMakeLists.txt +++ b/src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(${CLR_SRC_NATIVE_DIR}/public public_api) # add the library add_library (mono-embedding-api-test SHARED mono-embedding-api-test.c api-types.h api-functions.h) +set_target_properties(mono-embedding-api-test PROPERTIES MSVC_WARNING_LEVEL 3) target_link_libraries(mono-embedding-api-test monoapi ${LINK_LIBRARIES_ADDITIONAL}) if(CLR_CMAKE_HOST_OSX)