<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 - non-constexpr dereferencing a constexpr reference to extern crashes the compiler"
   href="https://bugs.llvm.org/show_bug.cgi?id=50787">50787</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>non-constexpr dereferencing a constexpr reference to extern crashes the compiler
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>12.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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++2a
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>development@jordi.vilar.cat
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code breaks the compiler:

```
extern int x_;
consteval auto& X() { return x_; }
constexpr auto& x1 = X();
auto x2 = X();
```

when compiling with clang 12.0.0 with -std=c++20. It compiles ok with gcc.

A live example shared in godbolt: <a href="https://godbolt.org/z/TGKM79KPj">https://godbolt.org/z/TGKM79KPj</a>

The diagnostics message is:

PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-12.0.0/bin/clang++ -g
-o /app/output.s -mllvm --x86-asm-syntax=intel -S
--gcc-toolchain=/opt/compiler-explorer/gcc-10.3.0 -fcolor-diagnostics
-fno-crash-diagnostics -std=c++20 <source>
1.      <eof> parser at end of file
2.      <source>:4:6: LLVM IR generation of declaration 'x2'
3.      <source>:4:6: Generating code for declaration 'x2'
 #0 0x0000558bc1c43b2c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3000b2c)
 #1 0x0000558bc1c418d4 llvm::sys::RunSignalHandlers()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2ffe8d4)
 #2 0x0000558bc1c41b55 llvm::sys::CleanupOnSignal(unsigned long)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2ffeb55)
 #3 0x0000558bc1baa4e8 CrashRecoverySignalHandler(int)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2f674e8)
 #4 0x00007f32af30d3c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #5 0x0000558bc1f191f0
clang::CodeGen::ConstantEmitter::tryEmitConstantExpr(clang::ConstantExpr
const*) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x32d61f0)
 #6 0x0000558bc1f1b5cc clang::StmtVisitorBase<std::add_pointer, (anonymous
namespace)::ConstExprEmitter, llvm::Constant*,
clang::QualType>::Visit(clang::Stmt*, clang::QualType)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x32d85cc)
 #7 0x0000558bc1f1b1de (anonymous
namespace)::ConstExprEmitter::VisitCastExpr(clang::CastExpr*, clang::QualType)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x32d81de)
 #8 0x0000558bc1f1b58e clang::StmtVisitorBase<std::add_pointer, (anonymous
namespace)::ConstExprEmitter, llvm::Constant*,
clang::QualType>::Visit(clang::Stmt*, clang::QualType)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x32d858e)
 #9 0x0000558bc1f1bcea
clang::CodeGen::ConstantEmitter::tryEmitPrivateForVarInit(clang::VarDecl
const&) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x32d8cea)
#10 0x0000558bc1f1bec0
clang::CodeGen::ConstantEmitter::tryEmitForInitializer(clang::VarDecl const&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x32d8ec0)
#11 0x0000558bc1fad3c9
clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*,
bool) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x336a3c9)
#12 0x0000558bc1fc81b2
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x33851b2)
#13 0x0000558bc1fc8a03
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3385a03)
#14 0x0000558bc1fce55d
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.5081)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x338b55d)
#15 0x0000558bc2a92e01 (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3e4fe01)
#16 0x0000558bc2a86b62
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3e43b62)
#17 0x0000558bc3850ef4 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c0def4)
#18 0x0000558bc2a90e42 clang::CodeGenAction::ExecuteAction()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3e4de42)
#19 0x0000558bc2498191 clang::FrontendAction::Execute()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3855191)
#20 0x0000558bc243e593
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x37fb593)
#21 0x0000558bc2560363
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x391d363)
#22 0x0000558bbfc1309c cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xfd009c)
#23 0x0000558bbfc0f61d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xfcc61d)
#24 0x0000558bc2300215 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const::'lambda'()>(long)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36bd215)
#25 0x0000558bc1baa5c3
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2f675c3)
#26 0x0000558bc2300d68
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const (.part.174)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36bdd68)
#27 0x0000558bc22d98ba
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36968ba)
#28 0x0000558bc22da40f
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x369740f)
#29 0x0000558bc22e3215
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36a0215)
#30 0x0000558bbfb3bb4c main
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xef8b4c)
#31 0x00007f32aedbe0b3 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#32 0x0000558bbfc0f19a _start
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xfcc19a)
clang-12: error: clang frontend command failed with exit code 139 (use -v to
see invocation)
Compiler returned: 139</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>