authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-22 20:10:34-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-22 20:10:34-05:00
log87f5bed11fa9b92f63f6c2eea1e3c8d4fcefa44d
treed7e5f59e73526939bb7d90cc228a6fccd9406dca
parent3b2eeb839bb34903596edeae041b5d9ab189282d
parent3bec3b9f9ba49bbc2e7244737c50bdbaa12a6b14

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


6 files changed, 87 insertions(+), 27 deletions(-)

cmake/Findllvm.cmake+9
...@@ -15,6 +15,15 @@ find_program(LLVM_CONFIG_EXE...@@ -15,6 +15,15 @@ find_program(LLVM_CONFIG_EXE
15 "c:/msys64/mingw64/bin"15 "c:/msys64/mingw64/bin"
16 "C:/Libraries/llvm-8.0.0/bin")16 "C:/Libraries/llvm-8.0.0/bin")
1717
18execute_process(
19 COMMAND ${LLVM_CONFIG_EXE} --version
20 OUTPUT_VARIABLE LLVM_CONFIG_VERSION
21 OUTPUT_STRIP_TRAILING_WHITESPACE)
22
23if(LLVM_CONFIG_VERSION VERSION_LESS 7)
24 message(FATAL_ERROR "expected LLVM version >=7 but found ${LLVM_CONFIG_VERSION}")
25endif()
26
18if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug") OR ZIG_STATIC)27if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug") OR ZIG_STATIC)
19 execute_process(28 execute_process(
20 COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static29 COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static
src/analyze.cpp+7
...@@ -5751,6 +5751,13 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v...@@ -5751,6 +5751,13 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v
5751}5751}
57525752
5753void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {5753void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {
5754 assert(type_entry->id == ZigTypeIdPointer);
5755
5756 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
5757 buf_append_buf(buf, &type_entry->name);
5758 return;
5759 }
5760
5754 switch (const_val->data.x_ptr.special) {5761 switch (const_val->data.x_ptr.special) {
5755 case ConstPtrSpecialInvalid:5762 case ConstPtrSpecialInvalid:
5756 zig_unreachable();5763 zig_unreachable();
std/debug/index.zig+47-24
...@@ -247,8 +247,7 @@ pub fn writeCurrentStackTraceWindows(...@@ -247,8 +247,7 @@ pub fn writeCurrentStackTraceWindows(
247 start_addr: ?usize,247 start_addr: ?usize,
248) !void {248) !void {
249 var addr_buf: [1024]usize = undefined;249 var addr_buf: [1024]usize = undefined;
250 const casted_len = @intCast(u32, addr_buf.len); // TODO shouldn't need this cast250 const n = windows.RtlCaptureStackBackTrace(0, addr_buf.len, @ptrCast(**c_void, &addr_buf), null);
251 const n = windows.RtlCaptureStackBackTrace(0, casted_len, @ptrCast(**c_void, &addr_buf), null);
252 const addrs = addr_buf[0..n];251 const addrs = addr_buf[0..n];
253 var start_i: usize = if (start_addr) |saddr| blk: {252 var start_i: usize = if (start_addr) |saddr| blk: {
254 for (addrs) |addr, i| {253 for (addrs) |addr, i| {
...@@ -338,50 +337,74 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -338,50 +337,74 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
338337
339 switch (subsect_hdr.Kind) {338 switch (subsect_hdr.Kind) {
340 pdb.DebugSubsectionKind.Lines => {339 pdb.DebugSubsectionKind.Lines => {
341 var line_index: usize = sect_offset;340 var line_index = sect_offset;
342341
343 const line_hdr = @ptrCast(*pdb.LineFragmentHeader, &subsect_info[line_index]);342 const line_hdr = @ptrCast(*pdb.LineFragmentHeader, &subsect_info[line_index]);
344 if (line_hdr.RelocSegment == 0) return error.MissingDebugInfo;343 if (line_hdr.RelocSegment == 0) return error.MissingDebugInfo;
345 line_index += @sizeOf(pdb.LineFragmentHeader);344 line_index += @sizeOf(pdb.LineFragmentHeader);
346
347 const block_hdr = @ptrCast(*pdb.LineBlockFragmentHeader, &subsect_info[line_index]);
348 line_index += @sizeOf(pdb.LineBlockFragmentHeader);
349
350 const has_column = line_hdr.Flags.LF_HaveColumns;
351
352 const frag_vaddr_start = coff_section.header.virtual_address + line_hdr.RelocOffset;345 const frag_vaddr_start = coff_section.header.virtual_address + line_hdr.RelocOffset;
353 const frag_vaddr_end = frag_vaddr_start + line_hdr.CodeSize;346 const frag_vaddr_end = frag_vaddr_start + line_hdr.CodeSize;
354 if (relative_address >= frag_vaddr_start and relative_address < frag_vaddr_end) {347
355 var line_i: usize = 0;348 // There is an unknown number of LineBlockFragmentHeaders (and their accompanying line and column records)
349 // from now on. We will iterate through them, and eventually find a LineInfo that we're interested in,
350 // breaking out to :subsections. If not, we will make sure to not read anything outside of this subsection.
351 const subsection_end_index = sect_offset + subsect_hdr.Length;
352 while (line_index < subsection_end_index) {
353 const block_hdr = @ptrCast(*pdb.LineBlockFragmentHeader, &subsect_info[line_index]);
354 line_index += @sizeOf(pdb.LineBlockFragmentHeader);
356 const start_line_index = line_index;355 const start_line_index = line_index;
357 while (line_i < block_hdr.NumLines) : (line_i += 1) {356
358 const line_num_entry = @ptrCast(*pdb.LineNumberEntry, &subsect_info[line_index]);357 const has_column = line_hdr.Flags.LF_HaveColumns;
359 line_index += @sizeOf(pdb.LineNumberEntry);358
360 const flags = @ptrCast(*pdb.LineNumberEntry.Flags, &line_num_entry.Flags);359 if (relative_address >= frag_vaddr_start and relative_address < frag_vaddr_end) {
361 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;360 // All line entries are stored inside their line block by ascending start address.
362 const vaddr_end = if (flags.End == 0) frag_vaddr_end else vaddr_start + flags.End;361 // Heuristic: we want to find the last line entry that has a vaddr_start <= relative_address.
363 if (relative_address >= vaddr_start and relative_address < vaddr_end) {362 // This is done with a simple linear search.
363 var line_i: u32 = 0;
364 while (line_i < block_hdr.NumLines) : (line_i += 1) {
365 const line_num_entry = @ptrCast(*pdb.LineNumberEntry, &subsect_info[line_index]);
366 line_index += @sizeOf(pdb.LineNumberEntry);
367
368 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;
369 if (relative_address <= vaddr_start) {
370 break;
371 }
372 }
373
374 // line_i == 0 would mean that no matching LineNumberEntry was found.
375 if (line_i > 0) {
364 const subsect_index = checksum_offset + block_hdr.NameIndex;376 const subsect_index = checksum_offset + block_hdr.NameIndex;
365 const chksum_hdr = @ptrCast(*pdb.FileChecksumEntryHeader, &mod.subsect_info[subsect_index]);377 const chksum_hdr = @ptrCast(*pdb.FileChecksumEntryHeader, &mod.subsect_info[subsect_index]);
366 const strtab_offset = @sizeOf(pdb.PDBStringTableHeader) + chksum_hdr.FileNameOffset;378 const strtab_offset = @sizeOf(pdb.PDBStringTableHeader) + chksum_hdr.FileNameOffset;
367 try di.pdb.string_table.seekTo(strtab_offset);379 try di.pdb.string_table.seekTo(strtab_offset);
368 const source_file_name = try di.pdb.string_table.readNullTermString(allocator);380 const source_file_name = try di.pdb.string_table.readNullTermString(allocator);
369 const line = flags.Start;381
382 const line_entry_idx = line_i - 1;
383
370 const column = if (has_column) blk: {384 const column = if (has_column) blk: {
371 line_index = start_line_index + @sizeOf(pdb.LineNumberEntry) * block_hdr.NumLines;385 const start_col_index = start_line_index + @sizeOf(pdb.LineNumberEntry) * block_hdr.NumLines;
372 line_index += @sizeOf(pdb.ColumnNumberEntry) * line_i;386 const col_index = start_col_index + @sizeOf(pdb.ColumnNumberEntry) * line_entry_idx;
373 const col_num_entry = @ptrCast(*pdb.ColumnNumberEntry, &subsect_info[line_index]);387 const col_num_entry = @ptrCast(*pdb.ColumnNumberEntry, &subsect_info[col_index]);
374 break :blk col_num_entry.StartColumn;388 break :blk col_num_entry.StartColumn;
375 } else 0;389 } else 0;
390
391 const found_line_index = start_line_index + line_entry_idx * @sizeOf(pdb.LineNumberEntry);
392 const line_num_entry = @ptrCast(*pdb.LineNumberEntry, &subsect_info[found_line_index]);
393 const flags = @ptrCast(*pdb.LineNumberEntry.Flags, &line_num_entry.Flags);
394
376 break :subsections LineInfo{395 break :subsections LineInfo{
377 .allocator = allocator,396 .allocator = allocator,
378 .file_name = source_file_name,397 .file_name = source_file_name,
379 .line = line,398 .line = flags.Start,
380 .column = column,399 .column = column,
381 };400 };
382 }401 }
383 }402 }
384 break :subsections null;403 }
404
405 // Checking that we are not reading garbage after the (possibly) multiple block fragments.
406 if (line_index != subsection_end_index) {
407 return error.InvalidDebugInfo;
385 }408 }
386 },409 },
387 else => {},410 else => {},
std/math/atan2.zig+3-3
...@@ -22,10 +22,10 @@ const std = @import("../index.zig");...@@ -22,10 +22,10 @@ const std = @import("../index.zig");
22const math = std.math;22const math = std.math;
23const assert = std.debug.assert;23const assert = std.debug.assert;
2424
25pub fn atan2(comptime T: type, x: T, y: T) T {25pub fn atan2(comptime T: type, y: T, x: T) T {
26 return switch (T) {26 return switch (T) {
27 f32 => atan2_32(x, y),27 f32 => atan2_32(y, x),
28 f64 => atan2_64(x, y),28 f64 => atan2_64(y, x),
29 else => @compileError("atan2 not implemented for " ++ @typeName(T)),29 else => @compileError("atan2 not implemented for " ++ @typeName(T)),
30 };30 };
31}31}
std/pdb.zig+12
...@@ -9,6 +9,10 @@ const coff = std.coff;...@@ -9,6 +9,10 @@ const coff = std.coff;
99
10const ArrayList = std.ArrayList;10const ArrayList = std.ArrayList;
1111
12// Note: most of this is based on information gathered from LLVM source code,
13// documentation and/or contributors.
14
15
12// https://llvm.org/docs/PDB/DbiStream.html#stream-header16// https://llvm.org/docs/PDB/DbiStream.html#stream-header
13pub const DbiStreamHeader = packed struct {17pub const DbiStreamHeader = packed struct {
14 VersionSignature: i32,18 VersionSignature: i32,
...@@ -345,6 +349,10 @@ pub const RecordPrefix = packed struct {...@@ -345,6 +349,10 @@ pub const RecordPrefix = packed struct {
345 RecordKind: SymbolKind,349 RecordKind: SymbolKind,
346};350};
347351
352/// The following variable length array appears immediately after the header.
353/// The structure definition follows.
354/// LineBlockFragmentHeader Blocks[]
355/// Each `LineBlockFragmentHeader` as specified below.
348pub const LineFragmentHeader = packed struct {356pub const LineFragmentHeader = packed struct {
349 /// Code offset of line contribution.357 /// Code offset of line contribution.
350 RelocOffset: u32,358 RelocOffset: u32,
...@@ -386,7 +394,11 @@ pub const LineNumberEntry = packed struct {...@@ -386,7 +394,11 @@ pub const LineNumberEntry = packed struct {
386394
387 /// TODO runtime crash when I make the actual type of Flags this395 /// TODO runtime crash when I make the actual type of Flags this
388 const Flags = packed struct {396 const Flags = packed struct {
397 /// Start line number
389 Start: u24,398 Start: u24,
399
400 /// Delta of lines to the end of the expression. Still unclear.
401 // TODO figure out the point of this field.
390 End: u7,402 End: u7,
391 IsStatement: bool,403 IsStatement: bool,
392 };404 };
test/compile_errors.zig+9
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "compile log a pointer to an opaque value",
6 \\export fn entry() void {
7 \\ @compileLog(@ptrCast(*const c_void, &entry));
8 \\}
9 ,
10 ".tmp_source.zig:2:5: error: found compile log statement",
11 );
12
4 cases.add(13 cases.add(
5 "duplicate boolean switch value",14 "duplicate boolean switch value",
6 \\comptime {15 \\comptime {