Merge branch 'master' into json_stricter_number_parsing

This commit is contained in:
Daniel Berg 2024-11-14 10:39:22 +01:00 committed by GitHub
commit 84b7364b59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
209 changed files with 506 additions and 2711 deletions

View File

@ -6,28 +6,13 @@ const Point = struct {
y: f32,
};
// Maybe we want to pass it to OpenGL so we want to be particular about
// how the bytes are arranged.
const Point2 = packed struct {
x: f32,
y: f32,
};
// Declare an instance of a struct.
const p = Point{
const p: Point = .{
.x = 0.12,
.y = 0.34,
};
// Maybe we're not ready to fill out some of the fields.
var p2 = Point{
.x = 0.12,
.y = undefined,
};
// Structs can have methods
// Struct methods are not special, they are only namespaced
// functions that you can call with dot syntax.
// Functions in the struct's namespace can be called with dot syntax.
const Vec3 = struct {
x: f32,
y: f32,
@ -46,7 +31,6 @@ const Vec3 = struct {
}
};
const expect = @import("std").testing.expect;
test "dot product" {
const v1 = Vec3.init(1.0, 0.0, 0.0);
const v2 = Vec3.init(0.0, 1.0, 0.0);
@ -67,14 +51,14 @@ test "struct namespaced variable" {
try expect(Empty.PI == 3.14);
try expect(@sizeOf(Empty) == 0);
// you can still instantiate an empty struct
const does_nothing = Empty{};
// Empty structs can be instantiated the same as usual.
const does_nothing: Empty = .{};
_ = does_nothing;
}
// struct field order is determined by the compiler for optimal performance.
// however, you can still calculate a struct base pointer given a field pointer:
// Struct field order is determined by the compiler, however, a base pointer
// can be computed from a field pointer:
fn setYBasedOnX(x: *f32, y: f32) void {
const point: *Point = @fieldParentPtr("x", x);
point.y = y;
@ -88,8 +72,7 @@ test "field parent pointer" {
try expect(point.y == 0.9);
}
// You can return a struct from a function. This is how we do generics
// in Zig:
// Structs can be returned from functions.
fn LinkedList(comptime T: type) type {
return struct {
pub const Node = struct {
@ -105,8 +88,7 @@ fn LinkedList(comptime T: type) type {
}
test "linked list" {
// Functions called at compile-time are memoized. This means you can
// do this:
// Functions called at compile-time are memoized.
try expect(LinkedList(i32) == LinkedList(i32));
const list = LinkedList(i32){
@ -139,4 +121,6 @@ test "linked list" {
// instead of try expect(list2.first.?.*.data == 1234);
}
const expect = @import("std").testing.expect;
// test

View File

@ -11,16 +11,14 @@ const native_os = builtin.os.tag;
const native_arch = builtin.cpu.arch;
const native_abi = builtin.abi;
const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong;
const is_wasm = switch (native_arch) {
.wasm32, .wasm64 => true,
else => false,
};
const is_msvc = switch (native_abi) {
.msvc => true,
else => false,
};
const is_freestanding = switch (native_os) {
.freestanding => true,
.freestanding, .other => true,
else => false,
};
@ -30,14 +28,14 @@ comptime {
}
if (builtin.link_libc) {
@export(&strcmp, .{ .name = "strcmp", .linkage = .strong });
@export(&strncmp, .{ .name = "strncmp", .linkage = .strong });
@export(&strerror, .{ .name = "strerror", .linkage = .strong });
@export(&strlen, .{ .name = "strlen", .linkage = .strong });
@export(&strcpy, .{ .name = "strcpy", .linkage = .strong });
@export(&strncpy, .{ .name = "strncpy", .linkage = .strong });
@export(&strcat, .{ .name = "strcat", .linkage = .strong });
@export(&strncat, .{ .name = "strncat", .linkage = .strong });
@export(&strcmp, .{ .name = "strcmp", .linkage = linkage });
@export(&strncmp, .{ .name = "strncmp", .linkage = linkage });
@export(&strerror, .{ .name = "strerror", .linkage = linkage });
@export(&strlen, .{ .name = "strlen", .linkage = linkage });
@export(&strcpy, .{ .name = "strcpy", .linkage = linkage });
@export(&strncpy, .{ .name = "strncpy", .linkage = linkage });
@export(&strcat, .{ .name = "strcat", .linkage = linkage });
@export(&strncat, .{ .name = "strncat", .linkage = linkage });
}
}

View File

@ -1076,7 +1076,7 @@ pub fn toElfMachine(target: Target) std.elf.EM {
pub fn toCoffMachine(target: Target) std.coff.MachineType {
return switch (target.cpu.arch) {
.arm => .ARM,
.thumb => .THUMB,
.thumb => .ARMNT,
.aarch64 => .ARM64,
.loongarch32 => .LOONGARCH32,
.loongarch64 => .LOONGARCH64,

View File

@ -408,79 +408,87 @@ test spinLoopHint {
}
}
pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
return switch (cpu.arch) {
// x86_64: Starting from Intel's Sandy Bridge, the spatial prefetcher pulls in pairs of 64-byte cache lines at a time.
// - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf
// - https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107
//
// aarch64: Some big.LITTLE ARM archs have "big" cores with 128-byte cache lines:
// - https://www.mono-project.com/news/2016/09/12/arm64-icache/
// - https://cpufun.substack.com/p/more-m1-fun-hardware-information
//
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/arc/Kconfig#L212
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_ppc64x.go#L9
.x86_64,
.aarch64,
.aarch64_be,
.arc,
.powerpc64,
.powerpc64le,
=> 128,
// https://github.com/llvm/llvm-project/blob/e379094328e49731a606304f7e3559d4f1fa96f9/clang/lib/Basic/Targets/Hexagon.h#L145-L151
.hexagon,
=> if (std.Target.hexagon.featureSetHas(cpu.features, .v73)) 64 else 32,
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_arm.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mipsle.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips64x.go#L9
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_riscv64.go#L7
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sparc/include/asm/cache.h#L14
.arm,
.armeb,
.thumb,
.thumbeb,
.mips,
.mipsel,
.mips64,
.mips64el,
.riscv32,
.riscv64,
.sparc,
.sparc64,
=> 32,
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/m68k/include/asm/cache.h#L10
.m68k,
=> 16,
// - https://www.ti.com/lit/pdf/slaa498
.msp430,
=> 8,
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_s390x.go#L7
// - https://sxauroratsubasa.sakura.ne.jp/documents/guide/pdfs/Aurora_ISA_guide.pdf
.s390x,
.ve,
=> 256,
// Other x86 and WASM platforms have 64-byte cache lines.
// The rest of the architectures are assumed to be similar.
// - https://github.com/golang/go/blob/dda2991c2ea0c5914714469c4defc2562a907230/src/internal/cpu/cpu_x86.go#L9
// - https://github.com/golang/go/blob/0a9321ad7f8c91e1b0c7184731257df923977eb9/src/internal/cpu/cpu_loong64.go#L11
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_wasm.go#L7
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/xtensa/variants/csp/include/variant/core.h#L209
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/csky/Kconfig#L183
// - https://www.xmos.com/download/The-XMOS-XS3-Architecture.pdf
else => 64,
};
}
/// The estimated size of the CPU's cache line when atomically updating memory.
/// Add this much padding or align to this boundary to avoid atomically-updated
/// memory from forcing cache invalidations on near, but non-atomic, memory.
///
/// https://en.wikipedia.org/wiki/False_sharing
/// https://github.com/golang/go/search?q=CacheLinePadSize
pub const cache_line = switch (builtin.cpu.arch) {
// x86_64: Starting from Intel's Sandy Bridge, the spatial prefetcher pulls in pairs of 64-byte cache lines at a time.
// - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf
// - https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107
//
// aarch64: Some big.LITTLE ARM archs have "big" cores with 128-byte cache lines:
// - https://www.mono-project.com/news/2016/09/12/arm64-icache/
// - https://cpufun.substack.com/p/more-m1-fun-hardware-information
//
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/arc/Kconfig#L212
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_ppc64x.go#L9
.x86_64,
.aarch64,
.aarch64_be,
.arc,
.powerpc64,
.powerpc64le,
=> 128,
pub const cache_line = cacheLineForCpu(builtin.cpu);
// https://github.com/llvm/llvm-project/blob/e379094328e49731a606304f7e3559d4f1fa96f9/clang/lib/Basic/Targets/Hexagon.h#L145-L151
.hexagon,
=> if (std.Target.hexagon.featureSetHas(builtin.target.cpu.features, .v73)) 64 else 32,
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_arm.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mipsle.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips64x.go#L9
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_riscv64.go#L7
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sparc/include/asm/cache.h#L14
.arm,
.armeb,
.thumb,
.thumbeb,
.mips,
.mipsel,
.mips64,
.mips64el,
.riscv32,
.riscv64,
.sparc,
.sparc64,
=> 32,
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/m68k/include/asm/cache.h#L10
.m68k,
=> 16,
// - https://www.ti.com/lit/pdf/slaa498
.msp430,
=> 8,
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_s390x.go#L7
// - https://sxauroratsubasa.sakura.ne.jp/documents/guide/pdfs/Aurora_ISA_guide.pdf
.s390x,
.ve,
=> 256,
// Other x86 and WASM platforms have 64-byte cache lines.
// The rest of the architectures are assumed to be similar.
// - https://github.com/golang/go/blob/dda2991c2ea0c5914714469c4defc2562a907230/src/internal/cpu/cpu_x86.go#L9
// - https://github.com/golang/go/blob/0a9321ad7f8c91e1b0c7184731257df923977eb9/src/internal/cpu/cpu_loong64.go#L11
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_wasm.go#L7
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/xtensa/variants/csp/include/variant/core.h#L209
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/csky/Kconfig#L183
// - https://www.xmos.com/download/The-XMOS-XS3-Architecture.pdf
else => 64,
};
test "current CPU has a cache line size" {
_ = cache_line;
}
const std = @import("std.zig");
const builtin = @import("builtin");

View File

@ -8813,7 +8813,7 @@ pub const NOTE = switch (native_os) {
pub const EXIT_DETAIL = 0x02000000;
/// mask for signal & exit status
pub const PDATAMASK = 0x000fffff;
pub const PCTRLMASK = (~PDATAMASK);
pub const PCTRLMASK = 0xf0000000;
pub const EXIT_DETAIL_MASK = 0x00070000;
pub const EXIT_DECRYPTFAIL = 0x00010000;
pub const EXIT_MEMORY = 0x00020000;
@ -8947,7 +8947,7 @@ pub const NOTE = switch (native_os) {
pub const EXEC = 0x20000000;
/// mask for signal & exit status
pub const PDATAMASK = 0x000fffff;
pub const PCTRLMASK = (~PDATAMASK);
pub const PCTRLMASK = 0xf0000000;
/// data is seconds
pub const SECONDS = 0x00000001;
/// data is milliseconds
@ -9669,7 +9669,6 @@ pub const system_info = haiku.system_info;
pub const team_id = haiku.team_id;
pub const team_info = haiku.team_info;
pub const thread_id = haiku.thread_id;
pub const vregs = haiku.vregs;
pub const AUTH = openbsd.AUTH;
pub const BI = openbsd.BI;

View File

@ -59,6 +59,7 @@ pub const EXC = enum(exception_type_t) {
pub const SOFT_SIGNAL = 0x10003;
pub const MASK = packed struct(u32) {
_0: u1 = 0,
BAD_ACCESS: bool = false,
BAD_INSTRUCTION: bool = false,
ARITHMETIC: bool = false,
@ -72,6 +73,7 @@ pub const EXC = enum(exception_type_t) {
RESOURCE: bool = false,
GUARD: bool = false,
CORPSE_NOTIFY: bool = false,
_14: u18 = 0,
pub const MACHINE: MASK = @bitCast(@as(u32, 0));

View File

@ -7121,6 +7121,19 @@ pub const SIOCPROTOPRIVATE = 0x89E0;
pub const IFNAMESIZE = 16;
pub const IFF = packed struct(u16) {
UP: bool = false,
BROADCAST: bool = false,
DEBUG: bool = false,
LOOPBACK: bool = false,
POINTOPOINT: bool = false,
NOTRAILERS: bool = false,
RUNNING: bool = false,
NOARP: bool = false,
PROMISC: bool = false,
_9: u7 = 0,
};
pub const ifmap = extern struct {
mem_start: usize,
mem_end: usize,
@ -7140,7 +7153,7 @@ pub const ifreq = extern struct {
broadaddr: sockaddr,
netmask: sockaddr,
hwaddr: sockaddr,
flags: i16,
flags: IFF,
ivalue: i32,
mtu: i32,
map: ifmap,

View File

@ -1110,7 +1110,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
pub const MoveFileError = error{ FileNotFound, AccessDenied, Unexpected };
pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) MoveFileError!void {
pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) (MoveFileError || Wtf8ToPrefixedFileWError)!void {
const old_path_w = try sliceToPrefixedFileW(null, old_path);
const new_path_w = try sliceToPrefixedFileW(null, new_path);
return MoveFileExW(old_path_w.span().ptr, new_path_w.span().ptr, flags);
@ -1518,7 +1518,7 @@ pub const GetFileAttributesError = error{
Unexpected,
};
pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD {
pub fn GetFileAttributes(filename: []const u8) (GetFileAttributesError || Wtf8ToPrefixedFileWError)!DWORD {
const filename_w = try sliceToPrefixedFileW(null, filename);
return GetFileAttributesW(filename_w.span().ptr);
}
@ -1667,7 +1667,7 @@ pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.so
pub fn sendmsg(
s: ws2_32.SOCKET,
msg: *const ws2_32.WSAMSG,
msg: *ws2_32.WSAMSG_const,
flags: u32,
) i32 {
var bytes_send: DWORD = undefined;

View File

@ -104,6 +104,7 @@ pub const SIOCGIFINDEX = system.SIOCGIFINDEX;
pub const SO = system.SO;
pub const SOCK = system.SOCK;
pub const SOL = system.SOL;
pub const IFF = system.IFF;
pub const STDERR_FILENO = system.STDERR_FILENO;
pub const STDIN_FILENO = system.STDIN_FILENO;
pub const STDOUT_FILENO = system.STDOUT_FILENO;
@ -154,7 +155,6 @@ pub const socklen_t = system.socklen_t;
pub const stack_t = system.stack_t;
pub const time_t = system.time_t;
pub const timespec = system.timespec;
pub const timestamp_t = system.timestamp_t;
pub const timeval = system.timeval;
pub const timezone = system.timezone;
pub const ucontext_t = system.ucontext_t;
@ -5614,7 +5614,7 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
/// TODO: change this to return the timespec as a return value
pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void {
if (native_os == .wasi and !builtin.link_libc) {
var ts: timestamp_t = undefined;
var ts: wasi.timestamp_t = undefined;
switch (system.clock_time_get(clock_id, 1, &ts)) {
.SUCCESS => {
tp.* = .{
@ -5655,7 +5655,7 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void
pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void {
if (native_os == .wasi and !builtin.link_libc) {
var ts: timestamp_t = undefined;
var ts: wasi.timestamp_t = undefined;
switch (system.clock_res_get(@bitCast(clock_id), &ts)) {
.SUCCESS => res.* = .{
.sec = @intCast(ts / std.time.ns_per_s),

View File

@ -41,14 +41,14 @@ fn print(comptime fmt: []const u8, args: anytype) void {
pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {
if (actual_error_union) |actual_payload| {
print("expected error.{s}, found {any}\n", .{ @errorName(expected_error), actual_payload });
return error.TestUnexpectedError;
return error.TestExpectedError;
} else |actual_error| {
if (expected_error != actual_error) {
print("expected error.{s}, found error.{s}\n", .{
@errorName(expected_error),
@errorName(actual_error),
});
return error.TestExpectedError;
return error.TestUnexpectedError;
}
}
}

View File

@ -2435,6 +2435,7 @@ fn blockExpr(
if (!block_scope.endsWithNoReturn()) {
// As our last action before the break, "pop" the error trace if needed
_ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node);
// No `rvalue` call here, as the block result is always `void`, so we do that below.
_ = try block_scope.addBreak(.@"break", block_inst, .void_value);
}
@ -2531,7 +2532,8 @@ fn labeledBlockExpr(
if (!block_scope.endsWithNoReturn()) {
// As our last action before the return, "pop" the error trace if needed
_ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node);
_ = try block_scope.addBreak(.@"break", block_inst, .void_value);
const result = try rvalue(gz, block_scope.break_result_info, .void_value, block_node);
_ = try block_scope.addBreak(.@"break", block_inst, result);
}
if (!block_scope.label.?.used) {

View File

@ -89,7 +89,6 @@ windows_libs: std.StringArrayHashMapUnmanaged(void),
version: ?std.SemanticVersion,
libc_installation: ?*const LibCInstallation,
skip_linker_dependencies: bool,
no_builtin: bool,
function_sections: bool,
data_sections: bool,
link_eh_frame_hdr: bool,
@ -852,6 +851,7 @@ pub const cache_helpers = struct {
hh.add(mod.fuzz);
hh.add(mod.unwind_tables);
hh.add(mod.structured_cfg);
hh.add(mod.no_builtin);
hh.addListOfBytes(mod.cc_argv);
}
@ -1057,7 +1057,6 @@ pub const CreateOptions = struct {
want_lto: ?bool = null,
function_sections: bool = false,
data_sections: bool = false,
no_builtin: bool = false,
time_report: bool = false,
stack_report: bool = false,
link_eh_frame_hdr: bool = false,
@ -1299,7 +1298,11 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
},
.fully_qualified_name = "compiler_rt",
.cc_argv = &.{},
.inherited = .{},
.inherited = .{
.stack_check = false,
.stack_protector = 0,
.no_builtin = true,
},
.global = options.config,
.parent = options.root_mod,
.builtin_mod = options.root_mod.getBuiltinDependency(),
@ -1353,7 +1356,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
cache.hash.add(options.config.link_mode);
cache.hash.add(options.function_sections);
cache.hash.add(options.data_sections);
cache.hash.add(options.no_builtin);
cache.hash.add(link_libc);
cache.hash.add(options.config.link_libcpp);
cache.hash.add(options.config.link_libunwind);
@ -1490,7 +1492,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.framework_dirs = options.framework_dirs,
.llvm_opt_bisect_limit = options.llvm_opt_bisect_limit,
.skip_linker_dependencies = options.skip_linker_dependencies,
.no_builtin = options.no_builtin,
.job_queued_update_builtin_zig = have_zcu,
.function_sections = options.function_sections,
.data_sections = options.data_sections,
@ -5261,7 +5262,7 @@ pub fn addCCArgs(
try argv.append("-fdata-sections");
}
if (comp.no_builtin) {
if (mod.no_builtin) {
try argv.append("-fno-builtin");
}
@ -5624,6 +5625,10 @@ pub fn addCCArgs(
},
}
if (comp.mingw_unicode_entry_point) {
try argv.append("-municode");
}
if (target.cpu.arch.isThumb()) {
try argv.append("-mthumb");
}
@ -6154,7 +6159,6 @@ fn buildOutputFromZig(
assert(output_mode != .Exe);
const unwind_tables = comp.link_eh_frame_hdr;
const strip = comp.compilerRtStrip();
const optimize_mode = comp.compilerRtOptMode();
@ -6168,7 +6172,6 @@ fn buildOutputFromZig(
.root_optimize_mode = optimize_mode,
.root_strip = strip,
.link_libc = comp.config.link_libc,
.any_unwind_tables = unwind_tables,
});
const root_mod = try Package.Module.create(arena, .{
@ -6185,10 +6188,11 @@ fn buildOutputFromZig(
.stack_protector = 0,
.red_zone = comp.root_mod.red_zone,
.omit_frame_pointer = comp.root_mod.omit_frame_pointer,
.unwind_tables = unwind_tables,
.unwind_tables = comp.root_mod.unwind_tables,
.pic = comp.root_mod.pic,
.optimize_mode = optimize_mode,
.structured_cfg = comp.root_mod.structured_cfg,
.no_builtin = true,
.code_model = comp.root_mod.code_model,
},
.global = config,
@ -6237,7 +6241,6 @@ fn buildOutputFromZig(
},
.function_sections = true,
.data_sections = true,
.no_builtin = true,
.emit_h = null,
.verbose_cc = comp.verbose_cc,
.verbose_link = comp.verbose_link,
@ -6262,16 +6265,24 @@ fn buildOutputFromZig(
comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);
}
pub const CrtFileOptions = struct {
function_sections: ?bool = null,
data_sections: ?bool = null,
omit_frame_pointer: ?bool = null,
pic: ?bool = null,
no_builtin: ?bool = null,
};
pub fn build_crt_file(
comp: *Compilation,
root_name: []const u8,
output_mode: std.builtin.OutputMode,
pic: ?bool,
misc_task_tag: MiscTask,
prog_node: std.Progress.Node,
/// These elements have to get mutated to add the owner module after it is
/// created within this function.
c_source_files: []CSourceFile,
options: CrtFileOptions,
) !void {
const tracy_trace = trace(@src());
defer tracy_trace.end();
@ -6316,13 +6327,16 @@ pub fn build_crt_file(
.sanitize_c = false,
.sanitize_thread = false,
.red_zone = comp.root_mod.red_zone,
.omit_frame_pointer = comp.root_mod.omit_frame_pointer,
// Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer.
.omit_frame_pointer = options.omit_frame_pointer orelse comp.root_mod.omit_frame_pointer,
.valgrind = false,
.unwind_tables = false,
// Some CRT objects (rcrt1.o, Scrt1.o) are opinionated about PIC.
.pic = pic orelse comp.root_mod.pic,
// Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC.
.pic = options.pic orelse comp.root_mod.pic,
.optimize_mode = comp.compilerRtOptMode(),
.structured_cfg = comp.root_mod.structured_cfg,
// Some libcs (e.g. musl) are opinionated about -fno-builtin.
.no_builtin = options.no_builtin orelse comp.root_mod.no_builtin,
},
.global = config,
.cc_argv = &.{},
@ -6350,6 +6364,8 @@ pub fn build_crt_file(
.directory = null, // Put it in the cache directory.
.basename = basename,
},
.function_sections = options.function_sections orelse false,
.data_sections = options.data_sections orelse false,
.emit_h = null,
.c_source_files = c_source_files,
.verbose_cc = comp.verbose_cc,

View File

@ -662,6 +662,9 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
// * path-based location is used without a hash.
// - Hash is added to the table based on the path alone before
// calling run(); no need to add it again.
//
// If we add a dep as lazy and then later try to add the same dep as eager,
// eagerness takes precedence and the existing entry is updated.
for (dep_names, deps) |dep_name, dep| {
const new_fetch = &new_fetches[new_fetch_index];
@ -673,7 +676,12 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
const digest_len = @typeInfo(Manifest.MultiHashHexDigest).array.len;
const multihash_digest = h[0..digest_len].*;
const gop = f.job_queue.table.getOrPutAssumeCapacity(multihash_digest);
if (gop.found_existing) continue;
if (gop.found_existing) {
if (!dep.lazy) {
gop.value_ptr.*.lazy_status = .eager;
}
continue;
}
gop.value_ptr.* = new_fetch;
break :h multihash_digest;
},
@ -684,7 +692,12 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
const new_root = try f.package_root.resolvePosix(parent_arena, rel_path);
const multihash_digest = relativePathDigest(new_root, cache_root);
const gop = f.job_queue.table.getOrPutAssumeCapacity(multihash_digest);
if (gop.found_existing) continue;
if (gop.found_existing) {
if (!dep.lazy) {
gop.value_ptr.*.lazy_status = .eager;
}
continue;
}
gop.value_ptr.* = new_fetch;
break :l .{ .relative_path = new_root };
},

View File

@ -31,6 +31,7 @@ unwind_tables: bool,
cc_argv: []const []const u8,
/// (SPIR-V) whether to generate a structured control flow graph or not
structured_cfg: bool,
no_builtin: bool,
/// If the module is an `@import("builtin")` module, this is the `File` that
/// is preallocated for it. Otherwise this field is null.
@ -95,6 +96,7 @@ pub const CreateOptions = struct {
sanitize_thread: ?bool = null,
fuzz: ?bool = null,
structured_cfg: ?bool = null,
no_builtin: ?bool = null,
};
};
@ -298,6 +300,13 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
};
};
const no_builtin = b: {
if (options.inherited.no_builtin) |x| break :b x;
if (options.parent) |p| break :b p.no_builtin;
break :b target.cpu.arch.isBpf();
};
const llvm_cpu_features: ?[*:0]const u8 = b: {
if (resolved_target.llvm_cpu_features) |x| break :b x;
if (!options.global.use_llvm) break :b null;
@ -350,6 +359,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
.unwind_tables = unwind_tables,
.cc_argv = options.cc_argv,
.structured_cfg = structured_cfg,
.no_builtin = no_builtin,
.builtin_file = null,
};
@ -442,6 +452,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
.unwind_tables = unwind_tables,
.cc_argv = &.{},
.structured_cfg = structured_cfg,
.no_builtin = no_builtin,
.builtin_file = new_file,
};
new_file.* = .{
@ -502,6 +513,7 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P
.unwind_tables = undefined,
.cc_argv = undefined,
.structured_cfg = undefined,
.no_builtin = undefined,
.builtin_file = null,
};
return mod;

View File

@ -532,6 +532,8 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)
},
else => unreachable,
};
} else {
return lower.fail("TODO: bin format '{s}'", .{@tagName(lower.bin_file.tag)});
}
},
},

View File

@ -3222,8 +3222,6 @@ pub const Object = struct {
owner_mod: *Package.Module,
omit_frame_pointer: bool,
) Allocator.Error!void {
const comp = o.pt.zcu.comp;
if (!owner_mod.red_zone) {
try attributes.addFnAttr(.noredzone, &o.builder);
}
@ -3242,8 +3240,7 @@ pub const Object = struct {
if (owner_mod.unwind_tables) {
try attributes.addFnAttr(.{ .uwtable = Builder.Attribute.UwTable.default }, &o.builder);
}
const target = owner_mod.resolved_target.result;
if (comp.skip_linker_dependencies or comp.no_builtin or target.cpu.arch.isBpf()) {
if (owner_mod.no_builtin) {
// The intent here is for compiler-rt and libc functions to not generate
// infinite recursion. For example, if we are compiling the memcpy function,
// and llvm detects that the body is equivalent to memcpy, it may replace the
@ -3258,6 +3255,7 @@ pub const Object = struct {
try attributes.addFnAttr(.minsize, &o.builder);
try attributes.addFnAttr(.optsize, &o.builder);
}
const target = owner_mod.resolved_target.result;
if (target.cpu.model.llvm_name) |s| {
try attributes.addFnAttr(.{ .string = .{
.kind = try o.builder.string("target-cpu"),
@ -5578,6 +5576,10 @@ pub const FuncGen = struct {
var attributes: Builder.FunctionAttributes.Wip = .{};
defer attributes.deinit(&o.builder);
if (self.ng.ownerModule().no_builtin) {
try attributes.addFnAttr(.nobuiltin, &o.builder);
}
switch (modifier) {
.auto, .never_tail, .always_tail => {},
.never_inline => try attributes.addFnAttr(.@"noinline", &o.builder),
@ -12728,6 +12730,8 @@ fn backendSupportsF16(target: std.Target) bool {
.mips64,
.mips64el,
.s390x,
.sparc,
.sparc64,
=> false,
.arm,
.armeb,

View File

@ -1,10 +1,3 @@
const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const process = std.process;
const Allocator = std.mem.Allocator;
const Color = std.zig.Color;
const usage_fmt =
\\Usage: zig fmt [file]...
\\
@ -36,14 +29,11 @@ const Fmt = struct {
const SeenMap = std.AutoHashMap(fs.File.INode, void);
};
pub fn main() !void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_instance.deinit();
const arena = arena_instance.allocator();
const gpa = arena;
const args = try process.argsAlloc(arena);
pub fn run(
gpa: Allocator,
arena: Allocator,
args: []const []const u8,
) !void {
var color: Color = .auto;
var stdin_flag: bool = false;
var check_flag: bool = false;
@ -54,7 +44,7 @@ pub fn main() !void {
defer excluded_files.deinit();
{
var i: usize = 1;
var i: usize = 0;
while (i < args.len) : (i += 1) {
const arg = args[i];
if (mem.startsWith(u8, arg, "-")) {
@ -337,7 +327,10 @@ fn fmtPathFile(
}
}
fn fatal(comptime format: []const u8, args: anytype) noreturn {
std.log.err(format, args);
process.exit(1);
}
const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const process = std.process;
const Allocator = std.mem.Allocator;
const Color = std.zig.Color;
const fatal = std.process.fatal;

View File

@ -221,7 +221,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = comp.root_mod,
},
};
return comp.build_crt_file("crti", .Obj, null, .@"glibc crti.o", prog_node, &files);
return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &files, .{});
},
.crtn_o => {
var args = std.ArrayList([]const u8).init(arena);
@ -242,7 +242,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
return comp.build_crt_file("crtn", .Obj, null, .@"glibc crtn.o", prog_node, &files);
return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &files, .{});
},
.scrt1_o => {
const start_o: Compilation.CSourceFile = blk: {
@ -295,7 +295,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
};
var files = [_]Compilation.CSourceFile{ start_o, abi_note_o, init_o };
const basename = if (comp.config.output_mode == .Exe and !comp.config.pie) "crt1" else "Scrt1";
return comp.build_crt_file(basename, .Obj, null, .@"glibc Scrt1.o", prog_node, &files);
return comp.build_crt_file(basename, .Obj, .@"glibc Scrt1.o", prog_node, &files, .{});
},
.libc_nonshared_a => {
const s = path.sep_str;
@ -373,7 +373,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
"-fmerge-all-constants",
"-frounding-math",
"-Wno-unsupported-floating-point-opt", // For targets that don't support -frounding-math.
"-fno-stack-protector",
"-fno-common",
"-fmath-errno",
"-ftls-model=initial-exec",
@ -413,7 +412,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
files_index += 1;
}
const files = files_buf[0..files_index];
return comp.build_crt_file("c_nonshared", .Lib, null, .@"glibc libc_nonshared.a", prog_node, files);
return comp.build_crt_file("c_nonshared", .Lib, .@"glibc libc_nonshared.a", prog_node, files, .{});
},
}
}

View File

@ -195,7 +195,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
.valgrind = false,
.optimize_mode = optimize_mode,
.structured_cfg = comp.root_mod.structured_cfg,
.pic = comp.root_mod.pic,
.pic = if (target_util.supports_fpic(target)) true else null,
},
.global = config,
.cc_argv = &.{},
@ -278,9 +278,6 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
try cflags.append("-faligned-allocation");
}
if (target_util.supports_fpic(target)) {
try cflags.append("-fPIC");
}
try cflags.append("-nostdinc++");
try cflags.append("-std=c++23");
try cflags.append("-Wno-user-defined-literals");

View File

@ -29,11 +29,11 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
const root_name = switch (target.os.tag) {
// On Apple platforms, we use the same name as LLVM because the
// TSAN library implementation hard-codes a check for these names.
.macos => "clang_rt.tsan_osx_dynamic",
.ios => switch (target.abi) {
.simulator => "clang_rt.tsan_iossim_dynamic",
else => "clang_rt.tsan_ios_dynamic",
},
.driverkit, .macos => "clang_rt.tsan_osx_dynamic",
.ios => if (target.abi == .simulator) "clang_rt.tsan_iossim_dynamic" else "clang_rt.tsan_ios_dynamic",
.tvos => if (target.abi == .simulator) "clang_rt.tsan_tvossim_dynamic" else "clang_rt.tsan_tvos_dynamic",
.visionos => if (target.abi == .simulator) "clang_rt.tsan_xrossim_dynamic" else "clang_rt.tsan_xros_dynamic",
.watchos => if (target.abi == .simulator) "clang_rt.tsan_watchossim_dynamic" else "clang_rt.tsan_watchos_dynamic",
else => "tsan",
};
const link_mode: std.builtin.LinkMode = if (target.isDarwin()) .dynamic else .static;
@ -93,11 +93,12 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
.sanitize_c = false,
.sanitize_thread = false,
.red_zone = comp.root_mod.red_zone,
.omit_frame_pointer = comp.root_mod.omit_frame_pointer,
.omit_frame_pointer = optimize_mode != .Debug and !target.os.tag.isDarwin(),
.valgrind = false,
.optimize_mode = optimize_mode,
.structured_cfg = comp.root_mod.structured_cfg,
.pic = true,
.no_builtin = true,
},
.global = config,
.cc_argv = &common_flags,
@ -123,10 +124,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
try cflags.append("-I");
try cflags.append(tsan_include_path);
try cflags.append("-nostdinc++");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-std=c++17");
try cflags.append("-fno-rtti");
try addCcArgs(target, &cflags);
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &.{ "tsan", tsan_src }),
@ -147,10 +145,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
try cflags.append("-I");
try cflags.append(tsan_include_path);
try cflags.append("-nostdinc++");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-std=c++17");
try cflags.append("-fno-rtti");
try addCcArgs(target, &cflags);
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }),
@ -195,10 +190,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
try cflags.append("-I");
try cflags.append(tsan_include_path);
try cflags.append("-nostdinc++");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-std=c++17");
try cflags.append("-fno-rtti");
try addCcArgs(target, &cflags);
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -222,10 +214,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
try cflags.append("-I");
try cflags.append(tsan_include_path);
try cflags.append("-nostdinc++");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-std=c++17");
try cflags.append("-fno-rtti");
try addCcArgs(target, &cflags);
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -243,10 +232,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
try cflags.append("-I");
try cflags.append(tsan_include_path);
try cflags.append("-nostdinc++");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-std=c++17");
try cflags.append("-fno-rtti");
try addCcArgs(target, &cflags);
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -272,10 +258,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
try cflags.append("-I");
try cflags.append(tsan_include_path);
try cflags.append("-nostdinc++");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-std=c++17");
try cflags.append("-fno-rtti");
try addCcArgs(target, &cflags);
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -348,6 +331,25 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
comp.tsan_lib = crt_file;
}
fn addCcArgs(target: std.Target, args: *std.ArrayList([]const u8)) error{OutOfMemory}!void {
try args.appendSlice(&[_][]const u8{
"-nostdinc++",
"-fvisibility=hidden",
"-fvisibility-inlines-hidden",
"-std=c++17",
"-fno-rtti",
"-fno-exceptions",
});
if (target.abi.isAndroid() and target.os.version_range.linux.android >= 29) {
try args.append("-fno-emulated-tls");
}
if (target.isMinGW()) {
try args.append("-fms-extensions");
}
}
const tsan_sources = [_][]const u8{
"tsan_debugging.cpp",
"tsan_external.cpp",

View File

@ -46,6 +46,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
);
return error.SubCompilationFailed;
};
const target = comp.root_mod.resolved_target.result;
const root_mod = Module.create(arena, .{
.global_cache_directory = comp.global_cache_directory,
.paths = .{
@ -63,8 +64,9 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
.valgrind = false,
.sanitize_c = false,
.sanitize_thread = false,
.unwind_tables = false,
.pic = comp.root_mod.pic,
// necessary so that libunwind can unwind through its own stack frames
.unwind_tables = true,
.pic = if (target_util.supports_fpic(target)) true else null,
.optimize_mode = comp.compilerRtOptMode(),
},
.global = config,
@ -83,7 +85,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
const root_name = "unwind";
const link_mode = .static;
const target = comp.root_mod.resolved_target.result;
const basename = try std.zig.binNameAlloc(arena, .{
.root_name = root_name,
.target = target,
@ -114,16 +115,11 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
try cflags.append("-fno-exceptions");
try cflags.append("-I");
try cflags.append(try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libunwind", "include" }));
if (target_util.supports_fpic(target)) {
try cflags.append("-fPIC");
}
try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");
try cflags.append("-Wa,--noexecstack");
try cflags.append("-fvisibility=hidden");
try cflags.append("-fvisibility-inlines-hidden");
try cflags.append("-fvisibility-global-new-delete=force-hidden");
// necessary so that libunwind can unwind through its own stack frames
try cflags.append("-funwind-tables");
// This is intentionally always defined because the macro definition means, should it only
// build for the target specified by compiler defines. Since we pass -target the compiler

View File

@ -309,10 +309,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
.server = use_server,
});
} else if (mem.eql(u8, cmd, "fmt")) {
return jitCmd(gpa, arena, cmd_args, .{
.cmd_name = "fmt",
.root_src_path = "fmt.zig",
});
return @import("fmt.zig").run(gpa, arena, cmd_args);
} else if (mem.eql(u8, cmd, "objcopy")) {
return jitCmd(gpa, arena, cmd_args, .{
.cmd_name = "objcopy",
@ -810,7 +807,6 @@ fn buildOutputType(
var compatibility_version: ?std.SemanticVersion = null;
var function_sections = false;
var data_sections = false;
var no_builtin = false;
var listen: Listen = .none;
var debug_compile_errors = false;
var verbose_link = (native_os != .wasi or builtin.link_libc) and
@ -1550,9 +1546,9 @@ fn buildOutputType(
} else if (mem.eql(u8, arg, "-fno-data-sections")) {
data_sections = false;
} else if (mem.eql(u8, arg, "-fbuiltin")) {
no_builtin = false;
mod_opts.no_builtin = false;
} else if (mem.eql(u8, arg, "-fno-builtin")) {
no_builtin = true;
mod_opts.no_builtin = true;
} else if (mem.startsWith(u8, arg, "-fopt-bisect-limit=")) {
const next_arg = arg["-fopt-bisect-limit=".len..];
llvm_opt_bisect_limit = std.fmt.parseInt(c_int, next_arg, 0) catch |err|
@ -1963,8 +1959,8 @@ fn buildOutputType(
.no_function_sections => function_sections = false,
.data_sections => data_sections = true,
.no_data_sections => data_sections = false,
.builtin => no_builtin = false,
.no_builtin => no_builtin = true,
.builtin => mod_opts.no_builtin = false,
.no_builtin => mod_opts.no_builtin = true,
.color_diagnostics => color = .on,
.no_color_diagnostics => color = .off,
.stack_check => mod_opts.stack_check = true,
@ -3468,7 +3464,6 @@ fn buildOutputType(
.image_base = image_base,
.function_sections = function_sections,
.data_sections = data_sections,
.no_builtin = no_builtin,
.clang_passthrough_mode = clang_passthrough_mode,
.clang_preprocessor_mode = clang_preprocessor_mode,
.version = optional_version,

View File

@ -41,7 +41,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
return comp.build_crt_file("crt2", .Obj, null, .@"mingw-w64 crt2.o", prog_node, &files);
return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{});
},
.dllcrt2_o => {
@ -56,7 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
return comp.build_crt_file("dllcrt2", .Obj, null, .@"mingw-w64 dllcrt2.o", prog_node, &files);
return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{});
},
.mingw32_lib => {
@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
} else {
@panic("unsupported arch");
}
return comp.build_crt_file("mingw32", .Lib, null, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);
return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{});
},
}
}

View File

@ -38,7 +38,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
.owner = undefined,
},
};
return comp.build_crt_file("crti", .Obj, null, .@"musl crti.o", prog_node, &files);
return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &files, .{
.function_sections = true,
.data_sections = true,
.omit_frame_pointer = true,
.no_builtin = true,
});
},
.crtn_o => {
var args = std.ArrayList([]const u8).init(arena);
@ -50,15 +55,17 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
.owner = undefined,
},
};
return comp.build_crt_file("crtn", .Obj, null, .@"musl crtn.o", prog_node, &files);
return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &files, .{
.function_sections = true,
.data_sections = true,
.omit_frame_pointer = true,
.no_builtin = true,
});
},
.crt1_o => {
var args = std.ArrayList([]const u8).init(arena);
try addCcArgs(comp, arena, &args, false);
try args.appendSlice(&[_][]const u8{
"-fno-stack-protector",
"-DCRT",
});
try args.append("-DCRT");
var files = [_]Compilation.CSourceFile{
.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -68,15 +75,17 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
.owner = undefined,
},
};
return comp.build_crt_file("crt1", .Obj, null, .@"musl crt1.o", prog_node, &files);
return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{
.function_sections = true,
.data_sections = true,
.omit_frame_pointer = true,
.no_builtin = true,
});
},
.rcrt1_o => {
var args = std.ArrayList([]const u8).init(arena);
try addCcArgs(comp, arena, &args, false);
try args.appendSlice(&[_][]const u8{
"-fno-stack-protector",
"-DCRT",
});
try args.append("-DCRT");
var files = [_]Compilation.CSourceFile{
.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -86,15 +95,18 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
.owner = undefined,
},
};
return comp.build_crt_file("rcrt1", .Obj, true, .@"musl rcrt1.o", prog_node, &files);
return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{
.function_sections = true,
.data_sections = true,
.omit_frame_pointer = true,
.pic = true,
.no_builtin = true,
});
},
.scrt1_o => {
var args = std.ArrayList([]const u8).init(arena);
try addCcArgs(comp, arena, &args, false);
try args.appendSlice(&[_][]const u8{
"-fno-stack-protector",
"-DCRT",
});
try args.append("-DCRT");
var files = [_]Compilation.CSourceFile{
.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
@ -104,7 +116,13 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
.owner = undefined,
},
};
return comp.build_crt_file("Scrt1", .Obj, true, .@"musl Scrt1.o", prog_node, &files);
return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{
.function_sections = true,
.data_sections = true,
.omit_frame_pointer = true,
.pic = true,
.no_builtin = true,
});
},
.libc_a => {
// When there is a src/<arch>/foo.* then it should substitute for src/foo.*
@ -197,7 +215,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
.owner = undefined,
};
}
return comp.build_crt_file("c", .Lib, null, .@"musl libc.a", prog_node, c_source_files.items);
return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{
.function_sections = true,
.data_sections = true,
.omit_frame_pointer = true,
.no_builtin = true,
});
},
.libc_so => {
const optimize_mode = comp.compilerRtOptMode();
@ -410,7 +433,6 @@ fn addCcArgs(
try args.appendSlice(&[_][]const u8{
"-std=c99",
"-ffreestanding",
"-fno-builtin",
"-fexcess-precision=standard",
"-frounding-math",
"-ffp-contract=off",
@ -441,12 +463,6 @@ fn addCcArgs(
o_arg,
"-fomit-frame-pointer",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
"-ffunction-sections",
"-fdata-sections",
"-Qunused-arguments",
"-w", // disable all warnings
});

View File

@ -327,9 +327,8 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
}
pub fn clangMightShellOutForAssembly(target: std.Target) bool {
// Clang defaults to using the system assembler over the internal one
// when targeting a non-BSD OS.
return target.cpu.arch.isSPARC();
// Clang defaults to using the system assembler in some cases.
return target.cpu.arch.isNvptx() or target.cpu.arch == .xcore;
}
/// Each backend architecture in Clang has a different codepath which may or may not

View File

@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
return comp.build_crt_file("crt1-reactor", .Obj, null, .@"wasi crt1-reactor.o", prog_node, &files);
return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files, .{});
},
.crt1_command_o => {
var args = std.ArrayList([]const u8).init(arena);
@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
return comp.build_crt_file("crt1-command", .Obj, null, .@"wasi crt1-command.o", prog_node, &files);
return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files, .{});
},
.libc_a => {
var libc_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
@ -150,7 +150,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
}
}
try comp.build_crt_file("c", .Lib, null, .@"wasi libc.a", prog_node, libc_sources.items);
try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{});
},
.libwasi_emulated_process_clocks_a => {
var args = std.ArrayList([]const u8).init(arena);
@ -167,7 +167,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
});
}
try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, null, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);
try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items, .{});
},
.libwasi_emulated_getpid_a => {
var args = std.ArrayList([]const u8).init(arena);
@ -184,7 +184,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
});
}
try comp.build_crt_file("wasi-emulated-getpid", .Lib, null, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);
try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items, .{});
},
.libwasi_emulated_mman_a => {
var args = std.ArrayList([]const u8).init(arena);
@ -201,7 +201,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
});
}
try comp.build_crt_file("wasi-emulated-mman", .Lib, null, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);
try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items, .{});
},
.libwasi_emulated_signal_a => {
var emu_signal_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
@ -238,7 +238,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
}
}
try comp.build_crt_file("wasi-emulated-signal", .Lib, null, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items);
try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items, .{});
},
}
}
@ -279,7 +279,6 @@ fn addCCArgs(
try args.appendSlice(&[_][]const u8{
"-std=gnu17",
"-fno-trapping-math",
"-fno-stack-protector",
"-w", // ignore all warnings
o_arg,

View File

@ -1,10 +0,0 @@
pub fn main() void {
add(3, 4);
}
fn add(a: u32, b: u32) void {
if (a + b != 7) unreachable;
}
// run
//

View File

@ -1,12 +0,0 @@
pub fn main() void {
if (x - 7 != 0) unreachable;
}
fn add(a: u32, b: u32) u32 {
return a + b;
}
const x = add(3, 4);
// run
//

View File

@ -1,13 +0,0 @@
pub fn main() void {
var x: usize = 3;
_ = &x;
const y = add(1, 2, x);
if (y - 6 != 0) unreachable;
}
inline fn add(a: usize, b: usize, c: usize) usize {
return a + b + c;
}
// run
//

View File

@ -1,17 +0,0 @@
const std = @import("std");
pub fn main() void {
print(2, 4);
print(1, 7);
}
fn print(a: u32, b: u32) void {
const str = "123456789";
const len = a + b;
_ = std.posix.write(1, str[0..len]) catch {};
}
// run
// target=x86_64-linux,x86_64-macos
//
// 12345612345678

View File

@ -1,16 +0,0 @@
const std = @import("std");
pub fn main() void {
print(10, 5);
print(4, 3);
}
fn print(a: u32, b: u32) void {
const str = "123456789";
const len = a - b;
_ = std.posix.write(1, str[0..len]) catch {};
}
// run
//
// 123451

View File

@ -1,16 +0,0 @@
const std = @import("std");
pub fn main() void {
print(8, 9);
print(3, 7);
}
fn print(a: u32, b: u32) void {
const str = "123456789";
const len = a & b;
_ = std.posix.write(1, str[0..len]) catch {};
}
// run
//
// 12345678123

View File

@ -1,16 +0,0 @@
const std = @import("std");
pub fn main() void {
print(4, 2);
print(3, 7);
}
fn print(a: u32, b: u32) void {
const str = "123456789";
const len = a | b;
_ = std.posix.write(1, str[0..len]) catch {};
}
// run
//
// 1234561234567

View File

@ -1,16 +0,0 @@
const std = @import("std");
pub fn main() void {
print(42, 42);
print(3, 5);
}
fn print(a: u32, b: u32) void {
const str = "123456789";
const len = a ^ b;
_ = std.posix.write(1, str[0..len]) catch {};
}
// run
//
// 123456

View File

@ -1,15 +0,0 @@
pub fn main() void {
var x: u32 = 1;
assert(x << 1 == 2);
x <<= 1;
assert(x << 2 == 8);
assert(x << 3 == 16);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,21 +0,0 @@
pub fn main() void {
var a: u32 = 1024;
assert(a >> 1 == 512);
a >>= 1;
assert(a >> 2 == 128);
assert(a >> 3 == 64);
assert(a >> 4 == 32);
assert(a >> 5 == 16);
assert(a >> 6 == 8);
assert(a >> 7 == 4);
assert(a >> 8 == 2);
assert(a >> 9 == 1);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,15 +0,0 @@
pub fn main() void {
add(3, 4);
}
fn add(a: u32, b: u32) void {
assert(a + b == 7);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
// target=x86_64-macos,x86_64-linux
// link_libc=true

View File

@ -1,17 +0,0 @@
pub fn main() void {
add(3, 4);
}
fn add(a: u32, b: u32) void {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
assert(e == 14);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,27 +0,0 @@
pub fn main() void {
assert(add(3, 4) == 116);
}
fn add(a: u32, b: u32) u32 {
const x: u32 = blk: {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
const f = d + e; // 24
const g = e + f; // 38
const h = f + g; // 62
const i = g + h; // 100
const j = i + d; // 110
break :blk j;
};
const y = x + a; // 113
const z = y + a; // 116
return z;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,66 +0,0 @@
pub fn main() void {
assert(add(3, 4) == 1221);
assert(mul(3, 4) == 21609);
}
fn add(a: u32, b: u32) u32 {
const x: u32 = blk: {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
const f = d + e; // 24
const g = e + f; // 38
const h = f + g; // 62
const i = g + h; // 100
const j = i + d; // 110
const k = i + j; // 210
const l = j + k; // 320
const m = l + c; // 327
const n = m + d; // 337
const o = n + e; // 351
const p = o + f; // 375
const q = p + g; // 413
const r = q + h; // 475
const s = r + i; // 575
const t = s + j; // 685
const u = t + k; // 895
const v = u + l; // 1215
break :blk v;
};
const y = x + a; // 1218
const z = y + a; // 1221
return z;
}
fn mul(a: u32, b: u32) u32 {
const x: u32 = blk: {
const c = a * a * a * a; // 81
const d = a * a * a * b; // 108
const e = a * a * b * a; // 108
const f = a * a * b * b; // 144
const g = a * b * a * a; // 108
const h = a * b * a * b; // 144
const i = a * b * b * a; // 144
const j = a * b * b * b; // 192
const k = b * a * a * a; // 108
const l = b * a * a * b; // 144
const m = b * a * b * a; // 144
const n = b * a * b * b; // 192
const o = b * b * a * a; // 144
const p = b * b * a * b; // 192
const q = b * b * b * a; // 192
const r = b * b * b * b; // 256
const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
break :blk s;
};
const y = x * a; // 7203
const z = y * a; // 21609
return z;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,47 +0,0 @@
pub fn main() void {
assert(add(3, 4) == 791);
assert(add(4, 3) == 79);
}
fn add(a: u32, b: u32) u32 {
const x: u32 = if (a < b) blk: {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
const f = d + e; // 24
const g = e + f; // 38
const h = f + g; // 62
const i = g + h; // 100
const j = i + d; // 110
const k = i + j; // 210
const l = k + c; // 217
const m = l + d; // 227
const n = m + e; // 241
const o = n + f; // 265
const p = o + g; // 303
const q = p + h; // 365
const r = q + i; // 465
const s = r + j; // 575
const t = s + k; // 785
break :blk t;
} else blk: {
const t = b + b + a; // 10
const c = a + t; // 14
const d = c + t; // 24
const e = d + t; // 34
const f = e + t; // 44
const g = f + t; // 54
const h = c + g; // 68
break :blk h + b; // 71
};
const y = x + a; // 788, 75
const z = y + a; // 791, 79
return z;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,19 +0,0 @@
pub fn main() void {
const ignore =
\\ cool thx
\\
;
_ = ignore;
add('ぁ', '\x03');
}
fn add(a: u32, b: u32) void {
assert(a + b == 12356);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,17 +0,0 @@
pub fn main() void {
add(aa, bb);
}
const aa = 'ぁ';
const bb = '\x03';
fn add(a: u32, b: u32) void {
assert(a + b == 12356);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,10 +0,0 @@
pub fn main() void {
assert("hello"[0] == 'h');
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,11 +0,0 @@
const hello = "hello".*;
pub fn main() void {
assert(hello[1] == 'e');
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,12 +0,0 @@
pub fn main() void {
var i: u64 = 0xFFEEDDCCBBAA9988;
_ = &i;
assert(i == 0xFFEEDDCCBBAA9988);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,20 +0,0 @@
const builtin = @import("builtin");
extern "c" fn write(c_int, usize, usize) usize;
pub fn main() void {
for ("hello") |_| print();
}
fn print() void {
_ = write(1, @intFromPtr("hello\n"), 6);
}
// run
//
// hello
// hello
// hello
// hello
// hello
//

View File

@ -1,21 +0,0 @@
pub fn main() void {
add(3, 4);
}
fn add(a: u32, b: u32) void {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
const f = d + e; // 24
const g = e + f; // 38
const h = f + g; // 62
const i = g + h; // 100
assert(i == 100);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,22 +0,0 @@
pub fn main() void {
add(3, 4);
}
fn add(a: u32, b: u32) void {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
const f = d + e; // 24
const g = e + f; // 38
const h = f + g; // 62
const i = g + h; // 100
const j = i + d; // 110
assert(j == 110);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,15 +0,0 @@
pub fn main() void {
assert(add(3, 4) == 7);
assert(add(20, 10) == 30);
}
fn add(a: u32, b: u32) u32 {
return a + b;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,19 +0,0 @@
pub fn main() void {
assert(add(3, 4) == 7);
assert(add(20, 10) == 30);
}
fn add(a: u32, b: u32) u32 {
var x: u32 = undefined;
x = 0;
x += a;
x += b;
return x;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
const a: u32 = 2;
const b: ?u32 = a;
const c = b.?;
if (c != 2) unreachable;
}
// run
//

View File

@ -1,23 +0,0 @@
extern "c" fn write(c_int, usize, usize) usize;
pub fn main() void {
var i: u32 = 0;
while (i < 4) : (i += 1) print();
assert(i == 4);
}
fn print() void {
_ = write(1, @intFromPtr("hello\n"), 6);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//
// hello
// hello
// hello
// hello
//

View File

@ -1,20 +0,0 @@
extern "c" fn write(c_int, usize, usize) usize;
pub fn main() void {
var i: u32 = 0;
inline while (i < 4) : (i += 1) print();
assert(i == 4);
}
fn print() void {
_ = write(1, @intFromPtr("hello\n"), 6);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// error
//
// :5:21: error: unable to resolve comptime value
// :5:21: note: condition in comptime branch must be comptime-known

View File

@ -1,22 +0,0 @@
pub fn main() void {
assert(add(3, 4) == 20);
}
fn add(a: u32, b: u32) u32 {
const x: u32 = blk: {
const c = a + b; // 7
const d = a + c; // 10
const e = d + b; // 14
break :blk e;
};
const y = x + a; // 17
const z = y + a; // 20
return z;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: u8 = 5;
i += 20;
if (i != 25) unreachable;
}
// run
// target=wasm32-wasi
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: i32 = 2147483647;
_ = &i;
if (i +% 1 != -2147483648) unreachable;
return;
}
// run
//

View File

@ -1,14 +0,0 @@
pub fn main() void {
var i: u32 = 5;
i *= 7;
var result: u32 = foo(i, 10);
_ = &result;
if (result != 350) unreachable;
return;
}
fn foo(x: u32, y: u32) u32 {
return x * y;
}
// run
//

View File

@ -1,10 +0,0 @@
pub fn main() void {
var i: i32 = 2147483647;
_ = &i;
const result = i *% 2;
if (result != -2) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: u3 = 3;
_ = &i;
if (i *% 3 != 1) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: i4 = 3;
_ = &i;
if (i *% 3 != -7) unreachable;
return;
}
// run
//

View File

@ -1,13 +0,0 @@
pub fn main() void {
var i: u32 = 352;
i /= 7; // i = 50
const result: u32 = foo(i, 7);
if (result != 7) unreachable;
return;
}
fn foo(x: u32, y: u32) u32 {
return x / y;
}
// run
//

View File

@ -1,8 +0,0 @@
pub fn main() u8 {
var i: u8 = 5;
i &= 6;
return i - 4;
}
// run
//

View File

@ -1,8 +0,0 @@
pub fn main() u8 {
var i: u8 = 5;
i |= 6;
return i - 7;
}
// run
//

View File

@ -1,8 +0,0 @@
pub fn main() u8 {
var i: u8 = 5;
i ^= 6;
return i - 3;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = false;
b = b or false;
if (b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = true;
b = b or false;
if (!b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: i4 = 7;
_ = &i;
if (i +% 1 != -8) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = false;
b = b or true;
if (!b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = true;
b = b or true;
if (!b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = false;
b = b and false;
if (b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = true;
b = b and false;
if (b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = false;
b = b and true;
if (b) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var b: bool = true;
b = b and true;
if (!b) unreachable;
return;
}
// run
//

View File

@ -1,8 +0,0 @@
pub fn main() u8 {
var i: u8 = 255;
_ = &i;
return i +% 1;
}
// run
//

View File

@ -1,12 +0,0 @@
pub fn main() u8 {
var i: u8 = 5;
i += 20;
const result: u8 = foo(i, 10);
return result - 35;
}
fn foo(x: u8, y: u8) u8 {
return x + y;
}
// run
//

View File

@ -1,8 +0,0 @@
pub fn main() u8 {
var i: u8 = 20;
i -= 5;
return i - 15;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: i32 = -2147483648;
_ = &i;
if (i -% 1 != 2147483647) unreachable;
return;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
var i: i7 = -64;
_ = &i;
if (i -% 1 != 63) unreachable;
return;
}
// run
//

View File

@ -1,8 +0,0 @@
pub fn main() void {
var i: u4 = 0;
_ = &i;
if (i -% 1 != 15) unreachable;
}
// run
//

View File

@ -1,13 +0,0 @@
pub fn main() u8 {
var i: u8 = 5;
i -= 3;
var result: u8 = foo(i, 10);
_ = &result;
return result - 8;
}
fn foo(x: u8, y: u8) u8 {
return y - x;
}
// run
//

View File

@ -1,9 +0,0 @@
pub fn main() void {
while (true) {
break;
}
}
// run
// target=x86_64-linux,x86_64-macos
//

View File

@ -1,8 +0,0 @@
pub fn main() void {
foo: while (true) {
break :foo;
}
}
// run
//

View File

@ -1,10 +0,0 @@
pub fn main() void {
var i: u64 = 0;
while (true) : (i += 1) {
if (i == 4) return;
continue;
}
}
// run
//

View File

@ -1,10 +0,0 @@
pub fn main() void {
var i: u64 = 0;
foo: while (true) : (i += 1) {
if (i == 4) return;
continue :foo;
}
}
// run
//

View File

@ -1,11 +0,0 @@
pub fn main() void {
const i: anyerror!u64 = 0;
const caught = i catch 5;
assert(caught == 0);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -1,11 +0,0 @@
pub fn main() void {
const i: anyerror!u64 = error.B;
const caught = i catch 5;
assert(caught == 5);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -1,11 +0,0 @@
pub fn main() void {
const a: anyerror!comptime_int = 42;
const b: *const comptime_int = &(a catch unreachable);
assert(b.* == 42);
}
fn assert(b: bool) void {
if (!b) unreachable; // assertion failure
}
// run
//

View File

@ -1,10 +0,0 @@
pub fn main() void {
const a: anyerror!u32 = error.B;
_ = &(a catch |err| assert(err == error.B));
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -1,10 +0,0 @@
pub fn main() void {
const a: anyerror!u32 = error.Bar;
a catch |err| assert(err == error.Bar);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,10 @@
export fn foo() void {
const result: u32 = b: {
if (false) break :b 1;
};
_ = result;
}
// error
//
// :2:28: error: expected type 'u32', found 'void'

View File

@ -1,22 +0,0 @@
export fn _start() noreturn {
const b = true;
var f: u32 = 1;
@compileLog(b, 20, f, x);
@compileLog(1000);
var bruh: usize = true;
_ = .{ &f, &bruh };
unreachable;
}
export fn other() void {
@compileLog(1234);
}
fn x() void {}
// error
//
// :6:23: error: expected type 'usize', found 'bool'
//
// Compile Log Output:
// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
// @as(comptime_int, 1000)
// @as(comptime_int, 1234)

View File

@ -1,21 +0,0 @@
export fn _start() noreturn {
const b = true;
var f: u32 = 1;
_ = &f;
@compileLog(b, 20, f, x);
@compileLog(1000);
unreachable;
}
export fn other() void {
@compileLog(1234);
}
fn x() void {}
// error
//
// :9:5: error: found compile log statement
// :4:5: note: also here
//
// Compile Log Output:
// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
// @as(comptime_int, 1000)

View File

@ -1,14 +0,0 @@
pub fn main() void {
var a: u32 = 0;
_ = &a;
comptime var b: u32 = 0;
if (a == 0) b = 3;
}
// error
// output_mode=Exe
// target=x86_64-macos,x86_64-linux
// link_libc=true
//
// :5:19: error: store to comptime variable depends on runtime condition
// :5:11: note: runtime condition here

View File

@ -1,14 +0,0 @@
pub fn main() void {
var a: u32 = 0;
_ = &a;
comptime var b: u32 = 0;
switch (a) {
0 => {},
else => b = 3,
}
}
// error
//
// :6:19: error: store to comptime variable depends on runtime condition
// :4:13: note: runtime condition here

View File

@ -1,17 +0,0 @@
extern "c" fn write(c_int, usize, usize) usize;
pub fn main() void {
comptime var len: u32 = 5;
print(len);
len += 9;
print(len);
}
fn print(len: usize) void {
_ = write(1, @intFromPtr("Hello, World!\n"), len);
}
// run
//
// HelloHello, World!
//

View File

@ -1,10 +0,0 @@
comptime {
var x: i32 = 1;
x += 1;
if (x != 1) unreachable;
}
pub fn main() void {}
// error
//
// :4:17: error: reached unreachable code

View File

@ -1,9 +0,0 @@
pub fn main() void {
comptime var i: u64 = 0;
while (i < 5) : (i += 1) {}
}
// error
//
// :3:24: error: cannot store to comptime variable in non-inline loop
// :3:5: note: non-inline loop here

View File

@ -1,16 +0,0 @@
pub fn main() void {
var a: u32 = 0;
_ = &a;
if (a == 0) {
comptime var b: u32 = 0;
b = 1;
}
}
comptime {
var x: i32 = 1;
x += 1;
if (x != 2) unreachable;
}
// run
//

View File

@ -1,15 +0,0 @@
extern "c" fn write(c_int, usize, usize) usize;
pub fn main() void {
comptime var i: u64 = 2;
inline while (i < 6) : (i += 1) {
print(i);
}
}
fn print(len: usize) void {
_ = write(1, @intFromPtr("Hello"), len);
}
// run
//
// HeHelHellHello

Some files were not shown because too many files have changed in this diff Show More