[llvm-bugs] [Bug 50787] New: non-constexpr dereferencing a constexpr reference to extern crashes the compiler

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 21 08:39:24 PDT 2021


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

            Bug ID: 50787
           Summary: non-constexpr dereferencing a constexpr reference to
                    extern crashes the compiler
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: development at jordi.vilar.cat
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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: https://godbolt.org/z/TGKM79KPj

The diagnostics message is:

PLEASE submit a bug report to https://bugs.llvm.org/ 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>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
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>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
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

-- 
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/20210621/c0c64e8a/attachment-0001.html>


More information about the llvm-bugs mailing list