1519 Commits

Author SHA1 Message Date
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
Robin Voetter
3e2553c712 spirv: lower ptr constants 2023-09-23 12:36:44 -07:00
Robin Voetter
cc13864dfb spirv: lower enum_tag constants 2023-09-23 12:36:44 -07:00
Robin Voetter
aeaaa953a0 spirv: assign type names to (error) unions 2023-09-23 12:36:44 -07:00
Robin Voetter
ece52640eb spirv: construct error union at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter
ced8a2c3a6 spirv: add type_map to map AIR types to SPIR-V types
This will help us both to make the implementation a little
more efficient by caching emission for certain types like structs,
and also allow us to attach extra information about types that we
can use while lowering without performing a search over the entire
type tree for some property.
2023-09-23 12:36:44 -07:00
Robin Voetter
79f7481575 spirv: disable failing tests 2023-09-23 12:36:44 -07:00
kcbanner
f2a24b48e1 sema: rework the comptime representation of comptime unions
When the tag is not known, it's set to `.none`. In this case, the value is either an
array of bytes (for extern unions) or an integer (for packed unions).
2023-09-23 13:05:04 -04:00
kcbanner
2fddd767ba sema: add support for unions in readFromMemory and writeToMemory 2023-09-23 13:04:56 -04:00
Andrew Kelley
747440677d LLVM: fix UAF when lowering debug info for structs
Gotta call the get() function inside the loop if the loop adds anything
to InternPool.
2023-09-21 21:55:41 -07:00
Andrew Kelley
81b5df347a compiler: fix structFieldName crash for tuples
When struct types have no field names, the names are implicitly
understood to be strings corresponding to the field indexes in
declaration order. It used to be the case that a NullTerminatedString
would be stored for each field in this case, however, now, callers must
handle the possibility that there are no names stored at all. This
commit introduces `legacyStructFieldName`, a function to fake the
previous behavior. Probably something better could be done by reworking
all the callsites of this function.
2023-09-21 17:29:34 -07:00
mlugg
1b672e41c5 InternPool,Sema,type,llvm: alignment fixes
This changeset fixes the handling of alignment in several places. The
new rules are:
* `@alignOf(T)` where `T` is a runtime zero-bit type is at least 1,
  maybe greater.
* Zero-bit fields in `extern` structs *do* force alignment, potentially
  offsetting following fields.
* Zero-bit fields *do* have addresses within structs which can be
  observed and are consistent with `@offsetOf`.

These are not necessarily all implemented correctly yet (see disabled
test), but this commit fixes all regressions compared to master, and
makes one new test pass.
2023-09-21 14:48:41 -07:00
mlugg
ada83fa557 compiler: get codegen of behavior tests working on at least one backend
We're hitting false compile errors, but this is progress!
2023-09-21 14:48:40 -07:00
Andrew Kelley
baea62a8ad fix regressions from this branch 2023-09-21 14:48:40 -07:00