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

Invalid C code generated with too-large array type #24600

Closed
tersec opened this issue Jan 5, 2025 · 3 comments
Closed

Invalid C code generated with too-large array type #24600

tersec opened this issue Jan 5, 2025 · 3 comments

Comments

@tersec
Copy link
Contributor

tersec commented Jan 5, 2025

Description

discard sizeof(array[4611686018427387904, uint64])

Nim Version

Nim Compiler Version 2.0.14 [Linux: amd64]
Compiled at 2025-01-05
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: bf4de6a394e040d9810cba8c69fb2829ff04dcc6
active boot switches: -d:release
Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2025-01-05
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1876726a49c69d65629ab433ea1310ece1
active boot switches: -d:release
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-01-05
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: e8bf6af0da52ce91dd0b5a7474d386d9a66809b9
active boot switches: -d:release

All with

gcc (Debian 14.2.0-12) 14.2.0

Current Output

error: size of array ‘tyArray__e7ovic9cojb5RXym3zh9aYIw’ exceeds maximum object size ‘9223372036854775807’
   30 | typedef NU64 tyArray__e7ovic9cojb5RXym3zh9aYIw[4611686018427387904];
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Output

No invalid C code generated

Known Workarounds

No response

Additional Information

No response

@Araq
Copy link
Member

Araq commented Jan 5, 2025

What's "too large"? How can we ensure the C compiler's idea agrees with our idea of too large?

@tersec
Copy link
Contributor Author

tersec commented Jan 5, 2025

https://stackoverflow.com/questions/42574890/why-is-the-maximum-size-of-an-array-too-large does suggest the C spec does not define this tightly enough to in general match the C compiler's behavior. There is a SIZE_MAX, but it isn't helpful here.

This doesn't look resolvable in a clean or portable way.

@tersec tersec closed this as completed Jan 5, 2025
@demotomohiro
Copy link
Contributor

How about to defining types larger than or equal to int.high + 1 or size of memory space (2^(pointer bit size)) is compile error?
9223372036854775807 (the number in the GCC error message) == int.high (2^63 - 1).
So making types larger than int.high is a compile error prevents the compile error from GCC.
Even if other C/C++ compilers has smaller type size limits, rejecting types larger than memory space makes sense.

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

No branches or pull requests

3 participants