Skip to content

Commit ade8322

Browse files
authored
[runtime] Adopt safer native compiler flags: Wmissing-field-initializers (#24071)
Example warning: ``` In file included from macios/appex-deduplicate-frameworks/macios/runtime/runtime.m:98: macios/runtime/delegates.inc:189:41: error: missing field 'register_assembly' initializer [-Werror,-Wmissing-field-initializers] 189 | static struct Delegates delegates = { 0 }; | ^ ``` References: * https://developer.apple.com/documentation/xcode/enabling-enhanced-security-for-your-app * https://releases.llvm.org/8.0.0/tools/clang/docs/ReleaseNotes.html#major-new-features (for -ftrivial-auto-var-init=zero) Contributes towards #23023.
1 parent 53f7714 commit ade8322

File tree

6 files changed

+11
-16
lines changed

6 files changed

+11
-16
lines changed

mk/rules.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CFLAGS=\
3737
-fdiagnostics-absolute-paths \
3838
-Wno-objc-protocol-property-synthesis \
3939
-Wignored-qualifiers \
40+
-Wmissing-field-initializers \
4041
-g \
4142
-I.
4243
SWIFTFLAGS=-g -emit-library

runtime/coreclr-bridge.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@
425425
return NULL;
426426
}
427427

428-
struct stat stat_buf = { 0 };
428+
struct stat stat_buf = { };
429429
if (fstat (fd, &stat_buf) == -1) {
430430
LOG (PRODUCT ": Could not stat the runtime config file '%s' in the app bundle: %s\n", path, strerror (errno));
431431
close (fd);

runtime/delegates.inc.t4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Delegates {
2525
<# } #>
2626
};
2727

28-
static struct Delegates delegates = { 0 };
28+
static struct Delegates delegates = { };
2929

3030
static GCHandle
3131
create_linked_away_exception (const char *func)

runtime/runtime.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
(void *) &xamarin_get_nsobject_data_trampoline,
187187
};
188188

189-
static struct InitializationOptions options = { 0 };
189+
static struct InitializationOptions options = { };
190190

191191
#if !defined (CORECLR_RUNTIME)
192192
void

runtime/trampolines.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@
905905

906906
pthread_mutex_lock (&gchandle_hash_lock);
907907
if (gchandle_hash == NULL) {
908-
CFDictionaryValueCallBacks value_callbacks = { 0 };
908+
CFDictionaryValueCallBacks value_callbacks = { };
909909
value_callbacks.release = release_gchandle_dictionary_entry;
910910
gchandle_hash = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, NULL, &value_callbacks);
911911
}
@@ -1411,7 +1411,7 @@
14111411
element_class = e_class;
14121412
}
14131413

1414-
struct conversion_data data = { 0 };
1414+
struct conversion_data data = { };
14151415
data.domain = mono_domain_get ();
14161416
data.element_class = element_class;
14171417
data.element_type = mono_class_get_type (data.element_class);
@@ -1437,7 +1437,7 @@
14371437
element_class = e_class;
14381438
}
14391439

1440-
struct conversion_data data = { 0 };
1440+
struct conversion_data data = { };
14411441
data.domain = mono_domain_get ();
14421442
data.element_class = element_class;
14431443
data.element_type = mono_class_get_type (data.element_class);
@@ -1463,7 +1463,7 @@
14631463
element_class = e_class;
14641464
}
14651465

1466-
struct conversion_data data = { 0 };
1466+
struct conversion_data data = { };
14671467
data.element_class = element_class;
14681468
data.element_type = mono_class_get_type (data.element_class);
14691469
data.iface_token_ref = iface_token_ref;

tools/common/StaticRegistrar.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@ void Specialize (AutoIndentStringBuilder sb, out string initialization_method)
31073107
sb.WriteLine ();
31083108
}
31093109

3110-
map.AppendLine ("{ NULL, 0 },");
3110+
map.AppendLine ("{ NULL, 0, 0 },");
31113111
map.AppendLine ("};");
31123112
map.AppendLine ();
31133113

@@ -4342,14 +4342,8 @@ void SpecializePrepareReturnValue (AutoIndentStringBuilder sb, ObjCMethod method
43424342
if (isVoid)
43434343
return;
43444344

4345-
switch (rettype) {
4346-
case "CGRect":
4347-
body_setup.AppendLine ("{0} res = {{{{0}}}};", rettype);
4348-
break;
4349-
default:
4350-
body_setup.AppendLine ("{0} res = {{0}};", rettype);
4351-
break;
4352-
}
4345+
body_setup.AppendLine ("{0} res = {{ }};", rettype);
4346+
43534347
var isArray = returntype is ArrayType;
43544348
var type = returntype.Resolve () ?? returntype;
43554349
var retain = method.RetainReturnValue;

0 commit comments

Comments
 (0)