authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-13 16:51:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-16 21:58:52-05:00
log8bf425957b253d0ab2e4902d57340b19b7436698
tree3a62b6c16a64313195c5b01154bf8ee631aec97f
parente48157c3cb817ff1551f74fc1da9f420e38ccbd5
signaturelock-open Commit is signed but in an unrecognized format.

fix regressions double implicit casting return ptr


6 files changed, 55 insertions(+), 32 deletions(-)

src/analyze.cpp+28-3
......@@ -9396,6 +9396,9 @@ static void dump_value_indent(ZigValue *val, int indent) {
93969396 case ZigTypeIdUnreachable:
93979397 fprintf(stderr, "<unreachable>\n");
93989398 return;
9399 case ZigTypeIdUndefined:
9400 fprintf(stderr, "<undefined>\n");
9401 return;
93999402 case ZigTypeIdVoid:
94009403 fprintf(stderr, "<{}>\n");
94019404 return;
......@@ -9405,11 +9408,16 @@ static void dump_value_indent(ZigValue *val, int indent) {
94059408 case ZigTypeIdBool:
94069409 fprintf(stderr, "<%s>\n", val->data.x_bool ? "true" : "false");
94079410 return;
9408 case ZigTypeIdComptimeFloat:
94099411 case ZigTypeIdComptimeInt:
9410 case ZigTypeIdInt:
9412 case ZigTypeIdInt: {
9413 Buf *tmp_buf = buf_alloc();
9414 bigint_append_buf(tmp_buf, &val->data.x_bigint, 10);
9415 fprintf(stderr, "<%s>\n", buf_ptr(tmp_buf));
9416 buf_destroy(tmp_buf);
9417 return;
9418 }
9419 case ZigTypeIdComptimeFloat:
94119420 case ZigTypeIdFloat:
9412 case ZigTypeIdUndefined:
94139421 fprintf(stderr, "<TODO dump number>\n");
94149422 return;
94159423
......@@ -9458,6 +9466,23 @@ static void dump_value_indent(ZigValue *val, int indent) {
94589466 fprintf(stderr, "<ref\n");
94599467 dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1);
94609468 break;
9469 case ConstPtrSpecialBaseStruct: {
9470 ZigValue *struct_val = val->data.x_ptr.data.base_struct.struct_val;
9471 size_t field_index = val->data.x_ptr.data.base_struct.field_index;
9472 fprintf(stderr, "<struct %p field %zu\n", struct_val, field_index);
9473 if (struct_val != nullptr) {
9474 ZigValue *field_val = struct_val->data.x_struct.fields[field_index];
9475 if (field_val != nullptr) {
9476 dump_value_indent(field_val, indent + 1);
9477 } else {
9478 for (int i = 0; i < indent; i += 1) {
9479 fprintf(stderr, " ");
9480 }
9481 fprintf(stderr, "(invalid null field)\n");
9482 }
9483 }
9484 break;
9485 }
94619486 default:
94629487 fprintf(stderr, "TODO dump more pointer things\n");
94639488 }
src/codegen.cpp+1
......@@ -20,6 +20,7 @@
2020#include "zig_llvm.h"
2121#include "userland.h"
2222#include "dump_analysis.hpp"
23#include "softfloat.hpp"
2324
2425#include <stdio.h>
2526#include <errno.h>
src/ir.cpp+6-9
......@@ -12313,8 +12313,8 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1231312313 if (type_is_invalid(casted_payload->value->type))
1231412314 return ira->codegen->invalid_instruction;
1231512315
12316 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
12317 if (!val)
12316 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
12317 if (val == nullptr)
1231812318 return ira->codegen->invalid_instruction;
1231912319
1232012320 ZigValue *err_set_val = create_const_vals(1);
......@@ -17519,6 +17519,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1751917519 {
1752017520 result_loc_pass1 = no_result_loc();
1752117521 }
17522 bool was_written = result_loc_pass1->written;
1752217523 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
1752317524 value, force_runtime, allow_discard);
1752417525 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
......@@ -17596,6 +17597,9 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1759617597 result_loc_pass1->resolved_loc = result_loc;
1759717598 }
1759817599
17600 if (was_written) {
17601 return result_loc;
17602 }
1759917603
1760017604 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
1760117605 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
......@@ -18242,13 +18246,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1824218246 return ira->codegen->invalid_instruction;
1824318247 }
1824418248
18245 if (fn_proto_node->data.fn_proto.is_var_args) {
18246 ir_add_error(ira, source_instr,
18247 buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313"));
18248 return ira->codegen->invalid_instruction;
18249 }
18250
18251
1825218249 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
1825318250 IrInstruction *old_arg = args_ptr[call_i];
1825418251
src/softfloat.hpp+17
......@@ -12,4 +12,21 @@ extern "C" {
1212#include "softfloat.h"
1313}
1414
15static inline float16_t zig_double_to_f16(double x) {
16 float64_t y;
17 static_assert(sizeof(x) == sizeof(y), "");
18 memcpy(&y, &x, sizeof(x));
19 return f64_to_f16(y);
20}
21
22
23// Return value is safe to coerce to float even when |x| is NaN or Infinity.
24static inline double zig_f16_to_double(float16_t x) {
25 float64_t y = f16_to_f64(x);
26 double z;
27 static_assert(sizeof(y) == sizeof(z), "");
28 memcpy(&z, &y, sizeof(y));
29 return z;
30}
31
1532#endif
src/util.hpp+2-19
......@@ -38,6 +38,8 @@
3838
3939#if defined(__MINGW32__) || defined(__MINGW64__)
4040#define BREAKPOINT __debugbreak()
41#elif defined(__i386__) || defined(__x86_64__)
42#define BREAKPOINT __asm__ volatile("int $0x03");
4143#elif defined(__clang__)
4244#define BREAKPOINT __builtin_debugtrap()
4345#elif defined(__GNUC__)
......@@ -49,8 +51,6 @@
4951
5052#endif
5153
52#include "softfloat.hpp"
53
5454ATTRIBUTE_COLD
5555ATTRIBUTE_NORETURN
5656ATTRIBUTE_PRINTF(1, 2)
......@@ -244,23 +244,6 @@ static inline uint8_t log2_u64(uint64_t x) {
244244 return (63 - clzll(x));
245245}
246246
247static inline float16_t zig_double_to_f16(double x) {
248 float64_t y;
249 static_assert(sizeof(x) == sizeof(y), "");
250 memcpy(&y, &x, sizeof(x));
251 return f64_to_f16(y);
252}
253
254
255// Return value is safe to coerce to float even when |x| is NaN or Infinity.
256static inline double zig_f16_to_double(float16_t x) {
257 float64_t y = f16_to_f64(x);
258 double z;
259 static_assert(sizeof(y) == sizeof(z), "");
260 memcpy(&z, &y, sizeof(y));
261 return z;
262}
263
264247void zig_pretty_print_bytes(FILE *f, double n);
265248
266249template<typename T>
test/stage1/behavior.zig+1-1
......@@ -59,7 +59,7 @@ comptime {
5959 _ = @import("behavior/defer.zig");
6060 _ = @import("behavior/enum.zig");
6161 _ = @import("behavior/enum_with_members.zig");
62 //_ = @import("behavior/error.zig");
62 _ = @import("behavior/error.zig");
6363 _ = @import("behavior/eval.zig");
6464 _ = @import("behavior/field_parent_ptr.zig");
6565 _ = @import("behavior/floatop.zig");