<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - using #pragma omp simd along with -O2 lead to a segfault at runtime"
   href="https://bugs.llvm.org/show_bug.cgi?id=48104">48104</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>using #pragma omp simd along with -O2 lead to a segfault at runtime
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Clang Compiler Support
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>evatux@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24141" name="attach_24141" title="simple reproducer">attachment 24141</a> <a href="attachment.cgi?id=24141&action=edit" title="simple reproducer">[details]</a></span>
simple reproducer

It seems #pragma omp simd may lead to omitting checking some conditionals
inside the loop.

See attached reproducer (also shown below). It is worth mentioning that the
issue appear only with -O2; with -O3 the test passes just fine.

$ clang++ -fopenmp -O2 repro_01.cpp && ./a.out; echo $?
139

$ clang++ -fopenmp -O3 repro_01.cpp && ./a.out; echo $?
0

Clang-version:
- 12-master (85f4be09124cc53e1a18a884ac7caf19988ab2a5, [2])
- 10, 9, 8, 7
- I haven't checked 11, and below 7.

OS:
- At least Linux and FreeBSD
- I haven't checked Windows

------

[1]

// repro_01.cpp
struct data_kernel_t {
    void operator()(float *dst, const float *ss) const
__attribute__((noinline)) {
#       pragma omp simd
        for (int c = 0; c < C_; ++c)
            dst[c] = (use_scaleshift_ ? ss[c] : 1.0f);
    }
    bool use_scaleshift_;
    int C_;
};

int main() {
    float dst[100];
    data_kernel_t ker{false, 100};
    ker(dst, nullptr);
    return 0;
}


[2]
commit 85f4be09124cc53e1a18a884ac7caf19988ab2a5
Author: Valentin Churavy <<a href="mailto:v.churavy@gmail.com">v.churavy@gmail.com</a>>
Date:   Fri Nov 6 14:08:30 2020 -0500</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>