| author | |
| committer | |
| log | 558ae2f21a49ae5d75d1836cf86dbe4250d5fdbe |
| tree | fbb83e35a1070db0fc70dabfcaf144473d5747b9 |
| parent | ddd9624e2d03b71754e1591637f0f4f835c01a35 |
4 files changed, 18 insertions(+), 4 deletions(-)
src/ir.cpp+5-2| ... | ... | @@ -4349,7 +4349,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction * |
| 4349 | 4349 | |
| 4350 | 4350 | // We needed a pointer to a value, but we got a value. So we create |
| 4351 | 4351 | // an instruction which just makes a const pointer of it. |
| 4352 | return ir_build_ref(irb, scope, value->source_node, value, true, false); | |
| 4352 | return ir_build_ref(irb, scope, value->source_node, value, lval.is_const, lval.is_volatile); | |
| 4353 | 4353 | } |
| 4354 | 4354 | |
| 4355 | 4355 | static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *node, |
| ... | ... | @@ -9420,7 +9420,10 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 9420 | 9420 | return ira->codegen->builtin_types.entry_invalid; |
| 9421 | 9421 | |
| 9422 | 9422 | if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 9423 | assert(ptr->value.data.x_ptr.mut != ConstPtrMutComptimeConst); | |
| 9423 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) { | |
| 9424 | ir_add_error(ira, &store_ptr_instruction->base, buf_sprintf("cannot assign to constant")); | |
| 9425 | return ira->codegen->builtin_types.entry_invalid; | |
| 9426 | } | |
| 9424 | 9427 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) { |
| 9425 | 9428 | if (instr_is_comptime(casted_value)) { |
| 9426 | 9429 | ConstExprValue *dest_val = const_ptr_pointee(&ptr->value); |
test/cases/const_slice_child.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | var argv: &&const u8 = undefined; | |
| 3 | var argv: &const &const u8 = undefined; | |
| 4 | 4 | |
| 5 | 5 | fn constSliceChild() { |
| 6 | 6 | @setFnTest(this); |
test/cases/misc.zig+1-1| ... | ... | @@ -450,7 +450,7 @@ fn pointerComparison() { |
| 450 | 450 | const b = &a; |
| 451 | 451 | assert(ptrEql(b, b)); |
| 452 | 452 | } |
| 453 | fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool { | |
| 453 | fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool { | |
| 454 | 454 | a == b |
| 455 | 455 | } |
| 456 | 456 |
test/run_tests.cpp+11| ... | ... | @@ -1713,6 +1713,17 @@ pub fn pass(in: []u8) -> []u8 { |
| 1713 | 1713 | return (*out)[0...1]; |
| 1714 | 1714 | } |
| 1715 | 1715 | )SOURCE", 1, ".tmp_source.zig:5:5: error: attempt to dereference non pointer type '[10]u8'"); |
| 1716 | ||
| 1717 | add_compile_fail_case("pass const ptr to mutable ptr fn", R"SOURCE( | |
| 1718 | fn foo() -> bool { | |
| 1719 | const a = ([]const u8)("a"); | |
| 1720 | const b = &a; | |
| 1721 | return ptrEql(b, b); | |
| 1722 | } | |
| 1723 | fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool { | |
| 1724 | return true; | |
| 1725 | } | |
| 1726 | )SOURCE", 1, ".tmp_source.zig:5:19: error: expected type '&[]const u8', found '&const []const u8'"); | |
| 1716 | 1727 | } |
| 1717 | 1728 | |
| 1718 | 1729 | ////////////////////////////////////////////////////////////////////////////// |