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...@@ -795,7 +795,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
795 std.zig.Token.Id.Keyword_null,795 std.zig.Token.Id.Keyword_null,
796 std.zig.Token.Id.Keyword_true,796 std.zig.Token.Id.Keyword_true,
797 std.zig.Token.Id.Keyword_false,797 std.zig.Token.Id.Keyword_false,
798 std.zig.Token.Id.Keyword_this,
799 => {798 => {
800 try out.write("<span class=\"tok-null\">");799 try out.write("<span class=\"tok-null\">");
801 try writeEscaped(out, src[token.start..token.end]);800 try writeEscaped(out, src[token.start..token.end]);
src-self-hosted/ir.zig-1
...@@ -1151,7 +1151,6 @@ pub const Builder = struct {...@@ -1151,7 +1151,6 @@ pub const Builder = struct {
1151 ast.Node.Id.BoolLiteral => return error.Unimplemented,1151 ast.Node.Id.BoolLiteral => return error.Unimplemented,
1152 ast.Node.Id.NullLiteral => return error.Unimplemented,1152 ast.Node.Id.NullLiteral => return error.Unimplemented,
1153 ast.Node.Id.UndefinedLiteral => return error.Unimplemented,1153 ast.Node.Id.UndefinedLiteral => return error.Unimplemented,
1154 ast.Node.Id.ThisLiteral => return error.Unimplemented,
1155 ast.Node.Id.Unreachable => return error.Unimplemented,1154 ast.Node.Id.Unreachable => return error.Unimplemented,
1156 ast.Node.Id.Identifier => {1155 ast.Node.Id.Identifier => {
1157 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node);1156 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) {...@@ -601,7 +601,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
601 if (child_type->zero_bits) {601 if (child_type->zero_bits) {
602 entry->type_ref = LLVMInt1Type();602 entry->type_ref = LLVMInt1Type();
603 entry->di_type = g->builtin_types.entry_bool->di_type;603 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) {
605 assert(child_type->di_type);605 assert(child_type->di_type);
606 // this is an optimization but also is necessary for calling C606 // this is an optimization but also is necessary for calling C
607 // functions where all pointers are maybe pointers607 // functions where all pointers are maybe pointers
...@@ -4145,11 +4145,7 @@ ZigType *get_codegen_ptr_type(ZigType *type) {...@@ -4145,11 +4145,7 @@ ZigType *get_codegen_ptr_type(ZigType *type) {
4145}4145}
41464146
4147bool type_is_nonnull_ptr(ZigType *type) {4147bool type_is_nonnull_ptr(ZigType *type) {
4148 return type_is_non_optional_pointer(type) && !ptr_allows_addr_zero(type);4148 return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);
4149}
4150
4151bool type_is_non_optional_pointer(ZigType *type) {
4152 return get_codegen_ptr_type(type) == type;
4153}4149}
41544150
4155uint32_t get_ptr_align(CodeGen *g, ZigType *type) {4151uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
...@@ -4667,7 +4663,7 @@ bool handle_is_ptr(ZigType *type_entry) {...@@ -4667,7 +4663,7 @@ bool handle_is_ptr(ZigType *type_entry) {
4667 return type_has_bits(type_entry->data.error_union.payload_type);4663 return type_has_bits(type_entry->data.error_union.payload_type);
4668 case ZigTypeIdOptional:4664 case ZigTypeIdOptional:
4669 return type_has_bits(type_entry->data.maybe.child_type) &&4665 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) &&
4671 type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;4667 type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;
4672 case ZigTypeIdUnion:4668 case ZigTypeIdUnion:
4673 assert(type_entry->data.unionation.zero_bits_known);4669 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...@@ -60,7 +60,6 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c
60Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);60Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
61Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);61Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
62void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);62void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
63bool type_is_non_optional_pointer(ZigType *type);
6463
65ZigType *get_src_ptr_type(ZigType *type);64ZigType *get_src_ptr_type(ZigType *type);
66ZigType *get_codegen_ptr_type(ZigType *type);65ZigType *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) {...@@ -362,6 +362,13 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
362 ctok->cur_tok->id = CTokIdNumLitFloat;362 ctok->cur_tok->id = CTokIdNumLitFloat;
363 buf_append_char(&ctok->buf, '.');363 buf_append_char(&ctok->buf, '.');
364 break;364 break;
365 case 'l':
366 case 'L':
367 case 'u':
368 case 'U':
369 c -= 1;
370 ctok->state = CTokStateDecimal;
371 continue;
365 default:372 default:
366 c -= 1;373 c -= 1;
367 ctok->state = CTokStateOctal;374 ctok->state = CTokStateOctal;
src/codegen.cpp+6-6
...@@ -3948,10 +3948,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3948,10 +3948,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
3948static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {3948static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
3949 assert(maybe_type->id == ZigTypeIdOptional);3949 assert(maybe_type->id == ZigTypeIdOptional);
3950 ZigType *child_type = maybe_type->data.maybe.child_type;3950 ZigType *child_type = maybe_type->data.maybe.child_type;
3951 if (child_type->zero_bits) {3951 if (!type_has_bits(child_type)) {
3952 return maybe_handle;3952 return maybe_handle;
3953 } else {3953 } 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);
3955 if (is_scalar) {3955 if (is_scalar) {
3956 return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), "");3956 return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), "");
3957 } else {3957 } else {
...@@ -3991,7 +3991,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec...@@ -3991,7 +3991,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec
3991 if (child_type->zero_bits) {3991 if (child_type->zero_bits) {
3992 return nullptr;3992 return nullptr;
3993 } else {3993 } 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);
3995 if (is_scalar) {3995 if (is_scalar) {
3996 return maybe_ptr;3996 return maybe_ptr;
3997 } else {3997 } else {
...@@ -4854,7 +4854,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I...@@ -4854,7 +4854,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
4854 }4854 }
48554855
4856 LLVMValueRef payload_val = ir_llvm_value(g, instruction->value);4856 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)) {
4858 return payload_val;4858 return payload_val;
4859 }4859 }
48604860
...@@ -8690,10 +8690,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -8690,10 +8690,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
8690 case ZigTypeIdOptional:8690 case ZigTypeIdOptional:
8691 {8691 {
8692 ZigType *child_type = type_entry->data.maybe.child_type;8692 ZigType *child_type = type_entry->data.maybe.child_type;
8693 if (child_type->zero_bits) {8693 if (!type_has_bits(child_type)) {
8694 buf_init_from_str(out_buf, "bool");8694 buf_init_from_str(out_buf, "bool");
8695 return;8695 return;
8696 } else if (type_is_non_optional_pointer(child_type)) {8696 } else if (type_is_nonnull_ptr(child_type)) {
8697 return get_c_type(g, gen_h, child_type, out_buf);8697 return get_c_type(g, gen_h, child_type, out_buf);
8698 } else {8698 } else {
8699 zig_unreachable();8699 zig_unreachable();
std/zig/ast.zig-18
...@@ -302,7 +302,6 @@ pub const Node = struct {...@@ -302,7 +302,6 @@ pub const Node = struct {
302 BoolLiteral,302 BoolLiteral,
303 NullLiteral,303 NullLiteral,
304 UndefinedLiteral,304 UndefinedLiteral,
305 ThisLiteral,
306 Unreachable,305 Unreachable,
307 Identifier,306 Identifier,
308 GroupedExpression,307 GroupedExpression,
...@@ -1997,23 +1996,6 @@ pub const Node = struct {...@@ -1997,23 +1996,6 @@ pub const Node = struct {
1997 }1996 }
1998 };1997 };
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
2017 pub const AsmOutput = struct {1999 pub const AsmOutput = struct {
2018 base: Node,2000 base: Node,
2019 lbracket: TokenIndex,2001 lbracket: TokenIndex,
std/zig/parse.zig-4
...@@ -2563,10 +2563,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2563,10 +2563,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2563 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.NullLiteral, token.index);2563 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.NullLiteral, token.index);
2564 continue;2564 continue;
2565 },2565 },
2566 Token.Id.Keyword_this => {
2567 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.ThisLiteral, token.index);
2568 continue;
2569 },
2570 Token.Id.Keyword_var => {2566 Token.Id.Keyword_var => {
2571 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.VarType, token.index);2567 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.VarType, token.index);
2572 continue;2568 continue;
std/zig/render.zig-4
...@@ -880,10 +880,6 @@ fn renderExpression(...@@ -880,10 +880,6 @@ fn renderExpression(
880 const null_literal = @fieldParentPtr(ast.Node.NullLiteral, "base", base);880 const null_literal = @fieldParentPtr(ast.Node.NullLiteral, "base", base);
881 return renderToken(tree, stream, null_literal.token, indent, start_col, space);881 return renderToken(tree, stream, null_literal.token, indent, start_col, space);
882 },882 },
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 },
887 ast.Node.Id.Unreachable => {883 ast.Node.Id.Unreachable => {
888 const unreachable_node = @fieldParentPtr(ast.Node.Unreachable, "base", base);884 const unreachable_node = @fieldParentPtr(ast.Node.Unreachable, "base", base);
889 return renderToken(tree, stream, unreachable_node.token, indent, start_col, space);885 return renderToken(tree, stream, unreachable_node.token, indent, start_col, space);
std/zig/tokenizer.zig-2
...@@ -52,7 +52,6 @@ pub const Token = struct {...@@ -52,7 +52,6 @@ pub const Token = struct {
52 Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend },52 Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend },
53 Keyword{ .bytes = "switch", .id = Id.Keyword_switch },53 Keyword{ .bytes = "switch", .id = Id.Keyword_switch },
54 Keyword{ .bytes = "test", .id = Id.Keyword_test },54 Keyword{ .bytes = "test", .id = Id.Keyword_test },
55 Keyword{ .bytes = "this", .id = Id.Keyword_this },
56 Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal },55 Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal },
57 Keyword{ .bytes = "true", .id = Id.Keyword_true },56 Keyword{ .bytes = "true", .id = Id.Keyword_true },
58 Keyword{ .bytes = "try", .id = Id.Keyword_try },57 Keyword{ .bytes = "try", .id = Id.Keyword_try },
...@@ -183,7 +182,6 @@ pub const Token = struct {...@@ -183,7 +182,6 @@ pub const Token = struct {
183 Keyword_suspend,182 Keyword_suspend,
184 Keyword_switch,183 Keyword_switch,
185 Keyword_test,184 Keyword_test,
186 Keyword_this,
187 Keyword_threadlocal,185 Keyword_threadlocal,
188 Keyword_true,186 Keyword_true,
189 Keyword_try,187 Keyword_try,
test/translate_c.zig+42
...@@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1425 \\pub export fn bar() void {}1425 \\pub export fn bar() void {}
1426 );1426 );
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
1428 // cases.add("empty array with initializer",1470 // cases.add("empty array with initializer",
1429 // "int a[4] = {};"1471 // "int a[4] = {};"
1430 // ,1472 // ,