| author | |
| committer | |
| log | b4e42042cf27177479f448248601b9be92ca6345 |
| tree | c01e6aef384cd51ece2baa1c437272eb2c3a2c5a |
| parent | 569cf286ff79a10126b9f20f39fa8c64df9b8b25 |
closes #5272 files changed, 50 insertions(+), 0 deletions(-)
src/ir.cpp+5| ... | @@ -11314,6 +11314,8 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field | ... | @@ -11314,6 +11314,8 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field |
| 11314 | 11314 | ||
| 11315 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | 11315 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 11316 | ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val); | 11316 | ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val); |
| 11317 | if (type_is_invalid(struct_val->type)) | ||
| 11318 | return ira->codegen->builtin_types.entry_invalid; | ||
| 11317 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; | 11319 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; |
| 11318 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, | 11320 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, |
| 11319 | is_const, is_volatile, align_bytes, | 11321 | is_const, is_volatile, align_bytes, |
| ... | @@ -11732,6 +11734,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -11732,6 +11734,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 11732 | } | 11734 | } |
| 11733 | ir_add_error(ira, &store_ptr_instruction->base, | 11735 | ir_add_error(ira, &store_ptr_instruction->base, |
| 11734 | buf_sprintf("cannot store runtime value in compile time variable")); | 11736 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 11737 | ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value); | ||
| 11738 | dest_val->type = ira->codegen->builtin_types.entry_invalid; | ||
| 11739 | |||
| 11735 | return ira->codegen->builtin_types.entry_invalid; | 11740 | return ira->codegen->builtin_types.entry_invalid; |
| 11736 | } | 11741 | } |
| 11737 | } | 11742 | } |
test/compile_errors.zig+45| ... | @@ -2186,4 +2186,49 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2186,4 +2186,49 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2186 | , | 2186 | , |
| 2187 | ".tmp_source.zig:3:5: error: alignstack set twice", | 2187 | ".tmp_source.zig:3:5: error: alignstack set twice", |
| 2188 | ".tmp_source.zig:2:5: note: first set here"); | 2188 | ".tmp_source.zig:2:5: note: first set here"); |
| 2189 | |||
| 2190 | cases.add("storing runtime value in compile time variable then using it", | ||
| 2191 | \\const Mode = @import("builtin").Mode; | ||
| 2192 | \\ | ||
| 2193 | \\fn Free(comptime filename: []const u8) -> TestCase { | ||
| 2194 | \\ TestCase { | ||
| 2195 | \\ .filename = filename, | ||
| 2196 | \\ .problem_type = ProblemType.Free, | ||
| 2197 | \\ } | ||
| 2198 | \\} | ||
| 2199 | \\ | ||
| 2200 | \\fn LibC(comptime filename: []const u8) -> TestCase { | ||
| 2201 | \\ TestCase { | ||
| 2202 | \\ .filename = filename, | ||
| 2203 | \\ .problem_type = ProblemType.LinkLibC, | ||
| 2204 | \\ } | ||
| 2205 | \\} | ||
| 2206 | \\ | ||
| 2207 | \\const TestCase = struct { | ||
| 2208 | \\ filename: []const u8, | ||
| 2209 | \\ problem_type: ProblemType, | ||
| 2210 | \\}; | ||
| 2211 | \\ | ||
| 2212 | \\const ProblemType = enum { | ||
| 2213 | \\ Free, | ||
| 2214 | \\ LinkLibC, | ||
| 2215 | \\}; | ||
| 2216 | \\ | ||
| 2217 | \\export fn entry() { | ||
| 2218 | \\ const tests = []TestCase { | ||
| 2219 | \\ Free("001"), | ||
| 2220 | \\ Free("002"), | ||
| 2221 | \\ LibC("078"), | ||
| 2222 | \\ Free("116"), | ||
| 2223 | \\ Free("117"), | ||
| 2224 | \\ }; | ||
| 2225 | \\ | ||
| 2226 | \\ for ([]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { | ||
| 2227 | \\ inline for (tests) |test_case| { | ||
| 2228 | \\ const foo = test_case.filename ++ ".zig"; | ||
| 2229 | \\ } | ||
| 2230 | \\ } | ||
| 2231 | \\} | ||
| 2232 | , | ||
| 2233 | ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable"); | ||
| 2189 | } | 2234 | } |