authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-27 22:04:00-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-27 22:04:00-07:00
logc650ccfca719b695fe7752f9126e8dbcc2ab4d6d
treedc112b2472f53e44e377dee68d30db02caed8c03
parentdfc7493dcb049788b92137ca09b8bd47cee23865
parent3ccb6a0cd4d4f436a6009ed614436bb3e2e27a7c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #12265 from ziglang/stage3-run-translated-c

CI: test-run-translated-c with stage3

8 files changed, 194 insertions(+), 88 deletions(-)

ci/zinc/linux_test.sh+13-13
...@@ -52,22 +52,22 @@ stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --searc...@@ -52,22 +52,22 @@ stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --searc
52stage3/bin/zig build # test building self-hosted without LLVM52stage3/bin/zig build # test building self-hosted without LLVM
53stage3/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm53stage3/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm
5454
55stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Denable-llvm55stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Denable-llvm
56stage3/bin/zig build test-behavior -fqemu -fwasmtime -Denable-llvm56stage3/bin/zig build test-behavior -fqemu -fwasmtime -Denable-llvm
57stage3/bin/zig build test-std -fqemu -fwasmtime -Denable-llvm57stage3/bin/zig build test-std -fqemu -fwasmtime -Denable-llvm
58stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Denable-llvm58stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Denable-llvm
59stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Denable-llvm59stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Denable-llvm
60stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm60stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm
61stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm61stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm
62stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm62stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm
63stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm63stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Denable-llvm
64stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm64stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm
65stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm
65# https://github.com/ziglang/zig/issues/1214466# https://github.com/ziglang/zig/issues/12144
66stage3/bin/zig build test-cases -fqemu -fwasmtime67stage3/bin/zig build test-cases -fqemu -fwasmtime
67stage3/bin/zig build test-link -fqemu -fwasmtime -Denable-llvm68stage3/bin/zig build test-link -fqemu -fwasmtime -Denable-llvm
6869
69$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime70$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime
70$STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime
71$STAGE1_ZIG build docs -fqemu -fwasmtime71$STAGE1_ZIG build docs -fqemu -fwasmtime
7272
73# Produce the experimental std lib documentation.73# Produce the experimental std lib documentation.
src/AstGen.zig+21-20
...@@ -10282,11 +10282,11 @@ const GenZir = struct {...@@ -10282,11 +10282,11 @@ const GenZir = struct {
10282 try astgen.extra.ensureUnusedCapacity(10282 try astgen.extra.ensureUnusedCapacity(
10283 gpa,10283 gpa,
10284 @typeInfo(Zir.Inst.FuncFancy).Struct.fields.len +10284 @typeInfo(Zir.Inst.FuncFancy).Struct.fields.len +
10285 fancyFnExprExtraLen(align_body, args.align_ref) +10285 fancyFnExprExtraLen(astgen, align_body, args.align_ref) +
10286 fancyFnExprExtraLen(addrspace_body, args.addrspace_ref) +10286 fancyFnExprExtraLen(astgen, addrspace_body, args.addrspace_ref) +
10287 fancyFnExprExtraLen(section_body, args.section_ref) +10287 fancyFnExprExtraLen(astgen, section_body, args.section_ref) +
10288 fancyFnExprExtraLen(cc_body, args.cc_ref) +10288 fancyFnExprExtraLen(astgen, cc_body, args.cc_ref) +
10289 fancyFnExprExtraLen(ret_body, ret_ref) +10289 fancyFnExprExtraLen(astgen, ret_body, ret_ref) +
10290 body_len + src_locs.len +10290 body_len + src_locs.len +
10291 @boolToInt(args.lib_name != 0) +10291 @boolToInt(args.lib_name != 0) +
10292 @boolToInt(args.noalias_bits != 0),10292 @boolToInt(args.noalias_bits != 0),
...@@ -10322,36 +10322,36 @@ const GenZir = struct {...@@ -10322,36 +10322,36 @@ const GenZir = struct {
1032210322
10323 const zir_datas = astgen.instructions.items(.data);10323 const zir_datas = astgen.instructions.items(.data);
10324 if (align_body.len != 0) {10324 if (align_body.len != 0) {
10325 astgen.extra.appendAssumeCapacity(@intCast(u32, align_body.len));10325 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body));
10326 astgen.extra.appendSliceAssumeCapacity(align_body);10326 astgen.appendBodyWithFixups(align_body);
10327 zir_datas[align_body[align_body.len - 1]].@"break".block_inst = new_index;10327 zir_datas[align_body[align_body.len - 1]].@"break".block_inst = new_index;
10328 } else if (args.align_ref != .none) {10328 } else if (args.align_ref != .none) {
10329 astgen.extra.appendAssumeCapacity(@enumToInt(args.align_ref));10329 astgen.extra.appendAssumeCapacity(@enumToInt(args.align_ref));
10330 }10330 }
10331 if (addrspace_body.len != 0) {10331 if (addrspace_body.len != 0) {
10332 astgen.extra.appendAssumeCapacity(@intCast(u32, addrspace_body.len));10332 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body));
10333 astgen.extra.appendSliceAssumeCapacity(addrspace_body);10333 astgen.appendBodyWithFixups(addrspace_body);
10334 zir_datas[addrspace_body[addrspace_body.len - 1]].@"break".block_inst = new_index;10334 zir_datas[addrspace_body[addrspace_body.len - 1]].@"break".block_inst = new_index;
10335 } else if (args.addrspace_ref != .none) {10335 } else if (args.addrspace_ref != .none) {
10336 astgen.extra.appendAssumeCapacity(@enumToInt(args.addrspace_ref));10336 astgen.extra.appendAssumeCapacity(@enumToInt(args.addrspace_ref));
10337 }10337 }
10338 if (section_body.len != 0) {10338 if (section_body.len != 0) {
10339 astgen.extra.appendAssumeCapacity(@intCast(u32, section_body.len));10339 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body));
10340 astgen.extra.appendSliceAssumeCapacity(section_body);10340 astgen.appendBodyWithFixups(section_body);
10341 zir_datas[section_body[section_body.len - 1]].@"break".block_inst = new_index;10341 zir_datas[section_body[section_body.len - 1]].@"break".block_inst = new_index;
10342 } else if (args.section_ref != .none) {10342 } else if (args.section_ref != .none) {
10343 astgen.extra.appendAssumeCapacity(@enumToInt(args.section_ref));10343 astgen.extra.appendAssumeCapacity(@enumToInt(args.section_ref));
10344 }10344 }
10345 if (cc_body.len != 0) {10345 if (cc_body.len != 0) {
10346 astgen.extra.appendAssumeCapacity(@intCast(u32, cc_body.len));10346 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body));
10347 astgen.extra.appendSliceAssumeCapacity(cc_body);10347 astgen.appendBodyWithFixups(cc_body);
10348 zir_datas[cc_body[cc_body.len - 1]].@"break".block_inst = new_index;10348 zir_datas[cc_body[cc_body.len - 1]].@"break".block_inst = new_index;
10349 } else if (args.cc_ref != .none) {10349 } else if (args.cc_ref != .none) {
10350 astgen.extra.appendAssumeCapacity(@enumToInt(args.cc_ref));10350 astgen.extra.appendAssumeCapacity(@enumToInt(args.cc_ref));
10351 }10351 }
10352 if (ret_body.len != 0) {10352 if (ret_body.len != 0) {
10353 astgen.extra.appendAssumeCapacity(@intCast(u32, ret_body.len));10353 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body));
10354 astgen.extra.appendSliceAssumeCapacity(ret_body);10354 astgen.appendBodyWithFixups(ret_body);
10355 zir_datas[ret_body[ret_body.len - 1]].@"break".block_inst = new_index;10355 zir_datas[ret_body[ret_body.len - 1]].@"break".block_inst = new_index;
10356 } else if (ret_ref != .none) {10356 } else if (ret_ref != .none) {
10357 astgen.extra.appendAssumeCapacity(@enumToInt(ret_ref));10357 astgen.extra.appendAssumeCapacity(@enumToInt(ret_ref));
...@@ -10389,11 +10389,12 @@ const GenZir = struct {...@@ -10389,11 +10389,12 @@ const GenZir = struct {
10389 try astgen.extra.ensureUnusedCapacity(10389 try astgen.extra.ensureUnusedCapacity(
10390 gpa,10390 gpa,
10391 @typeInfo(Zir.Inst.Func).Struct.fields.len + 1 +10391 @typeInfo(Zir.Inst.Func).Struct.fields.len + 1 +
10392 @maximum(ret_body.len, @boolToInt(ret_ref != .none)) +10392 fancyFnExprExtraLen(astgen, ret_body, ret_ref) +
10393 body_len + src_locs.len,10393 body_len + src_locs.len,
10394 );10394 );
10395
10395 const ret_body_len = if (ret_body.len != 0)10396 const ret_body_len = if (ret_body.len != 0)
10396 @intCast(u32, ret_body.len)10397 countBodyLenAfterFixups(astgen, ret_body)
10397 else10398 else
10398 @boolToInt(ret_ref != .none);10399 @boolToInt(ret_ref != .none);
1039910400
...@@ -10404,7 +10405,7 @@ const GenZir = struct {...@@ -10404,7 +10405,7 @@ const GenZir = struct {
10404 });10405 });
10405 const zir_datas = astgen.instructions.items(.data);10406 const zir_datas = astgen.instructions.items(.data);
10406 if (ret_body.len != 0) {10407 if (ret_body.len != 0) {
10407 astgen.extra.appendSliceAssumeCapacity(ret_body);10408 astgen.appendBodyWithFixups(ret_body);
10408 zir_datas[ret_body[ret_body.len - 1]].@"break".block_inst = new_index;10409 zir_datas[ret_body[ret_body.len - 1]].@"break".block_inst = new_index;
10409 } else if (ret_ref != .none) {10410 } else if (ret_ref != .none) {
10410 astgen.extra.appendAssumeCapacity(@enumToInt(ret_ref));10411 astgen.extra.appendAssumeCapacity(@enumToInt(ret_ref));
...@@ -10435,10 +10436,10 @@ const GenZir = struct {...@@ -10435,10 +10436,10 @@ const GenZir = struct {
10435 }10436 }
10436 }10437 }
1043710438
10438 fn fancyFnExprExtraLen(body: []Zir.Inst.Index, ref: Zir.Inst.Ref) usize {10439 fn fancyFnExprExtraLen(astgen: *AstGen, body: []Zir.Inst.Index, ref: Zir.Inst.Ref) u32 {
10439 // In the case of non-empty body, there is one for the body length,10440 // In the case of non-empty body, there is one for the body length,
10440 // and then one for each instruction.10441 // and then one for each instruction.
10441 return body.len + @boolToInt(ref != .none);10442 return countBodyLenAfterFixups(astgen, body) + @boolToInt(ref != .none);
10442 }10443 }
1044310444
10444 fn addVar(gz: *GenZir, args: struct {10445 fn addVar(gz: *GenZir, args: struct {
src/codegen/llvm.zig+33-3
...@@ -3646,6 +3646,24 @@ pub const DeclGen = struct {...@@ -3646,6 +3646,24 @@ pub const DeclGen = struct {
3646 },3646 },
3647 .Struct => {3647 .Struct => {
3648 const field_ty = parent_ty.structFieldType(field_index);3648 const field_ty = parent_ty.structFieldType(field_index);
3649 if (parent_ty.containerLayout() == .Packed) {
3650 const llvm_usize = dg.context.intType(target.cpu.arch.ptrBitWidth());
3651 const base_addr = parent_llvm_ptr.constPtrToInt(llvm_usize);
3652 // count bits of fields before this one
3653 const prev_bits = b: {
3654 var b: usize = 0;
3655 for (parent_ty.structFields().values()[0..field_index]) |field| {
3656 if (field.is_comptime or !field.ty.hasRuntimeBitsIgnoreComptime()) continue;
3657 b += field.ty.bitSize(target);
3658 }
3659 break :b b;
3660 };
3661 const byte_offset = llvm_usize.constInt((prev_bits + 7) / 8, .False);
3662 const field_addr = base_addr.constAdd(byte_offset);
3663 bitcast_needed = false;
3664 const final_llvm_ty = (try dg.lowerType(ptr_child_ty)).pointerType(0);
3665 break :blk field_addr.constIntToPtr(final_llvm_ty);
3666 }
3649 bitcast_needed = !field_ty.eql(ptr_child_ty, dg.module);3667 bitcast_needed = !field_ty.eql(ptr_child_ty, dg.module);
36503668
3651 var ty_buf: Type.Payload.Pointer = undefined;3669 var ty_buf: Type.Payload.Pointer = undefined;
...@@ -4473,17 +4491,29 @@ pub const FuncGen = struct {...@@ -4473,17 +4491,29 @@ pub const FuncGen = struct {
4473 }4491 }
4474 return null;4492 return null;
4475 }4493 }
4494
4476 const abi_ret_ty = try lowerFnRetTy(self.dg, fn_info);4495 const abi_ret_ty = try lowerFnRetTy(self.dg, fn_info);
4496 const ptr_abi_ty = abi_ret_ty.pointerType(0);
4477 const operand = try self.resolveInst(un_op);4497 const operand = try self.resolveInst(un_op);
4498 const target = self.dg.module.getTarget();
4499 const alignment = ret_ty.abiAlignment(target);
4500
4501 if (isByRef(ret_ty)) {
4502 // operand is a pointer however self.ret_ptr is null so that means
4503 // we need to return a value.
4504 const casted_ptr = self.builder.buildBitCast(operand, ptr_abi_ty, "");
4505 const load_inst = self.builder.buildLoad(casted_ptr, "");
4506 load_inst.setAlignment(alignment);
4507 _ = self.builder.buildRet(load_inst);
4508 return null;
4509 }
4510
4478 const llvm_ret_ty = operand.typeOf();4511 const llvm_ret_ty = operand.typeOf();
4479 if (abi_ret_ty == llvm_ret_ty) {4512 if (abi_ret_ty == llvm_ret_ty) {
4480 _ = self.builder.buildRet(operand);4513 _ = self.builder.buildRet(operand);
4481 return null;4514 return null;
4482 }4515 }
44834516
4484 const target = self.dg.module.getTarget();
4485 const alignment = ret_ty.abiAlignment(target);
4486 const ptr_abi_ty = abi_ret_ty.pointerType(0);
4487 const rp = self.buildAlloca(llvm_ret_ty);4517 const rp = self.buildAlloca(llvm_ret_ty);
4488 rp.setAlignment(alignment);4518 rp.setAlignment(alignment);
4489 const store_inst = self.builder.buildStore(operand, rp);4519 const store_inst = self.builder.buildStore(operand, rp);
src/codegen/llvm/bindings.zig+3
...@@ -169,6 +169,9 @@ pub const Value = opaque {...@@ -169,6 +169,9 @@ pub const Value = opaque {
169 pub const constNot = LLVMConstNot;169 pub const constNot = LLVMConstNot;
170 extern fn LLVMConstNot(ConstantVal: *const Value) *const Value;170 extern fn LLVMConstNot(ConstantVal: *const Value) *const Value;
171171
172 pub const constAdd = LLVMConstAdd;
173 extern fn LLVMConstAdd(LHSConstant: *const Value, RHSConstant: *const Value) *const Value;
174
172 pub const setWeak = LLVMSetWeak;175 pub const setWeak = LLVMSetWeak;
173 extern fn LLVMSetWeak(CmpXchgInst: *const Value, IsWeak: Bool) void;176 extern fn LLVMSetWeak(CmpXchgInst: *const Value, IsWeak: Bool) void;
174177
test/behavior/fn.zig+14
...@@ -408,3 +408,17 @@ test "function with inferred error set but returning no error" {...@@ -408,3 +408,17 @@ test "function with inferred error set but returning no error" {
408 const return_ty = @typeInfo(@TypeOf(S.foo)).Fn.return_type.?;408 const return_ty = @typeInfo(@TypeOf(S.foo)).Fn.return_type.?;
409 try expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len);409 try expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len);
410}410}
411
412test "import passed byref to function in return type" {
413 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
414 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
415
416 const S = struct {
417 fn get() @import("std").ArrayListUnmanaged(i32) {
418 var x: @import("std").ArrayListUnmanaged(i32) = .{};
419 return x;
420 }
421 };
422 var list = S.get();
423 try expect(list.items.len == 0);
424}
test/behavior/packed-struct.zig+22
...@@ -436,3 +436,25 @@ test "load pointer from packed struct" {...@@ -436,3 +436,25 @@ test "load pointer from packed struct" {
436 try expect(i == 123);436 try expect(i == 123);
437 }437 }
438}438}
439
440test "@ptrToInt on a packed struct field" {
441 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
442 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
443 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
444 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
445 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
446
447 const S = struct {
448 const P = packed struct {
449 x: u8,
450 y: u8,
451 z: u32,
452 };
453 var p0: P = P{
454 .x = 1,
455 .y = 2,
456 .z = 0,
457 };
458 };
459 try expect(@ptrToInt(&S.p0.z) - @ptrToInt(&S.p0.x) == 2);
460}
test/behavior/union.zig+30
...@@ -1226,3 +1226,33 @@ test "extern union most-aligned field is smaller" {...@@ -1226,3 +1226,33 @@ test "extern union most-aligned field is smaller" {
1226 var a: ?U = .{ .un = [_]u8{0} ** 110 };1226 var a: ?U = .{ .un = [_]u8{0} ** 110 };
1227 try expect(a != null);1227 try expect(a != null);
1228}1228}
1229
1230test "return an extern union from C calling convention" {
1231 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1232 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1233 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1234
1235 const namespace = struct {
1236 const S = extern struct {
1237 x: c_int,
1238 };
1239 const U = extern union {
1240 l: c_long,
1241 d: f64,
1242 s: S,
1243 };
1244
1245 fn bar(arg_u: U) callconv(.C) U {
1246 var u = arg_u;
1247 return u;
1248 }
1249 };
1250
1251 var u: namespace.U = namespace.U{
1252 .l = @as(c_long, 42),
1253 };
1254 u = namespace.bar(namespace.U{
1255 .d = 4.0,
1256 });
1257 try expect(u.d == 4.0);
1258}
test/run_translated_c.zig+58-52
...@@ -891,39 +891,42 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {...@@ -891,39 +891,42 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
891 \\}891 \\}
892 , "");892 , "");
893893
894 cases.add("Obscure ways of calling functions; issue #4124",894 if (@import("builtin").zig_backend == .stage1) {
895 \\#include <stdlib.h>895 // https://github.com/ziglang/zig/issues/12263
896 \\static int add(int a, int b) {896 cases.add("Obscure ways of calling functions; issue #4124",
897 \\ return a + b;897 \\#include <stdlib.h>
898 \\}898 \\static int add(int a, int b) {
899 \\typedef int (*adder)(int, int);899 \\ return a + b;
900 \\typedef void (*funcptr)(void);900 \\}
901 \\int main() {901 \\typedef int (*adder)(int, int);
902 \\ if ((add)(1, 2) != 3) abort();902 \\typedef void (*funcptr)(void);
903 \\ if ((&add)(1, 2) != 3) abort();903 \\int main() {
904 \\ if (add(3, 1) != 4) abort();904 \\ if ((add)(1, 2) != 3) abort();
905 \\ if ((*add)(2, 3) != 5) abort();905 \\ if ((&add)(1, 2) != 3) abort();
906 \\ if ((**add)(7, -1) != 6) abort();906 \\ if (add(3, 1) != 4) abort();
907 \\ if ((***add)(-2, 9) != 7) abort();907 \\ if ((*add)(2, 3) != 5) abort();
908 \\908 \\ if ((**add)(7, -1) != 6) abort();
909 \\ int (*ptr)(int a, int b);909 \\ if ((***add)(-2, 9) != 7) abort();
910 \\ ptr = add;910 \\
911 \\911 \\ int (*ptr)(int a, int b);
912 \\ if (ptr(1, 2) != 3) abort();912 \\ ptr = add;
913 \\ if ((*ptr)(3, 1) != 4) abort();913 \\
914 \\ if ((**ptr)(2, 3) != 5) abort();914 \\ if (ptr(1, 2) != 3) abort();
915 \\ if ((***ptr)(7, -1) != 6) abort();915 \\ if ((*ptr)(3, 1) != 4) abort();
916 \\ if ((****ptr)(-2, 9) != 7) abort();916 \\ if ((**ptr)(2, 3) != 5) abort();
917 \\917 \\ if ((***ptr)(7, -1) != 6) abort();
918 \\ funcptr addr1 = (funcptr)(add);918 \\ if ((****ptr)(-2, 9) != 7) abort();
919 \\ funcptr addr2 = (funcptr)(&add);919 \\
920 \\920 \\ funcptr addr1 = (funcptr)(add);
921 \\ if (addr1 != addr2) abort();921 \\ funcptr addr2 = (funcptr)(&add);
922 \\ if (((int(*)(int, int))addr1)(1, 2) != 3) abort();922 \\
923 \\ if (((adder)addr2)(1, 2) != 3) abort();923 \\ if (addr1 != addr2) abort();
924 \\ return 0;924 \\ if (((int(*)(int, int))addr1)(1, 2) != 3) abort();
925 \\}925 \\ if (((adder)addr2)(1, 2) != 3) abort();
926 , "");926 \\ return 0;
927 \\}
928 , "");
929 }
927930
928 cases.add("Return boolean expression as int; issue #6215",931 cases.add("Return boolean expression as int; issue #6215",
929 \\#include <stdlib.h>932 \\#include <stdlib.h>
...@@ -1319,25 +1322,28 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {...@@ -1319,25 +1322,28 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
1319 \\}1322 \\}
1320 , "");1323 , "");
13211324
1322 cases.add("basic vector expressions",1325 if (@import("builtin").zig_backend == .stage1) {
1323 \\#include <stdlib.h>1326 // https://github.com/ziglang/zig/issues/12264
1324 \\#include <stdint.h>1327 cases.add("basic vector expressions",
1325 \\typedef int16_t __v8hi __attribute__((__vector_size__(16)));1328 \\#include <stdlib.h>
1326 \\int main(int argc, char**argv) {1329 \\#include <stdint.h>
1327 \\ __v8hi uninitialized;1330 \\typedef int16_t __v8hi __attribute__((__vector_size__(16)));
1328 \\ __v8hi empty_init = {};1331 \\int main(int argc, char**argv) {
1329 \\ __v8hi partial_init = {0, 1, 2, 3};1332 \\ __v8hi uninitialized;
1330 \\1333 \\ __v8hi empty_init = {};
1331 \\ __v8hi a = {0, 1, 2, 3, 4, 5, 6, 7};1334 \\ __v8hi partial_init = {0, 1, 2, 3};
1332 \\ __v8hi b = (__v8hi) {100, 200, 300, 400, 500, 600, 700, 800};1335 \\
1333 \\1336 \\ __v8hi a = {0, 1, 2, 3, 4, 5, 6, 7};
1334 \\ __v8hi sum = a + b;1337 \\ __v8hi b = (__v8hi) {100, 200, 300, 400, 500, 600, 700, 800};
1335 \\ for (int i = 0; i < 8; i++) {1338 \\
1336 \\ if (sum[i] != a[i] + b[i]) abort();1339 \\ __v8hi sum = a + b;
1337 \\ }1340 \\ for (int i = 0; i < 8; i++) {
1338 \\ return 0;1341 \\ if (sum[i] != a[i] + b[i]) abort();
1339 \\}1342 \\ }
1340 , "");1343 \\ return 0;
1344 \\}
1345 , "");
1346 }
13411347
1342 cases.add("__builtin_shufflevector",1348 cases.add("__builtin_shufflevector",
1343 \\#include <stdlib.h>1349 \\#include <stdlib.h>