diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-04-22 12:54:00 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-04-22 12:54:00 -0400 |
| commit | ad9040443cc35b7c250015a272a121a93244db31 (patch) | |
| tree | d5fab07bcb2c186ff8f207f51b700261fa4ab9d0 /src/ir.cpp | |
| parent | aafb0b90822e55135e1c50962768e54e6c62b164 (diff) | |
| download | zig-ad9040443cc35b7c250015a272a121a93244db31.tar.gz zig-ad9040443cc35b7c250015a272a121a93244db31.zip | |
new compile errors for setGlobalAlign and setGlobalSection builtins
if you try to use them on an external variable or function
then you get a compile error, since the alignment/section
is set externally in this case.
closes #244
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 00dc9229e6..4055cbce8e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -9887,6 +9887,10 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira, Tld *tld = instruction->tld; IrInstruction *align_value = instruction->value->other; + resolve_top_level_decl(ira->codegen, tld, true); + if (tld->resolution == TldResolutionInvalid) + return ira->codegen->builtin_types.entry_invalid; + uint64_t scalar_align; if (!ir_resolve_usize(ira, align_value, &scalar_align)) return ira->codegen->builtin_types.entry_invalid; @@ -9902,11 +9906,25 @@ static TypeTableEntry *ir_analyze_instruction_set_global_align(IrAnalyze *ira, TldVar *tld_var = (TldVar *)tld; set_global_align_node = &tld_var->set_global_align_node; alignment_ptr = &tld_var->alignment; + + if (tld_var->var->linkage == VarLinkageExternal) { + ErrorMsg *msg = ir_add_error(ira, &instruction->base, + buf_sprintf("cannot set alignment of external variable '%s'", buf_ptr(&tld_var->var->name))); + add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); + return ira->codegen->builtin_types.entry_invalid; + } } else if (tld->id == TldIdFn) { TldFn *tld_fn = (TldFn *)tld; FnTableEntry *fn_entry = tld_fn->fn_entry; set_global_align_node = &fn_entry->set_global_align_node; alignment_ptr = &fn_entry->alignment; + + if (fn_entry->def_scope == nullptr) { + ErrorMsg *msg = ir_add_error(ira, &instruction->base, + buf_sprintf("cannot set alignment of external function '%s'", buf_ptr(&fn_entry->symbol_name))); + add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); + return ira->codegen->builtin_types.entry_invalid; + } } else { // error is caught in pass1 IR gen zig_unreachable(); @@ -9932,6 +9950,10 @@ static TypeTableEntry *ir_analyze_instruction_set_global_section(IrAnalyze *ira, Tld *tld = instruction->tld; IrInstruction *section_value = instruction->value->other; + resolve_top_level_decl(ira->codegen, tld, true); + if (tld->resolution == TldResolutionInvalid) + return ira->codegen->builtin_types.entry_invalid; + Buf *section_name = ir_resolve_str(ira, section_value); if (!section_name) return ira->codegen->builtin_types.entry_invalid; @@ -9942,11 +9964,25 @@ static TypeTableEntry *ir_analyze_instruction_set_global_section(IrAnalyze *ira, TldVar *tld_var = (TldVar *)tld; set_global_section_node = &tld_var->set_global_section_node; section_name_ptr = &tld_var->section_name; + + if (tld_var->var->linkage == VarLinkageExternal) { + ErrorMsg *msg = ir_add_error(ira, &instruction->base, + buf_sprintf("cannot set section of external variable '%s'", buf_ptr(&tld_var->var->name))); + add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); + return ira->codegen->builtin_types.entry_invalid; + } } else if (tld->id == TldIdFn) { TldFn *tld_fn = (TldFn *)tld; FnTableEntry *fn_entry = tld_fn->fn_entry; set_global_section_node = &fn_entry->set_global_section_node; section_name_ptr = &fn_entry->section_name; + + if (fn_entry->def_scope == nullptr) { + ErrorMsg *msg = ir_add_error(ira, &instruction->base, + buf_sprintf("cannot set section of external function '%s'", buf_ptr(&fn_entry->symbol_name))); + add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); + return ira->codegen->builtin_types.entry_invalid; + } } else { // error is caught in pass1 IR gen zig_unreachable(); |
