1482 Commits

Author SHA1 Message Date
Jacob Young
a9b37ac637 cbe: fix crash on error
This hashmap value used to be assigned much later during `flushModule`,
which never happens if an error is returned by the backend, and
attempting to the undefined values would cause a crash.
2023-10-08 00:06:17 -04:00
Jakub Konka
8b4e3b6aee comp: add support for -fdata-sections 2023-10-04 11:21:56 -07:00
Andrew Kelley
c4b0b7a30b C backend: render anon decls
Introduce the new mechanism needed to render anonymous decls to C code
that the frontend is now using.

The current strategy is to collect the set of used anonymous decls into
one ArrayHashMap for the entire compilation, and then render them during
flush().

In the future this may need to be adjusted for incremental compilation
purposes, so that removing a Decl from decl_table means that newly
unused anonymous decls are no longer rendered. However, let's do one
thing at a time. The only goal of this branch is to stop using
Module.Decl objects for unnamed constants.
2023-10-03 12:12:51 -07:00
Andrew Kelley
9d069d98e3 C backend: start handling anonymous decls
Start keeping track of dependencies on anon decls for dependency
ordering during flush()

Currently this causes use of undefined symbols because these
dependencies need to get rendered into the output.
2023-10-03 12:12:51 -07:00
Andrew Kelley
c0b5512544 compiler: start handling anonymous decls differently
Instead of explicitly creating a `Module.Decl` object for each anonymous
declaration, each `InternPool.Index` value is implicitly understood to
be an anonymous declaration when encountered by backend codegen.

The memory management strategy for these anonymous decls then becomes to
garbage collect them along with standard InternPool garbage.

In the interest of a smooth transition, this commit only implements this
new scheme for string literals and leaves all the previous mechanisms in
place.
2023-10-03 12:12:50 -07:00
ocrap7
c933a7c58c llvm: remove extra copy of wrapped payloads 2023-10-03 11:16:11 -07:00
Andrew Kelley
5c3393dc2e
Merge pull request #17375 from xxxbxxx/packed-struct
codegen: fix field offsets in packed structs
2023-10-03 11:13:40 -07:00
Andrew Kelley
7733894761
Merge pull request #17341 from rzezeski/illumos-updates
Illumos/Solaris updates
2023-10-03 11:04:41 -07:00
Xavier Bouchoux
405705cb76 codegen: fix byte-aligned field offsets in unaligned nested packed structs 2023-10-03 05:34:19 +00:00
Xavier Bouchoux
62d178e91a codegen: fix field offsets in packed structs
* add nested packed struct/union behavior tests
 * use ptr_info.packed_offset rather than trying to duplicate the logic from Sema.structFieldPtrByIndex()
 * use the container_ptr_info.packed_offset to account for non-aligned nested structs.
 * dedup type.packedStructFieldBitOffset() and module.structPackedFieldBitOffset()
2023-10-03 06:39:20 +02:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Jacob Young
3bd1b9e15f x86_64: implement and test unary float builtins 2023-10-01 15:09:52 -04:00
Andrew Kelley
7c605ba62c C backend: remove ?*Decl from DeclGen
Another simplification. DeclGen already has `decl_index` which can be
used to retrieve the `*Decl` if needed.
2023-09-29 19:14:17 -07:00
antlilja
6a29646a55 Rename @fabs to @abs and accept integers
Replaces the @fabs builtin with a new @abs builtins which accepts
floats, signed integers and vectors of said types.
2023-09-27 11:15:53 -07:00
Andrew Kelley
1606717b5f C backend: flatten out some of the long-lived state
When the compiler's state lives through multiple Compilation.update()
calls, the C backend stores the rendered C source code for each
decl code body and forward declarations.

With this commit, the state is still stored, but it is managed in one
big array list in link/C.zig rather than many array lists, one for each
decl. This means simpler serialization and deserialization.
2023-09-27 04:09:22 -07:00
Veikka Tuominen
f4c884617f
Merge pull request #17215 from kcbanner/read_from_memory_union
sema: add support for unions in readFromMemory and writeToMemory
2023-09-26 11:16:03 +03:00
Michael Dusan
127198e58c cbe: support more symbol attributes
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

windows msvc:
- `__declspec(selectany)` is not supported for functions
- skip weak linkage for functions

closes #17050
2023-09-24 14:44:15 -07:00
Robin Voetter
cff8ab88f5 spirv: fixes 2023-09-23 12:36:56 -07:00
Robin Voetter
572517376a spirv: air dbg_var_val and dbg_var_ptr 2023-09-23 12:36:56 -07:00
Robin Voetter
68c7fc5c59 spirv: fix blocks that return no value 2023-09-23 12:36:56 -07:00
Robin Voetter
63512192de spirv: fix source line numbers 2023-09-23 12:36:56 -07:00
Robin Voetter
075584a4d7 spirv: enable passing tests 2023-09-23 12:36:56 -07:00
Robin Voetter
d9a8c779d8 spirv: constant elem ptr 2023-09-23 12:36:56 -07:00
Robin Voetter
a75300c8d8 spirv: air slice 2023-09-23 12:36:56 -07:00
Robin Voetter
8895025688 spirv: air wrap_errunion_payload 2023-09-23 12:36:56 -07:00
Robin Voetter
4f215a6d28 spirv: air unwrap_errunion_payload 2023-09-23 12:36:56 -07:00
Robin Voetter
48ab11639a spirv: air is_err, is_non_err 2023-09-23 12:36:56 -07:00
Robin Voetter
b845c9d532 spirv: generate module initializer 2023-09-23 12:36:56 -07:00
Robin Voetter
5d844faf7c spirv: air array_elem_val using hack
SPIR-V doesn't support true element indexing, so we probably
need to switch over to isByRef like in llvm for this to work
properly. Currently a temporary is used, which at least
seems to work.
2023-09-23 12:36:56 -07:00
Robin Voetter
26c279cca2 spirv: air aggregate_init for array 2023-09-23 12:36:56 -07:00
Robin Voetter
8d49b2ef4e spirv: air array_to_slice 2023-09-23 12:36:56 -07:00
Robin Voetter
66b1f6c163 spirv: air sub_with_overflow 2023-09-23 12:36:56 -07:00
Robin Voetter
749307dbb2 spirv: air union_init 2023-09-23 12:36:56 -07:00
Robin Voetter
98046b4c3c spirv: air set_union_tag + improve load()/store() 2023-09-23 12:36:56 -07:00
Robin Voetter
6f55a68964 spirv: air struct_field_ptr for unions 2023-09-23 12:36:56 -07:00
Robin Voetter
5dffbf32bf spirv: air struct_field_val for unions 2023-09-23 12:36:56 -07:00
Robin Voetter
decdedf97d spirv: add names to globals and initializers 2023-09-23 12:36:56 -07:00
Robin Voetter
924235a023 spirv: emit OpLogical(Not)Equal for comparing bools 2023-09-23 12:36:56 -07:00
Robin Voetter
c7c0517ac0 spirv: emit OpNot for arithmetic not 2023-09-23 12:36:56 -07:00
Robin Voetter
5141b4e05c spirv: fix store of undef 2023-09-23 12:36:56 -07:00
Robin Voetter
f16d1603ab spirv: fix type_map use-after-realloc issues 2023-09-23 12:36:44 -07:00
Robin Voetter
42226fc1b7 spirv: make construct(Struct|Array) use the Function storage class 2023-09-23 12:36:44 -07:00
Robin Voetter
06d9e3b2eb spirv: always emit unsigned integers
This is required for SPIR-V in Kernel mode. The Intel
implementation just didn't care about this fact.
2023-09-23 12:36:44 -07:00
Robin Voetter
18d0909ada spirv: fixes 2023-09-23 12:36:44 -07:00
Robin Voetter
66036e6000 spirv: remove indirect constant lowering
It is stupid and I hate it.
2023-09-23 12:36:44 -07:00
Robin Voetter
b30cd67987 spirv: put global var initializers in functions 2023-09-23 12:36:44 -07:00
Robin Voetter
240f9d740d spirv: lower union initialization at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter
d06862b759 spirv: lower struct aggregate initialization at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter
001d76a412 spirv: lower array aggregate at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter
ae17831cc0 spirv: lower opt constants 2023-09-23 12:36:44 -07:00