Commit Graph

439 Commits

Author SHA1 Message Date
Andrew Kelley
29e8e67a7e CBE: use bool, true, false, instead of zig_ prefixes
In general the C backend should lower to human-maintainable C code
whenever possible. Directly using C types that one would use when
writing C code is one part of the strategy.

The concern with including stdint.h is C89 compatibility. Well, we can
just check the C std lib version before deciding to include that header.
2022-12-02 16:12:49 -07:00
Andrew Kelley
665eba93c1 CBE: eliminate zig_void
C void is perfectly fine.
2022-12-02 00:46:27 -05:00
Veikka Tuominen
8eea73fb92 add tests for tuple declarations 2022-11-23 22:16:31 +02:00
Jacob Young
fa46f9a3d7 cbe: fix extern 2022-11-02 21:42:40 -04:00
Jacob Young
e470cf361f cbe: update test cases 2022-10-25 05:11:29 -04:00
Veikka Tuominen
34e4b07d0c Sema: allow runtime only instructions to be emitted in outside functions
It is possible to get comptime-known values from runtime-known values
for example the length of array. Allowing runtime only instructions to
be emitted outside function bodies allows these operations to happen.
In places where comptime-known values are required we have other methods
to ensure that and they usually result in more specific compile errors too.

Closes #12240
2022-10-20 20:11:00 +03:00
Guillaume Wenzek
419855c475 fix test 2022-10-15 10:39:19 -07:00
Guillaume Wenzek
b425d88737 re-enable nvptx tests 2022-10-15 10:39:19 -07:00
Veikka Tuominen
233049503a Sema: allow empty enums and unions 2022-08-17 23:03:04 +03:00
Veikka Tuominen
5b29275240 Sema: add some more 'declared here' notes 2022-07-23 15:40:12 +03:00
Veikka Tuominen
1705a21f80 Sema: more union and enum tag type validation 2022-07-21 12:21:30 -07:00
Veikka Tuominen
76e7959a90 Sema: explain why comptime is needed 2022-07-21 12:21:30 -07:00
Veikka Tuominen
e6ebf56dd6 Sema: validate @intToEnum int operand type 2022-07-01 10:22:25 +03:00
Veikka Tuominen
3204d00a5e move passing stage1 compile error tests to stage2 2022-06-30 09:57:38 +02:00
Andrew Kelley
436aafd3e2 remove a stage2 test case that relies on a very deep compiler stack
It's causing Drone CI failure on aarch64. I will open a follow-up issue
to track this missing test case.
2022-06-09 20:00:59 -07:00
Jakub Konka
5a5648c0f0 test: migrate llvm incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
495bb12e6a test: migrate plan9 and sparcv9 incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
ed51a5d02a test: migrate arm incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
fc4fbfe8e1 test: migrate aarch64 incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
7e17cbbda5 test: migrate riscv64 incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
8e05e6a1ed test: migrate wasm incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
e4a8a66504 test: remove incremental tests that were ported to the new harness 2022-04-28 18:35:01 +02:00
Koakuma
c07213269f stage2: zig fmt 2022-04-14 23:26:03 +07:00
Koakuma
2ee83e76f7 stage2: Adjust line numbers in tests 2022-04-14 23:15:56 +07:00
Koakuma
f6b95166eb stage2: sparcv9: Add simple test case 2022-04-14 22:18:06 +07:00
Andrew Kelley
44f9061b71 fix merge conflicts and test cases 2022-03-22 15:58:19 -07:00
Daniel Hooper
911c839e97
add error when binary ops don't have matching whitespace on both sides
This change also moves the warning about "&&" from the AstGen into the parser so that the "&&" warning can supersede the whitespace warning.
2022-03-20 12:55:04 +02:00
Andrew Kelley
69d78bdae4 stage2 test harness: ask for the backend explicitly
Follow-up to 35d6ee08c4
2022-03-17 20:10:00 -07:00
Mitchell Hashimoto
7ec2261dbf stage2: add compiler test to ensure typed null doesn't coerce to any
In stage1, this behavior was allowed (by accident?) and also
accidentally exercised by the behavior test changed in this commit. In
discussion on Discord, Andrew decided this should not be allowed in
stage2 since there is currently on real world reason to allow this
strange edge case.

I've added the compiler test to solidify that this behavior should NOT
occur and updated the behavior test to the new valid semantics.
2022-03-12 22:03:01 -05:00
Guillaume Wenzek
f000f8a59a fix nvptx test failure #10968
allow test cases to chose wether to link libc or not.
default behavior is to not link libc, except for `exeUsingLLVMBackend`
2022-03-12 14:25:59 -05:00
Andrew Kelley
078037ab9b stage2: passing threadlocal tests for x86_64-linux
* use the real start code for LLVM backend with x86_64-linux
   - there is still a check for zig_backend after initializing the TLS
     area to skip some stuff.
 * introduce new AIR instructions and implement them for the LLVM
   backend. They are the same as `call` except with a modifier.
   - call_always_tail
   - call_never_tail
   - call_never_inline
 * LLVM backend calls hasRuntimeBitsIgnoringComptime in more places to
   avoid unnecessarily depending on comptimeOnly being resolved for some
   types.
 * LLVM backend: remove duplicate code for setting linkage and value
   name. The canonical place for this is in `updateDeclExports`.
 * LLVM backend: do some assembly template massaging to make `%%`
   rendered as `%`. More hacks will be needed to make inline assembly
   catch up with stage1.
2022-03-11 00:04:42 -07:00
Mitchell Hashimoto
569870ca41 stage2: error_set_merged type equality
This implements type equality for error sets. This is done
through element-wise error set comparison.

Inferred error sets are always distinct types and other error sets are
always sorted. See #11022.
2022-03-10 14:20:16 -07:00
Veikka Tuominen
7691013d10 stage2: add 'called from here' error note 2022-03-03 22:14:43 +02:00
gwenzek
628e9e6d04
enable Gpu address spaces (#10884) 2022-02-21 14:05:27 -05:00
Veikka Tuominen
9c36cf92f0 parser: make some errors point to end of previous token
For some errors if the found token is not on the same line as
the previous token, point to the end of the previous token.
This usually results in more helpful errors.
2022-02-17 14:23:35 +02:00
joachimschmidt557
783e216e7d
stage2 AArch64: Fix issue in binOp and add regression test 2022-02-14 22:09:44 +01:00
joachimschmidt557
3a33f31334
stage2 AArch64: implement cond_br for other MCValues 2022-02-14 22:09:44 +01:00
Veikka Tuominen
8a432436ae update compile error tests 2022-02-13 13:48:20 +02:00
Luuk de Gram
f50203c836 wasm: update test runner
This updates the test runner for stage2 to emit to stdout with the passed, skipped and failed tests
similar to the LLVM backend.

Another change to this is the start function, as it's now more in line with stage1's.
The stage2 test infrastructure for wasm/wasi has been updated to reflect this as well.
2022-02-08 10:03:29 +01:00
Jakub Konka
5944e89016 stage2: lower unnamed constants in Elf and MachO
* link: add a virtual function `lowerUnnamedConsts`, similar to
  `updateFunc` or `updateDecl` which needs to be implemented by the
  linker backend in order to be used with the `CodeGen` code
* elf: implement `lowerUnnamedConsts` specialization where we
  lower unnamed constants to `.rodata` section. We keep track of the
  atoms encompassing the lowered unnamed consts in a global table
  indexed by parent `Decl`. When the `Decl` is updated or destroyed,
  we clear the unnamed consts referenced within the `Decl`.
* macho: implement `lowerUnnamedConsts` specialization where we
  lower unnamed constants to `__TEXT,__const` section. We keep track of the
  atoms encompassing the lowered unnamed consts in a global table
  indexed by parent `Decl`. When the `Decl` is updated or destroyed,
  we clear the unnamed consts referenced within the `Decl`.
* x64: change `MCValue.linker_sym_index` into two `MCValue`s: `.got_load` and
  `.direct_load`. The former signifies to the emitter that it should
  emit a GOT load relocation, while the latter that it should emit
  a direct load (`SIGNED`) relocation.
* x64: lower `struct` instantiations
2022-02-07 08:39:00 +01:00
Jakub Konka
8f3be0e04f stage2: update stage2 tests with qualified import lib names for externs
From

```zig
extern fn write(...);
```

to

```zig
extern "c" fn write(...);
```
2022-02-02 16:25:46 +01:00
Andrew Kelley
a2abbeef90 stage2: rework a lot of stuff
AstGen:
 * rename the known_has_bits flag to known_non_opv to make it better
   reflect what it actually means.
 * add a known_comptime_only flag.
 * make the flags take advantage of identifiers of primitives and the
   fact that zig has no shadowing.
 * correct the known_non_opv flag for function bodies.

Sema:
 * Rename `hasCodeGenBits` to `hasRuntimeBits` to better reflect what it
   does.
   - This function got a bit more complicated in this commit because of
     the duality of function bodies: on one hand they have runtime bits,
     but on the other hand they require being comptime known.
 * WipAnonDecl now takes a LazySrcDecl parameter and performs the type
   resolutions that it needs during finish().
 * Implement comptime `@ptrToInt`.

Codegen:
 * Improved handling of lowering decl_ref; make it work for
   comptime-known ptr-to-int values.
   - This same change had to be made many different times; perhaps we
     should look into merging the implementations of `genTypedValue`
     across x86, arm, aarch64, and riscv.
2022-01-24 21:53:57 -07:00
Jakub Konka
3af4e28dda stage2: implement signed compare 2022-01-15 19:32:16 +01:00
Jakub Konka
4d4bbd7624 stage2: refactor handling of immediates in x86_64 backend
Fixes issues with incorrect operand sizes in a handful of cases
and allows for usage of differently sized integers in Zig sources.
2022-01-15 18:28:39 +01:00
Jakub Konka
a4e6291fbd
stage2: enable zig test on x86_64-macos (#10551)
* stage2: put decls in different MachO sections

Use `getDeclVAddrWithReloc` when targeting MachO backend rather than
`getDeclVAddr` - this fn returns a zero vaddr and instead creates a
relocation on the linker side which will get automatically updated
whenever the target decl is moved in memory. This fn also records
a rebase of the target pointer so that its value is correctly slid
in presence of ASLR.

This commit enables `zig test` on x86_64-macos.

* stage2: fix output section selection for type,val pairs
2022-01-10 16:02:07 +01:00
Jakub Konka
97e76bf36c stage2: temporarily disable offending stage2 test on macOS
Another caveat, `zig test` doesn't currently work on stage2.
2022-01-06 12:57:34 +01:00
Jakub Konka
b215241ef2 stage2: fix airSliceElemVal
Refactor codegen and fix a bug in Isel.
2022-01-06 09:54:33 +01:00
Jakub Konka
e9f069f536 stage2: implement isErr/isNonErr and unwrap error 2022-01-04 01:21:24 +01:00
joachimschmidt557
c710d5eefe stage2 ARM: implement wrap_errunion_err for empty payloads 2022-01-02 15:15:59 -05:00
Jakub Konka
885d96735d
Merge pull request #10480 from joachimschmidt557/stage2-arm
stage2 ARM: zig test working
2022-01-01 17:02:31 +01:00