aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-04-07 14:24:50 -0400
committerGitHub <noreply@github.com>2020-04-07 14:24:50 -0400
commit87a7ea4c420ca0db0e13fab82ce08ab4e293d1da (patch)
treefed7d84fc1ce023c47f3b4a8f77b898b4396c111 /src/ir.cpp
parent1ee59c5c31efca394d7e6d9da3f64c289a996b99 (diff)
parent95fefcd4c91e517a51f4b55924979421c6f7e8d3 (diff)
downloadzig-87a7ea4c420ca0db0e13fab82ce08ab4e293d1da.tar.gz
zig-87a7ea4c420ca0db0e13fab82ce08ab4e293d1da.zip
Merge pull request #4971 from Vexu/const-ref
Fix missing const on address of literal
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 5a96bc2d52..b570117177 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -3290,13 +3290,9 @@ static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *sour
return &instruction->base;
}
-static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value,
- bool is_const, bool is_volatile)
-{
+static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node);
instruction->value = value;
- instruction->is_const = is_const;
- instruction->is_volatile = is_volatile;
ir_ref_instruction(value, irb->current_basic_block);
@@ -5938,7 +5934,7 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node,
} else {
IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type);
if (lval == LValPtr) {
- return ir_build_ref_src(irb, scope, node, value, false, false);
+ return ir_build_ref_src(irb, scope, node, value);
} else {
return ir_expr_wrap(irb, scope, value, result_loc);
}
@@ -7486,7 +7482,7 @@ static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value
if (lval == LValPtr) {
// We needed a pointer to a value, but we got a value. So we create
// an instruction which just makes a pointer of it.
- return ir_build_ref_src(irb, scope, value->base.source_node, value, false, false);
+ return ir_build_ref_src(irb, scope, value->base.source_node, value);
} else if (result_loc != nullptr) {
return ir_expr_wrap(irb, scope, value, result_loc);
} else {
@@ -23348,7 +23344,16 @@ static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_i
IrInstGen *value = ref_instruction->value->child;
if (type_is_invalid(value->value->type))
return ira->codegen->invalid_inst_gen;
- return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile);
+
+ bool is_const = false;
+ bool is_volatile = false;
+
+ ZigValue *child_value = value->value;
+ if (child_value->special == ConstValSpecialStatic) {
+ is_const = true;
+ }
+
+ return ir_get_ref(ira, &ref_instruction->base.base, value, is_const, is_volatile);
}
static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,