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
signature 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) {...@@ -9396,6 +9396,9 @@ static void dump_value_indent(ZigValue *val, int indent) {
9396 case ZigTypeIdUnreachable:9396 case ZigTypeIdUnreachable:
9397 fprintf(stderr, "<unreachable>\n");9397 fprintf(stderr, "<unreachable>\n");
9398 return;9398 return;
9399 case ZigTypeIdUndefined:
9400 fprintf(stderr, "<undefined>\n");
9401 return;
9399 case ZigTypeIdVoid:9402 case ZigTypeIdVoid:
9400 fprintf(stderr, "<{}>\n");9403 fprintf(stderr, "<{}>\n");
9401 return;9404 return;
...@@ -9405,11 +9408,16 @@ static void dump_value_indent(ZigValue *val, int indent) {...@@ -9405,11 +9408,16 @@ static void dump_value_indent(ZigValue *val, int indent) {
9405 case ZigTypeIdBool:9408 case ZigTypeIdBool:
9406 fprintf(stderr, "<%s>\n", val->data.x_bool ? "true" : "false");9409 fprintf(stderr, "<%s>\n", val->data.x_bool ? "true" : "false");
9407 return;9410 return;
9408 case ZigTypeIdComptimeFloat:
9409 case ZigTypeIdComptimeInt:9411 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:
9411 case ZigTypeIdFloat:9420 case ZigTypeIdFloat:
9412 case ZigTypeIdUndefined:
9413 fprintf(stderr, "<TODO dump number>\n");9421 fprintf(stderr, "<TODO dump number>\n");
9414 return;9422 return;
94159423
...@@ -9458,6 +9466,23 @@ static void dump_value_indent(ZigValue *val, int indent) {...@@ -9458,6 +9466,23 @@ static void dump_value_indent(ZigValue *val, int indent) {
9458 fprintf(stderr, "<ref\n");9466 fprintf(stderr, "<ref\n");
9459 dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1);9467 dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1);
9460 break;9468 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 }
9461 default:9486 default:
9462 fprintf(stderr, "TODO dump more pointer things\n");9487 fprintf(stderr, "TODO dump more pointer things\n");
9463 }9488 }
src/codegen.cpp+1
...@@ -20,6 +20,7 @@...@@ -20,6 +20,7 @@
20#include "zig_llvm.h"20#include "zig_llvm.h"
21#include "userland.h"21#include "userland.h"
22#include "dump_analysis.hpp"22#include "dump_analysis.hpp"
23#include "softfloat.hpp"
2324
24#include <stdio.h>25#include <stdio.h>
25#include <errno.h>26#include <errno.h>
src/ir.cpp+6-9
...@@ -12313,8 +12313,8 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -12313,8 +12313,8 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
12313 if (type_is_invalid(casted_payload->value->type))12313 if (type_is_invalid(casted_payload->value->type))
12314 return ira->codegen->invalid_instruction;12314 return ira->codegen->invalid_instruction;
1231512315
12316 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);12316 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
12317 if (!val)12317 if (val == nullptr)
12318 return ira->codegen->invalid_instruction;12318 return ira->codegen->invalid_instruction;
1231912319
12320 ZigValue *err_set_val = create_const_vals(1);12320 ZigValue *err_set_val = create_const_vals(1);
...@@ -17519,6 +17519,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17519,6 +17519,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17519 {17519 {
17520 result_loc_pass1 = no_result_loc();17520 result_loc_pass1 = no_result_loc();
17521 }17521 }
17522 bool was_written = result_loc_pass1->written;
17522 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,17523 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
17523 value, force_runtime, allow_discard);17524 value, force_runtime, allow_discard);
17524 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))17525 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...@@ -17596,6 +17597,9 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17596 result_loc_pass1->resolved_loc = result_loc;17597 result_loc_pass1->resolved_loc = result_loc;
17597 }17598 }
1759817599
17600 if (was_written) {
17601 return result_loc;
17602 }
1759917603
17600 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);17604 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
17601 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;17605 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...@@ -18242,13 +18246,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18242 return ira->codegen->invalid_instruction;18246 return ira->codegen->invalid_instruction;
18243 }18247 }
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
18252 for (size_t call_i = 0; call_i < args_len; call_i += 1) {18249 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18253 IrInstruction *old_arg = args_ptr[call_i];18250 IrInstruction *old_arg = args_ptr[call_i];
1825418251
src/softfloat.hpp+17
...@@ -12,4 +12,21 @@ extern "C" {...@@ -12,4 +12,21 @@ extern "C" {
12#include "softfloat.h"12#include "softfloat.h"
13}13}
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
15#endif32#endif
src/util.hpp+2-19
...@@ -38,6 +38,8 @@...@@ -38,6 +38,8 @@
3838
39#if defined(__MINGW32__) || defined(__MINGW64__)39#if defined(__MINGW32__) || defined(__MINGW64__)
40#define BREAKPOINT __debugbreak()40#define BREAKPOINT __debugbreak()
41#elif defined(__i386__) || defined(__x86_64__)
42#define BREAKPOINT __asm__ volatile("int $0x03");
41#elif defined(__clang__)43#elif defined(__clang__)
42#define BREAKPOINT __builtin_debugtrap()44#define BREAKPOINT __builtin_debugtrap()
43#elif defined(__GNUC__)45#elif defined(__GNUC__)
...@@ -49,8 +51,6 @@...@@ -49,8 +51,6 @@
4951
50#endif52#endif
5153
52#include "softfloat.hpp"
53
54ATTRIBUTE_COLD54ATTRIBUTE_COLD
55ATTRIBUTE_NORETURN55ATTRIBUTE_NORETURN
56ATTRIBUTE_PRINTF(1, 2)56ATTRIBUTE_PRINTF(1, 2)
...@@ -244,23 +244,6 @@ static inline uint8_t log2_u64(uint64_t x) {...@@ -244,23 +244,6 @@ static inline uint8_t log2_u64(uint64_t x) {
244 return (63 - clzll(x));244 return (63 - clzll(x));
245}245}
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
264void zig_pretty_print_bytes(FILE *f, double n);247void zig_pretty_print_bytes(FILE *f, double n);
265248
266template<typename T>249template<typename T>
test/stage1/behavior.zig+1-1
...@@ -59,7 +59,7 @@ comptime {...@@ -59,7 +59,7 @@ comptime {
59 _ = @import("behavior/defer.zig");59 _ = @import("behavior/defer.zig");
60 _ = @import("behavior/enum.zig");60 _ = @import("behavior/enum.zig");
61 _ = @import("behavior/enum_with_members.zig");61 _ = @import("behavior/enum_with_members.zig");
62 //_ = @import("behavior/error.zig");62 _ = @import("behavior/error.zig");
63 _ = @import("behavior/eval.zig");63 _ = @import("behavior/eval.zig");
64 _ = @import("behavior/field_parent_ptr.zig");64 _ = @import("behavior/field_parent_ptr.zig");
65 _ = @import("behavior/floatop.zig");65 _ = @import("behavior/floatop.zig");