From e190f357f212f88d5e5b10c9057dae69ceac02bb Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:17:22 -0700 Subject: [PATCH 01/21] Remove disable of 4244 --- eng/native/configurecompiler.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 60d2b2b80296f3..082008f0e490fc 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -592,7 +592,6 @@ if (MSVC) 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 From 6c1f4de30d8ea359a898f53601484f128793f61b Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:17:49 -0700 Subject: [PATCH 02/21] GC --- src/coreclr/gc/gc.cpp | 20 +++++------ src/coreclr/gc/gcee.cpp | 14 ++++---- .../bitonic_sort.AVX2.int32_t.generated.h | 2 +- .../bitonic_sort.AVX2.int64_t.generated.h | 2 +- .../bitonic_sort.AVX512.int32_t.generated.h | 34 +++++++++---------- .../bitonic_sort.AVX512.int64_t.generated.h | 34 +++++++++---------- .../gc/vxsort/smallsort/codegen/avx2.py | 14 +++++--- .../gc/vxsort/smallsort/codegen/avx512.py | 21 +++++++++--- src/coreclr/gc/windows/gcenv.windows.cpp | 4 +-- 9 files changed, 81 insertions(+), 64 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 964cd85395ac68..fdac7d2dd080fd 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -3024,7 +3024,7 @@ void gc_heap::fire_pevents() // Not every heap will compact LOH, the ones that didn't will just have 0s // in its info. FIRE_EVENT(GCLOHCompact, - get_num_heaps(), + (uint16_t)get_num_heaps(), (uint32_t)(sizeof (etw_loh_compact_info)), (void *)loh_compact_info); } @@ -5039,7 +5039,7 @@ BOOL gc_heap::reserve_initial_memory (size_t normal_size, size_t large_size, siz int numa_node = block_index % numa_node_count; bool pinned_block = block_index >= numa_node_count; - block->memory_base = (uint8_t*)virtual_alloc (block->block_size, use_large_pages_p && !pinned_block, numa_node); + block->memory_base = (uint8_t*)virtual_alloc (block->block_size, use_large_pages_p && !pinned_block, (uint16_t)numa_node); if (block->memory_base == nullptr) { dprintf(2, ("failed to reserve %Id bytes for on NUMA node %u", block->block_size, numa_node)); @@ -5998,7 +5998,7 @@ class heap_select uint16_t proc_no[MAX_SUPPORTED_CPUS]; uint16_t node_no[MAX_SUPPORTED_CPUS]; uint16_t max_node_no = 0; - for (int i = 0; i < n_heaps; i++) + for (uint16_t i = 0; i < n_heaps; i++) { if (!GCToOSInterface::GetProcessorForHeap (i, &proc_no[i], &node_no[i])) break; @@ -6188,7 +6188,7 @@ class heap_select for (int i = gc_heap::n_heaps; i < (int)g_num_active_processors; i++) { - if (!GCToOSInterface::GetProcessorForHeap (i, &proc_no, &node_no)) + if (!GCToOSInterface::GetProcessorForHeap ((uint16_t)i, &proc_no, &node_no)) break; int start_heap = (int)numa_node_to_heap_map[node_no]; @@ -6211,8 +6211,8 @@ class heap_select current_heap_on_node = start_heap; } - proc_no_to_heap_no[proc_no] = current_heap_on_node; - proc_no_to_numa_node[proc_no] = node_no; + proc_no_to_heap_no[proc_no] = (uint16_t)current_heap_on_node; + proc_no_to_numa_node[proc_no] = (uint16_t)node_no; current_heap_on_node++; } @@ -6263,7 +6263,7 @@ class heap_select } } while (!found_node_with_heaps_p); - return start_index; + return (uint16_t)start_index; } }; uint8_t* heap_select::sniff_buffer; @@ -16178,7 +16178,7 @@ BOOL gc_heap::a_fit_segment_end_p (int gen_number, { #ifdef USE_REGIONS *commit_failed_p = TRUE; -#else +#else if (!hard_limit_short_seg_end_p) { dprintf (2, ("can't grow segment, doing a full gc")); @@ -32231,7 +32231,7 @@ heap_segment* gc_heap::walk_relocation_sip (heap_segment* current_heap_segment, } else { - if (!plug_start) + if (!plug_start) { plug_start = obj; } @@ -45769,7 +45769,7 @@ void gc_heap::do_post_gc() last_gc_info->memory_load = settings.exit_memory_load; else if (settings.entry_memory_load != 0) last_gc_info->memory_load = settings.entry_memory_load; - last_gc_info->condemned_generation = settings.condemned_generation; + last_gc_info->condemned_generation = (uint8_t)settings.condemned_generation; last_gc_info->compaction = settings.compaction; last_gc_info->concurrent = settings.concurrent; diff --git a/src/coreclr/gc/gcee.cpp b/src/coreclr/gc/gcee.cpp index afc5d3a8dd245e..0a0bbb3b6b55e2 100644 --- a/src/coreclr/gc/gcee.cpp +++ b/src/coreclr/gc/gcee.cpp @@ -64,7 +64,7 @@ void GCHeap::ReportGenerationBounds() { uint64_t range = static_cast(rangeEnd - rangeStart); uint64_t rangeReserved = static_cast(rangeEndReserved - rangeStart); - FIRE_EVENT(GCGenerationRange, generation, rangeStart, range, rangeReserved); + FIRE_EVENT(GCGenerationRange, (uint8_t)generation, rangeStart, range, rangeReserved); }, nullptr); } } @@ -325,19 +325,19 @@ bool GCHeap::IsConcurrentGCInProgress() } #ifdef FEATURE_EVENT_TRACE -void gc_heap::fire_etw_allocation_event (size_t allocation_amount, - int gen_number, +void gc_heap::fire_etw_allocation_event (size_t allocation_amount, + int gen_number, uint8_t* object_address, size_t object_size) { #ifdef FEATURE_REDHAWK FIRE_EVENT(GCAllocationTick_V1, (uint32_t)allocation_amount, (uint32_t)gen_to_oh (gen_number)); #else - FIRE_EVENT(GCAllocationTick_V4, - allocation_amount, + FIRE_EVENT(GCAllocationTick_V4, + allocation_amount, (uint32_t)gen_to_oh (gen_number), - heap_number, - object_address, + heap_number, + object_address, object_size); #endif //FEATURE_REDHAWK } diff --git a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int32_t.generated.h b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int32_t.generated.h index 8557cf4620336d..47e45c2dcfb3ee 100644 --- a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int32_t.generated.h +++ b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int32_t.generated.h @@ -3,7 +3,7 @@ ///////////////////////////////////////////////////////////////////////////// //// -// This file was auto-generated by a tool at 2020-07-21 14:05:39 +// This file was auto-generated by a tool at 2022-04-27 09:53:39 // // It is recommended you DO NOT directly edit this file but instead edit // the code-generator that generated this source file instead. diff --git a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int64_t.generated.h b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int64_t.generated.h index 475fac681b1bc8..e49d92b7cf6b9b 100644 --- a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int64_t.generated.h +++ b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX2.int64_t.generated.h @@ -3,7 +3,7 @@ ///////////////////////////////////////////////////////////////////////////// //// -// This file was auto-generated by a tool at 2020-07-21 14:05:39 +// This file was auto-generated by a tool at 2022-04-27 09:53:39 // // It is recommended you DO NOT directly edit this file but instead edit // the code-generator that generated this source file instead. diff --git a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int32_t.generated.h b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int32_t.generated.h index 1b1843ec093ce7..1326c8fee5e5c7 100644 --- a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int32_t.generated.h +++ b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int32_t.generated.h @@ -3,7 +3,7 @@ ///////////////////////////////////////////////////////////////////////////// //// -// This file was auto-generated by a tool at 2020-07-21 14:05:39 +// This file was auto-generated by a tool at 2022-04-27 09:53:39 // // It is recommended you DO NOT directly edit this file but instead edit // the code-generator that generated this source file instead. @@ -1031,7 +1031,7 @@ template<> struct bitonic { } static NOINLINE void sort_01v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_mask_loadu_epi32(_mm512_set1_epi32(MAX), mask, @@ -1041,7 +1041,7 @@ template<> struct bitonic { } static NOINLINE void sort_02v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_mask_loadu_epi32(_mm512_set1_epi32(MAX), @@ -1053,7 +1053,7 @@ template<> struct bitonic { } static NOINLINE void sort_03v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1067,7 +1067,7 @@ template<> struct bitonic { } static NOINLINE void sort_04v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1083,7 +1083,7 @@ template<> struct bitonic { } static NOINLINE void sort_05v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1101,7 +1101,7 @@ template<> struct bitonic { } static NOINLINE void sort_06v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1121,7 +1121,7 @@ template<> struct bitonic { } static NOINLINE void sort_07v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1143,7 +1143,7 @@ template<> struct bitonic { } static NOINLINE void sort_08v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1167,7 +1167,7 @@ template<> struct bitonic { } static NOINLINE void sort_09v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1193,7 +1193,7 @@ template<> struct bitonic { } static NOINLINE void sort_10v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1221,7 +1221,7 @@ template<> struct bitonic { } static NOINLINE void sort_11v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1251,7 +1251,7 @@ template<> struct bitonic { } static NOINLINE void sort_12v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1283,7 +1283,7 @@ template<> struct bitonic { } static NOINLINE void sort_13v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1317,7 +1317,7 @@ template<> struct bitonic { } static NOINLINE void sort_14v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1353,7 +1353,7 @@ template<> struct bitonic { } static NOINLINE void sort_15v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1391,7 +1391,7 @@ template<> struct bitonic { } static NOINLINE void sort_16v_alt(int32_t *ptr, int remainder) { - const auto mask = 0xFFFF >> ((N - remainder) & (N-1)); + const auto mask = (uint16_t)(0xFFFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; diff --git a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int64_t.generated.h b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int64_t.generated.h index b7f16d60737346..ac44992fe23920 100644 --- a/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int64_t.generated.h +++ b/src/coreclr/gc/vxsort/smallsort/bitonic_sort.AVX512.int64_t.generated.h @@ -3,7 +3,7 @@ ///////////////////////////////////////////////////////////////////////////// //// -// This file was auto-generated by a tool at 2020-07-21 14:05:39 +// This file was auto-generated by a tool at 2022-04-27 09:53:39 // // It is recommended you DO NOT directly edit this file but instead edit // the code-generator that generated this source file instead. @@ -991,7 +991,7 @@ template<> struct bitonic { } static NOINLINE void sort_01v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_mask_loadu_epi64(_mm512_set1_epi64(MAX), mask, @@ -1001,7 +1001,7 @@ template<> struct bitonic { } static NOINLINE void sort_02v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_mask_loadu_epi64(_mm512_set1_epi64(MAX), @@ -1013,7 +1013,7 @@ template<> struct bitonic { } static NOINLINE void sort_03v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1027,7 +1027,7 @@ template<> struct bitonic { } static NOINLINE void sort_04v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1043,7 +1043,7 @@ template<> struct bitonic { } static NOINLINE void sort_05v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1061,7 +1061,7 @@ template<> struct bitonic { } static NOINLINE void sort_06v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1081,7 +1081,7 @@ template<> struct bitonic { } static NOINLINE void sort_07v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1103,7 +1103,7 @@ template<> struct bitonic { } static NOINLINE void sort_08v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1127,7 +1127,7 @@ template<> struct bitonic { } static NOINLINE void sort_09v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1153,7 +1153,7 @@ template<> struct bitonic { } static NOINLINE void sort_10v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1181,7 +1181,7 @@ template<> struct bitonic { } static NOINLINE void sort_11v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1211,7 +1211,7 @@ template<> struct bitonic { } static NOINLINE void sort_12v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1243,7 +1243,7 @@ template<> struct bitonic { } static NOINLINE void sort_13v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1277,7 +1277,7 @@ template<> struct bitonic { } static NOINLINE void sort_14v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1313,7 +1313,7 @@ template<> struct bitonic { } static NOINLINE void sort_15v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; @@ -1351,7 +1351,7 @@ template<> struct bitonic { } static NOINLINE void sort_16v_alt(int64_t *ptr, int remainder) { - const auto mask = 0xFF >> ((N - remainder) & (N-1)); + const auto mask = (uint8_t)(0xFF >> ((N - remainder) & (N-1))); __m512i d01 = _mm512_loadu_si512((__m512i const *) ptr + 0);; __m512i d02 = _mm512_loadu_si512((__m512i const *) ptr + 1);; diff --git a/src/coreclr/gc/vxsort/smallsort/codegen/avx2.py b/src/coreclr/gc/vxsort/smallsort/codegen/avx2.py index 7bf5b86f041345..9944cbbc8968e6 100644 --- a/src/coreclr/gc/vxsort/smallsort/codegen/avx2.py +++ b/src/coreclr/gc/vxsort/smallsort/codegen/avx2.py @@ -258,7 +258,10 @@ def get_mask_store_intrinsic(self, ptr, offset, value, mask): def autogenerated_blabber(self): - return f"""///////////////////////////////////////////////////////////////////////////// + return f"""// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +///////////////////////////////////////////////////////////////////////////// //// // This file was auto-generated by a tool at {datetime.now().strftime("%F %H:%M:%S")} // @@ -282,7 +285,6 @@ def generate_prologue(self, f): #endif #endif -#include #include #include "bitonic_sort.h" @@ -301,7 +303,7 @@ def generate_prologue(self, f): template<> struct bitonic<{t}, AVX2> {{ static const int N = {self.vector_size()}; - static constexpr {t} MAX = std::numeric_limits<{t}>::max(); + static constexpr {t} MAX = std::numeric_limits<{t}>::Max(); public: """ print(s, file=f) @@ -545,7 +547,11 @@ def generate_entry_points(self, f): def generate_master_entry_point(self, f_header, f_src): basename = os.path.basename(f_header.name) - s = f"""#include "{basename}" + s = f"""// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "common.h" +#include "{basename}" using namespace vxsort; """ diff --git a/src/coreclr/gc/vxsort/smallsort/codegen/avx512.py b/src/coreclr/gc/vxsort/smallsort/codegen/avx512.py index 6cb6e9048356df..e259027c5636bb 100644 --- a/src/coreclr/gc/vxsort/smallsort/codegen/avx512.py +++ b/src/coreclr/gc/vxsort/smallsort/codegen/avx512.py @@ -257,7 +257,10 @@ def get_mask_store_intrinsic(self, ptr, offset, value, mask): return f"_mm512_mask_storeu_{int_suffix}((__m512i *) {ptr} + {offset}, {mask}, {value})" def autogenerated_blabber(self): - return f"""///////////////////////////////////////////////////////////////////////////// + return f"""// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +///////////////////////////////////////////////////////////////////////////// //// // This file was auto-generated by a tool at {datetime.now().strftime("%F %H:%M:%S")} // @@ -282,7 +285,6 @@ def generate_prologue(self, f): #endif #endif -#include #include #include "bitonic_sort.h" @@ -297,7 +299,7 @@ def generate_prologue(self, f): namespace smallsort {{ template<> struct bitonic<{t}, AVX512> {{ static const int N = {self.vector_size()}; - static constexpr {t} MAX = std::numeric_limits<{t}>::max(); + static constexpr {t} MAX = std::numeric_limits<{t}>::Max(); public: """ print(s, file=f) @@ -505,9 +507,14 @@ def generate_entry_points(self, f): type = self.type g = self for m in range(1, g.max_bitonic_sort_vectors() + 1): + if self.vector_size() == 8: + cast_to = "uint8_t" + elif self.vector_size() == 16: + cast_to = "uint16_t" + s = f""" static NOINLINE void sort_{m:02d}v_alt({type} *ptr, int remainder) {{ - const auto mask = 0x{((1 << self.vector_size()) - 1):X} >> ((N - remainder) & (N-1)); + const auto mask = ({cast_to})(0x{((1 << self.vector_size()) - 1):X} >> ((N - remainder) & (N-1))); """ print(s, file=f) @@ -531,7 +538,11 @@ def generate_entry_points(self, f): def generate_master_entry_point(self, f_header, f_src): basename = os.path.basename(f_header.name) - s = f"""#include "{basename}" + s = f"""// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "common.h" +#include "{basename}" using namespace vxsort; """ diff --git a/src/coreclr/gc/windows/gcenv.windows.cpp b/src/coreclr/gc/windows/gcenv.windows.cpp index 06ad13221b77fe..680361010f4bf1 100644 --- a/src/coreclr/gc/windows/gcenv.windows.cpp +++ b/src/coreclr/gc/windows/gcenv.windows.cpp @@ -1126,7 +1126,7 @@ bool GCToOSInterface::GetNumaInfo(uint16_t* total_nodes, uint32_t* max_procs_per for (uint32_t i = 0; i < g_nNodes; i++) { GROUP_AFFINITY processorMask; - if (GetNumaNodeProcessorMaskEx(i, &processorMask)) + if (GetNumaNodeProcessorMaskEx((uint16_t)i, &processorMask)) { DWORD procsOnNode = 0; uintptr_t mask = (uintptr_t)processorMask.Mask; @@ -1139,7 +1139,7 @@ bool GCToOSInterface::GetNumaInfo(uint16_t* total_nodes, uint32_t* max_procs_per currentProcsOnNode = max(currentProcsOnNode, procsOnNode); } *max_procs_per_node = currentProcsOnNode; - *total_nodes = g_nNodes; + *total_nodes = (uint16_t)g_nNodes; } return true; } From fd97df3d6eb429af9ca7097216b00a56b36f8ac8 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:18:46 -0700 Subject: [PATCH 03/21] Diagnostics --- src/coreclr/debug/daccess/daccess.cpp | 10 +++++++--- src/coreclr/debug/daccess/request.cpp | 2 +- src/coreclr/debug/daccess/task.cpp | 5 ++++- src/coreclr/debug/ee/amd64/amd64walker.cpp | 4 ++-- src/native/eventpipe/ep-stream.h | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 55fb9688ffe472..72fbf1b8dce4aa 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -4766,12 +4766,15 @@ ClrDataAccess::SetAllTypeNotifications( HRESULT STDMETHODCALLTYPE ClrDataAccess::SetAllCodeNotifications( /* [in] */ IXCLRDataModule* mod, - /* [in] */ ULONG32 flags) + /* [in] */ ULONG32 flagsRaw) { HRESULT status; DAC_ENTER(); + _ASSERTE(flagsRaw <= USHRT_MAX); + USHORT flags = (USHORT)flagsRaw; + EX_TRY { status = E_FAIL; @@ -4981,14 +4984,15 @@ ClrDataAccess::SetCodeNotifications( { for (ULONG32 check = 0; check < numTokens; check++) { - if (!IsValidMethodCodeNotification(flags[check])) + _ASSERTE(flags[check] <= USHRT_MAX); + if (!IsValidMethodCodeNotification((USHORT)flags[check])) { status = E_INVALIDARG; goto Exit; } } } - else if (!IsValidMethodCodeNotification(singleFlags)) + else if (!IsValidMethodCodeNotification((USHORT)singleFlags)) { status = E_INVALIDARG; goto Exit; diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 05450da10f90f2..977b65ac58dcc2 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -1738,7 +1738,7 @@ ClrDataAccess::GetMethodTableData(CLRDATA_ADDRESS mt, struct DacpMethodTableData MTData->Module = HOST_CDADDR(pMT->GetModule()); MTData->Class = HOST_CDADDR(pMT->GetClass()); MTData->ParentMethodTable = HOST_CDADDR(pMT->GetParentMethodTable());; - MTData->wNumInterfaces = pMT->GetNumInterfaces(); + MTData->wNumInterfaces = (WORD)pMT->GetNumInterfaces(); MTData->wNumMethods = pMT->GetNumMethods(); MTData->wNumVtableSlots = pMT->GetNumVtableSlots(); MTData->wNumVirtuals = pMT->GetNumVirtuals(); diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index 319d3506b9b889..300a1ee9c29583 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -3428,12 +3428,15 @@ ClrDataMethodDefinition::GetCodeNotification( HRESULT STDMETHODCALLTYPE ClrDataMethodDefinition::SetCodeNotification( - /* [in] */ ULONG32 flags) + /* [in] */ ULONG32 flagsRaw) { HRESULT status; DAC_ENTER_SUB(m_dac); + _ASSERTE(flagsRaw <= USHRT_MAX); + USHORT flags = (USHORT)flagsRaw; + EX_TRY { if (!IsValidMethodCodeNotification(flags)) diff --git a/src/coreclr/debug/ee/amd64/amd64walker.cpp b/src/coreclr/debug/ee/amd64/amd64walker.cpp index 98365382afeaa2..06cbc48e5edd72 100644 --- a/src/coreclr/debug/ee/amd64/amd64walker.cpp +++ b/src/coreclr/debug/ee/amd64/amd64walker.cpp @@ -486,9 +486,9 @@ static bool IsWrite(Amd64InstrDecode::InstrForm form, int pp, bool W, bool L, bo return isWrite; } -static int opSize(Amd64InstrDecode::InstrForm form, int pp, bool W, bool L, bool fPrefix66) +static uint8_t opSize(Amd64InstrDecode::InstrForm form, int pp, bool W, bool L, bool fPrefix66) { - int opSize = 0; + uint8_t opSize = 0; bool P = !((pp == 1) || fPrefix66); switch (form) { diff --git a/src/native/eventpipe/ep-stream.h b/src/native/eventpipe/ep-stream.h index c4b3dee44e21b8..9bd8651c2ff647 100644 --- a/src/native/eventpipe/ep-stream.h +++ b/src/native/eventpipe/ep-stream.h @@ -14,7 +14,7 @@ // the enumeration has a specific set of values to keep it compatible with consumer library // it's sibling is defined in https://github.com/Microsoft/perfview/blob/10d1f92b242c98073b3817ac5ee6d98cd595d39b/src/FastSerialization/FastSerialization.cs#L2295 -typedef enum +typedef enum : uint8_t { FAST_SERIALIZER_TAGS_ERROR = 0, // To improve debugabilty, 0 is an illegal tag. FAST_SERIALIZER_TAGS_NULL_REFERENCE = 1, // Tag for a null object forwardReference. From 53424b89d7235a437c0c2b54bebff7111cb46fe6 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:19:11 -0700 Subject: [PATCH 04/21] mscorpe --- src/coreclr/dlls/mscorpe/pewriter.cpp | 6 +++--- src/coreclr/dlls/mscorpe/pewriter.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/dlls/mscorpe/pewriter.cpp b/src/coreclr/dlls/mscorpe/pewriter.cpp index cf560b598cc009..cb670efc494b44 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.cpp +++ b/src/coreclr/dlls/mscorpe/pewriter.cpp @@ -109,7 +109,7 @@ void PERelocSection::AddBaseReloc(unsigned rva, int type, unsigned short highAdj relocSize++; unsigned short* offset = (unsigned short*) section->getBlock(2); if(offset) { - *offset = VAL16((rva & 0xFFF) | (type << 12)); + *offset = VAL16((unsigned short)(rva & 0xFFF) | (unsigned short)(type << 12)); } } @@ -1308,7 +1308,7 @@ HRESULT PEWriter::linkSortSections(entry * entries, _ASSERTE(index == -1 || index == atoi(p)); e->nameLength = (unsigned char)(p - e->name); - e->index = index; + e->index = (char)index; e->arrayIndex = (unsigned short)(cur - getSectStart()); e++; } @@ -1589,7 +1589,7 @@ HRESULT PEWriter::link() { iUniqueSections++; // One more for .reloc filePos = sizeof(IMAGE_DOS_HEADER)+sizeof(x86StubPgm) + m_ntHeadersSize; - m_ntHeaders->FileHeader.NumberOfSections = VAL16(iUniqueSections); + m_ntHeaders->FileHeader.NumberOfSections = (WORD)VAL16(iUniqueSections); filePos += iUniqueSections * sizeof(IMAGE_SECTION_HEADER); filePos = roundUp(filePos, VAL32(m_ntHeaders->OptionalHeader.FileAlignment)); diff --git a/src/coreclr/dlls/mscorpe/pewriter.h b/src/coreclr/dlls/mscorpe/pewriter.h index 84ec61f9275eca..11bba04a71b3f0 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.h +++ b/src/coreclr/dlls/mscorpe/pewriter.h @@ -305,9 +305,9 @@ inline unsigned PEWriter::getSubsystem() { } inline void PEWriter::setSubsystem(unsigned subsystem, unsigned major, unsigned minor) { - m_ntHeaders->OptionalHeader.Subsystem = VAL16(subsystem); - m_ntHeaders->OptionalHeader.MajorSubsystemVersion = VAL16(major); - m_ntHeaders->OptionalHeader.MinorSubsystemVersion = VAL16(minor); + m_ntHeaders->OptionalHeader.Subsystem = (USHORT)VAL16(subsystem); + m_ntHeaders->OptionalHeader.MajorSubsystemVersion = (USHORT)VAL16(major); + m_ntHeaders->OptionalHeader.MinorSubsystemVersion = (USHORT)VAL16(minor); } inline void PEWriter::setCharacteristics(unsigned mask) { From da013a8811ac380ceb6d54a0052490f8d98fb910 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:19:43 -0700 Subject: [PATCH 05/21] ILAsm --- src/coreclr/ilasm/asmparse.y | 4 ++-- src/coreclr/ilasm/assembler.cpp | 2 +- src/coreclr/ilasm/binstr.h | 4 ++-- src/coreclr/ilasm/grammar_after.cpp | 2 +- src/coreclr/ilasm/prebuilt/asmparse.cpp | 8 ++++---- src/coreclr/ilasm/writer.cpp | 9 ++++----- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/coreclr/ilasm/asmparse.y b/src/coreclr/ilasm/asmparse.y index ed4492404578f6..3f545d3a12ee99 100644 --- a/src/coreclr/ilasm/asmparse.y +++ b/src/coreclr/ilasm/asmparse.y @@ -898,7 +898,7 @@ methodDecl : _EMITBYTE int32 { PASM->EmitByte($2) PASM->m_pCurMethod->m_dwExportOrdinal = $3; PASM->m_pCurMethod->m_szExportAlias = NULL; if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1; - if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000; + if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = (WORD)($3 + 0x8000); } else PASM->report->warn("Duplicate .export directive, ignored\n"); @@ -908,7 +908,7 @@ methodDecl : _EMITBYTE int32 { PASM->EmitByte($2) PASM->m_pCurMethod->m_dwExportOrdinal = $3; PASM->m_pCurMethod->m_szExportAlias = $6; if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1; - if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000; + if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = (WORD)($3 + 0x8000); } else PASM->report->warn("Duplicate .export directive, ignored\n"); diff --git a/src/coreclr/ilasm/assembler.cpp b/src/coreclr/ilasm/assembler.cpp index 313088735d0f8f..297862bbecb30c 100644 --- a/src/coreclr/ilasm/assembler.cpp +++ b/src/coreclr/ilasm/assembler.cpp @@ -1681,7 +1681,7 @@ void Assembler::EmitInstrBrTarget(Instr* instr, _In_ __nullterminated char* labe int offset=0; if (pLabel == NULL) // branching forward -- no optimization { - int pcrelsize = 1+(isShort(instr->opcode) ? 1 : 4); //size of the instruction plus argument + BYTE pcrelsize = 1+(isShort(instr->opcode) ? 1 : 4); //size of the instruction plus argument AddDeferredFixup(label, m_pCurOutputPos+1, (m_CurPC + pcrelsize), pcrelsize-1); } diff --git a/src/coreclr/ilasm/binstr.h b/src/coreclr/ilasm/binstr.h index d0e8da1e4907a8..f22a5e21887750 100644 --- a/src/coreclr/ilasm/binstr.h +++ b/src/coreclr/ilasm/binstr.h @@ -19,9 +19,9 @@ class BinStr { BinStr(BYTE* pb, DWORD cb) { len = cb; max = cb+8; ptr_ = pb; } ~BinStr() { if (ptr_ != buff) delete [] ptr_; } - void insertInt8(int val) { if (len >= max) Realloc(); memmove(ptr_+1, ptr_, len); *ptr_ = val; len++; } + void insertInt8(int val) { if (len >= max) Realloc(); memmove(ptr_+1, ptr_, len); *ptr_ = (uint8_t)val; len++; } void insertInt32(int val) { if (len + 4 > max) Realloc(); memmove(ptr_+4, ptr_, len); SET_UNALIGNED_32(&ptr_[0], val); len+=4; } - void appendInt8(int val) { if (len >= max) Realloc(); ptr_[len++] = val; } + void appendInt8(int val) { if (len >= max) Realloc(); ptr_[len++] = (uint8_t)val; } void appendInt16(int val) { if (len + 2 > max) Realloc(); SET_UNALIGNED_16(&ptr_[len], val); len += 2; } void appendInt32(int val) { if (len + 4 > max) Realloc(); SET_UNALIGNED_32(&ptr_[len], val); len += 4; } void appendInt64(__int64 *pval) { if (len + 8 > max) Realloc(8); SET_UNALIGNED_64(&ptr_[len],(*pval)); len += 8; } diff --git a/src/coreclr/ilasm/grammar_after.cpp b/src/coreclr/ilasm/grammar_after.cpp index 6353ebedad0666..9df0cc05ec7f04 100644 --- a/src/coreclr/ilasm/grammar_after.cpp +++ b/src/coreclr/ilasm/grammar_after.cpp @@ -1414,7 +1414,7 @@ unsigned __int8* skipType(unsigned __int8* ptr, BOOL fFixupType) TyParFixupList.PEEK(n)); m = 0; } - *pb = (*pb == ELEMENT_TYPE_MVARFIXUP)? ELEMENT_TYPE_MVAR : ELEMENT_TYPE_VAR; + *pb = (BYTE)((*pb == ELEMENT_TYPE_MVARFIXUP) ? ELEMENT_TYPE_MVAR : ELEMENT_TYPE_VAR); int compressed_size_m = (int)CorSigCompressData(m,pb+1); // Note that CorSigCompressData() (and hence, CorSigUncompressData()) store a number diff --git a/src/coreclr/ilasm/prebuilt/asmparse.cpp b/src/coreclr/ilasm/prebuilt/asmparse.cpp index 1518a796d20f27..096ed433243c4d 100644 --- a/src/coreclr/ilasm/prebuilt/asmparse.cpp +++ b/src/coreclr/ilasm/prebuilt/asmparse.cpp @@ -1909,7 +1909,7 @@ YYLOCAL YYNEAR YYPASCAL YYPARSER() YYAPI_TOKENNAME = YYLEX(); YYAPI_CALLAFTERYYLEX(YYAPI_TOKENNAME); } - if( ((yyn += YYAPI_TOKENEME(YYAPI_TOKENNAME)) < 0) || (yyn >= YYLAST) ) { + if( ((yyn += (short)YYAPI_TOKENEME(YYAPI_TOKENNAME)) < 0) || (yyn >= YYLAST) ) { goto yydefault; } if( YYCHK[ yyn = YYACT[ yyn ] ] == YYAPI_TOKENEME(YYAPI_TOKENNAME) ) { /* valid shift */ @@ -2066,7 +2066,7 @@ YYLOCAL YYNEAR YYPASCAL YYPARSER() yyval = yypv[1]; yyprintf("REDUCE: rule %4d, popped %2d tokens, uncovered state %4d, ",yyn, YYR2[yyn], *yyps); yym = yyn; - yyn = YYR1[yyn]; /* consult goto table to find next state */ + yyn = (short)YYR1[yyn]; /* consult goto table to find next state */ yyj = YYPGO[yyn] + *yyps + 1; if( (yyj >= YYLAST) || (YYCHK[ yystate = YYACT[yyj] ] != -yyn) ) { yystate = YYACT[YYPGO[yyn]]; @@ -3139,7 +3139,7 @@ case 352: PASM->m_pCurMethod->m_dwExportOrdinal = yypvt[-1].int32; PASM->m_pCurMethod->m_szExportAlias = NULL; if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1; - if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = yypvt[-1].int32 + 0x8000; + if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = (WORD)(yypvt[-1].int32 + 0x8000); } else PASM->report->warn("Duplicate .export directive, ignored\n"); @@ -3151,7 +3151,7 @@ case 353: PASM->m_pCurMethod->m_dwExportOrdinal = yypvt[-3].int32; PASM->m_pCurMethod->m_szExportAlias = yypvt[-0].string; if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1; - if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = yypvt[-3].int32 + 0x8000; + if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = (WORD)(yypvt[-3].int32 + 0x8000); } else PASM->report->warn("Duplicate .export directive, ignored\n"); diff --git a/src/coreclr/ilasm/writer.cpp b/src/coreclr/ilasm/writer.cpp index de40e5d5f50a65..969eb120e5f56f 100644 --- a/src/coreclr/ilasm/writer.cpp +++ b/src/coreclr/ilasm/writer.cpp @@ -366,7 +366,6 @@ HRESULT Assembler::CreateExportDirectory() pAlias[i] = pEATE->szAlias; } bool swapped = true; - unsigned j; char* pch; while(swapped) { @@ -379,14 +378,14 @@ HRESULT Assembler::CreateExportDirectory() pch = pAlias[i-1]; pAlias[i-1] = pAlias[i]; pAlias[i] = pch; - j = pOT[i-1]; + WORD j = pOT[i-1]; pOT[i-1] = pOT[i]; pOT[i] = j; } } } // normalize ordinals - for(i = 0; i < Nentries; i++) pOT[i] -= ordBase; + for(i = 0; i < Nentries; i++) pOT[i] -= (WORD)ordBase; // fill the export address table #ifdef _PREFAST_ #pragma warning(push) @@ -401,7 +400,7 @@ HRESULT Assembler::CreateExportDirectory() #pragma warning(pop) #endif // fill the export names table - unsigned l; + unsigned l, j; for(i = 0, j = 0; i < Nentries; i++) { pNPT[i] = j; // relative offset in the table @@ -1065,7 +1064,7 @@ HRESULT Assembler::CreatePEFile(_In_ __nullterminated WCHAR *pwzOutputFilename) { if(pMD->m_wVTSlot >= 0x8000) { - pMD->m_wVTSlot -= 0x8000 + OrdBase - 1; + pMD->m_wVTSlot -= (WORD)(0x8000 + OrdBase - 1); } } } From 7b2d67f9df1a471c6e06cedb14349c333323df60 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:20:21 -0700 Subject: [PATCH 06/21] VM and Util --- src/coreclr/utilcode/outstring.cpp | 4 ++-- src/coreclr/utilcode/sstring.cpp | 4 ++-- src/coreclr/utilcode/util.cpp | 2 +- src/coreclr/vm/amd64/cgencpu.h | 4 ++-- src/coreclr/vm/arm/cgencpu.h | 6 +++--- src/coreclr/vm/arm64/cgencpu.h | 6 +++--- src/coreclr/vm/array.cpp | 2 +- src/coreclr/vm/callconvbuilder.cpp | 4 ++-- src/coreclr/vm/callconvbuilder.hpp | 4 ++-- src/coreclr/vm/callhelpers.cpp | 2 +- src/coreclr/vm/classlayoutinfo.cpp | 2 +- src/coreclr/vm/comdelegate.cpp | 8 ++++---- src/coreclr/vm/comtoclrcall.cpp | 4 +++- src/coreclr/vm/dllimport.cpp | 8 ++++---- src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | 2 +- src/coreclr/vm/gcenv.os.cpp | 6 +++--- src/coreclr/vm/i386/cgencpu.h | 4 ++-- src/coreclr/vm/i386/stublinkerx86.cpp | 2 +- src/coreclr/vm/i386/stublinkerx86.h | 2 +- src/coreclr/vm/jitinterface.cpp | 10 +++++----- src/coreclr/vm/loongarch64/cgencpu.h | 4 ++-- src/coreclr/vm/method.cpp | 2 +- src/coreclr/vm/methodtablebuilder.h | 2 +- src/coreclr/vm/mlinfo.cpp | 2 +- src/coreclr/vm/precode.h | 10 ++++++---- src/coreclr/vm/stublink.cpp | 6 +++--- 26 files changed, 58 insertions(+), 54 deletions(-) diff --git a/src/coreclr/utilcode/outstring.cpp b/src/coreclr/utilcode/outstring.cpp index 40b8e004066a19..a6b345fe7e6600 100644 --- a/src/coreclr/utilcode/outstring.cpp +++ b/src/coreclr/utilcode/outstring.cpp @@ -100,10 +100,10 @@ OutString& OutString::dec(int i, size_t minWidth) { for(;;) { if (val < 10) { - *--ptr = '0' + val; + *--ptr = (char)('0' + val); break; } - *--ptr = '0' + (val % 10); + *--ptr = (char)('0' + (val % 10)); val = val / 10; } diff --git a/src/coreclr/utilcode/sstring.cpp b/src/coreclr/utilcode/sstring.cpp index 9ab6790efb3f60..d4aa3d7f23e6c1 100644 --- a/src/coreclr/utilcode/sstring.cpp +++ b/src/coreclr/utilcode/sstring.cpp @@ -83,7 +83,7 @@ static WCHAR MapChar(WCHAR wc, DWORD dwFlags) if (dwFlags == LCMAP_UPPERCASE) { - wTmp = + wTmp = (WCHAR) #ifdef SELF_NO_HOST toupper(wc); #else @@ -93,7 +93,7 @@ static WCHAR MapChar(WCHAR wc, DWORD dwFlags) else { _ASSERTE(dwFlags == LCMAP_LOWERCASE); - wTmp = + wTmp = (WCHAR) #ifdef SELF_NO_HOST tolower(wc); #else diff --git a/src/coreclr/utilcode/util.cpp b/src/coreclr/utilcode/util.cpp index ee90f9db6c538a..c43265bcc35cb9 100644 --- a/src/coreclr/utilcode/util.cpp +++ b/src/coreclr/utilcode/util.cpp @@ -527,7 +527,7 @@ BYTE * ClrVirtualAllocWithinRange(const BYTE *pMinAddr, if (m_enableGCNumaAware) { DWORD currentProcsOnNode = 0; - for (int i = 0; i < m_nNodes; i++) + for (uint16_t i = 0; i < m_nNodes; i++) { GROUP_AFFINITY processorMask; if (GetNumaNodeProcessorMaskEx(i, &processorMask)) diff --git a/src/coreclr/vm/amd64/cgencpu.h b/src/coreclr/vm/amd64/cgencpu.h index d562627856295a..22e1593352d976 100644 --- a/src/coreclr/vm/amd64/cgencpu.h +++ b/src/coreclr/vm/amd64/cgencpu.h @@ -141,10 +141,10 @@ void R8ToFPSpill(void* pSpillSlot, SIZE_T srcDoubleAsSIZE_T) // Parameter size //********************************************************************** -inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) +inline uint16_t StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) { const unsigned stackSlotSize = 8; - return ALIGN_UP(parmSize, stackSlotSize); + return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); } //********************************************************************** diff --git a/src/coreclr/vm/arm/cgencpu.h b/src/coreclr/vm/arm/cgencpu.h index 598e11c9f41128..188b5008e7bc2e 100644 --- a/src/coreclr/vm/arm/cgencpu.h +++ b/src/coreclr/vm/arm/cgencpu.h @@ -99,10 +99,10 @@ EXTERN_C void setFPReturn(int fpSize, INT64 retVal); // Parameter size //********************************************************************** -inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) +inline uint16_t StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) { const unsigned stackSlotSize = 4; - return ALIGN_UP(parmSize, stackSlotSize); + return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); } //********************************************************************** @@ -1063,7 +1063,7 @@ struct ThisPtrRetBufPrecode { } CONTRACTL_END; - ExecutableWriterHolder precodeWriterHolder(this, sizeof(ThisPtrRetBufPrecode)); + ExecutableWriterHolder precodeWriterHolder(this, sizeof(ThisPtrRetBufPrecode)); return FastInterlockCompareExchange((LONG*)&precodeWriterHolder.GetRW()->m_pTarget, (LONG)target, (LONG)expected) == (LONG)expected; } #endif // !DACCESS_COMPILE diff --git a/src/coreclr/vm/arm64/cgencpu.h b/src/coreclr/vm/arm64/cgencpu.h index 28694df7d2b834..c3846456b31a92 100644 --- a/src/coreclr/vm/arm64/cgencpu.h +++ b/src/coreclr/vm/arm64/cgencpu.h @@ -82,7 +82,7 @@ void R8ToFPSpill(void* pSpillSlot, SIZE_T srcDoubleAsSIZE_T) // Parameter size //********************************************************************** -inline unsigned StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) +inline uint16_t StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) { #if defined(OSX_ARM64_ABI) if (!isValueType) @@ -96,12 +96,12 @@ inline unsigned StackElemSize(unsigned parmSize, bool isValueType, bool isFloatH { _ASSERTE((parmSize % 4) == 0); // float hfa is not considered a struct type and passed with 4-byte alignment. - return parmSize; + return (uint16_t)parmSize; } #endif const unsigned stackSlotSize = 8; - return ALIGN_UP(parmSize, stackSlotSize); + return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); } // diff --git a/src/coreclr/vm/array.cpp b/src/coreclr/vm/array.cpp index 1088bacb6275b4..cae5e2218b0091 100644 --- a/src/coreclr/vm/array.cpp +++ b/src/coreclr/vm/array.cpp @@ -457,7 +457,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy InterfaceInfo_t *pIntInfo = (InterfaceInfo_t *) (pMTHead + imapOffset + index * sizeof(InterfaceInfo_t)); pIntInfo->SetMethodTable((pParentClass->GetInterfaceMap() + index)->GetMethodTable()); } - pMT->SetInterfaceMap(pParentClass->GetNumInterfaces(), (InterfaceInfo_t *)(pMTHead + imapOffset)); + pMT->SetInterfaceMap((WORD)pParentClass->GetNumInterfaces(), (InterfaceInfo_t *)(pMTHead + imapOffset)); // Copy down flags for these interfaces as well. This is simplified a bit since we know that System.Array // only has a few interfaces and the flags will fit inline into the MethodTable's optional members. diff --git a/src/coreclr/vm/callconvbuilder.cpp b/src/coreclr/vm/callconvbuilder.cpp index b47a696f59b831..62038f7c955c8d 100644 --- a/src/coreclr/vm/callconvbuilder.cpp +++ b/src/coreclr/vm/callconvbuilder.cpp @@ -320,7 +320,7 @@ HRESULT CallConv::TryGetUnmanagedCallingConventionFromModOpt( _In_ PCCOR_SIGNATURE pSig, _In_ ULONG cSig, _Inout_ CallConvBuilder* builder, - _Out_ UINT *errorResID) + _Out_ WORD *errorResID) { CONTRACTL { @@ -413,7 +413,7 @@ namespace HRESULT CallConv::TryGetCallingConventionFromUnmanagedCallConv( _In_ MethodDesc* pMD, _Inout_ CallConvBuilder* builder, - _Out_opt_ UINT* errorResID) + _Out_opt_ WORD* errorResID) { CONTRACTL { diff --git a/src/coreclr/vm/callconvbuilder.hpp b/src/coreclr/vm/callconvbuilder.hpp index 6f197d92029dd4..cc8e0c60d7b086 100644 --- a/src/coreclr/vm/callconvbuilder.hpp +++ b/src/coreclr/vm/callconvbuilder.hpp @@ -78,7 +78,7 @@ namespace CallConv _In_ PCCOR_SIGNATURE pSig, _In_ ULONG cSig, _Inout_ CallConvBuilder *builder, - _Out_ UINT *errorResID); + _Out_ WORD *errorResID); //------------------------------------------------------------------------- // Gets the calling convention from the UnmanagedCallConv attribute @@ -92,7 +92,7 @@ namespace CallConv HRESULT TryGetCallingConventionFromUnmanagedCallConv( _In_ MethodDesc* pMD, _Inout_ CallConvBuilder* builder, - _Out_opt_ UINT* errorResID); + _Out_opt_ WORD* errorResID); //------------------------------------------------------------------------- // Gets the unmanaged calling convention from the UnmanagedCallersOnly attribute. diff --git a/src/coreclr/vm/callhelpers.cpp b/src/coreclr/vm/callhelpers.cpp index 7b99261c6fbde3..c0cf4cdb46aeae 100644 --- a/src/coreclr/vm/callhelpers.cpp +++ b/src/coreclr/vm/callhelpers.cpp @@ -246,7 +246,7 @@ void FillInRegTypeMap(int argOffset, CorElementType typ, BYTE * pMap) if (regArgNum < NUM_ARGUMENT_REGISTERS) { - pMap[regArgNum] = typ; + pMap[regArgNum] = (BYTE)typ; } } #endif // CALLDESCR_REGTYPEMAP diff --git a/src/coreclr/vm/classlayoutinfo.cpp b/src/coreclr/vm/classlayoutinfo.cpp index e198c6fd2502f5..ca9f3e85132bcd 100644 --- a/src/coreclr/vm/classlayoutinfo.cpp +++ b/src/coreclr/vm/classlayoutinfo.cpp @@ -148,7 +148,7 @@ namespace LayoutRawFieldInfo* pfwalk = *pSortWalk; RawFieldPlacementInfo* placementInfo = &pfwalk->m_placement; - BYTE alignmentRequirement = placementInfo->m_alignment; + BYTE alignmentRequirement = (BYTE)placementInfo->m_alignment; alignmentRequirement = min(alignmentRequirement, packingSize); diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp index 6a656571414afb..c4ae83ea62e5e0 100644 --- a/src/coreclr/vm/comdelegate.cpp +++ b/src/coreclr/vm/comdelegate.cpp @@ -295,9 +295,9 @@ class ShuffleIterator // Return an index of argument slot. First indices are reserved for general purpose registers, // the following ones for float registers and then the rest for stack slots. // This index is independent of how many registers are actually used to pass arguments. -int GetNormalizedArgumentSlotIndex(UINT16 offset) +static UINT16 GetNormalizedArgumentSlotIndex(UINT16 offset) { - int index; + UINT16 index; if (offset & ShuffleEntry::FPREGMASK) { @@ -531,8 +531,8 @@ BOOL GenerateShuffleArrayPortable(MethodDesc* pMethodSrc, MethodDesc *pMethodDst { ShuffleEntry entry = (*pShuffleEntryArray)[i]; - int srcIndex = GetNormalizedArgumentSlotIndex(entry.srcofs); - int dstIndex = GetNormalizedArgumentSlotIndex(entry.dstofs); + UINT16 srcIndex = GetNormalizedArgumentSlotIndex(entry.srcofs); + UINT16 dstIndex = GetNormalizedArgumentSlotIndex(entry.dstofs); _ASSERTE((srcIndex >= 0) && ((unsigned int)srcIndex < argSlots)); _ASSERTE((dstIndex >= 0) && ((unsigned int)dstIndex < argSlots)); diff --git a/src/coreclr/vm/comtoclrcall.cpp b/src/coreclr/vm/comtoclrcall.cpp index 44c98f4cec3744..0da23d98bdd9a1 100644 --- a/src/coreclr/vm/comtoclrcall.cpp +++ b/src/coreclr/vm/comtoclrcall.cpp @@ -775,7 +775,9 @@ PCODE ComCallMethodDesc::CreateCOMToCLRStub(DWORD dwStubFlags, MethodDesc **ppSt } else { - comCallMDWriterHolder.GetRW()->m_StackBytes = pStubMD->SizeOfArgStack(); + UINT size = pStubMD->SizeOfArgStack(); + _ASSERTE(size <= USHRT_MAX); + comCallMDWriterHolder.GetRW()->m_StackBytes = (UINT16)size; } #endif // TARGET_X86 diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index 26fda0fabb002f..879d20205035d2 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -2925,7 +2925,7 @@ void PInvokeStaticSigInfo::InitCallConv(_In_ CorInfoCallConvExtension callConv, if (callConv == CallConvWinApiSentinel) { CallConvBuilder builder; - UINT errorResID = 0; + WORD errorResID = 0; // System.Runtime.InteropServices.UnmanagedCallConvAttribute HRESULT hr = CallConv::TryGetCallingConventionFromUnmanagedCallConv(pMD, &builder, &errorResID); @@ -2953,7 +2953,7 @@ void PInvokeStaticSigInfo::InitCallConv(CorInfoCallConvExtension callConv, BOOL STANDARD_VM_CONTRACT; CallConvBuilder builder; - UINT errorResID; + WORD errorResID; HRESULT hr = CallConv::TryGetUnmanagedCallingConventionFromModOpt(GetScopeHandle(m_pModule), m_sig.GetRawSig(), m_sig.GetRawSigLen(), &builder, &errorResID); if (FAILED(hr)) { @@ -3147,7 +3147,7 @@ void NDirect::GetCallingConvention_IgnoreErrors(_In_ MethodDesc* pMD, _Out_opt_ Module* module = pMD->GetModule(); CallConvBuilder builder; - UINT errorResID; + WORD errorResID; // modopts (void)CallConv::TryGetUnmanagedCallingConventionFromModOpt(GetScopeHandle(module), sig.GetRawSig(), sig.GetRawSigLen(), &builder, &errorResID); @@ -6007,7 +6007,7 @@ PCODE GetILStubForCalli(VASigCookie *pVASigCookie, MethodDesc *pMD) else { CallConvBuilder builder; - UINT errorResID; + WORD errorResID; HRESULT hr = CallConv::TryGetUnmanagedCallingConventionFromModOpt(GetScopeHandle(pVASigCookie->pModule), signature.GetRawSig(), signature.GetRawSigLen(), &builder, &errorResID); if (FAILED(hr)) COMPlusThrowHR(hr, errorResID); diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 9744e84a89b691..7de959f0481f61 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1390,7 +1390,7 @@ ep_rt_provider_config_init (EventPipeProviderConfiguration *provider_config) STATIC_CONTRACT_NOTHROW; if (!ep_rt_utf8_string_compare (ep_config_get_rundown_provider_name_utf8 (), ep_provider_config_get_provider_name (provider_config))) { - MICROSOFT_WINDOWS_DOTNETRUNTIME_RUNDOWN_PROVIDER_DOTNET_Context.EventPipeProvider.Level = ep_provider_config_get_logging_level (provider_config); + MICROSOFT_WINDOWS_DOTNETRUNTIME_RUNDOWN_PROVIDER_DOTNET_Context.EventPipeProvider.Level = (UCHAR) ep_provider_config_get_logging_level (provider_config); MICROSOFT_WINDOWS_DOTNETRUNTIME_RUNDOWN_PROVIDER_DOTNET_Context.EventPipeProvider.EnabledKeywordsBitmask = ep_provider_config_get_keywords (provider_config); MICROSOFT_WINDOWS_DOTNETRUNTIME_RUNDOWN_PROVIDER_DOTNET_Context.EventPipeProvider.IsEnabled = true; } diff --git a/src/coreclr/vm/gcenv.os.cpp b/src/coreclr/vm/gcenv.os.cpp index 369d30e538ff27..c2bb155208d486 100644 --- a/src/coreclr/vm/gcenv.os.cpp +++ b/src/coreclr/vm/gcenv.os.cpp @@ -1171,8 +1171,8 @@ bool GCToOSInterface::ParseGCHeapAffinitizeRangesEntry(const char** config_strin return false; } - // If the user passes in 0 as the CPU group and they don't have > 64 cores, - // honor the affinitized range passed in by bypassing the check. + // If the user passes in 0 as the CPU group and they don't have > 64 cores, + // honor the affinitized range passed in by bypassing the check. bool bypass_cpu_range_check = !CanEnableGCCPUGroups() && group_number == 0; WORD group_begin; @@ -1188,7 +1188,7 @@ bool GCToOSInterface::ParseGCHeapAffinitizeRangesEntry(const char** config_strin { // the offset in this case where we bypass this check should be from 0 till the # of Processors. group_begin = 0; - group_size = GetTotalProcessorCount(); + group_size = (WORD)GetTotalProcessorCount(); } } diff --git a/src/coreclr/vm/i386/cgencpu.h b/src/coreclr/vm/i386/cgencpu.h index 1cc63b10d8b9d9..9b8a4ffa2977c4 100644 --- a/src/coreclr/vm/i386/cgencpu.h +++ b/src/coreclr/vm/i386/cgencpu.h @@ -97,10 +97,10 @@ EXTERN_C void SinglecastDelegateInvokeStub(); // Parameter size //********************************************************************** -inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) +inline uint16_t StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) { const unsigned stackSlotSize = 4; - return ALIGN_UP(parmSize, stackSlotSize); + return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); } #include "stublinkerx86.h" diff --git a/src/coreclr/vm/i386/stublinkerx86.cpp b/src/coreclr/vm/i386/stublinkerx86.cpp index 35750c87f18d2a..5126d2cc32685c 100644 --- a/src/coreclr/vm/i386/stublinkerx86.cpp +++ b/src/coreclr/vm/i386/stublinkerx86.cpp @@ -800,7 +800,7 @@ class X64LeaRIP : public InstructionFormat pOutBufferRW[0] = rex; pOutBufferRW[1] = 0x8D; - pOutBufferRW[2] = 0x05 | (reg << 3); + pOutBufferRW[2] = (BYTE)(0x05 | (reg << 3)); // only support absolute pushimm32 of the label address. The fixedUpReference is // the offset to the label from the current point, so add to get address *((__int32*)(3+pOutBufferRW)) = (__int32)(fixedUpReference); diff --git a/src/coreclr/vm/i386/stublinkerx86.h b/src/coreclr/vm/i386/stublinkerx86.h index c41441314d9827..922babee24a2fb 100644 --- a/src/coreclr/vm/i386/stublinkerx86.h +++ b/src/coreclr/vm/i386/stublinkerx86.h @@ -44,7 +44,7 @@ extern PCODE GetPreStubEntryPoint(); // Encodes X86 registers. The numbers are chosen to match Intel's opcode // encoding. //---------------------------------------------------------------------- -enum X86Reg +enum X86Reg : UCHAR { kEAX = 0, kECX = 1, diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 24aea8fbe7ddeb..522316aae0f5dc 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -2049,7 +2049,7 @@ static unsigned MarkGCField(BYTE* gcPtrs, CorInfoGCType type) // that we don't double count the data in the gc layout. if (*gcPtrs == TYPE_GC_NONE) { - *gcPtrs = type; + *gcPtrs = (BYTE)type; return 1; } else if (*gcPtrs != type) @@ -2245,14 +2245,14 @@ bool CEEInfo::getSystemVAmd64PassStructInRegisterDescriptor( structPassInRegDescPtr->passedInRegisters = true; - structPassInRegDescPtr->eightByteCount = helper.eightByteCount; + structPassInRegDescPtr->eightByteCount = (uint8_t)helper.eightByteCount; _ASSERTE(structPassInRegDescPtr->eightByteCount <= CLR_SYSTEMV_MAX_EIGHTBYTES_COUNT_TO_PASS_IN_REGISTERS); for (unsigned int i = 0; i < CLR_SYSTEMV_MAX_EIGHTBYTES_COUNT_TO_PASS_IN_REGISTERS; i++) { structPassInRegDescPtr->eightByteClassifications[i] = helper.eightByteClassifications[i]; - structPassInRegDescPtr->eightByteSizes[i] = helper.eightByteSizes[i]; - structPassInRegDescPtr->eightByteOffsets[i] = helper.eightByteOffsets[i]; + structPassInRegDescPtr->eightByteSizes[i] = (uint8_t)helper.eightByteSizes[i]; + structPassInRegDescPtr->eightByteOffsets[i] = (uint8_t)helper.eightByteOffsets[i]; } } @@ -9613,7 +9613,7 @@ namespace case IMAGE_CEE_CS_CALLCONV_UNMANAGED: { CallConvBuilder builder; - UINT errorResID; + WORD errorResID; HRESULT hr = CallConv::TryGetUnmanagedCallingConventionFromModOpt(mod, pSig, cbSig, &builder, &errorResID); if (FAILED(hr)) diff --git a/src/coreclr/vm/loongarch64/cgencpu.h b/src/coreclr/vm/loongarch64/cgencpu.h index ea682213c3aa46..495ca82fadf1e9 100644 --- a/src/coreclr/vm/loongarch64/cgencpu.h +++ b/src/coreclr/vm/loongarch64/cgencpu.h @@ -65,10 +65,10 @@ extern PCODE GetPreStubEntryPoint(); // Parameter size //********************************************************************** -inline unsigned StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) +inline uint16_t StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) { const unsigned stackSlotSize = 8; - return ALIGN_UP(parmSize, stackSlotSize); + return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); } // diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 08e4a3a278da6e..4e655a39f9f0c7 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -2131,7 +2131,7 @@ MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint) { return (MethodDesc*)((StubPrecode*)pInstr)->GetMethodDesc(); } - + if (PrecodeStubManager::g_pManager->GetFixupPrecodeRangeList()->IsInRange(entryPoint)) { return (MethodDesc*)((FixupPrecode*)pInstr)->GetMethodDesc(); diff --git a/src/coreclr/vm/methodtablebuilder.h b/src/coreclr/vm/methodtablebuilder.h index cb939810763460..9ebe250aaae64c 100644 --- a/src/coreclr/vm/methodtablebuilder.h +++ b/src/coreclr/vm/methodtablebuilder.h @@ -2073,7 +2073,7 @@ class MethodTableBuilder // -------------------------------------------------------------------------------------------- // Used for analyzing overlapped fields defined by explicit layout types. - enum bmtFieldLayoutTag {empty, nonoref, oref, byref}; + enum bmtFieldLayoutTag : BYTE {empty, nonoref, oref, byref}; // -------------------------------------------------------------------------------------------- // used for calculating pointer series for tdexplicit diff --git a/src/coreclr/vm/mlinfo.cpp b/src/coreclr/vm/mlinfo.cpp index 81ae1ab78468f7..9b2069f9a8204d 100644 --- a/src/coreclr/vm/mlinfo.cpp +++ b/src/coreclr/vm/mlinfo.cpp @@ -2968,7 +2968,7 @@ void MarshalInfo::SetupArgumentSizes() } CONTRACTL_END; - const unsigned targetPointerSize = TARGET_POINTER_SIZE; + const UINT16 targetPointerSize = TARGET_POINTER_SIZE; const bool pointerIsValueType = false; const bool pointerIsFloatHfa = false; _ASSERTE(targetPointerSize == StackElemSize(TARGET_POINTER_SIZE, pointerIsValueType, pointerIsFloatHfa)); diff --git a/src/coreclr/vm/precode.h b/src/coreclr/vm/precode.h index d4d02d430ce405..e456e6dbc1bc98 100644 --- a/src/coreclr/vm/precode.h +++ b/src/coreclr/vm/precode.h @@ -287,7 +287,7 @@ struct FixupPrecode PCODE target = (PCODE)this + FixupCodeOffset; - _ASSERTE(IS_ALIGNED(&GetData()->Target, sizeof(SIZE_T))); + _ASSERTE(IS_ALIGNED(&GetData()->Target, sizeof(SIZE_T))); InterlockedExchangeT(&GetData()->Target, target); } @@ -516,7 +516,7 @@ class Precode { } PTR_PCODE GetTargetSlot(); - + MethodDesc * GetMethodDesc(BOOL fSpeculative = FALSE); BOOL IsCorrectMethodDesc(MethodDesc * pMD); @@ -585,10 +585,12 @@ class Precode { static TADDR AllocateTemporaryEntryPoints(MethodDescChunk* pChunk, LoaderAllocator *pLoaderAllocator, AllocMemTracker *pamTracker); - static SIZE_T GetMaxTemporaryEntryPointsCount() + static DWORD GetMaxTemporaryEntryPointsCount() { SIZE_T maxPrecodeCodeSize = Max(FixupPrecode::CodeSize, StubPrecode::CodeSize); - return GetOsPageSize() / maxPrecodeCodeSize; + SIZE_T count = GetOsPageSize() / maxPrecodeCodeSize; + _ASSERTE(count < MAXDWORD); + return (DWORD)count; } #ifdef DACCESS_COMPILE diff --git a/src/coreclr/vm/stublink.cpp b/src/coreclr/vm/stublink.cpp index 5b29d6e31c1f17..13407c7f28fbc5 100644 --- a/src/coreclr/vm/stublink.cpp +++ b/src/coreclr/vm/stublink.cpp @@ -1213,11 +1213,11 @@ VOID StubLinker::UnwindAllocStack (SHORT FrameSizeIncrement) else { USHORT FrameOffset = (USHORT)FrameSizeIncrement; - BOOL fNeedExtraSlot = ((ULONG)FrameOffset != (ULONG)FrameSizeIncrement); + bool fNeedExtraSlot = ((ULONG)FrameOffset != (ULONG)FrameSizeIncrement); - UNWIND_CODE *pUnwindCode = AllocUnwindInfo(UWOP_ALLOC_LARGE, fNeedExtraSlot); + UNWIND_CODE *pUnwindCode = AllocUnwindInfo(UWOP_ALLOC_LARGE, fNeedExtraSlot ? 1 : 0); - pUnwindCode->OpInfo = fNeedExtraSlot; + pUnwindCode->OpInfo = fNeedExtraSlot ? 1 : 0; pUnwindCode[1].FrameOffset = FrameOffset; From afb951aac592f622781ed412216221d330f27de6 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:20:40 -0700 Subject: [PATCH 07/21] Metadata --- src/coreclr/binder/inc/bindertracing.h | 2 +- src/coreclr/inc/corhlpr.cpp | 4 ---- src/coreclr/md/ceefilegen/cceegen.cpp | 2 +- src/coreclr/md/compiler/custattr_emit.cpp | 8 ++++---- src/coreclr/md/compiler/disp.cpp | 8 ++++---- src/coreclr/md/enc/metamodelrw.cpp | 2 +- src/coreclr/md/enc/stgtiggerstorage.cpp | 2 +- src/coreclr/md/runtime/mdinternalro.cpp | 2 +- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/coreclr/binder/inc/bindertracing.h b/src/coreclr/binder/inc/bindertracing.h index ca28c045196388..0d5e0b670b1158 100644 --- a/src/coreclr/binder/inc/bindertracing.h +++ b/src/coreclr/binder/inc/bindertracing.h @@ -173,7 +173,7 @@ namespace BinderTracing }; // This must match the BindingPathSource value map in ClrEtwAll.man - enum PathSource + enum PathSource : uint16_t { ApplicationAssemblies, Unused, diff --git a/src/coreclr/inc/corhlpr.cpp b/src/coreclr/inc/corhlpr.cpp index 1a58e987153a3c..e01cdc58099a4b 100644 --- a/src/coreclr/inc/corhlpr.cpp +++ b/src/coreclr/inc/corhlpr.cpp @@ -253,11 +253,7 @@ unsigned __stdcall SectEH_Emit(unsigned size, unsigned ehCount, EHSect->Kind = CorILMethod_Sect_EHTable; if (moreSections) EHSect->Kind |= CorILMethod_Sect_MoreSects; -#ifndef SOS_INCLUDE - EHSect->DataSize = EHSect->Size(ehCount); -#else EHSect->DataSize = (BYTE) EHSect->Size(ehCount); -#endif // !SOS_INCLUDE EHSect->Reserved = 0; assert(EHSect->DataSize == EHSect->Size(ehCount)); // make sure didn't overflow outBuff = (BYTE*) &EHSect->Clauses[ehCount]; diff --git a/src/coreclr/md/ceefilegen/cceegen.cpp b/src/coreclr/md/ceefilegen/cceegen.cpp index 5d985b35c34983..3d11067d376e93 100644 --- a/src/coreclr/md/ceefilegen/cceegen.cpp +++ b/src/coreclr/md/ceefilegen/cceegen.cpp @@ -452,7 +452,7 @@ HRESULT CCeeGen::getSectionCreate (const char *name, DWORD flags, CeeSection **s name = ".text"; else if (strcmp(name, ".rdata") == 0) name = ".text"; - for (int i=0; iname(), name) == 0) { if (section) *section = m_sections[i]; diff --git a/src/coreclr/md/compiler/custattr_emit.cpp b/src/coreclr/md/compiler/custattr_emit.cpp index 02d3f8e9e3a4a1..9915e3604cf2ab 100644 --- a/src/coreclr/md/compiler/custattr_emit.cpp +++ b/src/coreclr/md/compiler/custattr_emit.cpp @@ -1318,9 +1318,9 @@ HRESULT RegMeta::_HandleKnownCustomAttribute( // S_OK or error. FALLTHROUGH; case CA_MethodImplAttribute3: // Validate bits. - if (qArgs[0].val.u4 & ~(miUserMask)) + if (qArgs[0].val.u2 & ~(miUserMask)) IfFailGo(PostError(META_E_CA_INVALID_VALUE)); - reinterpret_cast(pRow)->AddImplFlags(qArgs[0].val.u4); + reinterpret_cast(pRow)->AddImplFlags(qArgs[0].val.u2); if (!qNamedArgs[MI_CodeType].val.type.tag) break; // fall through to set the code type. @@ -1328,10 +1328,10 @@ HRESULT RegMeta::_HandleKnownCustomAttribute( // S_OK or error. case CA_MethodImplAttribute1: { USHORT usFlags = reinterpret_cast(pRow)->GetImplFlags(); - if (qNamedArgs[MI_CodeType].val.i4 & ~(miCodeTypeMask)) + if (qNamedArgs[MI_CodeType].val.u2 & ~(miCodeTypeMask)) IfFailGo(PostError(META_E_CA_INVALID_VALUE)); // Mask out old value, put in new one. - usFlags = (usFlags & ~miCodeTypeMask) | qNamedArgs[MI_CodeType].val.i4; + usFlags = (usFlags & ~miCodeTypeMask) | qNamedArgs[MI_CodeType].val.u2; reinterpret_cast(pRow)->SetImplFlags(usFlags); } break; diff --git a/src/coreclr/md/compiler/disp.cpp b/src/coreclr/md/compiler/disp.cpp index 4d9bd94841ed76..26f1e2ec789134 100644 --- a/src/coreclr/md/compiler/disp.cpp +++ b/src/coreclr/md/compiler/disp.cpp @@ -430,7 +430,7 @@ HRESULT Disp::OpenScopeOnITypeInfo( // Return code. //***************************************************************************** // Create a brand new scope which will be used for portable PDB metadata. // This is based on the CLSID that was used to get the dispenser. -// +// // The existing DefineScope method cannot be used for the purpose of PDB // metadata generation, since it internally creates module and type def table // entries. @@ -445,7 +445,7 @@ Disp::DefinePortablePdbScope( { #ifdef FEATURE_METADATA_EMIT HRESULT hr = S_OK; - + BEGIN_ENTRYPOINT_NOTHROW; RegMeta* pMeta = 0; @@ -457,7 +457,7 @@ Disp::DefinePortablePdbScope( IfFailGo(E_INVALIDARG); // Currently the portable PDB tables are treated as an extension to the MDVersion2 - // TODO: this extension might deserve its own version number e.g. 'MDVersion3' + // TODO: this extension might deserve its own version number e.g. 'MDVersion3' if (rclsid == CLSID_CLR_v2_MetaData) { optionForNewScope.m_MetadataVersion = MDVersion2; @@ -876,7 +876,7 @@ HRESULT Disp::GetOption( // Return code. { // Note: This is not used in CLR sources anymore, but we store the value and return it here, // so we keep it for backward-compat. V_VT(pvalue) = VT_BOOL; - V_BOOL(pvalue) = m_OptionValue.m_GenerateTCEAdapters; + V_BOOL(pvalue) = !!m_OptionValue.m_GenerateTCEAdapters ? VARIANT_TRUE : VARIANT_FALSE; } #endif //FEATURE_METADATA_EMIT_ALL || FEATURE_METADATA_EMIT_IN_DEBUGGER else diff --git a/src/coreclr/md/enc/metamodelrw.cpp b/src/coreclr/md/enc/metamodelrw.cpp index 3fde673faa5c43..ee8ded44bf0625 100644 --- a/src/coreclr/md/enc/metamodelrw.cpp +++ b/src/coreclr/md/enc/metamodelrw.cpp @@ -1806,7 +1806,7 @@ HRESULT CMiniMdRW::InitOnCustomDataSource(IMDCustomDataSource* pDataSource) m_Tables[i].Initialize(m_TableDefs[i].m_cbRec, tableRecordData, !fIsReadOnly); IfFailGo(pDataSource->GetTableSortable(i, &sortable)); - m_bSortable[i] = sortable; + m_bSortable[i] = !!sortable ? 1 : 0; } // Set the limits so we will know when to grow the database. diff --git a/src/coreclr/md/enc/stgtiggerstorage.cpp b/src/coreclr/md/enc/stgtiggerstorage.cpp index 3336a50d824cb5..28a5e483e0fec8 100644 --- a/src/coreclr/md/enc/stgtiggerstorage.cpp +++ b/src/coreclr/md/enc/stgtiggerstorage.cpp @@ -200,7 +200,7 @@ TiggerStorage::WriteHeader( SAVETRACE(DbgWriteEx(W("PSS: Header:\n"))); // Save the count and set flags. - m_StgHdr.SetiStreams(pList->Count()); + m_StgHdr.SetiStreams((USHORT)pList->Count()); if (cbExtraData != 0) m_StgHdr.AddFlags(STGHDR_EXTRADATA); diff --git a/src/coreclr/md/runtime/mdinternalro.cpp b/src/coreclr/md/runtime/mdinternalro.cpp index 7269552c854231..921280bfdbfe53 100644 --- a/src/coreclr/md/runtime/mdinternalro.cpp +++ b/src/coreclr/md/runtime/mdinternalro.cpp @@ -3164,7 +3164,7 @@ HRESULT _FillVariant( { case ELEMENT_TYPE_BOOLEAN: V_VT(pvar) = VT_BOOL; - V_BOOL(pvar) = pMDDefaultValue->m_bValue; + V_BOOL(pvar) = !!pMDDefaultValue->m_bValue ? VARIANT_TRUE : VARIANT_FALSE; break; case ELEMENT_TYPE_I1: V_VT(pvar) = VT_I1; From 7ec4d8a5ef0a390885d81ff14135a79345928396 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:20:54 -0700 Subject: [PATCH 08/21] SuperPMI --- .../tools/superpmi/superpmi-shared/methodcontextreader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp index 4b59b72114e9ed..a0f5ac9040b44a 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp @@ -28,7 +28,7 @@ HANDLE MethodContextReader::OpenFile(const char* inputFile, DWORD flags) static std::string to_lower(const std::string& input) { std::string res = input; - std::transform(input.cbegin(), input.cend(), res.begin(), tolower); + std::transform(input.cbegin(), input.cend(), res.begin(), (char(*)(char))tolower); return res; } From 3f752eba9c0a79a04d29765a5754a3c336504114 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 12:21:18 -0700 Subject: [PATCH 09/21] Updates to zlib-intel --- src/native/external/zlib-intel/deflate.c | 8 ++++---- src/native/external/zlib-intel/slide_sse.c | 2 +- src/native/external/zlib-intel/trees.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/native/external/zlib-intel/deflate.c b/src/native/external/zlib-intel/deflate.c index b5e7849d0023ca..505c89369504e2 100644 --- a/src/native/external/zlib-intel/deflate.c +++ b/src/native/external/zlib-intel/deflate.c @@ -1484,10 +1484,10 @@ local block_state deflate_stored(s, flush) _tr_stored_block(s, (char *)0, 0L, last); /* Replace the lengths in the dummy stored block with len. */ - s->pending_buf[s->pending - 4] = len; - s->pending_buf[s->pending - 3] = len >> 8; - s->pending_buf[s->pending - 2] = ~len; - s->pending_buf[s->pending - 1] = ~len >> 8; + s->pending_buf[s->pending - 4] = (Bytef)len; + s->pending_buf[s->pending - 3] = (Bytef)(len >> 8); + s->pending_buf[s->pending - 2] = (Bytef)~len; + s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8); /* Write the stored block header bytes. */ flush_pending(s->strm); diff --git a/src/native/external/zlib-intel/slide_sse.c b/src/native/external/zlib-intel/slide_sse.c index 342fd562dd1152..eb74202c5a04a8 100644 --- a/src/native/external/zlib-intel/slide_sse.c +++ b/src/native/external/zlib-intel/slide_sse.c @@ -18,7 +18,7 @@ void slide_hash_sse(deflate_state *s) unsigned n; Posf *p; uInt wsize = s->w_size; - z_const __m128i xmm_wsize = _mm_set1_epi16(s->w_size); + z_const __m128i xmm_wsize = _mm_set1_epi16((short)s->w_size); n = s->hash_size; p = &s->head[n] - 8; diff --git a/src/native/external/zlib-intel/trees.c b/src/native/external/zlib-intel/trees.c index 7480efc694d331..6b882e07c61eab 100644 --- a/src/native/external/zlib-intel/trees.c +++ b/src/native/external/zlib-intel/trees.c @@ -648,7 +648,7 @@ local void scan_tree (s, tree, max_code) if (++count < max_count && curlen == nextlen) { continue; } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; + s->bl_tree[curlen].Freq += (ush)count; } else if (curlen != 0) { if (curlen != prevlen) s->bl_tree[curlen].Freq++; s->bl_tree[REP_3_6].Freq++; From 379eb1877f1502753091e20438be6279045f454e Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 14:10:22 -0700 Subject: [PATCH 10/21] VM feedback. --- src/coreclr/vm/amd64/cgencpu.h | 4 ++-- src/coreclr/vm/arm/cgencpu.h | 4 ++-- src/coreclr/vm/arm64/cgencpu.h | 6 ++--- src/coreclr/vm/callconvbuilder.cpp | 4 ++-- src/coreclr/vm/callconvbuilder.hpp | 4 ++-- src/coreclr/vm/comdelegate.cpp | 4 ++-- src/coreclr/vm/dllimport.cpp | 10 ++++---- src/coreclr/vm/dllimport.h | 2 +- src/coreclr/vm/i386/cgencpu.h | 4 ++-- src/coreclr/vm/jitinterface.cpp | 2 +- src/coreclr/vm/loongarch64/cgencpu.h | 4 ++-- src/coreclr/vm/methodtablebuilder.cpp | 34 +++++++++++++-------------- src/coreclr/vm/methodtablebuilder.h | 8 +++---- src/coreclr/vm/mlinfo.cpp | 6 +++-- 14 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/coreclr/vm/amd64/cgencpu.h b/src/coreclr/vm/amd64/cgencpu.h index 22e1593352d976..d562627856295a 100644 --- a/src/coreclr/vm/amd64/cgencpu.h +++ b/src/coreclr/vm/amd64/cgencpu.h @@ -141,10 +141,10 @@ void R8ToFPSpill(void* pSpillSlot, SIZE_T srcDoubleAsSIZE_T) // Parameter size //********************************************************************** -inline uint16_t StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) +inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) { const unsigned stackSlotSize = 8; - return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); + return ALIGN_UP(parmSize, stackSlotSize); } //********************************************************************** diff --git a/src/coreclr/vm/arm/cgencpu.h b/src/coreclr/vm/arm/cgencpu.h index 188b5008e7bc2e..a9ba5ec08effc1 100644 --- a/src/coreclr/vm/arm/cgencpu.h +++ b/src/coreclr/vm/arm/cgencpu.h @@ -99,10 +99,10 @@ EXTERN_C void setFPReturn(int fpSize, INT64 retVal); // Parameter size //********************************************************************** -inline uint16_t StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) +inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) { const unsigned stackSlotSize = 4; - return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); + return ALIGN_UP(parmSize, stackSlotSize); } //********************************************************************** diff --git a/src/coreclr/vm/arm64/cgencpu.h b/src/coreclr/vm/arm64/cgencpu.h index c3846456b31a92..28694df7d2b834 100644 --- a/src/coreclr/vm/arm64/cgencpu.h +++ b/src/coreclr/vm/arm64/cgencpu.h @@ -82,7 +82,7 @@ void R8ToFPSpill(void* pSpillSlot, SIZE_T srcDoubleAsSIZE_T) // Parameter size //********************************************************************** -inline uint16_t StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) +inline unsigned StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) { #if defined(OSX_ARM64_ABI) if (!isValueType) @@ -96,12 +96,12 @@ inline uint16_t StackElemSize(unsigned parmSize, bool isValueType, bool isFloatH { _ASSERTE((parmSize % 4) == 0); // float hfa is not considered a struct type and passed with 4-byte alignment. - return (uint16_t)parmSize; + return parmSize; } #endif const unsigned stackSlotSize = 8; - return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); + return ALIGN_UP(parmSize, stackSlotSize); } // diff --git a/src/coreclr/vm/callconvbuilder.cpp b/src/coreclr/vm/callconvbuilder.cpp index 62038f7c955c8d..f3f88e3547e024 100644 --- a/src/coreclr/vm/callconvbuilder.cpp +++ b/src/coreclr/vm/callconvbuilder.cpp @@ -320,7 +320,7 @@ HRESULT CallConv::TryGetUnmanagedCallingConventionFromModOpt( _In_ PCCOR_SIGNATURE pSig, _In_ ULONG cSig, _Inout_ CallConvBuilder* builder, - _Out_ WORD *errorResID) + _Out_ UINT* errorResID) { CONTRACTL { @@ -413,7 +413,7 @@ namespace HRESULT CallConv::TryGetCallingConventionFromUnmanagedCallConv( _In_ MethodDesc* pMD, _Inout_ CallConvBuilder* builder, - _Out_opt_ WORD* errorResID) + _Out_opt_ UINT* errorResID) { CONTRACTL { diff --git a/src/coreclr/vm/callconvbuilder.hpp b/src/coreclr/vm/callconvbuilder.hpp index cc8e0c60d7b086..75fff6933fa4fc 100644 --- a/src/coreclr/vm/callconvbuilder.hpp +++ b/src/coreclr/vm/callconvbuilder.hpp @@ -78,7 +78,7 @@ namespace CallConv _In_ PCCOR_SIGNATURE pSig, _In_ ULONG cSig, _Inout_ CallConvBuilder *builder, - _Out_ WORD *errorResID); + _Out_ UINT* errorResID); //------------------------------------------------------------------------- // Gets the calling convention from the UnmanagedCallConv attribute @@ -92,7 +92,7 @@ namespace CallConv HRESULT TryGetCallingConventionFromUnmanagedCallConv( _In_ MethodDesc* pMD, _Inout_ CallConvBuilder* builder, - _Out_opt_ WORD* errorResID); + _Out_opt_ UINT* errorResID); //------------------------------------------------------------------------- // Gets the unmanaged calling convention from the UnmanagedCallersOnly attribute. diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp index c4ae83ea62e5e0..2c6d2689171067 100644 --- a/src/coreclr/vm/comdelegate.cpp +++ b/src/coreclr/vm/comdelegate.cpp @@ -534,8 +534,8 @@ BOOL GenerateShuffleArrayPortable(MethodDesc* pMethodSrc, MethodDesc *pMethodDst UINT16 srcIndex = GetNormalizedArgumentSlotIndex(entry.srcofs); UINT16 dstIndex = GetNormalizedArgumentSlotIndex(entry.dstofs); - _ASSERTE((srcIndex >= 0) && ((unsigned int)srcIndex < argSlots)); - _ASSERTE((dstIndex >= 0) && ((unsigned int)dstIndex < argSlots)); + _ASSERTE((srcIndex >= 0) && (srcIndex < argSlots)); + _ASSERTE((dstIndex >= 0) && (dstIndex < argSlots)); // Unmark the node to indicate that it was not processed yet pGraphNodes[srcIndex].isMarked = false; diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index 879d20205035d2..75aa9e65308d0b 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -2925,7 +2925,7 @@ void PInvokeStaticSigInfo::InitCallConv(_In_ CorInfoCallConvExtension callConv, if (callConv == CallConvWinApiSentinel) { CallConvBuilder builder; - WORD errorResID = 0; + UINT errorResID = 0; // System.Runtime.InteropServices.UnmanagedCallConvAttribute HRESULT hr = CallConv::TryGetCallingConventionFromUnmanagedCallConv(pMD, &builder, &errorResID); @@ -2953,7 +2953,7 @@ void PInvokeStaticSigInfo::InitCallConv(CorInfoCallConvExtension callConv, BOOL STANDARD_VM_CONTRACT; CallConvBuilder builder; - WORD errorResID; + UINT errorResID; HRESULT hr = CallConv::TryGetUnmanagedCallingConventionFromModOpt(GetScopeHandle(m_pModule), m_sig.GetRawSig(), m_sig.GetRawSigLen(), &builder, &errorResID); if (FAILED(hr)) { @@ -2983,7 +2983,7 @@ void PInvokeStaticSigInfo::InitCallConv(CorInfoCallConvExtension callConv, BOOL _ASSERTE(m_callConv != CallConvWinApiSentinel); } -void PInvokeStaticSigInfo::ThrowError(WORD errorResourceID) +void PInvokeStaticSigInfo::ThrowError(UINT errorResourceID) { CONTRACTL { @@ -3147,7 +3147,7 @@ void NDirect::GetCallingConvention_IgnoreErrors(_In_ MethodDesc* pMD, _Out_opt_ Module* module = pMD->GetModule(); CallConvBuilder builder; - WORD errorResID; + UINT errorResID; // modopts (void)CallConv::TryGetUnmanagedCallingConventionFromModOpt(GetScopeHandle(module), sig.GetRawSig(), sig.GetRawSigLen(), &builder, &errorResID); @@ -6007,7 +6007,7 @@ PCODE GetILStubForCalli(VASigCookie *pVASigCookie, MethodDesc *pMD) else { CallConvBuilder builder; - WORD errorResID; + UINT errorResID; HRESULT hr = CallConv::TryGetUnmanagedCallingConventionFromModOpt(GetScopeHandle(pVASigCookie->pModule), signature.GetRawSig(), signature.GetRawSigLen(), &builder, &errorResID); if (FAILED(hr)) COMPlusThrowHR(hr, errorResID); diff --git a/src/coreclr/vm/dllimport.h b/src/coreclr/vm/dllimport.h index 8b472e3a0aafb6..d3ac9847abf7ba 100644 --- a/src/coreclr/vm/dllimport.h +++ b/src/coreclr/vm/dllimport.h @@ -325,7 +325,7 @@ struct PInvokeStaticSigInfo PInvokeStaticSigInfo(_In_ MethodDesc* pMD, _Outptr_opt_ LPCUTF8* pLibName, _Outptr_opt_ LPCUTF8* pEntryPointName); private: - void ThrowError(_In_ WORD errorResourceID); + void ThrowError(_In_ UINT errorResourceID); void InitCallConv(_In_ CorInfoCallConvExtension callConv, _In_ MethodDesc* pMD); void InitCallConv(_In_ CorInfoCallConvExtension callConv, _In_ BOOL bIsVarArg); void DllImportInit(_In_ MethodDesc* pMD, _Outptr_opt_ LPCUTF8* pLibName, _Outptr_opt_ LPCUTF8* pEntryPointName); diff --git a/src/coreclr/vm/i386/cgencpu.h b/src/coreclr/vm/i386/cgencpu.h index 9b8a4ffa2977c4..1cc63b10d8b9d9 100644 --- a/src/coreclr/vm/i386/cgencpu.h +++ b/src/coreclr/vm/i386/cgencpu.h @@ -97,10 +97,10 @@ EXTERN_C void SinglecastDelegateInvokeStub(); // Parameter size //********************************************************************** -inline uint16_t StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) +inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unused */, bool isFloatHfa = false /* unused */) { const unsigned stackSlotSize = 4; - return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); + return ALIGN_UP(parmSize, stackSlotSize); } #include "stublinkerx86.h" diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 522316aae0f5dc..e73be506760d55 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -9613,7 +9613,7 @@ namespace case IMAGE_CEE_CS_CALLCONV_UNMANAGED: { CallConvBuilder builder; - WORD errorResID; + UINT errorResID; HRESULT hr = CallConv::TryGetUnmanagedCallingConventionFromModOpt(mod, pSig, cbSig, &builder, &errorResID); if (FAILED(hr)) diff --git a/src/coreclr/vm/loongarch64/cgencpu.h b/src/coreclr/vm/loongarch64/cgencpu.h index 495ca82fadf1e9..ea682213c3aa46 100644 --- a/src/coreclr/vm/loongarch64/cgencpu.h +++ b/src/coreclr/vm/loongarch64/cgencpu.h @@ -65,10 +65,10 @@ extern PCODE GetPreStubEntryPoint(); // Parameter size //********************************************************************** -inline uint16_t StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) +inline unsigned StackElemSize(unsigned parmSize, bool isValueType, bool isFloatHfa) { const unsigned stackSlotSize = 8; - return (uint16_t)ALIGN_UP(parmSize, stackSlotSize); + return ALIGN_UP(parmSize, stackSlotSize); } // diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index 2b7d73d12ee8af..fba71a74903f63 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -8414,8 +8414,8 @@ MethodTableBuilder::HandleExplicitLayout( } CQuickBytes qb; - PREFIX_ASSUME(sizeof(BYTE) == 1); - BYTE *pFieldLayout = (BYTE*) qb.AllocThrows(instanceSliceSize * sizeof(BYTE)); + PREFIX_ASSUME(sizeof(bmtFieldLayoutTag) == 1); + bmtFieldLayoutTag *pFieldLayout = (bmtFieldLayoutTag*)qb.AllocThrows(instanceSliceSize * sizeof(bmtFieldLayoutTag)); for (i=0; i < instanceSliceSize; i++) { pFieldLayout[i] = empty; @@ -8434,9 +8434,9 @@ MethodTableBuilder::HandleExplicitLayout( // 5. If a BYREF does overlap with another BYREF, the class is marked unverifiable. // 6. If an overlap of any kind occurs, the class will be marked NotTightlyPacked (affects ValueType.Equals()). // - char emptyObject[TARGET_POINTER_SIZE]; - char isObject[TARGET_POINTER_SIZE]; - char isByRef[TARGET_POINTER_SIZE]; + bmtFieldLayoutTag emptyObject[TARGET_POINTER_SIZE]; + bmtFieldLayoutTag isObject[TARGET_POINTER_SIZE]; + bmtFieldLayoutTag isByRef[TARGET_POINTER_SIZE]; for (i = 0; i < TARGET_POINTER_SIZE; i++) { emptyObject[i] = empty; @@ -8573,9 +8573,9 @@ MethodTableBuilder::HandleExplicitLayout( // If we got here, we are trying to place a non-OREF (or a valuetype composed of non-OREFs.) // Look for any orefs or byrefs under this field - BYTE *loc = NULL; - BYTE* currOffset = pFieldLayout + pFD->GetOffset_NoLogging(); - BYTE* endOffset = currOffset + fieldSize; + bmtFieldLayoutTag* loc = NULL; + bmtFieldLayoutTag* currOffset = pFieldLayout + pFD->GetOffset_NoLogging(); + bmtFieldLayoutTag* endOffset = currOffset + fieldSize; for (; currOffset < endOffset; ++currOffset) { if (*currOffset == oref || *currOffset == byref) @@ -8720,7 +8720,7 @@ MethodTableBuilder::HandleExplicitLayout( //******************************************************************************* // make sure that no object fields are overlapped incorrectly, returns the trust level -/*static*/ ExplicitFieldTrust::TrustLevel MethodTableBuilder::CheckValueClassLayout(MethodTable * pMT, BYTE *pFieldLayout) +/*static*/ ExplicitFieldTrust::TrustLevel MethodTableBuilder::CheckValueClassLayout(MethodTable * pMT, bmtFieldLayoutTag *pFieldLayout) { STANDARD_VM_CONTRACT; @@ -8738,7 +8738,7 @@ MethodTableBuilder::HandleExplicitLayout( UINT fieldSize = pMT->GetNumInstanceFieldBytes(); CQuickBytes qb; - BYTE *vcLayout = (BYTE*) qb.AllocThrows(fieldSize * sizeof(BYTE)); + bmtFieldLayoutTag *vcLayout = (bmtFieldLayoutTag*) qb.AllocThrows(fieldSize * sizeof(bmtFieldLayoutTag)); memset((void*)vcLayout, nonoref, fieldSize); // use pointer series to locate the orefs @@ -8811,7 +8811,7 @@ MethodTableBuilder::HandleExplicitLayout( //******************************************************************************* // make sure that no byref/object fields are overlapped, returns the trust level -/*static*/ ExplicitFieldTrust::TrustLevel MethodTableBuilder::CheckByRefLikeValueClassLayout(MethodTable * pMT, BYTE *pFieldLayout) +/*static*/ ExplicitFieldTrust::TrustLevel MethodTableBuilder::CheckByRefLikeValueClassLayout(MethodTable * pMT, bmtFieldLayoutTag *pFieldLayout) { STANDARD_VM_CONTRACT; _ASSERTE(pMT->IsByRefLike()); @@ -8861,7 +8861,7 @@ MethodTableBuilder::HandleExplicitLayout( //******************************************************************************* // Set the field's tag type and/or detect invalid overlap -/*static*/ ExplicitFieldTrust::TrustLevel MethodTableBuilder::MarkTagType(BYTE* field, SIZE_T fieldSize, bmtFieldLayoutTag tagType) +/*static*/ ExplicitFieldTrust::TrustLevel MethodTableBuilder::MarkTagType(bmtFieldLayoutTag* field, SIZE_T fieldSize, bmtFieldLayoutTag tagType) { STANDARD_VM_CONTRACT; _ASSERTE(field != NULL); @@ -8898,7 +8898,7 @@ MethodTableBuilder::HandleExplicitLayout( //******************************************************************************* void MethodTableBuilder::FindPointerSeriesExplicit(UINT instanceSliceSize, - BYTE *pFieldLayout) + bmtFieldLayoutTag *pFieldLayout) { STANDARD_VM_CONTRACT; @@ -8910,19 +8910,19 @@ void MethodTableBuilder::FindPointerSeriesExplicit(UINT instanceSliceSize, DWORD sz = (instanceSliceSize + (2 * TARGET_POINTER_SIZE) - 1); bmtGCSeries->pSeries = new bmtGCSeriesInfo::Series[sz/2/ TARGET_POINTER_SIZE]; - BYTE *loc = pFieldLayout; - BYTE *layoutEnd = pFieldLayout + instanceSliceSize; + bmtFieldLayoutTag *loc = pFieldLayout; + bmtFieldLayoutTag *layoutEnd = pFieldLayout + instanceSliceSize; while (loc < layoutEnd) { // Find the next OREF entry. - loc = (BYTE*)memchr((void*)loc, oref, layoutEnd-loc); + loc = (bmtFieldLayoutTag*)memchr((void*)loc, oref, layoutEnd-loc); if (loc == NULL) { break; } // Find the next non-OREF entry - BYTE *cur = loc; + bmtFieldLayoutTag *cur = loc; while(cur < layoutEnd && *cur == oref) { cur++; diff --git a/src/coreclr/vm/methodtablebuilder.h b/src/coreclr/vm/methodtablebuilder.h index 9ebe250aaae64c..174a820e827e91 100644 --- a/src/coreclr/vm/methodtablebuilder.h +++ b/src/coreclr/vm/methodtablebuilder.h @@ -2916,20 +2916,20 @@ class MethodTableBuilder static ExplicitFieldTrust::TrustLevel CheckValueClassLayout( MethodTable * pMT, - BYTE * pFieldLayout); + bmtFieldLayoutTag* pFieldLayout); static ExplicitFieldTrust::TrustLevel CheckByRefLikeValueClassLayout( MethodTable * pMT, - BYTE * pFieldLayout); + bmtFieldLayoutTag* pFieldLayout); static ExplicitFieldTrust::TrustLevel MarkTagType( - BYTE* field, + bmtFieldLayoutTag* field, SIZE_T size, bmtFieldLayoutTag tagType); void FindPointerSeriesExplicit( UINT instanceSliceSize, - BYTE * pFieldLayout); + bmtFieldLayoutTag* pFieldLayout); VOID HandleGCForExplicitLayout(); diff --git a/src/coreclr/vm/mlinfo.cpp b/src/coreclr/vm/mlinfo.cpp index 9b2069f9a8204d..04d72cbb1f45e5 100644 --- a/src/coreclr/vm/mlinfo.cpp +++ b/src/coreclr/vm/mlinfo.cpp @@ -2968,7 +2968,7 @@ void MarshalInfo::SetupArgumentSizes() } CONTRACTL_END; - const UINT16 targetPointerSize = TARGET_POINTER_SIZE; + const unsigned targetPointerSize = TARGET_POINTER_SIZE; const bool pointerIsValueType = false; const bool pointerIsFloatHfa = false; _ASSERTE(targetPointerSize == StackElemSize(TARGET_POINTER_SIZE, pointerIsValueType, pointerIsFloatHfa)); @@ -2981,7 +2981,9 @@ void MarshalInfo::SetupArgumentSizes() { const bool isValueType = IsValueClass(m_type); const bool isFloatHfa = isValueType && (m_pMT->GetHFAType() == CORINFO_HFA_ELEM_FLOAT); - m_nativeArgSize = StackElemSize(GetNativeSize(m_type), isValueType, isFloatHfa); + unsigned int argsSize = StackElemSize(GetNativeSize(m_type), isValueType, isFloatHfa); + _ASSERTE(argsSize <= USHRT_MAX); + m_nativeArgSize = (UINT16)argsSize; } #ifdef ENREGISTERED_PARAMTYPE_MAXSIZE From 3a8f0c9ab9f5d6c3a641724d351693f2a6692f46 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 14:10:33 -0700 Subject: [PATCH 11/21] Disable 4244 in tests --- src/tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 5e9d85e96e7065..fc50dc31451cae 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -23,6 +23,7 @@ endif() if (CLR_CMAKE_HOST_WIN32) # 4100 - unreferenced formal parameter + # 4244 - conversion from 'type1' to 'type2', possible loss of data # 4514 - unreferenced inline function has been removed # 4625 - copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted # 4626 - assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted @@ -35,7 +36,7 @@ if (CLR_CMAKE_HOST_WIN32) # 5026 - move constructor was implicitly defined as deleted # 5027 - move assignment operator was implicitly defined as deleted # 5039 - pointer or reference to potentially throwing function passed to extern C function under -EHc. Undefined behavior may occur if this function throws an exception. - add_compile_options(-wd4100 -wd4514 -wd4625 -wd4626 -wd4668 -wd4710 -wd4711 -wd4774 -wd4820 -wd5025 -wd5026 -wd5027 -wd5039) + add_compile_options(-wd4100 -wd4244 -wd4514 -wd4625 -wd4626 -wd4668 -wd4710 -wd4711 -wd4774 -wd4820 -wd5025 -wd5026 -wd5027 -wd5039) string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_compile_options(/EHa) # enable C++ EH (w/ SEH exceptions) From 1f791418d35da27a9ec4676a9cca1aad46b18f12 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 14:20:09 -0700 Subject: [PATCH 12/21] Revert "Updates to zlib-intel" This reverts commit 3f752eba9c0a79a04d29765a5754a3c336504114. --- src/native/external/zlib-intel/deflate.c | 8 ++++---- src/native/external/zlib-intel/slide_sse.c | 2 +- src/native/external/zlib-intel/trees.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/native/external/zlib-intel/deflate.c b/src/native/external/zlib-intel/deflate.c index 505c89369504e2..b5e7849d0023ca 100644 --- a/src/native/external/zlib-intel/deflate.c +++ b/src/native/external/zlib-intel/deflate.c @@ -1484,10 +1484,10 @@ local block_state deflate_stored(s, flush) _tr_stored_block(s, (char *)0, 0L, last); /* Replace the lengths in the dummy stored block with len. */ - s->pending_buf[s->pending - 4] = (Bytef)len; - s->pending_buf[s->pending - 3] = (Bytef)(len >> 8); - s->pending_buf[s->pending - 2] = (Bytef)~len; - s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8); + s->pending_buf[s->pending - 4] = len; + s->pending_buf[s->pending - 3] = len >> 8; + s->pending_buf[s->pending - 2] = ~len; + s->pending_buf[s->pending - 1] = ~len >> 8; /* Write the stored block header bytes. */ flush_pending(s->strm); diff --git a/src/native/external/zlib-intel/slide_sse.c b/src/native/external/zlib-intel/slide_sse.c index eb74202c5a04a8..342fd562dd1152 100644 --- a/src/native/external/zlib-intel/slide_sse.c +++ b/src/native/external/zlib-intel/slide_sse.c @@ -18,7 +18,7 @@ void slide_hash_sse(deflate_state *s) unsigned n; Posf *p; uInt wsize = s->w_size; - z_const __m128i xmm_wsize = _mm_set1_epi16((short)s->w_size); + z_const __m128i xmm_wsize = _mm_set1_epi16(s->w_size); n = s->hash_size; p = &s->head[n] - 8; diff --git a/src/native/external/zlib-intel/trees.c b/src/native/external/zlib-intel/trees.c index 6b882e07c61eab..7480efc694d331 100644 --- a/src/native/external/zlib-intel/trees.c +++ b/src/native/external/zlib-intel/trees.c @@ -648,7 +648,7 @@ local void scan_tree (s, tree, max_code) if (++count < max_count && curlen == nextlen) { continue; } else if (count < min_count) { - s->bl_tree[curlen].Freq += (ush)count; + s->bl_tree[curlen].Freq += count; } else if (curlen != 0) { if (curlen != prevlen) s->bl_tree[curlen].Freq++; s->bl_tree[REP_3_6].Freq++; From 108fb4b80a53ef05999359d63322d1238d3f5109 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 14:23:08 -0700 Subject: [PATCH 13/21] Suppress 4244 for zlib and zlib-intel. --- src/native/external/zlib-intel.cmake | 2 ++ src/native/external/zlib.cmake | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/native/external/zlib-intel.cmake b/src/native/external/zlib-intel.cmake index 4c283a2c05414c..8353dfa208fc92 100644 --- a/src/native/external/zlib-intel.cmake +++ b/src/native/external/zlib-intel.cmake @@ -1,3 +1,5 @@ +add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data + set(ZLIB_SOURCES_BASE adler32.c compress.c diff --git a/src/native/external/zlib.cmake b/src/native/external/zlib.cmake index 6365a1ea5585ac..84592d614c582a 100644 --- a/src/native/external/zlib.cmake +++ b/src/native/external/zlib.cmake @@ -1,3 +1,5 @@ +add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data + set(ZLIB_SOURCES_BASE adler32.c compress.c From 809fdec03928e7697ccad3e4494013ebcedc6184 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 14:38:08 -0700 Subject: [PATCH 14/21] Fix argument validation --- src/coreclr/debug/daccess/daccess.cpp | 7 ++----- src/coreclr/vm/util.cpp | 2 +- src/coreclr/vm/util.hpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 72fbf1b8dce4aa..628c7674eec489 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -4766,15 +4766,12 @@ ClrDataAccess::SetAllTypeNotifications( HRESULT STDMETHODCALLTYPE ClrDataAccess::SetAllCodeNotifications( /* [in] */ IXCLRDataModule* mod, - /* [in] */ ULONG32 flagsRaw) + /* [in] */ ULONG32 flags) { HRESULT status; DAC_ENTER(); - _ASSERTE(flagsRaw <= USHRT_MAX); - USHORT flags = (USHORT)flagsRaw; - EX_TRY { status = E_FAIL; @@ -4797,7 +4794,7 @@ ClrDataAccess::SetAllCodeNotifications( PTR_HOST_TO_TADDR(((ClrDataModule*)mod)->GetModule()) : NULL; - if (jn.SetAllNotifications(modulePtr, flags, &changedTable)) + if (jn.SetAllNotifications(modulePtr, (USHORT)flags, &changedTable)) { if (!changedTable || (changedTable && jn.UpdateOutOfProcTable())) diff --git a/src/coreclr/vm/util.cpp b/src/coreclr/vm/util.cpp index 1817a6c1f21086..e635568623d417 100644 --- a/src/coreclr/vm/util.cpp +++ b/src/coreclr/vm/util.cpp @@ -1281,7 +1281,7 @@ BOOL CLRFreeLibrary(HMODULE hModule) GPTR_IMPL(JITNotification, g_pNotificationTable); GVAL_IMPL(ULONG32, g_dacNotificationFlags); -BOOL IsValidMethodCodeNotification(USHORT Notification) +BOOL IsValidMethodCodeNotification(ULONG32 Notification) { // If any bit is on other than that given by a valid combination of flags, no good. if (Notification & ~( diff --git a/src/coreclr/vm/util.hpp b/src/coreclr/vm/util.hpp index 7f6a142b8512bb..51560bb09f758c 100644 --- a/src/coreclr/vm/util.hpp +++ b/src/coreclr/vm/util.hpp @@ -662,7 +662,7 @@ inline bool IsInCantStopRegion() } #endif // _DEBUG -BOOL IsValidMethodCodeNotification(USHORT Notification); +BOOL IsValidMethodCodeNotification(ULONG32 Notification); typedef DPTR(struct JITNotification) PTR_JITNotification; struct JITNotification From a96781f944aac57e791960bb6963de5c1cd9b218 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 15:21:29 -0700 Subject: [PATCH 15/21] Only disable warning on MSVC --- src/native/external/zlib-intel.cmake | 4 +++- src/native/external/zlib.cmake | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/native/external/zlib-intel.cmake b/src/native/external/zlib-intel.cmake index 8353dfa208fc92..c8352de35f2fc7 100644 --- a/src/native/external/zlib-intel.cmake +++ b/src/native/external/zlib-intel.cmake @@ -1,4 +1,6 @@ -add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data +if(MSVC) + add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data +endif(MSVC) set(ZLIB_SOURCES_BASE adler32.c diff --git a/src/native/external/zlib.cmake b/src/native/external/zlib.cmake index 84592d614c582a..ef8a1e1a635b22 100644 --- a/src/native/external/zlib.cmake +++ b/src/native/external/zlib.cmake @@ -1,4 +1,6 @@ -add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data +if(MSVC) + add_compile_options($<$:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data +endif(MSVC) set(ZLIB_SOURCES_BASE adler32.c From 2eb3306cda78fad776ec48dca5c526d7c2c689a6 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 15:21:44 -0700 Subject: [PATCH 16/21] Remove cast and use lambda instead. --- .../tools/superpmi/superpmi-shared/methodcontextreader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp index a0f5ac9040b44a..2f798cd3387e38 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontextreader.cpp @@ -28,7 +28,7 @@ HANDLE MethodContextReader::OpenFile(const char* inputFile, DWORD flags) static std::string to_lower(const std::string& input) { std::string res = input; - std::transform(input.cbegin(), input.cend(), res.begin(), (char(*)(char))tolower); + std::transform(input.cbegin(), input.cend(), res.begin(), [](const char c){ return (char)tolower(c); }); return res; } From eec5def63b1332bd81b8eabbda1431cf272a9f95 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 17:41:07 -0700 Subject: [PATCH 17/21] Fix x86 build. --- src/coreclr/vm/array.cpp | 12 +++++++++--- src/coreclr/vm/comtoclrcall.cpp | 6 +++--- src/coreclr/vm/mlinfo.cpp | 2 +- src/coreclr/vm/pgo.cpp | 12 ++++++------ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/coreclr/vm/array.cpp b/src/coreclr/vm/array.cpp index cae5e2218b0091..402acdb7a53233 100644 --- a/src/coreclr/vm/array.cpp +++ b/src/coreclr/vm/array.cpp @@ -1124,13 +1124,17 @@ void GenerateArrayOpScript(ArrayMethodDesc *pMD, ArrayOpScript *paos) ArgIterator argit(&msig); #ifdef TARGET_X86 - paos->m_cbretpop = argit.CbStackPop(); + UINT stackPop = argit.CbStackPop(); + _ASSERTE(stackPop <= USHRT_MAX); + paos->m_cbretpop = (UINT16)stackPop; #endif if (argit.HasRetBuffArg()) { paos->m_flags |= ArrayOpScript::HASRETVALBUFFER; - paos->m_fRetBufLoc = argit.GetRetBuffArgOffset(); + UINT refBuffOffset = argit.GetRetBuffArgOffset(); + _ASSERTE(refBuffOffset <= USHRT_MAX); + paos->m_fRetBufLoc = (UINT16)refBuffOffset; } if (paos->m_op == ArrayOpScript::LOADADDR) @@ -1149,7 +1153,9 @@ void GenerateArrayOpScript(ArrayMethodDesc *pMD, ArrayOpScript *paos) if (paos->m_op == paos->STORE) { - paos->m_fValLoc = argit.GetNextOffset(); + UINT offset = argit.GetNextOffset(); + _ASSERTE(offset <= USHRT_MAX); + paos->m_fValLoc = (UINT16)offset; } } diff --git a/src/coreclr/vm/comtoclrcall.cpp b/src/coreclr/vm/comtoclrcall.cpp index 0da23d98bdd9a1..6994afdd85c6a0 100644 --- a/src/coreclr/vm/comtoclrcall.cpp +++ b/src/coreclr/vm/comtoclrcall.cpp @@ -1097,7 +1097,7 @@ void ComCallMethodDesc::InitNativeInfo() { // Check to see if this is the parameter after which we need to read the LCID from. if (iArg == iLCIDArg) - nativeArgSize += StackElemSize(sizeof(LCID)); + nativeArgSize += (UINT16)StackElemSize(sizeof(LCID)); MarshalInfo info(msig.GetModule(), msig.GetArgProps(), msig.GetSigTypeContext(), params[iArg], MarshalInfo::MARSHAL_SCENARIO_COMINTEROP, @@ -1110,7 +1110,7 @@ void ComCallMethodDesc::InitNativeInfo() if (info.GetMarshalType() == MarshalInfo::MARSHAL_TYPE_UNKNOWN) { - nativeArgSize += StackElemSize(sizeof(LPVOID)); + nativeArgSize += (UINT16)StackElemSize(sizeof(LPVOID)); m_flags |= enum_HasMarshalError; } else @@ -1125,7 +1125,7 @@ void ComCallMethodDesc::InitNativeInfo() // Check to see if this is the parameter after which we need to read the LCID from. if (iArg == iLCIDArg) - nativeArgSize += StackElemSize(sizeof(LCID)); + nativeArgSize += (UINT16)StackElemSize(sizeof(LCID)); #endif // TARGET_X86 diff --git a/src/coreclr/vm/mlinfo.cpp b/src/coreclr/vm/mlinfo.cpp index 04d72cbb1f45e5..471cbb1165aaf6 100644 --- a/src/coreclr/vm/mlinfo.cpp +++ b/src/coreclr/vm/mlinfo.cpp @@ -2905,7 +2905,7 @@ void MarshalInfo::GenerateReturnIL(NDirectStubLinker* psl, // structure and 4-byte structure. The former is supposed to be returned by-ref using a secret argument // (at least in MSVC compiled code) while the latter is returned in EAX. We are keeping the behavior for // now for backward compatibility. - X86_ONLY(wNativeSize = StackElemSize(wNativeSize)); + X86_ONLY(wNativeSize = (UINT16)StackElemSize(wNativeSize)); pMarshaler->EmitMarshalReturnValue(pcsMarshal, pcsUnmarshal, pcsDispatch, m_paramidx + argOffset, wNativeSize, dwMarshalFlags, &m_args); diff --git a/src/coreclr/vm/pgo.cpp b/src/coreclr/vm/pgo.cpp index 17995635953297..9f2876292fce29 100644 --- a/src/coreclr/vm/pgo.cpp +++ b/src/coreclr/vm/pgo.cpp @@ -20,7 +20,7 @@ // // In the current implementation, the method stable hash code isn't a good replacement for "token" as it doesn't // carry any detail about signatures, and is probably quite slow to compute -// The plan is to swap over to the typenamehash +// The plan is to swap over to the typenamehash // Goals // 1. Need to be able to walk at any time. @@ -121,7 +121,7 @@ class SchemaWriterFunctor auto lambda = [&](int64_t thWritten) { - if (ICorJitInfo::IsUnknownTypeHandle(thWritten)) return; + if (ICorJitInfo::IsUnknownTypeHandle((intptr_t)thWritten)) return; if (thWritten != 0) { @@ -291,7 +291,7 @@ void ReadLineAndDiscard(FILE* file) auto stringLen = strlen(buffer); if (stringLen == 0) return; - + if (buffer[stringLen - 1] == '\n') { return; @@ -387,7 +387,7 @@ void PgoManager::ReadPgoData() // Read schema ICorJitInfo::PgoInstrumentationSchema schema; - + if (sscanf_s(buffer, s_RecordString, &schema.InstrumentationKind, &schema.ILOffset, &schema.Count, &schema.Other) != 4) { failed = true; @@ -639,7 +639,7 @@ HRESULT PgoManager::allocPgoInstrumentationBySchemaInstance(MethodDesc* pMD, } S_SIZE_T allocationSize = S_SIZE_T(sizeof(HeaderList)) + S_SIZE_T(pSchema[countSchemaItems - 1].Offset) + S_SIZE_T(pSchema[countSchemaItems - 1].Count) * S_SIZE_T(InstrumentationKindToSize(pSchema[countSchemaItems - 1].InstrumentationKind)); - + if (allocationSize.IsOverflow()) { return E_NOTIMPL; @@ -1020,7 +1020,7 @@ HRESULT PgoManager::getPgoInstrumentationResultsInstance(MethodDesc* pMD, BYTE** *pCountSchemaItems = schemaArray.GetCount(); memcpy(*pAllocatedData, schemaArray.OpenRawBuffer(), schemaDataSize); schemaArray.CloseRawBuffer(); - + size_t* pInstrumentationDataDst = (size_t*)((*pAllocatedData) + schemaDataSize); size_t* pInstrumentationDataDstEnd = (size_t*)((*pAllocatedData) + schemaDataSize + instrumentationDataSize); *pInstrumentationData = (BYTE*)pInstrumentationDataDst; From 1b6ab1cf65344b87d1e88aeaa9f3db81037cd89a Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 17:41:30 -0700 Subject: [PATCH 18/21] Revert update to C enum. --- src/native/eventpipe/ep-stream.c | 2 +- src/native/eventpipe/ep-stream.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/eventpipe/ep-stream.c b/src/native/eventpipe/ep-stream.c index 6ee479407f4ff8..3f3551674dd444 100644 --- a/src/native/eventpipe/ep-stream.c +++ b/src/native/eventpipe/ep-stream.c @@ -262,7 +262,7 @@ ep_fast_serializer_write_tag ( const uint8_t *payload, uint32_t payload_len) { - uint8_t tag_as_byte = tag; + uint8_t tag_as_byte = (uint8_t)tag; ep_fast_serializer_write_buffer (fast_serializer, &tag_as_byte, sizeof (tag_as_byte)); if (payload != NULL) { EP_ASSERT (payload_len > 0); diff --git a/src/native/eventpipe/ep-stream.h b/src/native/eventpipe/ep-stream.h index 9bd8651c2ff647..c4b3dee44e21b8 100644 --- a/src/native/eventpipe/ep-stream.h +++ b/src/native/eventpipe/ep-stream.h @@ -14,7 +14,7 @@ // the enumeration has a specific set of values to keep it compatible with consumer library // it's sibling is defined in https://github.com/Microsoft/perfview/blob/10d1f92b242c98073b3817ac5ee6d98cd595d39b/src/FastSerialization/FastSerialization.cs#L2295 -typedef enum : uint8_t +typedef enum { FAST_SERIALIZER_TAGS_ERROR = 0, // To improve debugabilty, 0 is an illegal tag. FAST_SERIALIZER_TAGS_NULL_REFERENCE = 1, // Tag for a null object forwardReference. From 2d82d920a4b77d74ae714e8ff46e9a48ed27d688 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 27 Apr 2022 17:48:14 -0700 Subject: [PATCH 19/21] Rely on the existing argument validation. --- src/coreclr/debug/daccess/task.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index 300a1ee9c29583..d27b8044aa71e6 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -3428,15 +3428,12 @@ ClrDataMethodDefinition::GetCodeNotification( HRESULT STDMETHODCALLTYPE ClrDataMethodDefinition::SetCodeNotification( - /* [in] */ ULONG32 flagsRaw) + /* [in] */ ULONG32 flags) { HRESULT status; DAC_ENTER_SUB(m_dac); - _ASSERTE(flagsRaw <= USHRT_MAX); - USHORT flags = (USHORT)flagsRaw; - EX_TRY { if (!IsValidMethodCodeNotification(flags)) @@ -3462,7 +3459,7 @@ ClrDataMethodDefinition::SetCodeNotification( } else { - if (jn.SetNotification(modulePtr, m_token, flags) && + if (jn.SetNotification(modulePtr, m_token, (USHORT)flags) && jn.UpdateOutOfProcTable()) { // new notification added From 654bb741843afef2bbf47815068380b3f4098982 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Sat, 30 Apr 2022 07:15:14 -0700 Subject: [PATCH 20/21] Remove casting around argument checking routine. --- src/coreclr/debug/daccess/daccess.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 628c7674eec489..8dc03c6c43c1b1 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -4981,15 +4981,14 @@ ClrDataAccess::SetCodeNotifications( { for (ULONG32 check = 0; check < numTokens; check++) { - _ASSERTE(flags[check] <= USHRT_MAX); - if (!IsValidMethodCodeNotification((USHORT)flags[check])) + if (!IsValidMethodCodeNotification(flags[check])) { status = E_INVALIDARG; goto Exit; } } } - else if (!IsValidMethodCodeNotification((USHORT)singleFlags)) + else if (!IsValidMethodCodeNotification(singleFlags)) { status = E_INVALIDARG; goto Exit; From cbb26f4ae25b78aa91d6a0fea8d9562b93e1eec2 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 4 May 2022 08:25:12 -0700 Subject: [PATCH 21/21] Fix build breaks on 32-bit. --- src/coreclr/inc/pgo_formatprocessing.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreclr/inc/pgo_formatprocessing.h b/src/coreclr/inc/pgo_formatprocessing.h index d761ad6bcbe483..d1c77c9e79a44f 100644 --- a/src/coreclr/inc/pgo_formatprocessing.h +++ b/src/coreclr/inc/pgo_formatprocessing.h @@ -92,7 +92,7 @@ bool ReadCompressedInts(const uint8_t *pByte, size_t cbDataMax, IntHandler intPr { if (cbDataMax < 2) return false; - + int shiftedInt = ((*pByte & 0x3f) << 8) | *(pByte + 1); signedInt = shiftedInt >> 1; if (shiftedInt & 1) @@ -206,7 +206,7 @@ bool ReadInstrumentationSchema(const uint8_t *pByte, size_t cbDataMax, SchemaHan { ProcessSchemaUpdateFunctor schemaHandlerUpdate; bool done = false; - + ReadCompressedInts(pByte, cbDataMax, [&handler, &schemaHandlerUpdate, &done](int64_t curValue) { if (schemaHandlerUpdate.ProcessInteger((int32_t)curValue)) @@ -237,7 +237,7 @@ bool ReadInstrumentationData(const uint8_t *pByte, size_t cbDataMax, SchemaAndDa int64_t lastTypeDataValue = 0; int64_t lastMethodDataValue = 0; int32_t dataCountToRead = 0; - + ReadCompressedInts(pByte, cbDataMax, [&](int64_t curValue) { if (dataCountToRead > 0) @@ -311,11 +311,11 @@ inline bool CountInstrumentationDataSize(const uint8_t *pByte, size_t cbDataMax, inline bool ComparePgoSchemaEquals(const uint8_t *pByte, size_t cbDataMax, const ICorJitInfo::PgoInstrumentationSchema* schemaTable, size_t cSchemas) { size_t iSchema = 0; - return ReadInstrumentationSchema(pByte, cbDataMax, [schemaTable, cSchemas, &iSchema](const ICorJitInfo::PgoInstrumentationSchema& schema) + return ReadInstrumentationSchema(pByte, cbDataMax, [schemaTable, cSchemas, &iSchema](const ICorJitInfo::PgoInstrumentationSchema& schema) { if (iSchema >= cSchemas) return false; - + if (schema.InstrumentationKind != schemaTable[iSchema].InstrumentationKind) return false; @@ -571,7 +571,7 @@ class SchemaAndDataWriter logicalDataToWrite = *(volatile intptr_t*)pData; // As there could be tearing otherwise, inform the caller of exactly what value was written. - thProcessor(logicalDataToWrite); + thProcessor((intptr_t)logicalDataToWrite); bool returnValue = WriteCompressedIntToBytes(logicalDataToWrite - lastTypeDataWritten, byteWriter); lastTypeDataWritten = logicalDataToWrite; @@ -585,7 +585,7 @@ class SchemaAndDataWriter logicalDataToWrite = *(volatile intptr_t*)pData; // As there could be tearing otherwise, inform the caller of exactly what value was written. - mhProcessor(logicalDataToWrite); + mhProcessor((intptr_t)logicalDataToWrite); bool returnValue = WriteCompressedIntToBytes(logicalDataToWrite - lastMethodDataWritten, byteWriter); lastMethodDataWritten = logicalDataToWrite;