972 Commits

Author SHA1 Message Date
Andrew Kelley
cee82c7ce4 improved ABI alignment/size for >= 128-bit integers
* riscv64: adjust alignment and size of 128-bit integers.
 * take ofmt=c into account for ABI alignment of 128-bit integers and
   structs.
 * Type: make packed struct support intInfo
 * fix f80 alignment for i386-windows-msvc
2022-08-18 20:34:36 -07:00
Andrew Kelley
6e313eb110 stage2: agree with LLVM that @alignOf(u128) is 8
on x86_64 and similar targets.
2022-08-18 17:11:32 -07:00
zooster
4055e6055b
AstGen: disallow leading zeroes in int literals and int types
This makes `0123` and `u0123` etc. illegal.

I'm now confident that this is a good change because
I actually caught two C header translation mistakes in `haiku.zig` with this.
Clearly, `0123` being octal in C (TIL) can cause confusion, and we make this easier to read by
requiring `0o` as the prefix and now also disallowing leading zeroes in integers.

For consistency and because it looks weird, we disallow it for integer types too (e.g. `u0123`).

Fixes #11963
Fixes #12417
2022-08-18 19:54:51 +03:00
Veikka Tuominen
b038dba06b
Merge pull request #12462 from Vexu/stage2-noreturn
Stage2: improve behavior of noreturn
2022-08-18 17:18:57 +03:00
Martin Hafskjold Thoresen
07f64a2e13 Sema: error on ambiguous coercion of comptime float and ints
The following, from the documentation as of the time of writing, illustrates
the problem:

```zig
// Compile time coercion of float to int
test "implicit cast to comptime_int" {
    var f: f32 = 54.0 / 5;
    _ = f;
}
```

It is not clear how to unify the types of 54.0 and 5 to perform the
division. We can either

 - cast 54.0 to comptime_int resulting in @as(comptime_int, 10), which is
   casted to @as(f32, 10), or
 - cast 5 to comptime_float resulting in @as(comptime_float, 10.8), which
   is casted to @as(f32, 10.8)

Since the two resulting values are different, a compiler error is appropriate.

If we know that casting to either type will result in the same value we
don't need to error.  For instance, 10.0 / 2 is okay, as is 10 / 2.0.

Fixes: #12364
2022-08-17 14:09:09 -07:00
Veikka Tuominen
233049503a Sema: allow empty enums and unions 2022-08-17 23:03:04 +03:00
Andrew Kelley
c764640e92 Sema: fix generics with struct literal coerced to tagged union
The `Value.eql` function has to test for value equality *as-if* the lhs
value parameter is coerced into the type of the rhs. For tagged unions,
there was a problematic case when the lhs was an anonymous struct,
because in such case the value is empty_struct_value and the type
contains all the value information. But the only type available in the
function was the rhs type.

So the fix involved making `Value.eqlAdvanced` also accept the lhs type,
and then enhancing the logic to handle the case of the `.anon_struct` tag.

closes #12418

Tests run locally:
 * test-behavior
 * test-cases
2022-08-17 13:02:57 -07:00
Veikka Tuominen
c3d5428cba Sema: properly handle noreturn fields in unions 2022-08-17 22:07:48 +03:00
Veikka Tuominen
b0a55e1b3b Sema: make noreturn error union behave correctly 2022-08-17 20:10:18 +03:00
Veikka Tuominen
db0f372da8 Sema: make optional noreturn behave correctly 2022-08-17 20:10:18 +03:00
Veikka Tuominen
c17793b487 Sema: ignore current declaration in ambiguous reference error
Closes #12429
2022-08-16 16:37:27 +03:00
Cody Tapscott
7e07f3d4f9 stage2 astgen: Use rl semantics for @Type
Resolves #12430.
2022-08-13 09:22:25 +03:00
Andrew Kelley
4d7f5a1917 stage2: fix crash with comptime vector reduce 2022-08-10 16:45:29 -07:00
Andrew Kelley
3c4e9b5983 disable failing behavior test
See #12360
2022-08-10 16:43:47 -07:00
Andrew Kelley
173952f4b8 disable failing behavior test
see tracking issue #12396
2022-08-10 16:13:59 -07:00
Andrew Kelley
e0178890ba
Merge pull request #12379 from ifreund/packed-struct-explicit-backing-int
stage2: Implement explicit backing integers for packed structs
2022-08-10 19:13:29 -04:00
Veikka Tuominen
40447b25e8 Sema: fix expansion of repeated value
Closes #12386
2022-08-10 15:18:09 -04:00
Isaac Freund
0d32b73078
stage2: Implement explicit backing integers for packed structs
Now the backing integer of a packed struct type may be explicitly
specified with e.g. `packed struct(u32) { ... }`.
2022-08-10 19:54:45 +02:00
Isaac Freund
bb1c3e8b7e
stage2: Handle lazy values for the % operator 2022-08-10 14:48:27 +02:00
Veikka Tuominen
0fd90749d1 stage2: generate call arguments in separate blocks 2022-08-09 16:19:55 +03:00
Meghan Denny
0879cbeed2 remove 'builtin.stage2_arch', Sema is smart enough now 2022-08-07 16:07:08 -07:00
Veikka Tuominen
eec2978fac Sema: better safety check on switch on corrupt value 2022-08-05 22:13:57 +03:00
Veikka Tuominen
292906fb23 Sema: fix reify Fn alignment and args 2022-08-02 18:33:03 +03:00
Veikka Tuominen
e47706f344 Sema: validate packed struct field types 2022-08-01 23:59:40 +03:00
Veikka Tuominen
57f9405a8f Sema: validate bitcast operand type 2022-08-01 23:37:01 +03:00
Veikka Tuominen
4758752e5d Sema: implement coercion from tuples to tuples
Closes #12242
2022-07-30 00:18:08 +03:00
Veikka Tuominen
f43ea43ac9 stage2: fix hashing of struct values
Closes #12279
2022-07-30 00:17:49 +03:00
joachimschmidt557
0fc79d602b stage2 ARM: more support for switch statements 2022-07-28 20:44:32 +00:00
Andrew Kelley
3ba7098a17 LLVM: fix returning extern union with C callconv 2022-07-27 17:56:15 -07:00
Andrew Kelley
6a4df2778e AstGen: fix ref instruction injection for functions
For the expressions regarding return type, alignment,
parameter type, etc.
2022-07-27 16:19:23 -07:00
Andrew Kelley
f880af369d LLVM: fix lowering byte-aligned packed struct field pointers 2022-07-27 16:19:23 -07:00
Evan Haas
7ba1f9bfb5 translate-c: take address of functions before passing them to @ptrToInt
Fixes #12194
2022-07-27 14:03:08 +03:00
Andrew Kelley
a2ab9e36fa
Merge pull request #12143 from Vexu/stage2-safety
Stage2 runtime safety progress
2022-07-23 20:09:24 -07:00
Andrew Kelley
9964324856 disable flaky behavior test
see #12208
2022-07-23 20:03:50 -07:00
Veikka Tuominen
baf516218e Sema: don't add union field access safety check for single field unions 2022-07-23 15:40:12 +03:00
Veikka Tuominen
711b656773 Sema: @floatToInt safety 2022-07-23 15:40:11 +03:00
Veikka Tuominen
ff7ec4efb5 Sema: bad union field access safety 2022-07-23 15:40:11 +03:00
Veikka Tuominen
55fe34100f Sema: exact division safety 2022-07-23 15:40:11 +03:00
Andrew Kelley
f591936480
Merge pull request #12198 from Vexu/stage2
Sema: fix loading and storing of optional pointers represented as pointers
2022-07-22 20:47:40 -07:00
Andrew Kelley
5dd59a5423
Merge pull request #12191 from ziglang/underaligned-fields
LLVM: fix lowering of structs with underaligned fields
2022-07-22 11:58:50 -07:00
Veikka Tuominen
03b1fbe50d stage2: fix airIsErr when is_ptr == true 2022-07-22 21:07:55 +03:00
Veikka Tuominen
1f748fe426 Sema: fix mutation of optional ptr represented as regular ptr 2022-07-22 19:50:11 +03:00
Veikka Tuominen
c619371ec1 Sema: fix loading and storing of optional pointers represented as pointers 2022-07-22 17:03:42 +03:00
Andrew Kelley
f550c29c4e LLVM: fix lowering of structs with underaligned fields
When lowering a struct type to an LLVM struct type, keep track of
whether there are any underaligned fields. If so, then make it a packed
llvm struct. This works because we already insert manual padding bytes
regardless.

We could unconditionally use an LLVM packed struct; the reason we bother
checking for underaligned fields is that it is a conservative choice, in
case LLVM handles packed structs less optimally. A future improvement
could simplify this code by unconditionally using packed LLVM structs
and then make sure measure perf is unaffected.

closes #12190
2022-07-21 22:51:17 -07:00
Veikka Tuominen
794beafb9c Sema: validate extern struct field types earlier
`validateExternType` does not require the type to be resolved so we can
check it earlier. Only doing it in `resolveTypeFully` lead to worse or
missing compile errors.
2022-07-21 12:21:30 -07:00
Veikka Tuominen
d851b24180 Sema: validate function pointer alignment 2022-07-21 12:21:30 -07:00
Veikka Tuominen
62120e3d0e Sema: fix non-exhaustive union switch checks 2022-07-21 12:21:30 -07:00
Andrew Kelley
5b7e332b28 disable new behavior test in stage1
I regressed this in 379beceffd1b0a0b0d8f3163dc02eba1e53ffa39; sorry
about that.
2022-07-20 16:17:33 -07:00
Andrew Kelley
379beceffd improve test case from previous commit
Now it checks that the code is correctly compiled rather than only checking
that it does not crash the compiler.
2022-07-20 15:21:24 -07:00
Veikka Tuominen
d41dd499a9 stage2 llvm: fix handling of pointer fields in packed structs 2022-07-20 17:07:12 +03:00