Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -2310,10 +2310,10 @@ test "while loop continue expression" {
}

test "while loop continue expression, more complicated" {
var i1: usize = 1;
var j1: usize = 1;
while (i1 * j1 < 2000) : ({ i1 *= 2; j1 *= 3; }) {
const my_ij1 = i1 * j1;
var i_1: usize = 1;
var j_1: usize = 1;
while (i_1 * j_1 < 2000) : ({ i_1 *= 2; j_1 *= 3; }) {
const my_ij1 = i_1 * j_1;
assert(my_ij1 < 2000);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ struct CodeGen {

struct {
TypeTableEntry *entry_bool;
TypeTableEntry *entry_int[2][12]; // [signed,unsigned][2,3,4,5,6,7,8,16,29,32,64,128]
TypeTableEntry *entry_int[2][128]; // [signed,unsigned][1-128]
TypeTableEntry *entry_c_int[CIntTypeCount];
TypeTableEntry *entry_c_longdouble;
TypeTableEntry *entry_c_void;
Expand Down
26 changes: 2 additions & 24 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4309,30 +4309,8 @@ void semantic_analyze(CodeGen *g) {

TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
size_t index;
if (size_in_bits == 2) {
index = 0;
} else if (size_in_bits == 3) {
index = 1;
} else if (size_in_bits == 4) {
index = 2;
} else if (size_in_bits == 5) {
index = 3;
} else if (size_in_bits == 6) {
index = 4;
} else if (size_in_bits == 7) {
index = 5;
} else if (size_in_bits == 8) {
index = 6;
} else if (size_in_bits == 16) {
index = 7;
} else if (size_in_bits == 29) {
index = 8;
} else if (size_in_bits == 32) {
index = 9;
} else if (size_in_bits == 64) {
index = 10;
} else if (size_in_bits == 128) {
index = 11;
if (0 < size_in_bits && size_in_bits <= 128) {
index = size_in_bits - 1;
} else {
return nullptr;
}
Expand Down
25 changes: 9 additions & 16 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ static LLVMValueRef get_write_register_fn_val(CodeGen *g) {
// !0 = !{!"sp\00"}

LLVMTypeRef param_types[] = {
LLVMMetadataTypeInContext(LLVMGetGlobalContext()),
LLVMMetadataTypeInContext(LLVMGetGlobalContext()),
LLVMIntType(g->pointer_size_bytes * 8),
};

Expand Down Expand Up @@ -3137,7 +3137,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr

LLVMCallConv llvm_cc = get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc);
LLVMValueRef result;

if (instruction->new_stack == nullptr) {
result = ZigLLVMBuildCall(g->builder, fn_val,
gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, "");
Expand Down Expand Up @@ -3581,7 +3581,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_

LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(u8_slice_type->type_ref, 0),
&tag_int_type->type_ref, 1, false);

Buf *fn_name = get_mangled_name(g, buf_sprintf("__zig_tag_name_%s", buf_ptr(&enum_type->name)), false);
LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
LLVMSetLinkage(fn_val, LLVMInternalLinkage);
Expand Down Expand Up @@ -6063,18 +6063,11 @@ static void do_code_gen(CodeGen *g) {
}

static const uint8_t int_sizes_in_bits[] = {
2,
3,
4,
5,
6,
7,
8,
16,
29,
32,
64,
128,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128
};

struct CIntTypeInfo {
Expand Down Expand Up @@ -6757,7 +6750,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
assert(ContainerLayoutAuto == 0);
assert(ContainerLayoutExtern == 1);
assert(ContainerLayoutPacked == 2);

assert(CallingConventionUnspecified == 0);
assert(CallingConventionC == 1);
assert(CallingConventionCold == 2);
Expand Down
1 change: 0 additions & 1 deletion std/json.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const std = @import("index.zig");
const debug = std.debug;
const mem = std.mem;

const u1 = @IntType(false, 1);
const u256 = @IntType(false, 256);

// A single token slice into the parent string.
Expand Down
1 change: 0 additions & 1 deletion std/os/time.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub fn sleep(seconds: usize, nanoseconds: usize) void {
}
}

const u63 = @IntType(false, 63);
pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
var req = posix.timespec{
.tv_sec = seconds,
Expand Down
40 changes: 18 additions & 22 deletions test/cases/misc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,33 @@ test "call disabled extern fn" {
}

test "@IntType builtin" {
assert(@IntType(true, 1) == i1);
assert(@IntType(true, 2) == i2);
assert(@IntType(true, 8) == i8);
assert(@IntType(true, 16) == i16);
assert(@IntType(true, 32) == i32);
assert(@IntType(true, 55) == i55);
assert(@IntType(true, 64) == i64);
assert(@IntType(true, 123) == i123);
assert(@IntType(true, 128) == i128);

assert(@IntType(false, 1) == u1);
assert(@IntType(false, 2) == u2);
assert(@IntType(false, 8) == u8);
assert(@IntType(false, 16) == u16);
assert(@IntType(false, 32) == u32);
assert(@IntType(false, 55) == u55);
assert(@IntType(false, 64) == u64);

assert(i8.bit_count == 8);
assert(i16.bit_count == 16);
assert(i32.bit_count == 32);
assert(i64.bit_count == 64);

assert(i8.is_signed);
assert(i16.is_signed);
assert(i32.is_signed);
assert(i64.is_signed);
assert(isize.is_signed);

assert(!u8.is_signed);
assert(!u16.is_signed);
assert(!u32.is_signed);
assert(!u64.is_signed);
assert(!usize.is_signed);
assert(@IntType(false, 123) == u123);
assert(@IntType(false, 128) == u128);

inline for([2]bool{true, false}) |signed| {
comptime var bit_count = 1;
inline while(bit_count <= 128) : (bit_count += 1) {
assert(@IntType(signed, bit_count).bit_count == bit_count);
assert(@IntType(signed, bit_count).is_signed == signed);
}
}
}

test "floating point primitive bit counts" {
Expand All @@ -58,11 +59,6 @@ test "floating point primitive bit counts" {
assert(f64.bit_count == 64);
}

const u1 = @IntType(false, 1);
const u63 = @IntType(false, 63);
const i1 = @IntType(true, 1);
const i63 = @IntType(true, 63);

test "@minValue and @maxValue" {
assert(@maxValue(u1) == 1);
assert(@maxValue(u8) == 255);
Expand Down
1 change: 0 additions & 1 deletion test/cases/struct.zig
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ fn getC(data: *const BitField1) u2 {
return data.c;
}

const u24 = @IntType(false, 24);
const Foo24Bits = packed struct {
field: u24,
};
Expand Down