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

Undefined value warnings/errors #566

Open
Akuli opened this issue Jan 8, 2025 · 0 comments
Open

Undefined value warnings/errors #566

Akuli opened this issue Jan 8, 2025 · 0 comments
Labels
errors and warnings Jou compiler error and warning messages

Comments

@Akuli
Copy link
Owner

Akuli commented Jan 8, 2025

The following program shouldn't compile:

def main() -> int:
    pass

The compiler written in C correctly refuses to compile this:

compiler error in file "asd.jou", line 1: function 'main' must return a value, because it is defined with '-> int'

But the self-hosted compiler compiles this with no warnings, and produces and executable that invokes UB.

In general, the self-hosted compiler has no warnings for using undefined values (return value, variable, anything else). For example, the following program prints an undefined value. The compiler written in C shows a warning about it, but the self-hosted compiler Jou does not.

import "stdlib/io.jou"

def main() -> int:
    x: int
    printf("%d\n", x)
    return 0

To fix this properly, the compiler should know whether a value is properly defined, undefined, or maybe undefined depending on e.g. user input. And to do that, we need to analyze Control Flow Graphs (CFGs).

The problem is that the self-hosted compiler doesn't have the simplify_cfg compilation step of the compiler written in C. I omitted simplify_cfg in #562.

@Akuli Akuli changed the title Warning/error if you forget to return a value Undefined value warnings/errors Jan 8, 2025
@Akuli Akuli added the errors and warnings Jou compiler error and warning messages label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors and warnings Jou compiler error and warning messages
Projects
None yet
Development

No branches or pull requests

1 participant