Commit Graph

336 Commits

Author SHA1 Message Date
LemonBoy
6f7939a452 Prevent too eager constant-folding of switch expression
A pointer was wrongly assumed to be comptime-available causing the
analysis pass to assume its initial value was constant.

Fixes #3481
2019-10-19 13:48:26 -04:00
LemonBoy
bab93e7561 Fix crash when generating constant unions with single field 2019-10-19 13:47:49 -04:00
Andrew Kelley
9050cd847a
fix non-byte-aligned packed struct field...
...passed as generic fn parameter causing invalid LLVM IR.

closes #3460
2019-10-15 18:00:16 -04:00
LemonBoy
22e60df680 Propagate user-defined function alignment to LLVM IR 2019-10-13 14:19:36 +02:00
LemonBoy
6cbb732b59 Extern unions should not trigger active field check
Fixes #3378
2019-10-10 13:57:48 -04:00
Michael Dusan
3464351d1e stage1: fix ir_resolve_str() to return slice
`ir_resolve_str()` bug returns array expression even when when sliced
to a lesser length. Fix is to return array if slice.len == array.len,
otherwise return slice.

Bug report use-case is based on one builtin function. However, at least
the following builtins were exposed to the bug:

    `@byteOffsetOf`
    `@cDefine`
    `@cImport`
    `@cInclude`
    `@cUndef`
    `@compileError`
    `@embedFile`
    `@export`
    `@fieldParentPtr`
    `@hasDecl`
    `@hasField`
    `@import`
    `@unionInit`

closes #3384
2019-10-10 10:20:04 -04:00
Michael Dusan
fd94d78ffc cleanup: unused imports in test 2019-10-10 10:16:35 -04:00
Nick Erdmann
ae7392e504
unicode character literals 2019-10-07 08:18:16 +02:00
Michael Dusan
a23a022820
fix container member access for fn/struct-fn
- decls brought in via `usingnamespace` were not always found
  because lookup was performed directly against decl_table and
  use_decls was never consulted
- fix to use find_container_decl() path instead
- closes #3367
2019-10-05 14:09:09 -04:00
Andrew Kelley
bd46c1c328
RISC-V: get to the linking phase of behavior tests
See #3338 and #3339
2019-09-29 12:21:22 -04:00
LemonBoy
67bd0267db
Correct calculation of padding length in struct
Make sure the resulting type is in-sync with the one produced and used
by LLVM.

Fixes #3138
2019-09-27 15:39:19 -04:00
Andrew Kelley
805f9b309b
add regression test for alignment of constants
closes #1741
2019-09-27 10:58:39 -04:00
Andrew Kelley
4d65373a3d
Merge pull request #3311 from LemonBoy/mips
Initial support for mipsel architecture
2019-09-26 13:44:36 -04:00
LemonBoy
2c8864f634 Don't warn about redeclaration for the same var node
Closes #3316
2019-09-26 13:39:09 -04:00
LemonBoy
dfb4446d09 Add comments about the test cases that have been disabled 2019-09-26 17:42:58 +02:00
LemonBoy
4ebcf64864 Initial support for mipsel architecture¬ 2019-09-26 09:31:55 +02:00
Michael Dusan
9983501ff2 add VarDecl support for struct-method call syntax
implements #3306
2019-09-24 19:24:48 -04:00
LemonBoy
5fb7af26ab
Fix result loc unwrapping with optional in error union
Fixes #2899
2019-09-24 01:09:26 -04:00
LemonBoy
93367adaa7
Fix assignment to optional payload
Closes #3081
2019-09-24 00:31:35 -04:00
LemonBoy
db988f42a7 Fix computation of switch coverage
Closes #3258
2019-09-23 16:13:28 -04:00
Andrew Kelley
2c681d7ba1
add behavior test for float widening f16 to f128
it's disabled on aarch64, see #3282
2019-09-21 14:22:23 -04:00
LemonBoy
34d02f249b Fix a test on ARM due to the use of undefined ptr 2019-09-21 11:39:50 +02:00
LemonBoy
57f751a864 Adjust tests for AArch64 2019-09-21 11:39:50 +02:00
LemonBoy
75ec7e4e00 Fix generation of tail fields for packed struct 2019-09-21 11:39:43 +02:00
Andrew Kelley
c9a5a6b83a
add test case for already fixed bug
closes #3046
2019-09-20 13:19:29 -04:00
Timon Kruiper
3b4a6679a6 Fix comptime bitcast inside an expression 2019-09-20 13:13:26 -04:00
Andrew Kelley
005a54a853
fixups for @splat
* Fix codegen for splat - instead of giving vectors of length N
   to shufflevector for both of the operands, it gives vectors of length
   1. The mask vector is the only one that needs N elements.
 * Separate Splat into SplatSrc and SplatGen; the `len` is not needed
   once it gets to codegen since it is redundant with the result type.
 * Refactor compile error for wrong vector element type so that the
   compile error message is not duplicated in zig source code
 * Improve implementation to correctly handle comptime values such as
   undefined and lazy values.
 * Improve compile error for bad vector element type to point to the
   correct place.
 * Delete dead code.
 * Modify behavior test to use an array cast instead of vector element
   indexing since I'm merging this splat commit out-of-order from
   Shawn's patch set.
2019-09-19 10:58:12 -04:00
Shawn Landden
01577a3af4
@splat 2019-09-19 10:11:06 -04:00
Andrew Kelley
380c8ec2c9
implement runtime @byteSwap and other fixups
* update docs for `@byteSwap`.
 * fix hash & eql functions for ZigLLVMFnIdBswap not updated to
   include vector len. this was causing incorrect bswap function
   being called in unrelated code
 * fix `@byteSwap` behavior tests only testing comptime and not
   runtime operations
 * implement runtime `@byteSwap`
 * fix incorrect logic in ir_render_vector_to_array and
   ir_render_array_to_vector with regards to whether or not to bitcast
 * `@byteSwap` accepts an array operand which it will cast to vector
 * simplify `@byteSwap` semantic analysis code and various fixes
2019-09-19 00:59:04 -04:00
Shawn Landden
76f5396077
@byteSwap on vectors 2019-09-18 16:49:14 -04:00
Andrew Kelley
2038f4d45a
rework the implementation
* update documentation
   - move `@shuffle` to be sorted alphabetically
   - remove mention of LLVM
   - minor clarifications & rewording
 * introduce ir_resolve_vector_elem_type to avoid duplicate compile
   error message and duplicate vector element checking logic
 * rework ir_analyze_shuffle_vector to solve various issues
 * improve `@shuffle` to allow implicit cast of arrays
 * the shuffle tests weren't being run
2019-09-18 16:15:19 -04:00
Shawn Landden
193604c837
stage1: add @shuffle() shufflevector support
I change the semantics of the mask operand, to make it a little more
flexible. There is no real danger in this because it is a compile-error
if you do it the LLVM way (and there is an appropiate error to tell you
this).

v2: avoid problems with double-free
2019-09-18 11:26:45 -04:00
Shawn Landden
74ce5e9e13
stage1: proper return type on vector comparisons 2019-09-18 10:36:10 -04:00
Shawn Landden
0e3ca4c63e
Fix array->vector and vector->array for many types. Allow vector of bool.
Vectors do not have the same packing as arrays, and just bitcasting
is not the correct way to convert them.
2019-09-18 09:52:58 -04:00
Andrew Kelley
914ad1ec2e
fix peer result location with typed parent, ...
...runtime condition, comptime prongs.

closes #3244
2019-09-17 22:30:49 -04:00
Andrew Kelley
c6e77f248d
fix tripping llvm assert
```
Assertion `!isa<DIType>(Scope) && "shouldn't
make a namespace scope for a type"
```

We've had this problem and solved it before; see #579.
2019-09-16 14:31:41 -04:00
LemonBoy
eb7d36ae0d Make single-element enum default to u0
* Allow comptime_int as explicit enum tag type

Closes #2997
2019-09-13 15:13:10 -04:00
Andrew Kelley
0eddee449d
add behavior test for @enumToInt(enum(u1){x}.x)
closes #2737
2019-09-11 15:05:00 -04:00
LemonBoy
8fbae77770
Force LLVM to generate byte-aligned packed unions
Sometimes the frontend and LLVM would disagree on the ABI alignment of a
packed union. Solve the problem by telling LLVM we're gonna manage the
struct layout by ourselves.

Closes #3184
2019-09-10 10:07:32 -04:00
Andrew Kelley
852679c369
fix a var decl in scope preventing for loop spills 2019-09-09 16:44:23 -04:00
Andrew Kelley
a3993465fe
Merge pull request #3200 from LemonBoy/eq-tagged-union
Allow comparison between union tag and enum literal
2019-09-09 16:17:45 -04:00
Andrew Kelley
f50bfb94b5
fix bad LLVM IR when for target expr needs to be spilled
Also reduce the size of ZigVar in memory by making the name
a `const char *` rather than a `Buf`.
2019-09-09 15:59:16 -04:00
LemonBoy
4b1cd45472 Comptime folding of enum/union comparisons 2019-09-09 19:09:56 +02:00
LemonBoy
cc63760587 Allow comparison between union tag and enum literal
Closes #2810
2019-09-09 18:51:13 +02:00
Andrew Kelley
f7721ac37c
implement spilling when returning error union async function call
closes #3190
2019-09-09 12:15:39 -04:00
Andrew Kelley
229323e13a
fix suspensions inside for loops generating invalid LLVM IR
closes #3076
2019-09-07 17:37:17 -04:00
Andrew Kelley
9a18db8a80
properly spill expressions with async function calls 2019-09-07 00:27:45 -04:00
Andrew Kelley
d1a98ccff4
implement spills when expressions used across suspend points
closes #3077
2019-09-07 00:13:12 -04:00
Andrew Kelley
9ca8d9e21a
fix await used in an expression generating bad LLVM 2019-09-07 00:13:12 -04:00
Andrew Kelley
0a3c6dbda9
implement noasync function calls
See #3157
2019-09-05 21:55:32 -04:00