4746 Commits

Author SHA1 Message Date
antlilja
ae8d26a6a0 Sema: add error for non-comptime param in comptime func
Adds error for taking a non comptime parameter in a function returning a
comptime-only type but not when that type is dependent on a parameter.

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-27 11:17:48 +03:00
David Gonzalez Martin
da95da438e Add behavior test coverage for nested packed struct field access
Closes #3091
2022-08-26 21:43:38 -04:00
Jakub Konka
02e6960966 coff: do not pull in std.log into coff.zig definitions 2022-08-26 16:14:44 +02:00
martinhath
3fa5415253
Sema: ensure resolveTypeFields is called for optional and error union types
We call `sema.resolveTypeFields` in order to get the fields of structs
and unions inserted into their data structures. If it isn't called, it
can happen that the fields of a type is queried before those fields are
inserted into (for instance) `Module.Union.fields`, which would result in
a wrong 'no field named' error.

Fixes: #12486
2022-08-26 11:37:17 +03:00
Evan Haas
bcaa9df5b4 translate-c: Don't add self-defined macros to global name table
A self-defined macro is one of the form `#define FOO FOO`

Those types of macros have never been translated; this change will cause
any macros which refer to them to be translated as `@compileError` instead
of referring to a non-existent identifier.

Closes #12471
2022-08-26 11:24:57 +03:00
David Gonzalez Martin
d6bb9af18d stage2: Reference to void constants
Closes #7567
2022-08-26 00:00:22 -04:00
Andrew Kelley
d2ad8afff4 LLVM: fix missing alignment on wrapping instructions
Previously, when lowering AIR instructions `wrap_errunion_payload`,
`wrap_errunion_err`, and `wrap_optional`, the LLVM backend would create
an alloca instruction to store the result, but did not set the alignment
on it. This caused UB which went undetected for a long time until we
started enabling the stack protector.

Closes #12594
Unblocks #12508
Inspires #12634

Tests passed locally:
 * test-behavior
 * test-cases
2022-08-25 16:15:48 -07:00
Jakub Konka
ba346ecfe9 run_translated_c: disable failing test on Windows
ziglang/zig#12630
2022-08-25 17:01:49 +02:00
Veikka Tuominen
4405188cf7 Sema: ignore comptime params in partial func type check
This fixes a bug exposed by cd1833044ab7505bc101c85f59889bd3ea3fac80
where a function type would be converted to generic_poison even after
being instantiated due to containing comptime only types.

This could also be fixed by just checking `is_generic_instantiation`
but this way also provides better type names.

Closes #12625
2022-08-25 16:29:23 +03:00
Andrew Kelley
7453f56e67 stage2: explicitly tagged enums no longer have one possible value
Previously, Zig had inconsistent semantics for an enum like this:

`enum(u8){zero = 0}`

Although in theory this can only hold one possible value, the tag
`zero`, Zig no longer will treat the type this way. It will do loads and
stores, as if the type has runtime bits.

Closes #12619

Tests passed locally:
 * test-behavior
 * test-cases
2022-08-24 22:20:31 -07:00
Andrew Kelley
7a881435ed
Merge pull request #12623 from Vexu/stage2-fixes
Stage2 fixes
2022-08-24 15:59:46 -04:00
Andrew Kelley
2a96209c40
Merge pull request #12574 from Vexu/remove-bit-op-type-param
stage2+stage1: remove type parameter from bit builtins
2022-08-24 15:57:44 -04:00
Andrew Kelley
80b8294bcc test-stack-traces: restore test coverage
reverts 1ce71c86bff351a4ade4321e188a13c9d3cff8b4
2022-08-24 12:57:31 -07:00
Veikka Tuominen
69a3c4e279 Sema: correctly reset inst_map for analyzeInlineCallArg
Closes #12622
2022-08-24 21:31:02 +03:00
Veikka Tuominen
f49dff64c6 Sema: check one possible value earlier in zirValidateArrayInit
Closes #12566
2022-08-24 21:31:02 +03:00
Veikka Tuominen
1d0b729f28 Sema: fix crash on slice of non-array type
Closes #12621
2022-08-24 21:31:02 +03:00
Veikka Tuominen
cd1833044a Sema: do not construct nested partial function types
Closes #12616
2022-08-24 21:31:02 +03:00
Jakub Konka
abfe21a4fe skip failing f80 behavior tests on Windows 2022-08-23 22:43:19 +02:00
Andrew Kelley
1ce71c86bf std.debug: implement support for DWARFv5 2022-08-23 00:28:45 -07:00
Andrew Kelley
9043e665a5 add behavior test for copying array of vectors
closes #12026
2022-08-22 18:37:42 -07:00
Andrew Kelley
5d2e9a1244 test harness: don't skip tests
The meaning of this "skip_stage2" flag was intended to mean the
self-hosted backends, not the stage2 frontend. Sorry for the confusion.

closes #12541
2022-08-22 19:50:32 -04:00
Veikka Tuominen
5404dcdfd8 Sema: fix fieldCallBind on tuples and anon structs
Closes #12573
2022-08-22 14:31:58 +03:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Veikka Tuominen
560baf67ce Sema: fix implicit cast from extern fn to fn ptr
Closes #12570
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b0bcd4add2 Sema: allow optional pointers in packed structs
Closes #12572
2022-08-22 11:16:36 +03:00
Veikka Tuominen
74c7782c60 Sema: make orelse with C pointers behave like stage1 for now
Closes #12537
2022-08-22 11:16:36 +03:00
Veikka Tuominen
c1afe57d70 Sema: resolve lazy values in resolveMaybeUndefValIntable
Closes #12512
Closes #12513
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b55a5007fa Sema: fix parameter of type 'T' must be comptime error
Closes #12519
Closes #12505
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b2f02a820f Sema: check for astgen failures in semaStructFields
The struct might be a top level struct in which case it might not have Zir.

Closes #12548
2022-08-22 11:16:36 +03:00
Jakub Konka
6c020cdb76
Merge pull request #12557 from Luukdegram/wasm-archive
wasm-linker: Improve archive linking
2022-08-22 08:38:41 +02:00
Veikka Tuominen
20d0018d79 Sema: ignore dbg_block instructions when checking for comptimeness
Closes #12514
2022-08-21 12:53:19 +03:00
Veikka Tuominen
d48af541c7 Sema: handle union and enum field order being different
Closes #12543
2022-08-21 12:51:40 +03:00
Veikka Tuominen
e8102d8738 Sema: add note about function call being comptime because of comptime only return type 2022-08-21 12:24:48 +03:00
Luuk de Gram
7fe2a3d104
test/link: add wasm linker-test for archives
Adds a test case that will pull-in compiler-rt symbols,
and therefore link with the compiler-rt archive file.
2022-08-20 15:46:39 +02:00
Andrew Kelley
a85f41ec2c test-stack-traces: relax parsing rules
* accept forward and backward slashes in file paths
 * strip multiple extensions; e.g. if the basename is "test.exe.obj"
   then it strips to "test".
2022-08-19 16:45:16 -07:00
Andrew Kelley
c4466496ff build: hook up -Dskip-stage2-tests and remove test-toolchain 2022-08-19 16:45:16 -07:00
Andrew Kelley
507aae4a1a make self-hosted the default compiler
stage1 is available behind the -fstage1 flag.

closes #89
2022-08-19 16:45:15 -07:00
Andrew Kelley
73bbd1069a build: remove the option to omit stage2 2022-08-19 16:45:15 -07:00
r00ster91
39f43fea8d fix: fix off-by-one for leading zeroes 2022-08-20 01:45:34 +03:00
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
Andrew Kelley
df507edffe
Merge pull request #12461 from ziglang/fix-12421
Fixes link-tests and `atomicSymLink` on Windows
2022-08-18 00:50:14 -04:00
Jakub Konka
9b595dd55f link-test: refactor and reorg
Move common tests by target file format (Wasm, MachO) into helper
functions in `link.zig`, and sort alphabetically within for easier
tracking versus file organization on disk.
2022-08-17 23:13:49 +02:00
Andrew Kelley
2cccd14491 fix typo in compile error message 2022-08-17 14:09:42 -07:00
Veikka Tuominen
59b6483d63 add test 2022-08-17 14:09:42 -07: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
Jakub Konka
070282a96e libstd: fix off-by-one error in def of ProcSym in pdb
Make sure `ProcSym` includes a single element byte-array which delimits
the start of the symbol's name as part of its definition. This makes
the code more elegant in that accessing the name is equivalent to taking
the address of this one element array.
2022-08-17 16:36:02 -04:00
Veikka Tuominen
233049503a Sema: allow empty enums and unions 2022-08-17 23:03:04 +03:00