Issue |
52804
|
Summary |
Frontend crash when compiling C++ constexpr function returning nullopt
|
Labels |
new issue
|
Assignees |
|
Reporter |
jcsp
|
I encountered a crash when returning a `nullopt` from a consteval function returning a `std::optional`. This code causes a crash in clang 13.0.0 (also tested 12.0.1, crashes there too).
The below examples are minimized with `cvise`.
## Reproducer
I'm including code sample inline b/c github does not allow a .cpp attachment.
Compile with `clang++ -std=c++20 -c`
```
struct nullopt_t {
} nullopt;
class optional {
public:
constexpr optional(nullopt_t) {}
};
class base_property {
virtual optional units_name() const;
};
namespace config {
template <class> class property : base_property {
optional units_name() const;
};
template <typename> consteval optional property_units_name() { return nullopt; }
template <typename T> optional property<T>::units_name() const {
property_units_name<T>();
}
property<int> optional_int;
} // namespace config
```
## Output
```
$ clang++ -std=c++20 -c ./nullopt_consteval.cpp
./nullopt_consteval.cpp:16:3: warning: _expression_ result unused [-Wunused-value]
property_units_name<T>();
^~~~~~~~~~~~~~~~~~~~~~~~
./nullopt_consteval.cpp:18:15: note: in instantiation of member function 'config::property<int>::units_name' requested here
property<int> optional_int;
^
./nullopt_consteval.cpp:17:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
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: /usr/bin/clang++ -std=c++20 -c -fcolor-diagnostics -o nullopt_consteval.o ./nullopt_consteval.cpp
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. ./nullopt_consteval.cpp:12:12: Generating code for declaration 'config::property<int>::units_name'
#0 0x00007f951436a9a6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM-13.so+0xb5f9a6)
#1 0x00007f9514368734 llvm::sys::RunSignalHandlers() (/lib64/libLLVM-13.so+0xb5d734)
#2 0x00007f951429ab28 (/lib64/libLLVM-13.so+0xa8fb28)
#3 0x00007f9513424760 __restore_rt (/lib64/libc.so.6+0x42760)
#4 0x00007f951b3f4a90 clang::CodeGen::CodeGenFunction::EmitAggregateStore(llvm::Value*, clang::CodeGen::Address, bool) (/lib64/libclang-cpp.so.13+0x1b89a90)
#5 0x00007f951b496839 clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/lib64/libclang-cpp.so.13+0x1c2b839)
#6 0x00007f951b475ca2 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/lib64/libclang-cpp.so.13+0x1c0aca2)
#7 0x00007f951b48e3c6 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/lib64/libclang-cpp.so.13+0x1c233c6)
#8 0x00007f951b5d51c2 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/lib64/libclang-cpp.so.13+0x1d6a1c2)
#9 0x00007f951b5db432 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/lib64/libclang-cpp.so.13+0x1d70432)
#10 0x00007f951b62caae clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/lib64/libclang-cpp.so.13+0x1dc1aae)
#11 0x00007f951b63aa93 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/lib64/libclang-cpp.so.13+0x1dcfa93)
#12 0x00007f951b66d03e clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/lib64/libclang-cpp.so.13+0x1e0203e)
#13 0x00007f951b66975b clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/lib64/libclang-cpp.so.13+0x1dfe75b)
#14 0x00007f951b670bd2 clang::CodeGen::CodeGenModule::EmitDeferred() (/lib64/libclang-cpp.so.13+0x1e05bd2)
#15 0x00007f951b67137c clang::CodeGen::CodeGenModule::Release() (/lib64/libclang-cpp.so.13+0x1e0637c)
#16 0x00007f951b6d588a (/lib64/libclang-cpp.so.13+0x1e6a88a)
#17 0x00007f951b627d0b (/lib64/libclang-cpp.so.13+0x1dbcd0b)
#18 0x00007f951a4485c9 clang::ParseAST(clang::Sema&, bool, bool) (/lib64/libclang-cpp.so.13+0xbdd5c9)
#19 0x00007f951bce6c69 clang::FrontendAction::Execute() (/lib64/libclang-cpp.so.13+0x247bc69)
#20 0x00007f951bc84219 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib64/libclang-cpp.so.13+0x2419219)
#21 0x00007f951bd5664b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/lib64/libclang-cpp.so.13+0x24eb64b)
#22 0x0000557460993430 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang+++0x16430)
#23 0x00005574609907bc (/usr/bin/clang+++0x137bc)
#24 0x00007f951b9a0f79 (/lib64/libclang-cpp.so.13+0x2135f79)
#25 0x00007f951429abf7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/lib64/libLLVM-13.so+0xa8fbf7)
#26 0x00007f951b9a181e (/lib64/libclang-cpp.so.13+0x213681e)
#27 0x00007f951b976dfb clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/lib64/libclang-cpp.so.13+0x210bdfb)
#28 0x00007f951b9775be clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/lib64/libclang-cpp.so.13+0x210c5be)
#29 0x00007f951b981532 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/lib64/libclang-cpp.so.13+0x2116532)
#30 0x000055746098e360 main (/usr/bin/clang+++0x11360)
#31 0x00007f951340f560 __libc_start_call_main (/lib64/libc.so.6+0x2d560)
#32 0x00007f951340f60c __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2d60c)
#33 0x000055746098fbf5 _start (/usr/bin/clang+++0x12bf5)
clang-13: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 13.0.0 (Fedora 13.0.0-3.fc35)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-13: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/nullopt_consteval-90b3bc.cpp
clang-13: note: diagnostic msg: /tmp/nullopt_consteval-90b3bc.sh
clang-13: note: diagnostic msg:
********************
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs