authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-13 12:14:30+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-13 14:19:36+02:00
log22e60df68024f3fd72c91ec7b17dbf7abc71c86c
tree4755b4e295d633f97f2b5adbcc4db094ca3b271d
parentb1f3f59d660bbe163502daa6f0acd560782f49d8

Propagate user-defined function alignment to LLVM IR


2 files changed, 11 insertions(+), 1 deletions(-)

src/analyze.cpp+4-1
...@@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1787 if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) {1787 if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) {
1788 return g->builtin_types.entry_invalid;1788 return g->builtin_types.entry_invalid;
1789 }1789 }
1790 fn_entry->align_bytes = fn_type_id.alignment;
1790 }1791 }
17911792
1792 if (fn_proto->return_var_token != nullptr) {1793 if (fn_proto->return_var_token != nullptr) {
...@@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3327 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);3328 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);
33283329
3329 if (fn_proto->section_expr != nullptr) {3330 if (fn_proto->section_expr != nullptr) {
3330 analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name);3331 if (!analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name)) {
3332 fn_table_entry->type_entry = g->builtin_types.entry_invalid;
3333 }
3331 }3334 }
33323335
3333 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {3336 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
test/stage1/behavior/align.zig+7
...@@ -328,3 +328,10 @@ test "align(@alignOf(T)) T does not force resolution of T" {...@@ -328,3 +328,10 @@ test "align(@alignOf(T)) T does not force resolution of T" {
328 _ = async S.doTheTest();328 _ = async S.doTheTest();
329 expect(S.ok);329 expect(S.ok);
330}330}
331
332test "align(N) on functions" {
333 expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0);
334}
335fn overaligned_fn() align(0x1000) i32 {
336 return 42;
337}