- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fixes for zero-sized allocation #1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
} | ||
|
||
assert(!struct_type->data.structure.zero_bits_loop_flag); | ||
assert(struct_type->data.structure.fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed assertion.
assert(decl_node->type == NodeTypeContainerDecl); | ||
|
||
size_t field_count = struct_type->data.structure.src_field_count; | ||
assert(struct_type->data.structure.fields != nullptr || field_count == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempted tweak.
struct_type->di_type = replacement_di_type; | ||
return; | ||
} | ||
assert(struct_type->di_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed assertion.
return; | ||
} | ||
assert(struct_type->di_type); | ||
assert(struct_type->di_type != nullptr || field_count == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempted tweak.
// if you hit this assert then probably this type or a related type didn't | ||
// get ensure_complete_type called on it before using it with something that | ||
// requires a complete type | ||
assert(LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref) > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed assertion.
// get ensure_complete_type called on it before using it with something that | ||
// requires a complete type | ||
assert(LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref) > 0); | ||
assert(LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref) > 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempted tweak.
128, | ||
}; | ||
|
||
struct CIntTypeInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Padding fix discussed in #993.
|
||
template<typename T> | ||
ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate(size_t count) { | ||
if (count == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes behavior for zero sized allocation portable.
T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T))); | ||
if (!ptr) | ||
zig_panic("allocation failed"); | ||
static inline T *reallocate(T *old, size_t old_count, size_t new_count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement reallocate
using reallocate_nonzero
to avoid code duplication.
errors[error_entry->value] = error_entry; | ||
} | ||
ZigList<ErrorTableEntry *> intersection_list = {}; | ||
ZigList<ErrorTableEntry *> intersection_list = {0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will see this in a few places. ZigList
needs to be initialized in order to guarantee the members are zeroed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you cite a source showing that {0}
is necessary and {}
is not sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you are right: https://stackoverflow.com/a/1069634/1930331. Maybe I'm thinking about C, but C++ will work.
See #1044.