mirror of
https://github.com/ziglang/zig.git
synced 2026-01-10 17:35:12 +00:00
fix assigning to const ptr through struct or index
This commit is contained in:
parent
7749ffd797
commit
d26bb3ae2e
@ -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);
|
||||
|
||||
22
src/ir.cpp
22
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user