Yet another compiler bug [?]

Правка en4, от Xiaohuba, 2024-09-18 11:15:23

I've recently found that the following code will generate wrong output.

#include <bits/stdc++.h>
const int N = 105;
std::bitset<N> ok[N][N];
int n, m;
int main() {
  std::cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    std::cin >> l >> r;
    for (int j = l; j <= r; j++)
      ok[l][r].set(j);
  }
  for (int i = n; i; i--)
    for (int j = i; j <= n; j++) {
      ok[i][j] = ok[i][j] | ok[i + 1][j] | ok[i][j - 1];
    }
  std::cerr << "! " << ok[2][5][2] << '\n';
  return 0;
}

Compiled with -O3 -mtune=skylake -march=skylake, the code outputs ! 0 when given the following input:

5 5
1 3
2 2
3 3
1 5
3 5

However if you simulate the code you will know that the correct answer should be ! 1.

Note that the compiler seems to generate wrong sse instruction.

Godbolt link

Again, I believe this code is ub-free, and has nothing to do with implementation-defined stuff.

Теги compiler bug

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский Xiaohuba 2024-09-18 18:04:57 326
en4 Английский Xiaohuba 2024-09-18 11:15:23 2 Tiny change: 'on.\n\n[Goldbot link](ht' -> 'on.\n\n[Godbolt link](ht'
en3 Английский Xiaohuba 2024-09-18 11:13:49 0 (published)
en2 Английский Xiaohuba 2024-09-18 11:11:54 174
en1 Английский Xiaohuba 2024-09-18 11:10:09 847 Initial revision (saved to drafts)