diff --git a/lib/compiler_rt.zig b/lib/compiler_rt.zig index 5ee5e7854c534c285ae7d6f2b73c0acbe2f68cf8..8b4ced2b229c04b3783217f6a41e855031a28cca 100644 --- a/lib/compiler_rt.zig +++ b/lib/compiler_rt.zig @@ -399,6 +399,14 @@ fn complexAbi(comptime Float: type, comptime float: type) type { }; } +pub const have_c_longdouble = if (builtin.target.cTypeBitSize(.longdouble)) |bits| switch (bits) { + else => true, + 80 => switch (std.zig.target.compilerRtFloatAbi(&builtin.target, bits)) { + .soft => false, + .hard => true, + }, +} else false; + pub fn Complex(comptime Float: type) type { return struct { real: Float, imag: Float }; } diff --git a/lib/compiler_rt/cos.zig b/lib/compiler_rt/cos.zig index 72ea9026472a1f8e31bca5cddc9e106cfd66155b..0d836ccfa9e8cff50ef2a2a7fc608a5b30d57ff9 100644 --- a/lib/compiler_rt/cos.zig +++ b/lib/compiler_rt/cos.zig @@ -25,8 +25,10 @@ comptime { symbol(&cos, "cos"); symbol(&__cosx, "__cosx"); symbol(&cosq, "cosf128"); - symbol(&cosl, "cosl"); - symbol(&cosl, "__cosl"); // required by musl + if (compiler_rt.have_c_longdouble) { + symbol(&cosl, "cosl"); + symbol(&cosl, "__cosl"); // required by musl + } } fn __cosh(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/exp.zig b/lib/compiler_rt/exp.zig index 6f9d19ddb3adbfe743fd278ce9e458ae45341502..4d26f7cff292ec5741b2b9501cdb10b3567b1080 100644 --- a/lib/compiler_rt/exp.zig +++ b/lib/compiler_rt/exp.zig @@ -22,7 +22,7 @@ comptime { symbol(&exp, "exp"); symbol(&__expx, "__expx"); symbol(&expq, "expf128"); - symbol(&expl, "expl"); + if (compiler_rt.have_c_longdouble) symbol(&expl, "expl"); } fn __exph(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/exp2.zig b/lib/compiler_rt/exp2.zig index 4f25cdec63332788d1bdda417503901b02ce6154..9c0e087b674d9c66e3a4abda3a923b2f8c222c0e 100644 --- a/lib/compiler_rt/exp2.zig +++ b/lib/compiler_rt/exp2.zig @@ -20,7 +20,7 @@ comptime { symbol(&exp2, "exp2"); symbol(&__exp2x, "__exp2x"); symbol(&exp2q, "exp2f128"); - symbol(&exp2l, "exp2l"); + if (compiler_rt.have_c_longdouble) symbol(&exp2l, "exp2l"); } fn __exp2h(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/fabs.zig b/lib/compiler_rt/fabs.zig index 2238e65e61292668cb2e7bc2e2be3f090470b2e9..971bb72893b3c683227f1456170f99c81c9758a6 100644 --- a/lib/compiler_rt/fabs.zig +++ b/lib/compiler_rt/fabs.zig @@ -10,7 +10,7 @@ comptime { symbol(&fabs, "fabs"); symbol(&__fabsx, "__fabsx"); symbol(&fabsq, "fabsf128"); - symbol(&fabsl, "fabsl"); + if (compiler_rt.have_c_longdouble) symbol(&fabsl, "fabsl"); } fn __fabsh(a: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/floor_ceil.zig b/lib/compiler_rt/floor_ceil.zig index 8bd82275e3787ae52587eb84c1391ee5949f616b..a11076bb0bcfa1da7a55e3608544c8c8b2f5d211 100644 --- a/lib/compiler_rt/floor_ceil.zig +++ b/lib/compiler_rt/floor_ceil.zig @@ -24,7 +24,7 @@ comptime { symbol(&floor, "floor"); symbol(&__floorx, "__floorx"); symbol(&floorq, "floorf128"); - symbol(&floorl, "floorl"); + if (compiler_rt.have_c_longdouble) symbol(&floorl, "floorl"); // ceil symbol(&__ceilh, "__ceilh"); @@ -32,7 +32,7 @@ comptime { symbol(&ceil, "ceil"); symbol(&__ceilx, "__ceilx"); symbol(&ceilq, "ceilf128"); - symbol(&ceill, "ceill"); + if (compiler_rt.have_c_longdouble) symbol(&ceill, "ceill"); } fn __floorh(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/fma.zig b/lib/compiler_rt/fma.zig index dfaefd0eb557e7be939f47d9340ef4d7ea3e094c..c244b72c03aa04e3e1381cf033e8028c80542c77 100644 --- a/lib/compiler_rt/fma.zig +++ b/lib/compiler_rt/fma.zig @@ -18,7 +18,7 @@ comptime { symbol(&fma, "fma"); symbol(&__fmax, "__fmax"); symbol(&fmaq, "fmaf128"); - symbol(&fmal, "fmal"); + if (compiler_rt.have_c_longdouble) symbol(&fmal, "fmal"); } fn __fmah(x: compiler_rt.f16.Abi, y: compiler_rt.f16.Abi, z: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/fmax.zig b/lib/compiler_rt/fmax.zig index f69912472044f62c50733968b382fec866d069c7..de72a1141d64878e80f5ebc99c69f6a69733e3ee 100644 --- a/lib/compiler_rt/fmax.zig +++ b/lib/compiler_rt/fmax.zig @@ -11,7 +11,7 @@ comptime { symbol(&fmax, "fmax"); symbol(&__fmaxx, "__fmaxx"); symbol(&fmaxq, "fmaxf128"); - symbol(&fmaxl, "fmaxl"); + if (compiler_rt.have_c_longdouble) symbol(&fmaxl, "fmaxl"); } fn __fmaxh(x: compiler_rt.f16.Abi, y: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/fmin.zig b/lib/compiler_rt/fmin.zig index bece9262f2a673919e33260576c2ce7d8730cdee..c00dab3ef6d2853f155f8d95e37dee0df1652edf 100644 --- a/lib/compiler_rt/fmin.zig +++ b/lib/compiler_rt/fmin.zig @@ -11,7 +11,7 @@ comptime { symbol(&fmin, "fmin"); symbol(&__fminx, "__fminx"); symbol(&fminq, "fminf128"); - symbol(&fminl, "fminl"); + if (compiler_rt.have_c_longdouble) symbol(&fminl, "fminl"); } fn __fminh(x: compiler_rt.f16.Abi, y: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/fmod.zig b/lib/compiler_rt/fmod.zig index 951b90d06e529e8a3a2606d7fe0eff1dcd9d667a..c079049f15d08ba6b59301db1523a3644dd1e940 100644 --- a/lib/compiler_rt/fmod.zig +++ b/lib/compiler_rt/fmod.zig @@ -13,7 +13,7 @@ comptime { symbol(&fmod, "fmod"); symbol(&__fmodx, "__fmodx"); symbol(&fmodq, "fmodf128"); - symbol(&fmodl, "fmodl"); + if (compiler_rt.have_c_longdouble) symbol(&fmodl, "fmodl"); } fn __fmodh(a: compiler_rt.f16.Abi, b: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/log.zig b/lib/compiler_rt/log.zig index 8b2937921d5998941e7731ac8decce71f60c85cb..d9935822b3a76cd47180ce9797f390c43e6ca5d5 100644 --- a/lib/compiler_rt/log.zig +++ b/lib/compiler_rt/log.zig @@ -19,7 +19,7 @@ comptime { symbol(&log, "log"); symbol(&__logx, "__logx"); symbol(&logq, "logf128"); - symbol(&logl, "logl"); + if (compiler_rt.have_c_longdouble) symbol(&logl, "logl"); } fn __logh(a: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/log10.zig b/lib/compiler_rt/log10.zig index 0813c1ae7c0dc6d71ae7aa2699f17e05bdffe039..75064c587c6ee632465bd6d695cf4fdc5aa7701a 100644 --- a/lib/compiler_rt/log10.zig +++ b/lib/compiler_rt/log10.zig @@ -19,7 +19,7 @@ comptime { symbol(&log10, "log10"); symbol(&__log10x, "__log10x"); symbol(&log10q, "log10f128"); - symbol(&log10l, "log10l"); + if (compiler_rt.have_c_longdouble) symbol(&log10l, "log10l"); } fn __log10h(a: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/log2.zig b/lib/compiler_rt/log2.zig index 0806fb079419787d33dd3b825b4057aac51f1397..d8033860a1b7ea63a2d391b940374f7613711fd2 100644 --- a/lib/compiler_rt/log2.zig +++ b/lib/compiler_rt/log2.zig @@ -20,7 +20,7 @@ comptime { symbol(&log2, "log2"); symbol(&__log2x, "__log2x"); symbol(&log2q, "log2f128"); - symbol(&log2l, "log2l"); + if (compiler_rt.have_c_longdouble) symbol(&log2l, "log2l"); } fn __log2h(a: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/round.zig b/lib/compiler_rt/round.zig index ffcaed60774e70e5067ff107380a8af5a057d718..f8074e46b473e34394b21aebff1c86f0fce4c4b5 100644 --- a/lib/compiler_rt/round.zig +++ b/lib/compiler_rt/round.zig @@ -19,7 +19,7 @@ comptime { symbol(&round, "round"); symbol(&__roundx, "__roundx"); symbol(&roundq, "roundf128"); - symbol(&roundl, "roundl"); + if (compiler_rt.have_c_longdouble) symbol(&roundl, "roundl"); } fn __roundh(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/sin.zig b/lib/compiler_rt/sin.zig index 3e0b8f0cbd823b0e57fe0172217c7726955c7fd1..004e55219e17902a0009fdd0a7dcc2c2aa56231d 100644 --- a/lib/compiler_rt/sin.zig +++ b/lib/compiler_rt/sin.zig @@ -25,8 +25,10 @@ comptime { symbol(&sin, "sin"); symbol(&__sinx, "__sinx"); symbol(&sinq, "sinf128"); - symbol(&sinl, "sinl"); - symbol(&sinl, "__sinl"); // required by musl + if (compiler_rt.have_c_longdouble) { + symbol(&sinl, "sinl"); + symbol(&sinl, "__sinl"); // required by musl + } } fn __sinh(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/sincos.zig b/lib/compiler_rt/sincos.zig index d43f55b623954f602edf850b75d409931b1aaee6..93b3965173ba4e9ef4c767889cb2ca8c19804975 100644 --- a/lib/compiler_rt/sincos.zig +++ b/lib/compiler_rt/sincos.zig @@ -19,7 +19,7 @@ comptime { symbol(&sincos, "sincos"); symbol(&sincosx, "__sincosx"); symbol(&sincosq, "sincosf128"); - symbol(&sincosl, "sincosl"); + if (compiler_rt.have_c_longdouble) symbol(&sincosl, "sincosl"); } fn sincosh(x: compiler_rt.f16.Abi, r_sin: *compiler_rt.f16.Abi, r_cos: *compiler_rt.f16.Abi) callconv(.c) void { diff --git a/lib/compiler_rt/sqrt.zig b/lib/compiler_rt/sqrt.zig index a37fe429c1458153dded08805982d118dedb8ebb..6ba6d62b8e92d8d07e9ca99f2dd65559bd2ecfdb 100644 --- a/lib/compiler_rt/sqrt.zig +++ b/lib/compiler_rt/sqrt.zig @@ -23,7 +23,7 @@ comptime { } else if (compiler_rt.want_sparc32_abi) { symbol(&sqrtq, "_Q_sqrt"); } - symbol(&sqrtl, "sqrtl"); + if (compiler_rt.have_c_longdouble) symbol(&sqrtl, "sqrtl"); } fn __sqrth(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/tan.zig b/lib/compiler_rt/tan.zig index 4ee4440dd6c5cd7417842de27084cab36ae85907..51b5078dbffb54e78bbc9822d10e15e839cae9e4 100644 --- a/lib/compiler_rt/tan.zig +++ b/lib/compiler_rt/tan.zig @@ -29,7 +29,7 @@ comptime { symbol(&tan, "tan"); symbol(&__tanx, "__tanx"); symbol(&tanq, "tanf128"); - symbol(&tanl, "tanl"); + if (compiler_rt.have_c_longdouble) symbol(&tanl, "tanl"); } fn __tanh(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/compiler_rt/trunc.zig b/lib/compiler_rt/trunc.zig index 0dbacf0e9d822385a8dc558a29bf0401f6d97e21..bba0751be28d13a3d5ac6084307e6a531579363f 100644 --- a/lib/compiler_rt/trunc.zig +++ b/lib/compiler_rt/trunc.zig @@ -18,7 +18,7 @@ comptime { symbol(&trunc, "trunc"); symbol(&__truncx, "__truncx"); symbol(&truncq, "truncf128"); - symbol(&truncl, "truncl"); + if (compiler_rt.have_c_longdouble) symbol(&truncl, "truncl"); } fn __trunch(x: compiler_rt.f16.Abi) callconv(.c) compiler_rt.f16.Abi { diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 629f07a5c8b56ffb7370b41a1a6f983edb6d82c3..bba3026b739c3dfd1da086be5ac6114513f83a01 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -3212,7 +3212,7 @@ pub const CType = enum { longdouble, }; -/// Returns `null` if no C ABI is defined for this target. +/// Returns `null` if no C ABI for `c_type` is defined for this target. pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16 { return switch (c_type) { .char, @@ -3238,7 +3238,7 @@ pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16 { }; } -/// Returns `null` if no C ABI is defined for this target. +/// Returns `null` if no C ABI for `c_type` is defined for this target. pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { return switch (target.os.tag) { .freestanding, @@ -3285,7 +3285,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { .x86, .x86_64, - => 80, + => if (target.cpu.has(.x86, .x87)) 80 else null, .alpha, .riscv32, @@ -3345,7 +3345,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { .x86_64, => switch (target.abi) { .android, .ohos => 64, - else => 80, + else => if (target.cpu.has(.x86, .x87)) 80 else null, }, .powerpc, @@ -3409,7 +3409,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { .long, .ulong => 32, .longlong, .ulonglong, .double => 64, .longdouble => switch (target.abi) { - .gnu => 80, + .gnu => if (target.cpu.has(.x86, .x87)) 80 else null, else => 64, }, }, @@ -3420,7 +3420,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { .long, .ulong => 32, .longlong, .ulonglong, .double => 64, .longdouble => switch (target.abi) { - .gnu => 80, + .gnu => if (target.cpu.has(.x86, .x87)) 80 else null, else => 64, }, }, @@ -3454,7 +3454,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { }, .longlong, .ulonglong, .double => 64, .longdouble => switch (target.cpu.arch) { - .x86_64 => 80, + .x86_64 => if (target.cpu.has(.x86, .x87)) 80 else null, else => 64, }, }, @@ -3492,14 +3492,14 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 { .short, .ushort => 16, .int, .uint, .float => 32, .long, .ulong, .longlong, .ulonglong, .double => 64, - .longdouble => 80, + .longdouble => if (target.cpu.has(.x86, .x87)) 80 else null, }, .opengl => null, }; } -/// Returns `null` if no C ABI is defined for this target. +/// Returns `null` if no C ABI for `c_type` is defined for this target. pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 { // Overrides for unusual alignments switch (target.cpu.arch) { diff --git a/lib/std/math/float.zig b/lib/std/math/float.zig index e84bcdc4f295e1edad123673991df5b85f1cea4c..0b16875cc3559756a91ac10f96afee9d9a9fb5f1 100644 --- a/lib/std/math/float.zig +++ b/lib/std/math/float.zig @@ -12,10 +12,11 @@ pub const long_double = struct { inline fn bitWidth(x: anytype) u16 { const T = @TypeOf(x); - return switch (T) { - f80, f128, c_longdouble => @typeInfo(T).float.bits, - else => @compileError("Unsupported type: " ++ @typeName(T) ++ "\nPass a `f80`, `f128`, or `c_longdouble`."), - }; + switch (@typeInfo(T)) { + .float => |float| if (float.bits >= 80) return float.bits, + else => {}, + } + @compileError("Unsupported type: " ++ @typeName(T) ++ "\nPass a `f80`, `f128`, or `c_longdouble`."); } /// Returns the sign + exponent bits of a `long double`. diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 4260ea1ce9d46694f484d912eae78f25a7d7f1f1..d29faf0747dcef2aa1b0ae828c94b947bc00ca64 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -8140,6 +8140,22 @@ fn identifier( // if not @"" syntax, just use raw token slice if (ident_name_raw[0] != '@') { if (primitive_instrs.get(ident_name_raw)) |zir_const_ref| { + const maybe_c_type: ?std.Target.CType = switch (zir_const_ref) { + else => null, + .c_char_type => .char, + .c_short_type => .short, + .c_ushort_type => .ushort, + .c_int_type => .int, + .c_uint_type => .uint, + .c_long_type => .long, + .c_ulong_type => .ulong, + .c_longlong_type => .longlong, + .c_ulonglong_type => .ulonglong, + .c_longdouble_type => .longdouble, + }; + if (maybe_c_type) |c_type| { + _ = try gz.addExtendedNodeSmall(.validate_c_type, ident, @backingInt(c_type)); + } return rvalue(gz, ri, zir_const_ref, ident); } diff --git a/lib/std/zig/Zir.zig b/lib/std/zig/Zir.zig index 17874289d8ed6b38f65309b86bbd0cddea8a8aee..ee43492c8fe9d26ec3f3484f7f1a7804e1c9869c 100644 --- a/lib/std/zig/Zir.zig +++ b/lib/std/zig/Zir.zig @@ -2186,6 +2186,11 @@ pub const Inst = struct { /// For example: Provided with `error{Foo}!?f64`, returns `f64`. /// `operand` is payload index to `UnNode`. float_op_result_ty, + /// Validate that the given `CType` is valid for the current target. + /// This can be folded into the `@CType` tag once that is implemented. + /// `operand` is `src_node: Ast.Node.Offset`. + /// `small` is a `std.Target.CType`. + validate_c_type, pub const InstData = struct { opcode: Extended, @@ -4441,6 +4446,7 @@ fn findTrackableInner( .astgen_error, .float_op_result_ty, .round_op_ty, + .validate_c_type, => return, // `@TypeOf` has a body. diff --git a/src/Compilation.zig b/src/Compilation.zig index 5a98fa435ce9f77181cb491f02a656b446cca4e2..38a905723bce8df08bcb2bf1850ecfd9bfe25870 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6761,39 +6761,40 @@ pub fn addCCArgs( else => &.{"-Xclang"}, }; - for (xclang_flags) |xclang| { - if (target_util.clangSupportsTargetCpuArg(target)) { - if (target.cpu.model.llvm_name) |llvm_name| { + if (target_util.clangSupportsTargetCpuArg(target)) { + if (target.cpu.model.llvm_name) |llvm_name| { + for (xclang_flags) |xclang| { try argv.appendSlice(&[_][]const u8{ xclang, "-target-cpu", xclang, llvm_name, }); } } + } - // It would be really nice if there was a more compact way to communicate this info to Clang. - const all_features_list = target.cpu.arch.allFeaturesList(); - try argv.ensureUnusedCapacity(all_features_list.len * 4); - for (all_features_list, 0..) |feature, index_usize| { - const index = @as(std.Target.Cpu.Feature.Set.Index, @intCast(index_usize)); - const is_enabled = target.cpu.features.isEnabled(index); + // It would be really nice if there was a more compact way to communicate this info to Clang. + const all_features_list = target.cpu.arch.allFeaturesList(); + try argv.ensureUnusedCapacity(all_features_list.len * xclang_flags.len * 4); + for (all_features_list, 0..) |feature, index_usize| { + const index = @as(std.Target.Cpu.Feature.Set.Index, @intCast(index_usize)); + const is_enabled = target.cpu.features.isEnabled(index); - if (feature.llvm_name) |llvm_name| { - // We communicate these to Clang through the dedicated options. - if (std.mem.startsWith(u8, llvm_name, "soft-float") or - std.mem.startsWith(u8, llvm_name, "hard-float") or - (target.cpu.arch.isPowerPC() and std.mem.startsWith(u8, llvm_name, "64bit")) or - (target.cpu.arch.isX86() and std.mem.startsWith(u8, llvm_name, "x32")) or - (target.cpu.arch == .s390x and std.mem.eql(u8, llvm_name, "backchain"))) - continue; + if (feature.llvm_name) |llvm_name| { + // We communicate these to Clang through the dedicated options. + if (std.mem.startsWith(u8, llvm_name, "soft-float") or + std.mem.startsWith(u8, llvm_name, "hard-float") or + (target.cpu.arch.isPowerPC() and std.mem.startsWith(u8, llvm_name, "64bit")) or + (target.cpu.arch.isX86() and std.mem.startsWith(u8, llvm_name, "x32")) or + (target.cpu.arch == .s390x and std.mem.eql(u8, llvm_name, "backchain"))) + continue; - // Ignore these until we figure out how to handle the concept of omitting features. - // See https://github.com/ziglang/zig/issues/23539 - if (target_util.isDynamicAMDGCNFeature(target, feature)) continue; + // Ignore these until we figure out how to handle the concept of omitting features. + // See https://github.com/ziglang/zig/issues/23539 + if (target_util.isDynamicAMDGCNFeature(target, feature)) continue; - argv.appendSliceAssumeCapacity(&[_][]const u8{ xclang, "-target-feature", xclang }); - const plus_or_minus = "-+"[@intFromBool(is_enabled)]; - const arg = try std.fmt.allocPrint(arena, "{c}{s}", .{ plus_or_minus, llvm_name }); - argv.appendAssumeCapacity(arg); + const plus_or_minus = "-+"[@intFromBool(is_enabled)]; + const arg = try std.fmt.allocPrint(arena, "{c}{s}", .{ plus_or_minus, llvm_name }); + for (xclang_flags) |xclang| { + argv.appendSliceAssumeCapacity(&[_][]const u8{ xclang, "-target-feature", xclang, arg }); } } } diff --git a/src/Sema.zig b/src/Sema.zig index b16561b3e58a84c044364cccb2c2aedb8cf53d2f..4904149cf0f1c47e59d0ee7e4d4c4e11307acf43 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1469,6 +1469,11 @@ fn analyzeBodyInner( }, .astgen_error => return sema.failTransitive(.astgen_error), .float_op_result_ty => try sema.zirFloatOpResultType(block, extended), + .validate_c_type => { + try sema.zirValidateCType(block, extended); + i += 1; + continue; + }, }; }, @@ -4315,6 +4320,14 @@ fn zirTryOperandTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: boo } } +fn zirValidateCType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { + const c_type: std.Target.CType = @fromBackingInt(@intCast(extended.small)); + if (sema.pt.zcu.getTarget().cTypeBitSize(c_type)) |_| return; + const src_node: std.zig.Ast.Node.Offset = @fromBackingInt(@bitCast(extended.operand)); + const src = block.nodeOffset(src_node); + return sema.fail(block, src, "'c_{t}' is not valid on this target", .{c_type}); +} + fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const pt = sema.pt; const zcu = pt.zcu; diff --git a/src/Type.zig b/src/Type.zig index 7a4256263882de8fe68ec8331e256b3dabd53db8..f2707c942e2f24a1e94f5f9058b23db4f3eccc4b 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -3178,7 +3178,10 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool }, .float => switch (ty.floatBits(zcu.getTarget())) { else => true, - 80 => |bits| std.zig.target.compilerRtFloatAbi(zcu.getTarget(), bits) == .hard, + 80 => |bits| switch (std.zig.target.compilerRtFloatAbi(zcu.getTarget(), bits)) { + .soft => false, + .hard => true, + }, }, .@"fn" => { if (position != .other) return false; diff --git a/src/print_zir.zig b/src/print_zir.zig index 427acc16ebbbbb30109b57ca7f2170330183ba97..191fa6e7aa783bbb56b03bd6a4e12dea6a6acb78 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -712,8 +712,14 @@ const Writer = struct { .std_lang_value => try self.writeStdLangValue(stream, extended), .inplace_arith_result_ty => try self.writeInplaceArithResultTy(stream, extended), - .dbg_empty_stmt => try stream.writeAll("))"), - .astgen_error => try stream.writeAll("))"), + .dbg_empty_stmt, .astgen_error => try stream.writeAll("))"), + + .validate_c_type => { + const c_type: std.Target.CType = @fromBackingInt(@intCast(extended.small)); + const src_node: Ast.Node.Offset = @fromBackingInt(@bitCast(extended.operand)); + try stream.print("{t})) ", .{c_type}); + try self.writeSrcNode(stream, src_node); + }, } }