authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-23 22:33:00-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-23 22:33:00-04:00
log643ab90ace52d6d752a12ece9d6a8655ca2ca596
tree6aac62b2b1274c272ecd1cbd3bb6f49e9b79471f
parentc1642355f0b05f182c0b6d81d294d12be79ad0a8

add maximum value for @setAlignStack


3 files changed, 13 insertions(+), 1 deletions(-)

src/ir.cpp+5
...@@ -15312,6 +15312,11 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir...@@ -15312,6 +15312,11 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
15312 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))15312 if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))
15313 return ira->codegen->builtin_types.entry_invalid;15313 return ira->codegen->builtin_types.entry_invalid;
1531415314
15315 if (align_bytes > 256) {
15316 ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
15317 return ira->codegen->builtin_types.entry_invalid;
15318 }
15319
15315 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);15320 FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
15316 if (fn_entry == nullptr) {15321 if (fn_entry == nullptr) {
15317 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));15322 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));
test/cases/align.zig+1-1
...@@ -188,6 +188,6 @@ test "alignstack" {...@@ -188,6 +188,6 @@ test "alignstack" {
188}188}
189189
190fn fnWithAlignedStack() -> i32 {190fn fnWithAlignedStack() -> i32 {
191 @setAlignStack(1024);191 @setAlignStack(256);
192 return 1234;192 return 1234;
193}193}
test/compile_errors.zig+7
...@@ -2187,6 +2187,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2187,6 +2187,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2187 ".tmp_source.zig:3:5: error: alignstack set twice",2187 ".tmp_source.zig:3:5: error: alignstack set twice",
2188 ".tmp_source.zig:2:5: note: first set here");2188 ".tmp_source.zig:2:5: note: first set here");
21892189
2190 cases.add("@setAlignStack too big",
2191 \\export fn entry() {
2192 \\ @setAlignStack(511 + 1);
2193 \\}
2194 ,
2195 ".tmp_source.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256");
2196
2190 cases.add("storing runtime value in compile time variable then using it",2197 cases.add("storing runtime value in compile time variable then using it",
2191 \\const Mode = @import("builtin").Mode;2198 \\const Mode = @import("builtin").Mode;
2192 \\2199 \\