authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-10 18:07:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-10 18:07:28-04:00
log4cb55d3af6a71467b7d4399bedb961c81e9ad3d5
treebab3cda68f650e04b453d2fcfa6853e0af840c05
parentb63b3dc75690b016309b19c9f91f454f5f7bf4bb
parentfec4555476e38d2eeb1dfb02572404b243acd0b2

Merge remote-tracking branch 'origin/master' into llvm8


11 files changed, 58 insertions(+), 44 deletions(-)

doc/docgen.zig-1
......@@ -795,7 +795,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
795795 std.zig.Token.Id.Keyword_null,
796796 std.zig.Token.Id.Keyword_true,
797797 std.zig.Token.Id.Keyword_false,
798 std.zig.Token.Id.Keyword_this,
799798 => {
800799 try out.write("<span class=\"tok-null\">");
801800 try writeEscaped(out, src[token.start..token.end]);
src-self-hosted/ir.zig-1
......@@ -1151,7 +1151,6 @@ pub const Builder = struct {
11511151 ast.Node.Id.BoolLiteral => return error.Unimplemented,
11521152 ast.Node.Id.NullLiteral => return error.Unimplemented,
11531153 ast.Node.Id.UndefinedLiteral => return error.Unimplemented,
1154 ast.Node.Id.ThisLiteral => return error.Unimplemented,
11551154 ast.Node.Id.Unreachable => return error.Unimplemented,
11561155 ast.Node.Id.Identifier => {
11571156 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node);
src/analyze.cpp+3-7
......@@ -601,7 +601,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
601601 if (child_type->zero_bits) {
602602 entry->type_ref = LLVMInt1Type();
603603 entry->di_type = g->builtin_types.entry_bool->di_type;
604 } else if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
604 } else if (type_is_nonnull_ptr(child_type) || child_type->id == ZigTypeIdErrorSet) {
605605 assert(child_type->di_type);
606606 // this is an optimization but also is necessary for calling C
607607 // functions where all pointers are maybe pointers
......@@ -4145,11 +4145,7 @@ ZigType *get_codegen_ptr_type(ZigType *type) {
41454145}
41464146
41474147bool type_is_nonnull_ptr(ZigType *type) {
4148 return type_is_non_optional_pointer(type) && !ptr_allows_addr_zero(type);
4149}
4150
4151bool type_is_non_optional_pointer(ZigType *type) {
4152 return get_codegen_ptr_type(type) == type;
4148 return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);
41534149}
41544150
41554151uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
......@@ -4667,7 +4663,7 @@ bool handle_is_ptr(ZigType *type_entry) {
46674663 return type_has_bits(type_entry->data.error_union.payload_type);
46684664 case ZigTypeIdOptional:
46694665 return type_has_bits(type_entry->data.maybe.child_type) &&
4670 !type_is_non_optional_pointer(type_entry->data.maybe.child_type) &&
4666 !type_is_nonnull_ptr(type_entry->data.maybe.child_type) &&
46714667 type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;
46724668 case ZigTypeIdUnion:
46734669 assert(type_entry->data.unionation.zero_bits_known);
src/analyze.hpp-1
......@@ -60,7 +60,6 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c
6060Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
6161Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
6262void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
63bool type_is_non_optional_pointer(ZigType *type);
6463
6564ZigType *get_src_ptr_type(ZigType *type);
6665ZigType *get_codegen_ptr_type(ZigType *type);
src/c_tokenizer.cpp+7
......@@ -362,6 +362,13 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
362362 ctok->cur_tok->id = CTokIdNumLitFloat;
363363 buf_append_char(&ctok->buf, '.');
364364 break;
365 case 'l':
366 case 'L':
367 case 'u':
368 case 'U':
369 c -= 1;
370 ctok->state = CTokStateDecimal;
371 continue;
365372 default:
366373 c -= 1;
367374 ctok->state = CTokStateOctal;
src/codegen.cpp+6-6
......@@ -3948,10 +3948,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
39483948static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
39493949 assert(maybe_type->id == ZigTypeIdOptional);
39503950 ZigType *child_type = maybe_type->data.maybe.child_type;
3951 if (child_type->zero_bits) {
3951 if (!type_has_bits(child_type)) {
39523952 return maybe_handle;
39533953 } else {
3954 bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
3954 bool is_scalar = !handle_is_ptr(maybe_type);
39553955 if (is_scalar) {
39563956 return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), "");
39573957 } else {
......@@ -3991,7 +3991,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec
39913991 if (child_type->zero_bits) {
39923992 return nullptr;
39933993 } else {
3994 bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
3994 bool is_scalar = !handle_is_ptr(maybe_type);
39953995 if (is_scalar) {
39963996 return maybe_ptr;
39973997 } else {
......@@ -4854,7 +4854,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
48544854 }
48554855
48564856 LLVMValueRef payload_val = ir_llvm_value(g, instruction->value);
4857 if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
4857 if (!handle_is_ptr(wanted_type)) {
48584858 return payload_val;
48594859 }
48604860
......@@ -8690,10 +8690,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
86908690 case ZigTypeIdOptional:
86918691 {
86928692 ZigType *child_type = type_entry->data.maybe.child_type;
8693 if (child_type->zero_bits) {
8693 if (!type_has_bits(child_type)) {
86948694 buf_init_from_str(out_buf, "bool");
86958695 return;
8696 } else if (type_is_non_optional_pointer(child_type)) {
8696 } else if (type_is_nonnull_ptr(child_type)) {
86978697 return get_c_type(g, gen_h, child_type, out_buf);
86988698 } else {
86998699 zig_unreachable();
std/zig/ast.zig-18
......@@ -302,7 +302,6 @@ pub const Node = struct {
302302 BoolLiteral,
303303 NullLiteral,
304304 UndefinedLiteral,
305 ThisLiteral,
306305 Unreachable,
307306 Identifier,
308307 GroupedExpression,
......@@ -1997,23 +1996,6 @@ pub const Node = struct {
19971996 }
19981997 };
19991998
2000 pub const ThisLiteral = struct {
2001 base: Node,
2002 token: TokenIndex,
2003
2004 pub fn iterate(self: *ThisLiteral, index: usize) ?*Node {
2005 return null;
2006 }
2007
2008 pub fn firstToken(self: *const ThisLiteral) TokenIndex {
2009 return self.token;
2010 }
2011
2012 pub fn lastToken(self: *const ThisLiteral) TokenIndex {
2013 return self.token;
2014 }
2015 };
2016
20171999 pub const AsmOutput = struct {
20182000 base: Node,
20192001 lbracket: TokenIndex,
std/zig/parse.zig-4
......@@ -2563,10 +2563,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25632563 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.NullLiteral, token.index);
25642564 continue;
25652565 },
2566 Token.Id.Keyword_this => {
2567 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.ThisLiteral, token.index);
2568 continue;
2569 },
25702566 Token.Id.Keyword_var => {
25712567 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.VarType, token.index);
25722568 continue;
std/zig/render.zig-4
......@@ -880,10 +880,6 @@ fn renderExpression(
880880 const null_literal = @fieldParentPtr(ast.Node.NullLiteral, "base", base);
881881 return renderToken(tree, stream, null_literal.token, indent, start_col, space);
882882 },
883 ast.Node.Id.ThisLiteral => {
884 const this_literal = @fieldParentPtr(ast.Node.ThisLiteral, "base", base);
885 return renderToken(tree, stream, this_literal.token, indent, start_col, space);
886 },
887883 ast.Node.Id.Unreachable => {
888884 const unreachable_node = @fieldParentPtr(ast.Node.Unreachable, "base", base);
889885 return renderToken(tree, stream, unreachable_node.token, indent, start_col, space);
std/zig/tokenizer.zig-2
......@@ -52,7 +52,6 @@ pub const Token = struct {
5252 Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend },
5353 Keyword{ .bytes = "switch", .id = Id.Keyword_switch },
5454 Keyword{ .bytes = "test", .id = Id.Keyword_test },
55 Keyword{ .bytes = "this", .id = Id.Keyword_this },
5655 Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal },
5756 Keyword{ .bytes = "true", .id = Id.Keyword_true },
5857 Keyword{ .bytes = "try", .id = Id.Keyword_try },
......@@ -183,7 +182,6 @@ pub const Token = struct {
183182 Keyword_suspend,
184183 Keyword_switch,
185184 Keyword_test,
186 Keyword_this,
187185 Keyword_threadlocal,
188186 Keyword_true,
189187 Keyword_try,
test/translate_c.zig+42
......@@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14251425 \\pub export fn bar() void {}
14261426 );
14271427
1428 cases.addC("u integer suffix after 0 (zero) in macro definition",
1429 "#define ZERO 0U"
1430 ,
1431 "pub const ZERO = c_uint(0);"
1432 );
1433
1434 cases.addC("l integer suffix after 0 (zero) in macro definition",
1435 "#define ZERO 0L"
1436 ,
1437 "pub const ZERO = c_long(0);"
1438 );
1439
1440 cases.addC("ul integer suffix after 0 (zero) in macro definition",
1441 "#define ZERO 0UL"
1442 ,
1443 "pub const ZERO = c_ulong(0);"
1444 );
1445
1446 cases.addC("lu integer suffix after 0 (zero) in macro definition",
1447 "#define ZERO 0LU"
1448 ,
1449 "pub const ZERO = c_ulong(0);"
1450 );
1451
1452 cases.addC("ll integer suffix after 0 (zero) in macro definition",
1453 "#define ZERO 0LL"
1454 ,
1455 "pub const ZERO = c_longlong(0);"
1456 );
1457
1458 cases.addC("ull integer suffix after 0 (zero) in macro definition",
1459 "#define ZERO 0ULL"
1460 ,
1461 "pub const ZERO = c_ulonglong(0);"
1462 );
1463
1464 cases.addC("llu integer suffix after 0 (zero) in macro definition",
1465 "#define ZERO 0LLU"
1466 ,
1467 "pub const ZERO = c_ulonglong(0);"
1468 );
1469
14281470 // cases.add("empty array with initializer",
14291471 // "int a[4] = {};"
14301472 // ,