Issue 114802
Summary Crash on usage incomplete type with __is_trivially_destructible
Labels new issue
Assignees
Reporter JVApen
    This problem was found while using clangd and was reduced from `std::optional` in the MSVC STL.
Problem was discovered on LLVM 16, though is reproducible on LLVM trunk.

````
class IncompleteType;

template<bool b>
struct ForceCalculate
{
 using type = IncompleteType;
};

template<typename t>
struct RequiresCompleteType
{
   static constexpr bool value = __is_trivially_destructible(t);
};

template<typename t>
using Base = typename ForceCalculate<RequiresCompleteType<t>::value>::type;

template<typename t>
struct Redirect : Base<t>
{
   using Base<t>::operator*;
};

void f(Redirect<IncompleteType> &a)
{
 *a;
}
````
[Compiler-explorer link](https://compiler-explorer.com/z/b3zWa3f49)

Compiler output:
````
<source>:14:34: error: incomplete type 'IncompleteType' used in type trait _expression_
   14 |    static constexpr bool value = __is_trivially_destructible(t);
      | ^
<source>:18:63: note: in instantiation of static data member 'RequiresCompleteType<IncompleteType>::value' requested here
   18 | using Base = typename ForceCalculate<RequiresCompleteType<t>::value>::type;
 | ^
<source>:21:19: note: in instantiation of template type alias 'Base' requested here
   21 | struct Redirect : Base<t>
      | ^
<source>:28:4: note: in instantiation of template class 'Redirect<IncompleteType>' requested here
   28 |    *a;
      | ^
<source>:3:7: note: forward declaration of 'IncompleteType'
    3 | class IncompleteType;
      |       ^
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.	<source>:28:6: current parser token ';'
2.	<source>:27:1: parsing function body 'f'
3.	<source>:27:1: in compound statement ('{}')
 #0 0x0000000003988e88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3988e88)
 #1 0x0000000003986fd4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3986fd4)
 #2 0x00000000038d7ac8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f70c2642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000000000bb19a2 clang::Sema::AddMethodCandidate(clang::CXXMethodDecl*, clang::DeclAccessPair, clang::CXXRecordDecl*, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, llvm::MutableArrayRef<clang::ImplicitConversionSequence>, clang::OverloadCandidateParamOrder) (.cold) SemaOverload.cpp:0:0
 #5 0x0000000006d8a571 clang::Sema::AddMethodCandidate(clang::DeclAccessPair, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, clang::OverloadCandidateParamOrder) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d8a571)
 #6 0x0000000006d8a76a clang::Sema::AddMemberOperatorCandidates(clang::OverloadedOperatorKind, clang::SourceLocation, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, clang::OverloadCandidateParamOrder) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d8a76a)
 #7 0x0000000006d9523f clang::Sema::CreateOverloadedUnaryOp(clang::SourceLocation, clang::UnaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d9523f)
 #8 0x000000000691db72 clang::Sema::BuildUnaryOp(clang::Scope*, clang::SourceLocation, clang::UnaryOperatorKind, clang::Expr*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x691db72)
 #9 0x000000000637f8ae clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x637f8ae)
#10 0x00000000063813ba clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63813ba)
#11 0x0000000006381589 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6381589)
#12 0x00000000063867d9 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63867d9)
#13 0x0000000006411b67 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6411b67)
#14 0x0000000006406111 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6406111)
#15 0x0000000006406b8d clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6406b8d)
#16 0x0000000006407ea4 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6407ea4)
#17 0x000000000640a11a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x640a11a)
#18 0x0000000006306426 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6306426)
#19 0x000000000634ffcf clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x634ffcf)
#20 0x00000000062fe9d7 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62fe9d7)
#21 0x00000000062ff7f3 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62ff7f3)
#22 0x00000000063090e2 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63090e2)
#23 0x000000000630a978 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x630a978)
#24 0x00000000062f904a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62f904a)
#25 0x00000000042d03a5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x42d03a5)
#26 0x00000000045996e1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x45996e1)
#27 0x000000000451968b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x451968b)
#28 0x000000000467db73 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x467db73)
#29 0x0000000000cee39c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xcee39c)
#30 0x0000000000ce6dfd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x0000000004318289 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#32 0x00000000038d7ef3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38d7ef3)
#33 0x00000000043184a9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#34 0x00000000042dfd8d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x42dfd8d)
#35 0x00000000042e0d8d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x42e0d8d)
#36 0x00000000042ea33c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x42ea33c)
#37 0x0000000000ceb0f1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xceb0f1)
#38 0x0000000000bbc204 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xbbc204)
#39 0x00007f70c2629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#40 0x00007f70c2629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#41 0x0000000000ce689e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xce689e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
````
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to