authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2024-08-11 13:03:19+01:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2024-08-12 00:36:51+01:00
log4ef956ef140a1c8cf606cd9b6a9606c0a85bf934
tree681414566bb7b57ba50e0a6182336040ef184d6b
parentfd434fcd3802cd51778cfc44bde8e6ff83f808bd

std.Target: Rename c_type_* functions to camel case

From https://ziglang.org/documentation/master/#Names: > If `x` is otherwise callable, then `x` should be `camelCase`.

11 files changed, 109 insertions(+), 109 deletions(-)

lib/compiler/aro/aro/Parser.zig+3-3
...@@ -5631,15 +5631,15 @@ pub const Result = struct {...@@ -5631,15 +5631,15 @@ pub const Result = struct {
5631 };5631 };
5632 const a_spec = a.ty.canonicalize(.standard).specifier;5632 const a_spec = a.ty.canonicalize(.standard).specifier;
5633 const b_spec = b.ty.canonicalize(.standard).specifier;5633 const b_spec = b.ty.canonicalize(.standard).specifier;
5634 if (p.comp.target.c_type_bit_size(.longdouble) == 128) {5634 if (p.comp.target.cTypeBitSize(.longdouble) == 128) {
5635 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;5635 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
5636 }5636 }
5637 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[1])) return;5637 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[1])) return;
5638 if (p.comp.target.c_type_bit_size(.longdouble) == 80) {5638 if (p.comp.target.cTypeBitSize(.longdouble) == 80) {
5639 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;5639 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
5640 }5640 }
5641 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[2])) return;5641 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[2])) return;
5642 if (p.comp.target.c_type_bit_size(.longdouble) == 64) {5642 if (p.comp.target.cTypeBitSize(.longdouble) == 64) {
5643 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;5643 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
5644 }5644 }
5645 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[3])) return;5645 if (try a.floatConversion(b, a_spec, b_spec, p, float_types[3])) return;
lib/compiler/aro/aro/Type.zig+23-23
...@@ -991,19 +991,19 @@ pub fn sizeof(ty: Type, comp: *const Compilation) ?u64 {...@@ -991,19 +991,19 @@ pub fn sizeof(ty: Type, comp: *const Compilation) ?u64 {
991 .incomplete_array => return if (comp.langopts.emulate == .msvc) @as(?u64, 0) else null,991 .incomplete_array => return if (comp.langopts.emulate == .msvc) @as(?u64, 0) else null,
992 .func, .var_args_func, .old_style_func, .void, .bool => 1,992 .func, .var_args_func, .old_style_func, .void, .bool => 1,
993 .char, .schar, .uchar => 1,993 .char, .schar, .uchar => 1,
994 .short => comp.target.c_type_byte_size(.short),994 .short => comp.target.cTypeByteSize(.short),
995 .ushort => comp.target.c_type_byte_size(.ushort),995 .ushort => comp.target.cTypeByteSize(.ushort),
996 .int => comp.target.c_type_byte_size(.int),996 .int => comp.target.cTypeByteSize(.int),
997 .uint => comp.target.c_type_byte_size(.uint),997 .uint => comp.target.cTypeByteSize(.uint),
998 .long => comp.target.c_type_byte_size(.long),998 .long => comp.target.cTypeByteSize(.long),
999 .ulong => comp.target.c_type_byte_size(.ulong),999 .ulong => comp.target.cTypeByteSize(.ulong),
1000 .long_long => comp.target.c_type_byte_size(.longlong),1000 .long_long => comp.target.cTypeByteSize(.longlong),
1001 .ulong_long => comp.target.c_type_byte_size(.ulonglong),1001 .ulong_long => comp.target.cTypeByteSize(.ulonglong),
1002 .long_double => comp.target.c_type_byte_size(.longdouble),1002 .long_double => comp.target.cTypeByteSize(.longdouble),
1003 .int128, .uint128 => 16,1003 .int128, .uint128 => 16,
1004 .fp16, .float16 => 2,1004 .fp16, .float16 => 2,
1005 .float => comp.target.c_type_byte_size(.float),1005 .float => comp.target.cTypeByteSize(.float),
1006 .double => comp.target.c_type_byte_size(.double),1006 .double => comp.target.cTypeByteSize(.double),
1007 .float80 => 16,1007 .float80 => 16,
1008 .float128 => 16,1008 .float128 => 16,
1009 .bit_int => {1009 .bit_int => {
...@@ -1049,7 +1049,7 @@ pub fn bitSizeof(ty: Type, comp: *const Compilation) ?u64 {...@@ -1049,7 +1049,7 @@ pub fn bitSizeof(ty: Type, comp: *const Compilation) ?u64 {
1049 .typeof_expr => ty.data.expr.ty.bitSizeof(comp),1049 .typeof_expr => ty.data.expr.ty.bitSizeof(comp),
1050 .attributed => ty.data.attributed.base.bitSizeof(comp),1050 .attributed => ty.data.attributed.base.bitSizeof(comp),
1051 .bit_int => return ty.data.int.bits,1051 .bit_int => return ty.data.int.bits,
1052 .long_double => comp.target.c_type_bit_size(.longdouble),1052 .long_double => comp.target.cTypeBitSize(.longdouble),
1053 .float80 => return 80,1053 .float80 => return 80,
1054 else => 8 * (ty.sizeof(comp) orelse return null),1054 else => 8 * (ty.sizeof(comp) orelse return null),
1055 };1055 };
...@@ -1104,24 +1104,24 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {...@@ -1104,24 +1104,24 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {
1104 => return ty.makeReal().alignof(comp),1104 => return ty.makeReal().alignof(comp),
1105 // zig fmt: on1105 // zig fmt: on
11061106
1107 .short => comp.target.c_type_alignment(.short),1107 .short => comp.target.cTypeAlignment(.short),
1108 .ushort => comp.target.c_type_alignment(.ushort),1108 .ushort => comp.target.cTypeAlignment(.ushort),
1109 .int => comp.target.c_type_alignment(.int),1109 .int => comp.target.cTypeAlignment(.int),
1110 .uint => comp.target.c_type_alignment(.uint),1110 .uint => comp.target.cTypeAlignment(.uint),
11111111
1112 .long => comp.target.c_type_alignment(.long),1112 .long => comp.target.cTypeAlignment(.long),
1113 .ulong => comp.target.c_type_alignment(.ulong),1113 .ulong => comp.target.cTypeAlignment(.ulong),
1114 .long_long => comp.target.c_type_alignment(.longlong),1114 .long_long => comp.target.cTypeAlignment(.longlong),
1115 .ulong_long => comp.target.c_type_alignment(.ulonglong),1115 .ulong_long => comp.target.cTypeAlignment(.ulonglong),
11161116
1117 .bit_int => @min(1117 .bit_int => @min(
1118 std.math.ceilPowerOfTwoPromote(u16, (ty.data.int.bits + 7) / 8),1118 std.math.ceilPowerOfTwoPromote(u16, (ty.data.int.bits + 7) / 8),
1119 16, // comp.target.maxIntAlignment(), please use your own logic for this value as it is implementation-defined1119 16, // comp.target.maxIntAlignment(), please use your own logic for this value as it is implementation-defined
1120 ),1120 ),
11211121
1122 .float => comp.target.c_type_alignment(.float),1122 .float => comp.target.cTypeAlignment(.float),
1123 .double => comp.target.c_type_alignment(.double),1123 .double => comp.target.cTypeAlignment(.double),
1124 .long_double => comp.target.c_type_alignment(.longdouble),1124 .long_double => comp.target.cTypeAlignment(.longdouble),
11251125
1126 .int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.isGnu()) 8 else 16,1126 .int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.isGnu()) 8 else 16,
1127 .fp16, .float16 => 2,1127 .fp16, .float16 => 2,
lib/compiler/aro/aro/target.zig+2-2
...@@ -306,7 +306,7 @@ pub const FPSemantics = enum {...@@ -306,7 +306,7 @@ pub const FPSemantics = enum {
306 /// Only intended for generating float.h macros for the preprocessor306 /// Only intended for generating float.h macros for the preprocessor
307 pub fn forType(ty: std.Target.CType, target: std.Target) FPSemantics {307 pub fn forType(ty: std.Target.CType, target: std.Target) FPSemantics {
308 std.debug.assert(ty == .float or ty == .double or ty == .longdouble);308 std.debug.assert(ty == .float or ty == .double or ty == .longdouble);
309 return switch (target.c_type_bit_size(ty)) {309 return switch (target.cTypeBitSize(ty)) {
310 32 => .IEEESingle,310 32 => .IEEESingle,
311 64 => .IEEEDouble,311 64 => .IEEEDouble,
312 80 => .x87ExtendedDouble,312 80 => .x87ExtendedDouble,
...@@ -350,7 +350,7 @@ pub const FPSemantics = enum {...@@ -350,7 +350,7 @@ pub const FPSemantics = enum {
350};350};
351351
352pub fn isLP64(target: std.Target) bool {352pub fn isLP64(target: std.Target) bool {
353 return target.c_type_bit_size(.int) == 32 and target.ptrBitWidth() == 64;353 return target.cTypeBitSize(.int) == 32 and target.ptrBitWidth() == 64;
354}354}
355355
356pub fn isKnownWindowsMSVCEnvironment(target: std.Target) bool {356pub fn isKnownWindowsMSVCEnvironment(target: std.Target) bool {
lib/std/Target.zig+9-9
...@@ -2009,7 +2009,7 @@ pub const CType = enum {...@@ -2009,7 +2009,7 @@ pub const CType = enum {
2009 longdouble,2009 longdouble,
2010};2010};
20112011
2012pub fn c_type_byte_size(t: Target, c_type: CType) u16 {2012pub fn cTypeByteSize(t: Target, c_type: CType) u16 {
2013 return switch (c_type) {2013 return switch (c_type) {
2014 .char,2014 .char,
2015 .short,2015 .short,
...@@ -2022,20 +2022,20 @@ pub fn c_type_byte_size(t: Target, c_type: CType) u16 {...@@ -2022,20 +2022,20 @@ pub fn c_type_byte_size(t: Target, c_type: CType) u16 {
2022 .ulonglong,2022 .ulonglong,
2023 .float,2023 .float,
2024 .double,2024 .double,
2025 => @divExact(c_type_bit_size(t, c_type), 8),2025 => @divExact(cTypeBitSize(t, c_type), 8),
20262026
2027 .longdouble => switch (c_type_bit_size(t, c_type)) {2027 .longdouble => switch (cTypeBitSize(t, c_type)) {
2028 16 => 2,2028 16 => 2,
2029 32 => 4,2029 32 => 4,
2030 64 => 8,2030 64 => 8,
2031 80 => @intCast(std.mem.alignForward(usize, 10, c_type_alignment(t, .longdouble))),2031 80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, .longdouble))),
2032 128 => 16,2032 128 => 16,
2033 else => unreachable,2033 else => unreachable,
2034 },2034 },
2035 };2035 };
2036}2036}
20372037
2038pub fn c_type_bit_size(target: Target, c_type: CType) u16 {2038pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2039 switch (target.os.tag) {2039 switch (target.os.tag) {
2040 .freestanding, .other => switch (target.cpu.arch) {2040 .freestanding, .other => switch (target.cpu.arch) {
2041 .msp430 => switch (c_type) {2041 .msp430 => switch (c_type) {
...@@ -2331,7 +2331,7 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {...@@ -2331,7 +2331,7 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
2331 }2331 }
2332}2332}
23332333
2334pub fn c_type_alignment(target: Target, c_type: CType) u16 {2334pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
2335 // Overrides for unusual alignments2335 // Overrides for unusual alignments
2336 switch (target.cpu.arch) {2336 switch (target.cpu.arch) {
2337 .avr => return 1,2337 .avr => return 1,
...@@ -2351,7 +2351,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {...@@ -2351,7 +2351,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {
23512351
2352 // Next-power-of-two-aligned, up to a maximum.2352 // Next-power-of-two-aligned, up to a maximum.
2353 return @min(2353 return @min(
2354 std.math.ceilPowerOfTwoAssert(u16, (c_type_bit_size(target, c_type) + 7) / 8),2354 std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
2355 @as(u16, switch (target.cpu.arch) {2355 @as(u16, switch (target.cpu.arch) {
2356 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {2356 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
2357 .netbsd => switch (target.abi) {2357 .netbsd => switch (target.abi) {
...@@ -2423,7 +2423,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {...@@ -2423,7 +2423,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {
2423 );2423 );
2424}2424}
24252425
2426pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {2426pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
2427 // Overrides for unusual alignments2427 // Overrides for unusual alignments
2428 switch (target.cpu.arch) {2428 switch (target.cpu.arch) {
2429 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {2429 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
...@@ -2476,7 +2476,7 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {...@@ -2476,7 +2476,7 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {
24762476
2477 // Next-power-of-two-aligned, up to a maximum.2477 // Next-power-of-two-aligned, up to a maximum.
2478 return @min(2478 return @min(
2479 std.math.ceilPowerOfTwoAssert(u16, (c_type_bit_size(target, c_type) + 7) / 8),2479 std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
2480 @as(u16, switch (target.cpu.arch) {2480 @as(u16, switch (target.cpu.arch) {
2481 .msp430 => 2,2481 .msp430 => 2,
24822482
src/Sema.zig+4-4
...@@ -30943,7 +30943,7 @@ fn coerceVarArgParam(...@@ -30943,7 +30943,7 @@ fn coerceVarArgParam(
30943 .Array => return sema.fail(block, inst_src, "arrays must be passed by reference to variadic function", .{}),30943 .Array => return sema.fail(block, inst_src, "arrays must be passed by reference to variadic function", .{}),
30944 .Float => float: {30944 .Float => float: {
30945 const target = zcu.getTarget();30945 const target = zcu.getTarget();
30946 const double_bits = target.c_type_bit_size(.double);30946 const double_bits = target.cTypeBitSize(.double);
30947 const inst_bits = uncasted_ty.floatBits(target);30947 const inst_bits = uncasted_ty.floatBits(target);
30948 if (inst_bits >= double_bits) break :float inst;30948 if (inst_bits >= double_bits) break :float inst;
30949 switch (double_bits) {30949 switch (double_bits) {
...@@ -30956,21 +30956,21 @@ fn coerceVarArgParam(...@@ -30956,21 +30956,21 @@ fn coerceVarArgParam(
30956 if (!try sema.validateExternType(uncasted_ty, .param_ty)) break :int inst;30956 if (!try sema.validateExternType(uncasted_ty, .param_ty)) break :int inst;
30957 const target = zcu.getTarget();30957 const target = zcu.getTarget();
30958 const uncasted_info = uncasted_ty.intInfo(zcu);30958 const uncasted_info = uncasted_ty.intInfo(zcu);
30959 if (uncasted_info.bits <= target.c_type_bit_size(switch (uncasted_info.signedness) {30959 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
30960 .signed => .int,30960 .signed => .int,
30961 .unsigned => .uint,30961 .unsigned => .uint,
30962 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {30962 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30963 .signed => Type.c_int,30963 .signed => Type.c_int,
30964 .unsigned => Type.c_uint,30964 .unsigned => Type.c_uint,
30965 }, inst, inst_src);30965 }, inst, inst_src);
30966 if (uncasted_info.bits <= target.c_type_bit_size(switch (uncasted_info.signedness) {30966 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
30967 .signed => .long,30967 .signed => .long,
30968 .unsigned => .ulong,30968 .unsigned => .ulong,
30969 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {30969 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30970 .signed => Type.c_long,30970 .signed => Type.c_long,
30971 .unsigned => Type.c_ulong,30971 .unsigned => Type.c_ulong,
30972 }, inst, inst_src);30972 }, inst, inst_src);
30973 if (uncasted_info.bits <= target.c_type_bit_size(switch (uncasted_info.signedness) {30973 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
30974 .signed => .longlong,30974 .signed => .longlong,
30975 .unsigned => .ulonglong,30975 .unsigned => .ulonglong,
30976 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {30976 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
src/Type.zig+36-36
...@@ -1005,15 +1005,15 @@ pub fn abiAlignmentAdvanced(...@@ -1005,15 +1005,15 @@ pub fn abiAlignmentAdvanced(
10051005
1006 .f16 => return .{ .scalar = .@"2" },1006 .f16 => return .{ .scalar = .@"2" },
1007 .f32 => return .{ .scalar = cTypeAlign(target, .float) },1007 .f32 => return .{ .scalar = cTypeAlign(target, .float) },
1008 .f64 => switch (target.c_type_bit_size(.double)) {1008 .f64 => switch (target.cTypeBitSize(.double)) {
1009 64 => return .{ .scalar = cTypeAlign(target, .double) },1009 64 => return .{ .scalar = cTypeAlign(target, .double) },
1010 else => return .{ .scalar = .@"8" },1010 else => return .{ .scalar = .@"8" },
1011 },1011 },
1012 .f80 => switch (target.c_type_bit_size(.longdouble)) {1012 .f80 => switch (target.cTypeBitSize(.longdouble)) {
1013 80 => return .{ .scalar = cTypeAlign(target, .longdouble) },1013 80 => return .{ .scalar = cTypeAlign(target, .longdouble) },
1014 else => return .{ .scalar = Type.u80.abiAlignment(pt) },1014 else => return .{ .scalar = Type.u80.abiAlignment(pt) },
1015 },1015 },
1016 .f128 => switch (target.c_type_bit_size(.longdouble)) {1016 .f128 => switch (target.cTypeBitSize(.longdouble)) {
1017 128 => return .{ .scalar = cTypeAlign(target, .longdouble) },1017 128 => return .{ .scalar = cTypeAlign(target, .longdouble) },
1018 else => return .{ .scalar = .@"16" },1018 else => return .{ .scalar = .@"16" },
1019 },1019 },
...@@ -1366,8 +1366,8 @@ pub fn abiSizeAdvanced(...@@ -1366,8 +1366,8 @@ pub fn abiSizeAdvanced(
1366 .f32 => return .{ .scalar = 4 },1366 .f32 => return .{ .scalar = 4 },
1367 .f64 => return .{ .scalar = 8 },1367 .f64 => return .{ .scalar = 8 },
1368 .f128 => return .{ .scalar = 16 },1368 .f128 => return .{ .scalar = 16 },
1369 .f80 => switch (target.c_type_bit_size(.longdouble)) {1369 .f80 => switch (target.cTypeBitSize(.longdouble)) {
1370 80 => return .{ .scalar = target.c_type_byte_size(.longdouble) },1370 80 => return .{ .scalar = target.cTypeByteSize(.longdouble) },
1371 else => return .{ .scalar = Type.u80.abiSize(pt) },1371 else => return .{ .scalar = Type.u80.abiSize(pt) },
1372 },1372 },
13731373
...@@ -1375,16 +1375,16 @@ pub fn abiSizeAdvanced(...@@ -1375,16 +1375,16 @@ pub fn abiSizeAdvanced(
1375 .isize,1375 .isize,
1376 => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },1376 => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },
13771377
1378 .c_char => return .{ .scalar = target.c_type_byte_size(.char) },1378 .c_char => return .{ .scalar = target.cTypeByteSize(.char) },
1379 .c_short => return .{ .scalar = target.c_type_byte_size(.short) },1379 .c_short => return .{ .scalar = target.cTypeByteSize(.short) },
1380 .c_ushort => return .{ .scalar = target.c_type_byte_size(.ushort) },1380 .c_ushort => return .{ .scalar = target.cTypeByteSize(.ushort) },
1381 .c_int => return .{ .scalar = target.c_type_byte_size(.int) },1381 .c_int => return .{ .scalar = target.cTypeByteSize(.int) },
1382 .c_uint => return .{ .scalar = target.c_type_byte_size(.uint) },1382 .c_uint => return .{ .scalar = target.cTypeByteSize(.uint) },
1383 .c_long => return .{ .scalar = target.c_type_byte_size(.long) },1383 .c_long => return .{ .scalar = target.cTypeByteSize(.long) },
1384 .c_ulong => return .{ .scalar = target.c_type_byte_size(.ulong) },1384 .c_ulong => return .{ .scalar = target.cTypeByteSize(.ulong) },
1385 .c_longlong => return .{ .scalar = target.c_type_byte_size(.longlong) },1385 .c_longlong => return .{ .scalar = target.cTypeByteSize(.longlong) },
1386 .c_ulonglong => return .{ .scalar = target.c_type_byte_size(.ulonglong) },1386 .c_ulonglong => return .{ .scalar = target.cTypeByteSize(.ulonglong) },
1387 .c_longdouble => return .{ .scalar = target.c_type_byte_size(.longdouble) },1387 .c_longdouble => return .{ .scalar = target.cTypeByteSize(.longdouble) },
13881388
1389 .anyopaque,1389 .anyopaque,
1390 .void,1390 .void,
...@@ -1724,16 +1724,16 @@ pub fn bitSizeAdvanced(...@@ -1724,16 +1724,16 @@ pub fn bitSizeAdvanced(
1724 .isize,1724 .isize,
1725 => return target.ptrBitWidth(),1725 => return target.ptrBitWidth(),
17261726
1727 .c_char => return target.c_type_bit_size(.char),1727 .c_char => return target.cTypeBitSize(.char),
1728 .c_short => return target.c_type_bit_size(.short),1728 .c_short => return target.cTypeBitSize(.short),
1729 .c_ushort => return target.c_type_bit_size(.ushort),1729 .c_ushort => return target.cTypeBitSize(.ushort),
1730 .c_int => return target.c_type_bit_size(.int),1730 .c_int => return target.cTypeBitSize(.int),
1731 .c_uint => return target.c_type_bit_size(.uint),1731 .c_uint => return target.cTypeBitSize(.uint),
1732 .c_long => return target.c_type_bit_size(.long),1732 .c_long => return target.cTypeBitSize(.long),
1733 .c_ulong => return target.c_type_bit_size(.ulong),1733 .c_ulong => return target.cTypeBitSize(.ulong),
1734 .c_longlong => return target.c_type_bit_size(.longlong),1734 .c_longlong => return target.cTypeBitSize(.longlong),
1735 .c_ulonglong => return target.c_type_bit_size(.ulonglong),1735 .c_ulonglong => return target.cTypeBitSize(.ulonglong),
1736 .c_longdouble => return target.c_type_bit_size(.longdouble),1736 .c_longdouble => return target.cTypeBitSize(.longdouble),
17371737
1738 .bool => return 1,1738 .bool => return 1,
1739 .void => return 0,1739 .void => return 0,
...@@ -2310,15 +2310,15 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {...@@ -2310,15 +2310,15 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
2310 },2310 },
2311 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },2311 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
2312 .isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },2312 .isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
2313 .c_char_type => return .{ .signedness = mod.getTarget().charSignedness(), .bits = target.c_type_bit_size(.char) },2313 .c_char_type => return .{ .signedness = mod.getTarget().charSignedness(), .bits = target.cTypeBitSize(.char) },
2314 .c_short_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.short) },2314 .c_short_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.short) },
2315 .c_ushort_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ushort) },2315 .c_ushort_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ushort) },
2316 .c_int_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.int) },2316 .c_int_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.int) },
2317 .c_uint_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.uint) },2317 .c_uint_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.uint) },
2318 .c_long_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.long) },2318 .c_long_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.long) },
2319 .c_ulong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulong) },2319 .c_ulong_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ulong) },
2320 .c_longlong_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.longlong) },2320 .c_longlong_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.longlong) },
2321 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },2321 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ulonglong) },
2322 else => switch (ip.indexToKey(ty.toIntern())) {2322 else => switch (ip.indexToKey(ty.toIntern())) {
2323 .int_type => |int_type| return int_type,2323 .int_type => |int_type| return int_type,
2324 .struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntTypeUnordered(ip)),2324 .struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntTypeUnordered(ip)),
...@@ -2427,7 +2427,7 @@ pub fn floatBits(ty: Type, target: Target) u16 {...@@ -2427,7 +2427,7 @@ pub fn floatBits(ty: Type, target: Target) u16 {
2427 .f64_type => 64,2427 .f64_type => 64,
2428 .f80_type => 80,2428 .f80_type => 80,
2429 .f128_type, .comptime_float_type => 128,2429 .f128_type, .comptime_float_type => 128,
2430 .c_longdouble_type => target.c_type_bit_size(.longdouble),2430 .c_longdouble_type => target.cTypeBitSize(.longdouble),
24312431
2432 else => unreachable,2432 else => unreachable,
2433 };2433 };
...@@ -4025,5 +4025,5 @@ pub fn smallestUnsignedBits(max: u64) u16 {...@@ -4025,5 +4025,5 @@ pub fn smallestUnsignedBits(max: u64) u16 {
4025pub const packed_struct_layout_version = 2;4025pub const packed_struct_layout_version = 2;
40264026
4027fn cTypeAlign(target: Target, c_type: Target.CType) Alignment {4027fn cTypeAlign(target: Target, c_type: Target.CType) Alignment {
4028 return Alignment.fromByteUnits(target.c_type_alignment(c_type));4028 return Alignment.fromByteUnits(target.cTypeAlignment(c_type));
4029}4029}
src/arch/riscv64/CodeGen.zig+1-1
...@@ -8304,7 +8304,7 @@ fn promoteVarArg(func: *Func, ty: Type) Type {...@@ -8304,7 +8304,7 @@ fn promoteVarArg(func: *Func, ty: Type) Type {
8304 switch (ty.floatBits(func.target.*)) {8304 switch (ty.floatBits(func.target.*)) {
8305 32, 64 => return Type.f64,8305 32, 64 => return Type.f64,
8306 else => |float_bits| {8306 else => |float_bits| {
8307 assert(float_bits == func.target.c_type_bit_size(.longdouble));8307 assert(float_bits == func.target.cTypeBitSize(.longdouble));
8308 return Type.c_longdouble;8308 return Type.c_longdouble;
8309 },8309 },
8310 }8310 }
src/arch/x86_64/CodeGen.zig+1-1
...@@ -19374,7 +19374,7 @@ fn promoteVarArg(self: *Self, ty: Type) Type {...@@ -19374,7 +19374,7 @@ fn promoteVarArg(self: *Self, ty: Type) Type {
19374 switch (ty.floatBits(self.target.*)) {19374 switch (ty.floatBits(self.target.*)) {
19375 32, 64 => return Type.f64,19375 32, 64 => return Type.f64,
19376 else => |float_bits| {19376 else => |float_bits| {
19377 assert(float_bits == self.target.c_type_bit_size(.longdouble));19377 assert(float_bits == self.target.cTypeBitSize(.longdouble));
19378 return Type.c_longdouble;19378 return Type.c_longdouble;
19379 },19379 },
19380 }19380 }
src/codegen/c/Type.zig+17-17
...@@ -326,9 +326,9 @@ pub fn renderLiteralSuffix(ctype: CType, writer: anytype, pool: *const Pool) @Ty...@@ -326,9 +326,9 @@ pub fn renderLiteralSuffix(ctype: CType, writer: anytype, pool: *const Pool) @Ty
326pub fn floatActiveBits(ctype: CType, mod: *Module) u16 {326pub fn floatActiveBits(ctype: CType, mod: *Module) u16 {
327 const target = &mod.resolved_target.result;327 const target = &mod.resolved_target.result;
328 return switch (ctype.index) {328 return switch (ctype.index) {
329 .float => target.c_type_bit_size(.float),329 .float => target.cTypeBitSize(.float),
330 .double => target.c_type_bit_size(.double),330 .double => target.cTypeBitSize(.double),
331 .@"long double", .zig_c_longdouble => target.c_type_bit_size(.longdouble),331 .@"long double", .zig_c_longdouble => target.cTypeBitSize(.longdouble),
332 .zig_f16 => 16,332 .zig_f16 => 16,
333 .zig_f32 => 32,333 .zig_f32 => 32,
334 .zig_f64 => 64,334 .zig_f64 => 64,
...@@ -344,17 +344,17 @@ pub fn byteSize(ctype: CType, pool: *const Pool, mod: *Module) u64 {...@@ -344,17 +344,17 @@ pub fn byteSize(ctype: CType, pool: *const Pool, mod: *Module) u64 {
344 .basic => |basic_info| switch (basic_info) {344 .basic => |basic_info| switch (basic_info) {
345 .void => 0,345 .void => 0,
346 .char, .@"signed char", ._Bool, .@"unsigned char", .bool, .uint8_t, .int8_t => 1,346 .char, .@"signed char", ._Bool, .@"unsigned char", .bool, .uint8_t, .int8_t => 1,
347 .short => target.c_type_byte_size(.short),347 .short => target.cTypeByteSize(.short),
348 .int => target.c_type_byte_size(.int),348 .int => target.cTypeByteSize(.int),
349 .long => target.c_type_byte_size(.long),349 .long => target.cTypeByteSize(.long),
350 .@"long long" => target.c_type_byte_size(.longlong),350 .@"long long" => target.cTypeByteSize(.longlong),
351 .@"unsigned short" => target.c_type_byte_size(.ushort),351 .@"unsigned short" => target.cTypeByteSize(.ushort),
352 .@"unsigned int" => target.c_type_byte_size(.uint),352 .@"unsigned int" => target.cTypeByteSize(.uint),
353 .@"unsigned long" => target.c_type_byte_size(.ulong),353 .@"unsigned long" => target.cTypeByteSize(.ulong),
354 .@"unsigned long long" => target.c_type_byte_size(.ulonglong),354 .@"unsigned long long" => target.cTypeByteSize(.ulonglong),
355 .float => target.c_type_byte_size(.float),355 .float => target.cTypeByteSize(.float),
356 .double => target.c_type_byte_size(.double),356 .double => target.cTypeByteSize(.double),
357 .@"long double" => target.c_type_byte_size(.longdouble),357 .@"long double" => target.cTypeByteSize(.longdouble),
358 .size_t,358 .size_t,
359 .ptrdiff_t,359 .ptrdiff_t,
360 .uintptr_t,360 .uintptr_t,
...@@ -364,11 +364,11 @@ pub fn byteSize(ctype: CType, pool: *const Pool, mod: *Module) u64 {...@@ -364,11 +364,11 @@ pub fn byteSize(ctype: CType, pool: *const Pool, mod: *Module) u64 {
364 .uint32_t, .int32_t, .zig_f32 => 4,364 .uint32_t, .int32_t, .zig_f32 => 4,
365 .uint64_t, .int64_t, .zig_f64 => 8,365 .uint64_t, .int64_t, .zig_f64 => 8,
366 .zig_u128, .zig_i128, .zig_f128 => 16,366 .zig_u128, .zig_i128, .zig_f128 => 16,
367 .zig_f80 => if (target.c_type_bit_size(.longdouble) == 80)367 .zig_f80 => if (target.cTypeBitSize(.longdouble) == 80)
368 target.c_type_byte_size(.longdouble)368 target.cTypeByteSize(.longdouble)
369 else369 else
370 16,370 16,
371 .zig_c_longdouble => target.c_type_byte_size(.longdouble),371 .zig_c_longdouble => target.cTypeByteSize(.longdouble),
372 .va_list => unreachable,372 .va_list => unreachable,
373 _ => unreachable,373 _ => unreachable,
374 },374 },
src/codegen/llvm.zig+6-6
...@@ -562,9 +562,9 @@ const DataLayoutBuilder = struct {...@@ -562,9 +562,9 @@ const DataLayoutBuilder = struct {
562 .float => &.{ .float, .double, .longdouble },562 .float => &.{ .float, .double, .longdouble },
563 .vector, .aggregate => &.{},563 .vector, .aggregate => &.{},
564 })) |cty| {564 })) |cty| {
565 if (self.target.c_type_bit_size(cty) != size) continue;565 if (self.target.cTypeBitSize(cty) != size) continue;
566 abi = self.target.c_type_alignment(cty) * 8;566 abi = self.target.cTypeAlignment(cty) * 8;
567 pref = self.target.c_type_preferred_alignment(cty) * 8;567 pref = self.target.cTypePreferredAlignment(cty) * 8;
568 break;568 break;
569 }569 }
570 switch (kind) {570 switch (kind) {
...@@ -3120,7 +3120,7 @@ pub const Object = struct {...@@ -3120,7 +3120,7 @@ pub const Object = struct {
3120 .c_ulong_type,3120 .c_ulong_type,
3121 .c_longlong_type,3121 .c_longlong_type,
3122 .c_ulonglong_type,3122 .c_ulonglong_type,
3123 => |tag| try o.builder.intType(target.c_type_bit_size(3123 => |tag| try o.builder.intType(target.cTypeBitSize(
3124 @field(std.Target.CType, @tagName(tag)["c_".len .. @tagName(tag).len - "_type".len]),3124 @field(std.Target.CType, @tagName(tag)["c_".len .. @tagName(tag).len - "_type".len]),
3125 )),3125 )),
3126 .c_longdouble_type,3126 .c_longdouble_type,
...@@ -11778,8 +11778,8 @@ fn backendSupportsF128(target: std.Target) bool {...@@ -11778,8 +11778,8 @@ fn backendSupportsF128(target: std.Target) bool {
11778fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {11778fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {
11779 return switch (scalar_ty.toIntern()) {11779 return switch (scalar_ty.toIntern()) {
11780 .f16_type => backendSupportsF16(target),11780 .f16_type => backendSupportsF16(target),
11781 .f80_type => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),11781 .f80_type => (target.cTypeBitSize(.longdouble) == 80) and backendSupportsF80(target),
11782 .f128_type => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),11782 .f128_type => (target.cTypeBitSize(.longdouble) == 128) and backendSupportsF128(target),
11783 else => true,11783 else => true,
11784 };11784 };
11785}11785}
tools/generate_c_size_and_align_checks.zig+7-7
...@@ -8,7 +8,7 @@...@@ -8,7 +8,7 @@
88
9const std = @import("std");9const std = @import("std");
1010
11fn c_name(ty: std.Target.CType) []const u8 {11fn cName(ty: std.Target.CType) []const u8 {
12 return switch (ty) {12 return switch (ty) {
13 .char => "char",13 .char => "char",
14 .short => "short",14 .short => "short",
...@@ -46,16 +46,16 @@ pub fn main() !void {...@@ -46,16 +46,16 @@ pub fn main() !void {
46 inline for (@typeInfo(std.Target.CType).Enum.fields) |field| {46 inline for (@typeInfo(std.Target.CType).Enum.fields) |field| {
47 const c_type: std.Target.CType = @enumFromInt(field.value);47 const c_type: std.Target.CType = @enumFromInt(field.value);
48 try stdout.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{48 try stdout.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
49 c_name(c_type),49 cName(c_type),
50 target.c_type_byte_size(c_type),50 target.cTypeByteSize(c_type),
51 });51 });
52 try stdout.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{52 try stdout.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{
53 c_name(c_type),53 cName(c_type),
54 target.c_type_alignment(c_type),54 target.cTypeAlignment(c_type),
55 });55 });
56 try stdout.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{56 try stdout.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{
57 c_name(c_type),57 cName(c_type),
58 target.c_type_preferred_alignment(c_type),58 target.cTypePreferredAlignment(c_type),
59 });59 });
60 }60 }
61}61}