authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-24 19:27:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-24 19:27:12-07:00
logf5cc7f65a3764e90b0daaa0388f683589ee105e0
treee77013dcc1462292eef2e21fdb9b27dc3d752696
parent419652ee8ff709deae988603ecca2c335599d969

fix parameter access of sret functions


5 files changed, 24 insertions(+), 27 deletions(-)

example/guess_number/main.zig+1-2
...@@ -18,8 +18,7 @@ pub fn main(args: [][]u8) %void => {...@@ -18,8 +18,7 @@ pub fn main(args: [][]u8) %void => {
18 return error.GetRandomFail;18 return error.GetRandomFail;
19 }19 }
2020
21 var rand : Rand;21 var rand = rand_new(seed);
22 rand.init(seed);
2322
24 const answer = rand.range_u64(0, 100) + 1;23 const answer = rand.range_u64(0, 100) + 1;
2524
src/analyze.cpp+1-7
...@@ -3955,7 +3955,6 @@ static void analyze_top_level_fn_def(CodeGen *g, ImportTableEntry *import, AstNo...@@ -3955,7 +3955,6 @@ static void analyze_top_level_fn_def(CodeGen *g, ImportTableEntry *import, AstNo
39553955
3956 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;3956 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;
3957 bool is_exported = (fn_proto->visib_mod == VisibModExport);3957 bool is_exported = (fn_proto->visib_mod == VisibModExport);
3958 int gen_arg_index = 0;
3959 for (int i = 0; i < fn_proto->params.length; i += 1) {3958 for (int i = 0; i < fn_proto->params.length; i += 1) {
3960 AstNode *param_decl_node = fn_proto->params.at(i);3959 AstNode *param_decl_node = fn_proto->params.at(i);
3961 assert(param_decl_node->type == NodeTypeParamDecl);3960 assert(param_decl_node->type == NodeTypeParamDecl);
...@@ -3978,12 +3977,7 @@ static void analyze_top_level_fn_def(CodeGen *g, ImportTableEntry *import, AstNo...@@ -3978,12 +3977,7 @@ static void analyze_top_level_fn_def(CodeGen *g, ImportTableEntry *import, AstNo
3978 var->src_arg_index = i;3977 var->src_arg_index = i;
3979 param_decl_node->data.param_decl.variable = var;3978 param_decl_node->data.param_decl.variable = var;
39803979
3981 if (type->size_in_bits > 0) {3980 var->gen_arg_index = param_decl_node->data.param_decl.gen_index;
3982 var->gen_arg_index = gen_arg_index;
3983 gen_arg_index += 1;
3984 } else {
3985 var->gen_arg_index = -1;
3986 }
3987 }3981 }
39883982
3989 TypeTableEntry *expected_type = unwrapped_node_type(fn_proto->return_type);3983 TypeTableEntry *expected_type = unwrapped_node_type(fn_proto->return_type);
src/codegen.cpp+4
...@@ -2319,6 +2319,10 @@ static void do_code_gen(CodeGen *g) {...@@ -2319,6 +2319,10 @@ static void do_code_gen(CodeGen *g) {
2319 if (param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) {2319 if (param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) {
2320 LLVMAddAttribute(argument_val, LLVMReadOnlyAttribute);2320 LLVMAddAttribute(argument_val, LLVMReadOnlyAttribute);
2321 }2321 }
2322 if (param_type->id == TypeTableEntryIdPointer) {
2323 // when https://github.com/andrewrk/zig/issues/82 is fixed, add
2324 // non null attribute here
2325 }
2322 if (param_node->data.param_decl.is_byval) {2326 if (param_node->data.param_decl.is_byval) {
2323 LLVMAddAttribute(argument_val, LLVMByValAttribute);2327 LLVMAddAttribute(argument_val, LLVMByValAttribute);
2324 }2328 }
std/rand.zig+14-14
...@@ -6,20 +6,6 @@ pub struct Rand {...@@ -6,20 +6,6 @@ pub struct Rand {
6 array: [ARRAY_SIZE]u32,6 array: [ARRAY_SIZE]u32,
7 index: isize,7 index: isize,
88
9 /// Initialize random state with the given seed.
10 pub fn init(r: &Rand, seed: u32) => {
11 r.index = 0;
12 r.array[0] = seed;
13 var i : isize = 1;
14 var prev_value: u64 = seed;
15 while (i < ARRAY_SIZE) {
16 r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + u32(i));
17 prev_value = r.array[i];
18 i += 1;
19 }
20 }
21
22
23 /// Get 32 bits of randomness.9 /// Get 32 bits of randomness.
24 pub fn get_u32(r: &Rand) u32 => {10 pub fn get_u32(r: &Rand) u32 => {
25 if (r.index == 0) {11 if (r.index == 0) {
...@@ -91,3 +77,17 @@ pub struct Rand {...@@ -91,3 +77,17 @@ pub struct Rand {
91 }77 }
92}78}
9379
80/// Initialize random state with the given seed.
81pub fn rand_new(seed: u32) Rand => {
82 var r: Rand;
83 r.index = 0;
84 r.array[0] = seed;
85 var i : isize = 1;
86 var prev_value: u64 = seed;
87 while (i < ARRAY_SIZE) {
88 r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + u32(i));
89 prev_value = r.array[i];
90 i += 1;
91 }
92 return r;
93}
test/run_tests.cpp+4-4
...@@ -1242,14 +1242,14 @@ struct Foo {...@@ -1242,14 +1242,14 @@ struct Foo {
1242 x: i32,1242 x: i32,
1243 y: i32,1243 y: i32,
1244}1244}
1245fn make_foo() Foo => {1245fn make_foo(x: i32, y: i32) Foo => {
1246 Foo {1246 Foo {
1247 .x = 1234,1247 .x = x,
1248 .y = 5678,1248 .y = y,
1249 }1249 }
1250}1250}
1251pub fn main(args: [][]u8) %void => {1251pub fn main(args: [][]u8) %void => {
1252 const foo = make_foo();1252 const foo = make_foo(1234, 5678);
1253 if (foo.y != 5678) {1253 if (foo.y != 5678) {
1254 print_str("BAD\n");1254 print_str("BAD\n");
1255 }1255 }