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

Crash: assign boolean or result to float #668

Closed
ehaas opened this issue Apr 5, 2024 · 1 comment · Fixed by #670
Closed

Crash: assign boolean or result to float #668

ehaas opened this issue Apr 5, 2024 · 1 comment · Fixed by #670
Labels
bug Something isn't working crash A bug that causes the compiler to crash

Comments

@ehaas
Copy link
Collaborator

ehaas commented Apr 5, 2024

void foo(void) {
    float f = 2.0 || 0;
}
panic: access of union field 'int' while field 'float' is active
/Users/ehaas/source/arocc/src/aro/Value.zig:205:46: 0x103d44402 in intToFloat (arocc)
    return switch (comp.interner.get(v.ref()).int) {
                                             ^
/Users/ehaas/source/arocc/src/aro/Parser.zig:5589:35: 0x103d15b0f in floatCast (arocc)
            try res.val.intToFloat(float_ty, p.comp);
                                  ^
/Users/ehaas/source/arocc/src/aro/Parser.zig:6086:34: 0x103ca033c in coerceExtra (arocc)
                try res.floatCast(p, unqual_ty);
                                 ^
@ehaas ehaas added bug Something isn't working crash A bug that causes the compiler to crash labels Apr 5, 2024
@ehaas
Copy link
Collaborator Author

ehaas commented Apr 5, 2024

Seems like value is not getting truncated to int after logical or:

_Static_assert(2.5 || 0, "");
static_assert: 'void'
 condition:
  implicit_cast: (int_to_bool) '_Bool'
    bool_or_expr: 'int' (value: 2.5)
     lhs:
      float_literal: 'double' (value: 2.5)
     rhs:
      implicit_cast: (int_to_float) 'double'
        int_literal: 'int' (value: 0)
 diagnostic:
  string_literal_expr: '[1]char' lvalue (value: "")

(note value of bool_or_expr)

ehaas added a commit to ehaas/arocc that referenced this issue Apr 6, 2024
…g it

Ensure that the value, if present, is zero or one.

Closes Vexu#668
@Vexu Vexu closed this as completed in #670 Apr 6, 2024
Vexu pushed a commit that referenced this issue Apr 6, 2024
…g it

Ensure that the value, if present, is zero or one.

Closes #668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash A bug that causes the compiler to crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant