<html>
    <head>
      <base href="http://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 --- - Trivial optimized code crashes on memory modification"
   href="http://llvm.org/bugs/show_bug.cgi?id=18438">18438</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Trivial optimized code crashes on memory modification
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vitaly@grechko.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11859" name="attach_11859" title="Slightly modified clang-interpreter example that reproduced the bug">attachment 11859</a> <a href="attachment.cgi?id=11859&action=edit" title="Slightly modified clang-interpreter example that reproduced the bug">[details]</a></span>
Slightly modified clang-interpreter example that reproduced the bug

Hi,
First of all, thank you for great library!
I've been successfully using JIT based on clang/examples/clang-interpreter many
years but now found a huge stopper. I spent 3 weeks localizing the problem and
did my best of reducing the case.

Summary:
Need Linux 64 bit (Windows is OK), LLVM versions tested 3.4,3.3,3.2.
If we write a function "f" in separate file crash_f.c that takes array of
integers and fills it (e.g. with zeros)

int f(int n,int* a) {
    for (int i=0; i<n; ++i) a[i] = 0;
    return 0;
}

then take tools/clang/examples/clang-interpeter, allocate array of integers
there (e.g. "new int[115]") then compile crash_f.c WITH OPTIMIZATION, take
pointer to "f" and pass this array to "f",

then compile clang-interpreter with -static option,
we got Segmentation Fault!

The problems disappeares if one of the conditions ommited:
- Args.push_back("-O2"); // add optimization to clang
- memory modification in function "f"
- compile clang-interpreter with -static
- Linux 64 bit

I prepared all the files for you to reproduce the bug:

How to reproduce:
1. LLVM version: 3.4
2. OS: any Linux (Ubuntu, Centos, ...)
3. Take slightly modified clang-interpreter example (attached main.cpp),
Makefile (attached), crash_f.c (attached)
4. Open Makefile and modify first 2 lines to your LLVM path and LLVM-build
path.
5. run "make" which should build a "crash" executable
6. run "./crash -c crash_f.c" - should be Segmentation fault

Thanks!</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>