Commit Graph

5005 Commits

Author SHA1 Message Date
Jacob Young
e20d2b3151 cbe: fix floating point builtins 2022-10-25 07:02:06 -04:00
Jacob Young
3d22327b23 cbe: enable test fixed by #13296 2022-10-25 05:43:00 -04:00
Jacob Young
94425fe46e cbe: improve floating point type support 2022-10-25 05:22:55 -04:00
Jacob Young
6021edd7ce cbe: add support for all float literals types 2022-10-25 05:22:55 -04:00
Jacob Young
54326cc554 cbe: implement field_parent_ptr 2022-10-25 05:11:29 -04:00
Jacob Young
361035fe7a cbe: implement cmp_lt_errors_len 2022-10-25 05:11:29 -04:00
Jacob Young
e470cf361f cbe: update test cases 2022-10-25 05:11:29 -04:00
Jacob Young
ab468d57e3 cbe: implement packed structs
Sometimes you have to break a test to make progress :)
2022-10-25 05:11:29 -04:00
Jacob Young
15df64ade8 std: add cbe hacks to more targets
These are needed because clang doesn't support anything in naked
functions, not even assembly register inputs.
2022-10-25 05:11:29 -04:00
Jacob Young
1bab854868 cbe: implement 128-bit and fix smaller integer builtins 2022-10-25 05:11:29 -04:00
Jacob Young
8b6a3ba74e cbe: fix typedef declaration order 2022-10-25 05:11:29 -04:00
Jacob Young
4765294ca4 cbe: get enough things working to support basic programs
* Enable advanced start support.
 * Enable advanced test_runner support.
 * Zig Language Reference's Hello World now works.
2022-10-25 05:11:29 -04:00
Jacob Young
912b84bbad cbe: fix atomics 2022-10-25 05:11:29 -04:00
Jacob Young
6921b0a850 cbe: implement some float ops 2022-10-25 05:11:29 -04:00
Jacob Young
b48417aed2 cbe: misc fixes 2022-10-25 05:11:29 -04:00
Jacob Young
1dd4a6102f cbe: implement global assembly 2022-10-25 05:11:29 -04:00
Jacob Young
e8bda9eb3a cbe: implement ptr slice ptr 2022-10-25 05:11:29 -04:00
Jacob Young
87d432328e cbe: implement aggregate_init of struct 2022-10-25 05:11:29 -04:00
Jacob Young
feb8f81cd9 cbe: canonicalize types that have the same C type when emitting typedefs 2022-10-25 05:11:29 -04:00
Jacob Young
5eafc10bf4 cbe: fix global access fix 2022-10-25 05:11:29 -04:00
Jacob Young
c126a1018e cbe: implement more asm features 2022-10-25 05:11:28 -04:00
Jacob Young
a12535f501 cbe: fix global access 2022-10-25 05:11:28 -04:00
Jacob Young
f399dd107a cbe: implement tag name 2022-10-25 05:11:28 -04:00
Jacob Young
40b5bb7161 cbe: fix loads and stores of 0-bit types 2022-10-25 05:11:28 -04:00
Jacob Young
962f33ee11 cbe: implement airUnionInit 2022-10-25 05:11:28 -04:00
Jacob Young
6a4266d62a cbe: fix infinite recursion on recursive types 2022-10-25 05:11:28 -04:00
Jacob Young
525dcaecba behavior: enable stage2_c tests that are currently passing
Also fix C warnings triggered by these tests.
2022-10-25 05:11:28 -04:00
Jacob Young
45c667eb21 behavior: fix redefined exports 2022-10-25 05:11:28 -04:00
Jacob Young
f81651932a c: hacks to fix incompatible redeclaration of library function warnings 2022-10-25 05:11:28 -04:00
Jacob Young
6f3654ad69 c: implement @errorName 2022-10-25 05:11:28 -04:00
Jacob Young
c8d0e71de6 c: fix mangling of error names
Closes #12751
2022-10-25 05:11:28 -04:00
Andrew Kelley
04472af328
Merge pull request #13251 from Vexu/c-abi
implement ARM C ABI, separate C ABI tests from standalone tests
2022-10-23 12:16:58 -07:00
Veikka Tuominen
f2a7aba586 x86_64 llvm: correct lowering of ptr sized float struct
Closes #13211
2022-10-22 22:00:59 +03:00
Veikka Tuominen
3f41979061 replace some panics with try in C ABI tests 2022-10-22 14:52:26 +03:00
Veikka Tuominen
5e0b4836a1 stage2: implement RISCV C ABI 2022-10-22 14:52:26 +03:00
Veikka Tuominen
8fa91939a8 build.zig: separate C ABI tests from standalone tests 2022-10-22 11:31:41 +03:00
Veikka Tuominen
12a2ccfb45 make C ABI tests compile on powerpc 2022-10-22 11:31:41 +03:00
Veikka Tuominen
031c768cc8 add C ABI tests for simd vectors 2022-10-22 11:31:41 +03:00
Cody Tapscott
74b9cbd895 stage2: Skip test exposing #13175
This PR (#12873) in combination with this particular test exposed
a pre-existing bug (#13175).

This means that the test for #13038 has regressed
2022-10-21 12:40:33 -07:00
Cody Tapscott
d060cbbec7 stage2: Keep error return traces alive when storing to const
This change extends the "lifetime" of the error return trace associated
with an error to continue throughout the block of a `const` variable
that it is assigned to.

This is necessary to support patterns like this one in test_runner.zig:
```zig
const result = foo();
if (result) |_| {
    // ... success logic
} else |err| {
    // `foo()` should be included in the error trace here
    return error.TestFailed;
}
```

To make this happen, the majority of the error return trace popping logic
needed to move into Sema, since `const x = foo();` cannot be examined
syntactically to determine whether it modifies the error return trace. We
also have to make sure not to delete pertinent block information before it
makes it to Sema, so that Sema can pop/restore around blocks correctly.

* Why do this only for `const` and not `var`? *

There is room to relax things for `var`, but only a little bit. We could
do the same thing we do for const and keep the error trace alive for the
remainder of the block where the *assignment* happens. Any wider scope
would violate the stack discipline for traces, so it's not viable.

In the end, I decided the most consistent behavior for the user is just
to kill all error return traces assigned to a mutable `var`.
2022-10-21 12:40:29 -07:00
Cody Tapscott
b529d8e48f stage2: Propagate error return trace into fn call
This change extends the "lifetime" of the error return trace associated
with an error to include the duration of a function call it is passed
to.

This means that if a function returns an error, its return trace will
include the error return trace for any error inputs. This is needed to
support `testing.expectError` and similar functions.

If a function returns a non-error, we have to clean up any error return
traces created by error-able call arguments.
2022-10-21 11:22:49 -07:00
Cody Tapscott
77720e30aa Re-factor: Change AstGen.ResultLoc to be a struct
This re-factor is intended to make it easier to track what kind of
operator/expression consumes a result location, without overloading the
ResultLoc union for this purpose.

This is used in the following commit to keep track of initializer
expressions of `const` variables to avoid popping error traces
pre-maturely. Hopefully this will also be useful for implementing
RLS temporaries in the future.
2022-10-21 11:22:46 -07:00
Cody Tapscott
3007fdde45 stage2: Pop error trace when storing error to var/const
In order to enforce a strict stack discipline for error return traces,
we cannot track error return traces that are stored in variables:

  ```zig
  const x = errorable(); // errorable()'s error return trace is killed here

  // v-- error trace starts here instead
  return x catch error.UnknownError;
  ```

In order to propagate error return traces, function calls need to be passed
directly to an error-handling expression (`if`, `catch`, `try` or `return`):

  ```zig
  // When passed directly to `catch`, the return trace is propagated
  return errorable() catch error.UnknownError;

  // Using a break also works
  return blk: {
      // code here
      break :blk errorable();
  } catch error.UnknownError;
  ```

Why do we need this restriction? Without it, multiple errors can co-exist
with their own error traces. Handling that situation correctly means either:
  a. Dynamically allocating trace memory and tracking lifetimes, OR
  b. Allowing the production of one error to interfere with the trace of another
     (which is the current status quo)

This is piece (3/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:44:20 -07:00
Cody Tapscott
0c3a50fe1c stage2: Do not pop error trace if result is an error
This allows for errors to be "re-thrown" by yielding any error as the
result of a catch block. For example:

```zig
fn errorable() !void {
    return error.FallingOutOfPlane;
}

fn foo(have_parachute: bool) !void {
    return errorable() catch |err| b: {
        if (have_parachute) {
            // error trace will include the call to errorable()
            break :b error.NoParachute;
        } else {
            return;
        }
    };
}

pub fn main() !void {
    // Anything that returns a non-error does not pollute the error trace.
    try foo(true);

    // This error trace will still include errorable(), whose error was "re-thrown" by foo()
    try foo(false);
}
```

This is piece (2/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:44:19 -07:00
Cody Tapscott
eda3eb1561 stage2: "Pop" error trace for break/return within catch
This implement trace "popping" for correctly handled errors within
`catch { ... }` and `else { ... }` blocks.

When breaking from these blocks with any non-error, we pop the error
trace frames corresponding to the operand. When breaking with an error,
we preserve the frames so that error traces "chain" together as usual.

```zig
fn foo(cond1: bool, cond2: bool) !void {
    bar() catch {
    	if (cond1) {
	    // If baz() result is a non-error, pop the error trace frames from bar()
	    // If baz() result is an error, leave the bar() frames on the error trace
            return baz();
	} else if (cond2) {
	    // If we break/return an error, then leave the error frames from bar() on the error trace
	    return error.Foo;
	}
    };

    // An error returned from here does not include bar()'s error frames in the trace
    return error.Bar;
}
```

Notice that if foo() does not return an error it, it leaves no extra
frames on the error trace.

This is piece (1/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:43:42 -07:00
Veikka Tuominen
9ae78a5890 stage2: implement ARM C ABI
Six new passing tests and the previously incorrectly passing
complex tests are now skipped.
2022-10-21 18:07:11 +03:00
Veikka Tuominen
972c39e2c0
Merge pull request #13219 from Vexu/stage2-fixes
Stage2 bug fixes
2022-10-21 12:11:49 +02:00
Veikka Tuominen
2609e33ab0 make C ABI tests compile on arm, mips and riscv
x86_64      24/25
x86         15/25
aarch64     25/25 - all
arm         18/25
mips        10/24
riscv64     13/25
wasm32      25/25 - all
2022-10-20 20:11:12 +03:00
Veikka Tuominen
646d927c79 stage2: fix handling of aarch64 C ABI float array like structs
Closes #11702
Closes #13125
2022-10-20 20:11:12 +03:00
Veikka Tuominen
07b6173cb8 delete failing recursive test
Don't forget to add these back when solving #12973
2022-10-20 20:11:12 +03:00