mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Assert when struct size would exceed 4 GB.
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
- Converting between simd/non-simd bool vector would hit a compiler assert. #2691
|
||||
- `i<n>` suffixes were not caught when n < 8, causing an assert.
|
||||
- Parse error in `$defined` was not handled correctly, leading to an assertion.
|
||||
- Assert when struct size would exceed 4 GB.
|
||||
|
||||
### Stdlib changes
|
||||
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.
|
||||
|
||||
@@ -637,7 +637,9 @@ static bool sema_analyse_struct_members(SemaContext *context, Decl *decl)
|
||||
|
||||
offset = align_offset;
|
||||
member->offset = offset;
|
||||
AlignSize sz = offset;
|
||||
offset += type_size(member->type);
|
||||
if (offset < sz || offset > MAX_STRUCT_SIZE) RETURN_SEMA_ERROR(member, "Struct member '%s' would cause the struct to become too large (exceeding 2 GB).", member->name);
|
||||
}
|
||||
|
||||
// Set the alignment:
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#define DEFAULT_STACK_OBJECT_SIZE 64
|
||||
#define MAX_ARRAY_SIZE INT64_MAX
|
||||
#define MAX_SOURCE_LOCATION_LEN 255
|
||||
#define MAX_STRUCT_SIZE (2U * 1024U * 1024U * 1024U)
|
||||
#define PROJECT_JSON "project.json"
|
||||
#define PROJECT_JSON5 "project.json5"
|
||||
|
||||
|
||||
12
test/test_suite/struct/struct_too_large.c3
Normal file
12
test/test_suite/struct/struct_too_large.c3
Normal file
@@ -0,0 +1,12 @@
|
||||
import std;
|
||||
struct Foo
|
||||
{
|
||||
int a;
|
||||
int[int.max] b; // #error: "Struct member 'b' would cause the struct to become too large
|
||||
}
|
||||
|
||||
fn int main()
|
||||
{
|
||||
Foo c = (Foo){};
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user