<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 - NRVO (elide-constructors) code generation is running in the C compiler"
   href="https://bugs.llvm.org/show_bug.cgi?id=39048">39048</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>NRVO (elide-constructors) code generation is running in the C compiler
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nat-llvmbugs@mulle-kybernetik.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I had to fix a really peculiar bug when migrating mulle-clang from clang 6 to
clang 7. Maybe this affects others maybe not. 

mulle-clang is an Objective-C compiler, based on C and its own runtime. It
can't do C++.


1)
In CompilerInvocation:

<a href="https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/CompilerInvocation.cpp#L2457">https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/CompilerInvocation.cpp#L2457</a>

 Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);

is turned on by default. Also the driver says:


<a href="https://github.com/llvm-mirror/clang/blob/master/lib/Driver/ToolChains/Clang.cpp#L4281">https://github.com/llvm-mirror/clang/blob/master/lib/Driver/ToolChains/Clang.cpp#L4281</a>

  // -felide-constructors is the default.


It's my opinion, that if the language is set to C,  C++ only features should
not even be queried in the CompilerInvocation and be set to off. Then you would
never have to think about a possible need to query two different
LanguageOptions. 


2)

During CodeGenFunction::EmitAutoVarAlloca

<a href="https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGDecl.cpp#L1143">https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGDecl.cpp#L1143</a>

a different path is taken, if the local variable is deemed to be NRVO
compatible:

```
  if (Ty->isConstantSizeType()) {
    bool NRVO = getLangOpts().ElideConstructors &&
D.isNRVOVariable();
```

The following NRVO code, which I didn't scrutinize, then triggers my type
assert. 

3)

My variable declaration got set as isNRVOVariable during
Scope::mergeNRVOIntoParent(). This is run unconditionally during
Sema::ActOnPopScope. 

I think it would be a fix and a general improvement for C anyway, to do this
only conditionally:

<a href="https://github.com/llvm-mirror/clang/blob/master/lib/Sema/SemaDecl.cpp#L1802">https://github.com/llvm-mirror/clang/blob/master/lib/Sema/SemaDecl.cpp#L1802</a>

```
  if( getLangOpts().CPlusPlus)
     S->mergeNRVOIntoParent();
```</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>