Skip to content

Conversation

mmicko
Copy link
Member

@mmicko mmicko commented Jul 29, 2025

This is warning introduced in #5221 so please @rocallahan check if this seems right for you.

[test-compile (ubuntu-latest, gcc-10): kernel/io.h#L373](https://github.com/YosysHQ/yosys/commit/1d229ae254eae9a8042f6c73a424a61e40fcb381#annotation_37197972849)
array subscript 2 is outside array bounds of ‘int [2]’ [-Warray-bounds]

@rocallahan
Copy link
Contributor

rocallahan commented Jul 29, 2025

I'm quite sure the warning is a false alarm, but you should check my logic. At line 369 we check specs->num_dynamic_ints > num_dynamic_ints. specs->num_dynamic_ints is a DynamicIntCount whose maximum value is 2. Therefore inside the if branch the maximum value of num_dynamic_ints is 1. Therefore at line 373 the array index cannot overflow an array of length 2.

I don't know what is your preferred way to deal with false warnings from gcc. Instead of making the array bigger, I would wrap the array assignment in an extra bounds check if (static_cast<int>(num_dynamic_ints) < 2) with a comment indicating why it's not necessary but we're adding it to silence gcc. I think that would be clearer for people reading the code --- an extra array element is not needed, but people reading the code would be confused into thinking it is needed.

@mmicko
Copy link
Member Author

mmicko commented Jul 30, 2025

Thanks, @rocallahan I like your suggestion. Problem with warnings is that if something new comes up it is hard to notice if there are too many of them, so we try to keep them cleaned whenever possible. Will close this PR.

@mmicko mmicko closed this Jul 30, 2025
@mmicko mmicko deleted the kernel_io_fix branch July 30, 2025 08:26
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