<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 --- - Unhelpful error and inconsistent behavior with "clang -E -o" and "clang -S -o" when compiling CUDA code"
   href="https://llvm.org/bugs/show_bug.cgi?id=31041">31041</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unhelpful error and inconsistent behavior with "clang -E -o" and "clang -S -o" when compiling CUDA code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>CUDA
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>justin.lebar@gmail.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>Without -o, -E does host compilation and prints to stdout:

$ echo 'XXX __CUDA_ARCH__' | llvm-run clang++ -E -x cuda - | grep XXX
XXX __CUDA_ARCH__

(That the __CUDA_ARCH__ macro is not defined indicates that the preprocessed
source is host code, rather than device code.)

But with -o, we raise a confusing error:
$ echo | llvm-run clang++ -E -x cuda - -o -
clang-4.0: error: cannot specify -o when generating multiple output files

The same thing happens with -S, except that -S outputs *device* assembly:

$ echo | llvm-run clang++ -S -x cuda -
$ cat -- '--cuda-nvptx64-nvidia-cuda-sm_20.s' 
//
// Generated by LLVM NVPTX Back-End
//
[...]

With -o, we raise the same confusing error:
$ echo | llvm-run clang++ -E -x cuda - -o -
clang-4.0: error: cannot specify -o when generating multiple output files


I can see two ways to rationalize our behavior:

1) Require --cuda-device-only or --cuda-host-only with -E and -S (with and
without -o), and improve the error message to mention these flags.

2) Default -E and -S to either host or device and make things work the same
with -o.

I kind of lean towards (1), but maybe that would break people?</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>