[llvm-bugs] [Bug 39048] New: NRVO (elide-constructors) code generation is running in the C compiler

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Sep 22 10:34:26 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39048

            Bug ID: 39048
           Summary: NRVO (elide-constructors) code generation is running
                    in the C compiler
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nat-llvmbugs at mulle-kybernetik.com
                CC: llvm-bugs at lists.llvm.org

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:

https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/CompilerInvocation.cpp#L2457

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

is turned on by default. Also the driver says:


https://github.com/llvm-mirror/clang/blob/master/lib/Driver/ToolChains/Clang.cpp#L4281

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

https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGDecl.cpp#L1143

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:

https://github.com/llvm-mirror/clang/blob/master/lib/Sema/SemaDecl.cpp#L1802

```
  if( getLangOpts().CPlusPlus)
     S->mergeNRVOIntoParent();
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180922/13afe17c/attachment.html>


More information about the llvm-bugs mailing list