diff options
| author | LemonBoy <thatlemon@gmail.com> | 2019-10-13 12:14:30 +0200 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2019-10-13 14:19:36 +0200 |
| commit | 22e60df68024f3fd72c91ec7b17dbf7abc71c86c (patch) | |
| tree | 4755b4e295d633f97f2b5adbcc4db094ca3b271d | |
| parent | b1f3f59d660bbe163502daa6f0acd560782f49d8 (diff) | |
| download | zig-22e60df68024f3fd72c91ec7b17dbf7abc71c86c.tar.gz zig-22e60df68024f3fd72c91ec7b17dbf7abc71c86c.zip | |
Propagate user-defined function alignment to LLVM IR
| -rw-r--r-- | src/analyze.cpp | 5 | ||||
| -rw-r--r-- | test/stage1/behavior/align.zig | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index a38766bc25..399966d041 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) { return g->builtin_types.entry_invalid; } + fn_entry->align_bytes = fn_type_id.alignment; } if (fn_proto->return_var_token != nullptr) { @@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry); if (fn_proto->section_expr != nullptr) { - analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name); + if (!analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name)) { + fn_table_entry->type_entry = g->builtin_types.entry_invalid; + } } if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) { diff --git a/test/stage1/behavior/align.zig b/test/stage1/behavior/align.zig index 266e5d3519..bb40270cda 100644 --- a/test/stage1/behavior/align.zig +++ b/test/stage1/behavior/align.zig @@ -328,3 +328,10 @@ test "align(@alignOf(T)) T does not force resolution of T" { _ = async S.doTheTest(); expect(S.ok); } + +test "align(N) on functions" { + expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0); +} +fn overaligned_fn() align(0x1000) i32 { + return 42; +} |
