<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - clang-3.9: OpenMP reduction with reference value crashes Clang"
   href="https://llvm.org/bugs/show_bug.cgi?id=30490">30490</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-3.9: OpenMP reduction with reference value crashes Clang
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>xucheng@me.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17334" name="attach_17334" title="bug code + report">attachment 17334</a> <a href="attachment.cgi?id=17334&action=edit" title="bug code + report">[details]</a></span>
bug code + report

A minimal example to reproduce the problem:
```cpp
#include <cstdio>

void sum(int* input, int N, int& result)
{
    result = 0;
#pragma omp parallel for reduction(+ : result)
    for (int i = 0; i < N; i++) {
        result += input[i];
    }
}

int main()
{
    int result;
    int input[3] = { 0, 1, 2 };
    sum(input, 3, result);
    printf("result=%d\n", result);
    return 0;
}
```

Compiling with LLVM 3.9, it outputs:
```
$ /usr/local/opt/llvm/bin/clang++ -fopenmp -L/usr/local/opt/llvm/lib/
llvm-3.9-bug.cpp
Stack dump:
0.    Program arguments: /usr/local/Cellar/llvm/3.9.0/bin/clang-3.9 -cc1
-triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage
-Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free
-disable-llvm-verifier -discard-value-names -main-file-name llvm-3.9-bug.cpp
-mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim
-masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 274.1
-dwarf-column-info -debugger-tuning=lldb -resource-dir
/usr/local/Cellar/llvm/3.9.0/bin/../lib/clang/3.9.0 -stdlib=libc++
-fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 100 -fopenmp -stack-protector 1 -fblocks
-fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature
-fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option
-fcolor-diagnostics -o
/var/folders/0b/tjnr_tzx3b3ckmf2s5260gx00000gp/T/llvm-3-c3d3cd.o -x c++
llvm-3.9-bug.cpp
1.    llvm-3.9-bug.cpp:6:47: at annotation token
2.    llvm-3.9-bug.cpp:4:1: parsing function body 'sum'
3.    llvm-3.9-bug.cpp:4:1: in compound statement ('{}')
clang-3.9: error: unable to execute command: Segmentation fault: 11
clang-3.9: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.9.0 (tags/RELEASE_390/final)
Target: x86_64-apple-darwin16.0.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
clang-3.9: note: diagnostic msg: PLEASE submit a bug report to
<a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and
associated run script.
clang-3.9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.9: note: diagnostic msg:
/var/folders/0b/tjnr_tzx3b3ckmf2s5260gx00000gp/T/llvm-3-39db7d.cpp
clang-3.9: note: diagnostic msg:
/var/folders/0b/tjnr_tzx3b3ckmf2s5260gx00000gp/T/llvm-3-39db7d.sh
clang-3.9: note: diagnostic msg:

********************
```

Changing `int &result` to `int result`, the compilation will be success.

Also, FYI, the same code has no problem to be compiled under GCC as shown in
below:
```
$ gcc-6 -fopenmp llvm-3.9-bug.cpp && ./a.out
result=3
```

Full reports are in the attachment.</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>