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

master
Andrew Kelley 2019-03-10 18:07:28 -04:00
commit 4cb55d3af6
11 changed files with 58 additions and 44 deletions

View File

@ -795,7 +795,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
std.zig.Token.Id.Keyword_null,
std.zig.Token.Id.Keyword_true,
std.zig.Token.Id.Keyword_false,
std.zig.Token.Id.Keyword_this,
=> {
try out.write("<span class=\"tok-null\">");
try writeEscaped(out, src[token.start..token.end]);

View File

@ -1151,7 +1151,6 @@ pub const Builder = struct {
ast.Node.Id.BoolLiteral => return error.Unimplemented,
ast.Node.Id.NullLiteral => return error.Unimplemented,
ast.Node.Id.UndefinedLiteral => return error.Unimplemented,
ast.Node.Id.ThisLiteral => return error.Unimplemented,
ast.Node.Id.Unreachable => return error.Unimplemented,
ast.Node.Id.Identifier => {
const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node);

View File

@ -601,7 +601,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
if (child_type->zero_bits) {
entry->type_ref = LLVMInt1Type();
entry->di_type = g->builtin_types.entry_bool->di_type;
} else if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
} else if (type_is_nonnull_ptr(child_type) || child_type->id == ZigTypeIdErrorSet) {
assert(child_type->di_type);
// this is an optimization but also is necessary for calling C
// functions where all pointers are maybe pointers
@ -4145,11 +4145,7 @@ ZigType *get_codegen_ptr_type(ZigType *type) {
}
bool type_is_nonnull_ptr(ZigType *type) {
return type_is_non_optional_pointer(type) && !ptr_allows_addr_zero(type);
}
bool type_is_non_optional_pointer(ZigType *type) {
return get_codegen_ptr_type(type) == type;
return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);
}
uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
@ -4667,7 +4663,7 @@ bool handle_is_ptr(ZigType *type_entry) {
return type_has_bits(type_entry->data.error_union.payload_type);
case ZigTypeIdOptional:
return type_has_bits(type_entry->data.maybe.child_type) &&
!type_is_non_optional_pointer(type_entry->data.maybe.child_type) &&
!type_is_nonnull_ptr(type_entry->data.maybe.child_type) &&
type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;
case ZigTypeIdUnion:
assert(type_entry->data.unionation.zero_bits_known);

View File

@ -60,7 +60,6 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
bool type_is_non_optional_pointer(ZigType *type);
ZigType *get_src_ptr_type(ZigType *type);
ZigType *get_codegen_ptr_type(ZigType *type);

View File

@ -362,6 +362,13 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
ctok->cur_tok->id = CTokIdNumLitFloat;
buf_append_char(&ctok->buf, '.');
break;
case 'l':
case 'L':
case 'u':
case 'U':
c -= 1;
ctok->state = CTokStateDecimal;
continue;
default:
c -= 1;
ctok->state = CTokStateOctal;

View File

@ -3948,10 +3948,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
assert(maybe_type->id == ZigTypeIdOptional);
ZigType *child_type = maybe_type->data.maybe.child_type;
if (child_type->zero_bits) {
if (!type_has_bits(child_type)) {
return maybe_handle;
} else {
bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
bool is_scalar = !handle_is_ptr(maybe_type);
if (is_scalar) {
return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), "");
} else {
@ -3991,7 +3991,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec
if (child_type->zero_bits) {
return nullptr;
} else {
bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
bool is_scalar = !handle_is_ptr(maybe_type);
if (is_scalar) {
return maybe_ptr;
} else {
@ -4854,7 +4854,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
}
LLVMValueRef payload_val = ir_llvm_value(g, instruction->value);
if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
if (!handle_is_ptr(wanted_type)) {
return payload_val;
}
@ -8690,10 +8690,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
case ZigTypeIdOptional:
{
ZigType *child_type = type_entry->data.maybe.child_type;
if (child_type->zero_bits) {
if (!type_has_bits(child_type)) {
buf_init_from_str(out_buf, "bool");
return;
} else if (type_is_non_optional_pointer(child_type)) {
} else if (type_is_nonnull_ptr(child_type)) {
return get_c_type(g, gen_h, child_type, out_buf);
} else {
zig_unreachable();

View File

@ -302,7 +302,6 @@ pub const Node = struct {
BoolLiteral,
NullLiteral,
UndefinedLiteral,
ThisLiteral,
Unreachable,
Identifier,
GroupedExpression,
@ -1997,23 +1996,6 @@ pub const Node = struct {
}
};
pub const ThisLiteral = struct {
base: Node,
token: TokenIndex,
pub fn iterate(self: *ThisLiteral, index: usize) ?*Node {
return null;
}
pub fn firstToken(self: *const ThisLiteral) TokenIndex {
return self.token;
}
pub fn lastToken(self: *const ThisLiteral) TokenIndex {
return self.token;
}
};
pub const AsmOutput = struct {
base: Node,
lbracket: TokenIndex,

View File

@ -2563,10 +2563,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
_ = try createToCtxLiteral(arena, opt_ctx, ast.Node.NullLiteral, token.index);
continue;
},
Token.Id.Keyword_this => {
_ = try createToCtxLiteral(arena, opt_ctx, ast.Node.ThisLiteral, token.index);
continue;
},
Token.Id.Keyword_var => {
_ = try createToCtxLiteral(arena, opt_ctx, ast.Node.VarType, token.index);
continue;

View File

@ -880,10 +880,6 @@ fn renderExpression(
const null_literal = @fieldParentPtr(ast.Node.NullLiteral, "base", base);
return renderToken(tree, stream, null_literal.token, indent, start_col, space);
},
ast.Node.Id.ThisLiteral => {
const this_literal = @fieldParentPtr(ast.Node.ThisLiteral, "base", base);
return renderToken(tree, stream, this_literal.token, indent, start_col, space);
},
ast.Node.Id.Unreachable => {
const unreachable_node = @fieldParentPtr(ast.Node.Unreachable, "base", base);
return renderToken(tree, stream, unreachable_node.token, indent, start_col, space);

View File

@ -52,7 +52,6 @@ pub const Token = struct {
Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend },
Keyword{ .bytes = "switch", .id = Id.Keyword_switch },
Keyword{ .bytes = "test", .id = Id.Keyword_test },
Keyword{ .bytes = "this", .id = Id.Keyword_this },
Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal },
Keyword{ .bytes = "true", .id = Id.Keyword_true },
Keyword{ .bytes = "try", .id = Id.Keyword_try },
@ -183,7 +182,6 @@ pub const Token = struct {
Keyword_suspend,
Keyword_switch,
Keyword_test,
Keyword_this,
Keyword_threadlocal,
Keyword_true,
Keyword_try,

View File

@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn bar() void {}
);
cases.addC("u integer suffix after 0 (zero) in macro definition",
"#define ZERO 0U"
,
"pub const ZERO = c_uint(0);"
);
cases.addC("l integer suffix after 0 (zero) in macro definition",
"#define ZERO 0L"
,
"pub const ZERO = c_long(0);"
);
cases.addC("ul integer suffix after 0 (zero) in macro definition",
"#define ZERO 0UL"
,
"pub const ZERO = c_ulong(0);"
);
cases.addC("lu integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LU"
,
"pub const ZERO = c_ulong(0);"
);
cases.addC("ll integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LL"
,
"pub const ZERO = c_longlong(0);"
);
cases.addC("ull integer suffix after 0 (zero) in macro definition",
"#define ZERO 0ULL"
,
"pub const ZERO = c_ulonglong(0);"
);
cases.addC("llu integer suffix after 0 (zero) in macro definition",
"#define ZERO 0LLU"
,
"pub const ZERO = c_ulonglong(0);"
);
// cases.add("empty array with initializer",
// "int a[4] = {};"
// ,