Skip to content

Commit 46b3abe

Browse files
authored
Reenable disabled nativeaot warnings and fix the issues (#95698)
Mostly missing explicit access modifiers. Use string.Contains() in XplatEventLogger.cs instead of string.IndexOf() Use sequential StructLayout in TransitionBlock instead
1 parent 7847872 commit 46b3abe

File tree

47 files changed

+202
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+202
-224
lines changed

src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<EnableDefaultItems>false</EnableDefaultItems>
@@ -47,7 +47,7 @@
4747
<InformationalVersion Condition="'$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
4848
<InformationalVersion Condition="'$(StabilizePackageVersion)' == 'true'">$(ProductVersion)</InformationalVersion>
4949
<!-- AD0001 : https://github.com/dotnet/runtime/issues/90356 -->
50-
<NoWarn>$(NoWarn),0419,0649,CA2249,CA1830;AD0001</NoWarn>
50+
<NoWarn>$(NoWarn),0419,0649;AD0001</NoWarn>
5151
<Nullable>enable</Nullable>
5252

5353
<!-- Ignore all previous constants since SPCL is sensitive to what is defined and the Sdk adds some by default -->

src/coreclr/nativeaot/Common/src/Internal/Runtime/TransitionBlock.cs

+116-114
Original file line numberDiff line numberDiff line change
@@ -44,65 +44,67 @@
4444
// provided with information mapping that argument into registers and/or stack locations.
4545

4646
using System;
47+
using System.Runtime.InteropServices;
4748

4849
namespace Internal.Runtime
4950
{
5051
#if TARGET_AMD64
51-
#pragma warning disable 0169
5252
#if UNIX_AMD64_ABI
53-
struct ReturnBlock
53+
[StructLayout(LayoutKind.Sequential)]
54+
internal struct ReturnBlock
5455
{
55-
IntPtr returnValue;
56-
IntPtr returnValue2;
56+
private IntPtr returnValue;
57+
private IntPtr returnValue2;
5758
}
5859

59-
struct ArgumentRegisters
60+
[StructLayout(LayoutKind.Sequential)]
61+
internal struct ArgumentRegisters
6062
{
61-
IntPtr rdi;
62-
IntPtr rsi;
63-
IntPtr rdx;
64-
IntPtr rcx;
65-
IntPtr r8;
66-
IntPtr r9;
63+
private IntPtr rdi;
64+
private IntPtr rsi;
65+
private IntPtr rdx;
66+
private IntPtr rcx;
67+
private IntPtr r8;
68+
private IntPtr r9;
6769
}
6870
#else // UNIX_AMD64_ABI
69-
struct ReturnBlock
71+
[StructLayout(LayoutKind.Sequential)]
72+
internal struct ReturnBlock
7073
{
71-
IntPtr returnValue;
74+
private IntPtr returnValue;
7275
}
7376

74-
struct ArgumentRegisters
77+
[StructLayout(LayoutKind.Sequential)]
78+
internal struct ArgumentRegisters
7579
{
76-
IntPtr rdx;
77-
IntPtr rcx;
78-
IntPtr r8;
79-
IntPtr r9;
80+
private IntPtr rdx;
81+
private IntPtr rcx;
82+
private IntPtr r8;
83+
private IntPtr r9;
8084
}
8185
#endif // UNIX_AMD64_ABI
82-
#pragma warning restore 0169
83-
84-
#pragma warning disable 0169
85-
struct M128A
86+
[StructLayout(LayoutKind.Sequential)]
87+
internal struct M128A
8688
{
87-
IntPtr a;
88-
IntPtr b;
89+
private IntPtr a;
90+
private IntPtr b;
8991
}
90-
struct FloatArgumentRegisters
92+
[StructLayout(LayoutKind.Sequential)]
93+
internal struct FloatArgumentRegisters
9194
{
92-
M128A d0;
93-
M128A d1;
94-
M128A d2;
95-
M128A d3;
95+
private M128A d0;
96+
private M128A d1;
97+
private M128A d2;
98+
private M128A d3;
9699
#if UNIX_AMD64_ABI
97-
M128A d4;
98-
M128A d5;
99-
M128A d6;
100-
M128A d7;
100+
private M128A d4;
101+
private M128A d5;
102+
private M128A d6;
103+
private M128A d7;
101104
#endif
102105
}
103-
#pragma warning restore 0169
104106

105-
struct ArchitectureConstants
107+
internal struct ArchitectureConstants
106108
{
107109
// To avoid corner case bugs, limit maximum size of the arguments with sufficient margin
108110
public const int MAX_ARG_SIZE = 0xFFFFFF;
@@ -121,48 +123,47 @@ struct ArchitectureConstants
121123
public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); }
122124
}
123125
#elif TARGET_ARM64
124-
#pragma warning disable 0169
125-
struct ReturnBlock
126+
[StructLayout(LayoutKind.Sequential)]
127+
internal struct ReturnBlock
126128
{
127-
IntPtr returnValue;
128-
IntPtr returnValue2;
129-
IntPtr returnValue3;
130-
IntPtr returnValue4;
129+
private IntPtr returnValue;
130+
private IntPtr returnValue2;
131+
private IntPtr returnValue3;
132+
private IntPtr returnValue4;
131133
}
132134

133-
struct ArgumentRegisters
135+
[StructLayout(LayoutKind.Sequential)]
136+
internal struct ArgumentRegisters
134137
{
135-
IntPtr x0;
136-
IntPtr x1;
137-
IntPtr x2;
138-
IntPtr x3;
139-
IntPtr x4;
140-
IntPtr x5;
141-
IntPtr x6;
142-
IntPtr x7;
143-
IntPtr x8;
138+
private IntPtr x0;
139+
private IntPtr x1;
140+
private IntPtr x2;
141+
private IntPtr x3;
142+
private IntPtr x4;
143+
private IntPtr x5;
144+
private IntPtr x6;
145+
private IntPtr x7;
146+
private IntPtr x8;
144147
public static unsafe int GetOffsetOfx8()
145148
{
146149
return sizeof(IntPtr) * 8;
147150
}
148151
}
149-
#pragma warning restore 0169
150152

151-
#pragma warning disable 0169
152-
struct FloatArgumentRegisters
153+
[StructLayout(LayoutKind.Sequential)]
154+
internal struct FloatArgumentRegisters
153155
{
154-
double d0;
155-
double d1;
156-
double d2;
157-
double d3;
158-
double d4;
159-
double d5;
160-
double d6;
161-
double d7;
156+
private double d0;
157+
private double d1;
158+
private double d2;
159+
private double d3;
160+
private double d4;
161+
private double d5;
162+
private double d6;
163+
private double d7;
162164
}
163-
#pragma warning restore 0169
164165

165-
struct ArchitectureConstants
166+
internal struct ArchitectureConstants
166167
{
167168
// To avoid corner case bugs, limit maximum size of the arguments with sufficient margin
168169
public const int MAX_ARG_SIZE = 0xFFFFFF;
@@ -177,14 +178,15 @@ struct ArchitectureConstants
177178
public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); }
178179
}
179180
#elif TARGET_X86
180-
#pragma warning disable 0169, 0649
181-
struct ReturnBlock
181+
[StructLayout(LayoutKind.Sequential)]
182+
internal struct ReturnBlock
182183
{
183184
public IntPtr returnValue;
184185
public IntPtr returnValue2;
185186
}
186187

187-
struct ArgumentRegisters
188+
[StructLayout(LayoutKind.Sequential)]
189+
internal struct ArgumentRegisters
188190
{
189191
public IntPtr edx;
190192
public static unsafe int GetOffsetOfEdx()
@@ -198,12 +200,12 @@ public static unsafe int GetOffsetOfEcx()
198200
}
199201
}
200202
// This struct isn't used by x86, but exists for compatibility with the definition of the CallDescrData struct
201-
struct FloatArgumentRegisters
203+
[StructLayout(LayoutKind.Sequential)]
204+
internal struct FloatArgumentRegisters
202205
{
203206
}
204-
#pragma warning restore 0169, 0649
205207

206-
struct ArchitectureConstants
208+
internal struct ArchitectureConstants
207209
{
208210
// To avoid corner case bugs, limit maximum size of the arguments with sufficient margin
209211
public const int MAX_ARG_SIZE = 0xFFFFFF;
@@ -217,41 +219,42 @@ struct ArchitectureConstants
217219
public static int StackElemSize(int size) { return (((size) + STACK_ELEM_SIZE - 1) & ~(STACK_ELEM_SIZE - 1)); }
218220
}
219221
#elif TARGET_ARM
220-
#pragma warning disable 0169
221-
struct ReturnBlock
222+
[StructLayout(LayoutKind.Sequential)]
223+
internal struct ReturnBlock
222224
{
223-
IntPtr returnValue;
224-
IntPtr returnValue2;
225-
IntPtr returnValue3;
226-
IntPtr returnValue4;
227-
IntPtr returnValue5;
228-
IntPtr returnValue6;
229-
IntPtr returnValue7;
230-
IntPtr returnValue8;
225+
private IntPtr returnValue;
226+
private IntPtr returnValue2;
227+
private IntPtr returnValue3;
228+
private IntPtr returnValue4;
229+
private IntPtr returnValue5;
230+
private IntPtr returnValue6;
231+
private IntPtr returnValue7;
232+
private IntPtr returnValue8;
231233
}
232234

233-
struct ArgumentRegisters
235+
[StructLayout(LayoutKind.Sequential)]
236+
internal struct ArgumentRegisters
234237
{
235-
IntPtr r0;
236-
IntPtr r1;
237-
IntPtr r2;
238-
IntPtr r3;
238+
private IntPtr r0;
239+
private IntPtr r1;
240+
private IntPtr r2;
241+
private IntPtr r3;
239242
}
240243

241-
struct FloatArgumentRegisters
244+
[StructLayout(LayoutKind.Sequential)]
245+
internal struct FloatArgumentRegisters
242246
{
243-
double d0;
244-
double d1;
245-
double d2;
246-
double d3;
247-
double d4;
248-
double d5;
249-
double d6;
250-
double d7;
247+
private double d0;
248+
private double d1;
249+
private double d2;
250+
private double d3;
251+
private double d4;
252+
private double d5;
253+
private double d6;
254+
private double d7;
251255
}
252-
#pragma warning restore 0169
253256

254-
struct ArchitectureConstants
257+
internal struct ArchitectureConstants
255258
{
256259
// To avoid corner case bugs, limit maximum size of the arguments with sufficient margin
257260
public const int MAX_ARG_SIZE = 0xFFFFFF;
@@ -266,24 +269,25 @@ struct ArchitectureConstants
266269
}
267270

268271
#elif TARGET_WASM
269-
#pragma warning disable 0169
270-
struct ReturnBlock
272+
[StructLayout(LayoutKind.Sequential)]
273+
internal struct ReturnBlock
271274
{
272-
IntPtr returnValue;
275+
private IntPtr returnValue;
273276
}
274277

275-
struct ArgumentRegisters
278+
[StructLayout(LayoutKind.Sequential)]
279+
internal struct ArgumentRegisters
276280
{
277281
// No registers on WASM
278282
}
279283

280-
struct FloatArgumentRegisters
284+
[StructLayout(LayoutKind.Sequential)]
285+
internal struct FloatArgumentRegisters
281286
{
282287
// No registers on WASM
283288
}
284-
#pragma warning restore 0169
285289

286-
struct ArchitectureConstants
290+
internal struct ArchitectureConstants
287291
{
288292
// To avoid corner case bugs, limit maximum size of the arguments with sufficient margin
289293
public const int MAX_ARG_SIZE = 0xFFFFFF;
@@ -302,10 +306,9 @@ struct ArchitectureConstants
302306
// TransitionBlock is layout of stack frame of method call, saved argument registers and saved callee saved registers. Even though not
303307
// all fields are used all the time, we use uniform form for simplicity.
304308
//
309+
[StructLayout(LayoutKind.Sequential)]
305310
internal struct TransitionBlock
306311
{
307-
#pragma warning disable 0169,0649
308-
309312
#if TARGET_X86
310313
public ArgumentRegisters m_argumentRegisters;
311314
public static unsafe int GetOffsetOfArgumentRegisters()
@@ -317,8 +320,8 @@ public static unsafe int GetOffsetOfReturnValuesBlock()
317320
{
318321
return sizeof(ArgumentRegisters);
319322
}
320-
IntPtr m_ebp;
321-
IntPtr m_ReturnAddress;
323+
private IntPtr m_ebp;
324+
private IntPtr m_ReturnAddress;
322325
#elif TARGET_AMD64
323326

324327
#if UNIX_AMD64_ABI
@@ -334,17 +337,17 @@ public static unsafe int GetOffsetOfArgumentRegisters()
334337
return sizeof(ReturnBlock);
335338
}
336339

337-
IntPtr m_alignmentPadding;
338-
IntPtr m_ReturnAddress;
340+
private IntPtr m_alignmentPadding;
341+
private IntPtr m_ReturnAddress;
339342
#else // UNIX_AMD64_ABI
340-
IntPtr m_returnBlockPadding;
341-
ReturnBlock m_returnBlock;
343+
private IntPtr m_returnBlockPadding;
344+
public ReturnBlock m_returnBlock;
342345
public static unsafe int GetOffsetOfReturnValuesBlock()
343346
{
344347
return sizeof(IntPtr);
345348
}
346-
IntPtr m_alignmentPadding;
347-
IntPtr m_ReturnAddress;
349+
private IntPtr m_alignmentPadding;
350+
private IntPtr m_ReturnAddress;
348351
public static unsafe int GetOffsetOfArgumentRegisters()
349352
{
350353
return sizeof(TransitionBlock);
@@ -392,7 +395,6 @@ public static unsafe int GetOffsetOfArgumentRegisters()
392395
#else
393396
#error Portability problem
394397
#endif
395-
#pragma warning restore 0169, 0649
396398

397399
// The transition block should define everything pushed by callee. The code assumes in number of places that
398400
// end of the transition block is caller's stack pointer.

src/coreclr/nativeaot/Common/src/Internal/Runtime/TypeLoader/ExternalReferencesTable.cs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
namespace Internal.Runtime.TypeLoader
99
{
10+
#if TYPE_LOADER_IMPLEMENTATION
11+
public
12+
#else
13+
internal
14+
#endif
1015
partial struct ExternalReferencesTable
1116
{
1217
private IntPtr _elements;

0 commit comments

Comments
 (0)