commit d26bb3ae2e9add11ef350e5d7b040dfbe10539be (tree)
parent 7749ffd797e927f93051060db49b76c595879697
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Sun, 5 Feb 2017 19:55:37 -0500
fix assigning to const ptr through struct or index
Diffstat:
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/ast_render.cpp b/src/ast_render.cpp
@@ -786,11 +786,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
}
case NodeTypeTryExpr:
{
- const char *var_str = node->data.try_expr.var_is_const ? "const" : "var";
- const char *var_name = buf_ptr(node->data.try_expr.var_symbol);
- const char *ptr_str = node->data.try_expr.var_is_ptr ? "*" : "";
- fprintf(ar->f, "try (%s %s%s", var_str, ptr_str, var_name);
- fprintf(ar->f, " = ");
+ fprintf(ar->f, "try (");
+ if (node->data.try_expr.var_symbol) {
+ const char *var_str = node->data.try_expr.var_is_const ? "const" : "var";
+ const char *var_name = buf_ptr(node->data.try_expr.var_symbol);
+ const char *ptr_str = node->data.try_expr.var_is_ptr ? "*" : "";
+ fprintf(ar->f, "%s %s%s = ", var_str, ptr_str, var_name);
+ }
render_node_grouped(ar, node->data.try_expr.target_node);
fprintf(ar->f, ") ");
render_node_grouped(ar, node->data.try_expr.then_node);
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -8819,7 +8819,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
ConstExprValue *array_ptr_val;
if (array_ptr->value.special != ConstValSpecialRuntime &&
(array_ptr_val = const_ptr_pointee(&array_ptr->value)) &&
- array_ptr_val->special != ConstValSpecialRuntime)
+ array_ptr_val->special != ConstValSpecialRuntime &&
+ (array_type->id != TypeTableEntryIdPointer || array_ptr_val->data.x_ptr.special != ConstPtrSpecialRuntime))
{
bool depends_on_compile_var = array_ptr_val->depends_on_compile_var ||
casted_elem_index->value.depends_on_compile_var;
@@ -8926,14 +8927,17 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field
if (!ptr_val)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *struct_val = const_ptr_pointee(ptr_val);
- if (value_is_comptime(struct_val)) {
- ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
- if (value_is_comptime(field_val)) {
- bool depends_on_compile_var = field_val->depends_on_compile_var ||
- struct_val->depends_on_compile_var || ptr_val->depends_on_compile_var;
- return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, field_val,
- field_val->type, depends_on_compile_var, ConstPtrSpecialNone, is_const, is_volatile);
+ if (ptr_val->data.x_ptr.special != ConstPtrSpecialRuntime) {
+ ConstExprValue *struct_val = const_ptr_pointee(ptr_val);
+ if (value_is_comptime(struct_val)) {
+ ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
+ if (value_is_comptime(field_val)) {
+ bool depends_on_compile_var = field_val->depends_on_compile_var ||
+ struct_val->depends_on_compile_var || ptr_val->depends_on_compile_var;
+ return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, field_val,
+ field_val->type, depends_on_compile_var, ConstPtrSpecialNone,
+ is_const, is_volatile);
+ }
}
}
}