Skip to content
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

feat: add additional pointer and type validations #1341

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

mhasel
Copy link
Member

@mhasel mhasel commented Oct 17, 2024

This commit adds some additional type validations for pointer variables being initialized with ADR/REF.
Also adds a validation to catch undeclared types, previously only reported during codegen.

@@ -1628,6 +1628,9 @@ impl Index {
if let DataTypeInformation::Pointer { inner_type_name, .. } = initial_type {
if let Some(ty) = self.find_effective_type_info(inner_type_name) {
return self.find_elementary_pointer_type(self.find_intrinsic_type(ty));
} else {
// the inner type can't be found, return VOID as placeholder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a stack-overflow in typesystem::is_same_type_class when dealing with pointers of undefined type

@mhasel mhasel force-pushed the fix-pointer-validation-stack-overflow branch from a13293b to d8ce876 Compare October 17, 2024 14:11
@mhasel mhasel force-pushed the fix-pointer-validation-stack-overflow branch from d8ce876 to 7a1d890 Compare October 17, 2024 14:41
@mhasel mhasel marked this pull request as ready for review October 18, 2024 07:00
@mhasel mhasel requested a review from volsa October 18, 2024 07:01
Copy link
Member

@volsa volsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -746,6 +746,7 @@ fn parse_pointer_definition(
(
DataTypeDeclaration::DataTypeDefinition {
data_type: DataType::PointerType { name, referenced_type: Box::new(decl), auto_deref },
// FIXME: this currently includes the initializer in the sourcelocation, resulting in 'REF_TO A := B' when creating a slice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we track this on GitHub instead in the code itself? I feel like these FIXMEs are easily forgotten

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've already set up a draft for this issue - just need to add a reproducible example.

Comment on lines +771 to +772
4 │ a: myDeclaredType;
│ ^^^^^^^^^^^^^^ Unknown type: myDeclaredType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already talked about this yesterday offline, but the UX isn't good here; maybe we should also track this in a issue seperately and see if there's a solution to this (minor however)

@mhasel mhasel merged commit 867e5d9 into master Oct 18, 2024
21 checks passed
@mhasel mhasel deleted the fix-pointer-validation-stack-overflow branch October 18, 2024 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants