saarraz / clang-concepts-monorepo

****** OBSOLETE - CONCEPTS HAS BEEN MERGED INTO CLANG TRUNK AND DEVELOPMENT CONTINUES THERE ****** This fork of llvm-project contains my implementation of C++2a Concepts for the Clang compiler, and will be updated regularly with bug fixes until the whole feature is merged to trunk. Follow the instructions here https://clang.llvm.org/get_started.html to build, then use the flags "-std=c++2a -Xclang -fconcepts-ts" to enable concepts.
27 stars 3 forks source link

Assertion failure with member access of result of function declared with decltype(expr) return type #24

Open davidstone opened 5 years ago

davidstone commented 5 years ago

The following code:

struct s {
    int x;
};

decltype(s()) f();

auto x = (f()).x;

Gives the following assertion failure:

clang-10: /home/david/llvm-concepts/clang/lib/Sema/SemaExprMember.cpp:510: clang::ExprResult clang::Sema::ActOnDependentMemberExpr(clang::Expr *, clang::QualType, bool, clang::SourceLocation, const clang::CXXScopeSpec &, clang::SourceLocation, clang::NamedDecl *, const clang::DeclarationNameInfo &, const clang::TemplateArgumentListInfo *): Assertion `BaseType->isDependentType() || (BaseExpr && BaseExpr->isTypeDependent()) || NameInfo.getName().isDependentName() || isDependentScopeSpecifier(SS)' failed.
Stack dump:
0.  Program arguments: /home/david/llvm-concepts/build/bin/clang-10 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name file.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /dev/null.gcno -resource-dir /home/david/llvm-concepts/build/lib/clang/10.0.0 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/x86_64-pc-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/backward -internal-isystem /usr/local/include -internal-isystem /home/david/llvm-concepts/build/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wfatal-errors -std=c++2a -fdeprecated-macro -fdebug-compilation-dir /home/david/tm/build-bi-clang-debug/reduce -ferror-limit 19 -fmessage-length 0 -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /dev/null -x c++ file.cpp 
1.  file.cpp:7:17: current parser token ';'
 #0 0x0000000003048d1d PrintStackTraceSignalHandler(void*) (.llvm.4153284813334431990) (/home/david/llvm-concepts/build/bin/clang-10+0x3048d1d)
 #1 0x00000000030464a0 llvm::sys::RunSignalHandlers() (/home/david/llvm-concepts/build/bin/clang-10+0x30464a0)
 #2 0x00000000030491b8 SignalHandler(int) (/home/david/llvm-concepts/build/bin/clang-10+0x30491b8)
 #3 0x00007fe26fc0b660 __restore_rt (/lib64/libpthread.so.0+0x14660)
 #4 0x00007fe26f61cd21 raise (/lib64/libc.so.6+0x38d21)
 #5 0x00007fe26f606535 abort (/lib64/libc.so.6+0x22535)
 #6 0x00007fe26f60640f _nl_load_domain.cold (/lib64/libc.so.6+0x2240f)
 #7 0x00007fe26f614712 (/lib64/libc.so.6+0x30712)
 #8 0x0000000004d3356e clang::Sema::ActOnDependentMemberExpr(clang::Expr*, clang::QualType, bool, clang::SourceLocation, clang::CXXScopeSpec const&, clang::SourceLocation, clang::NamedDecl*, clang::DeclarationNameInfo const&, clang::TemplateArgumentListInfo const*) (/home/david/llvm-concepts/build/bin/clang-10+0x4d3356e)
 #9 0x0000000004d3af9f clang::Sema::ActOnMemberAccessExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, clang::tok::TokenKind, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, clang::Decl*) (/home/david/llvm-concepts/build/bin/clang-10+0x4d3af9f)
#10 0x00000000048449fa clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/home/david/llvm-concepts/build/bin/clang-10+0x48449fa)
#11 0x0000000004847702 clang::Parser::ParseCastExpression(clang::Parser::CastParseOption, bool, bool&, clang::Parser::TypeCastState, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x4847702)
#12 0x00000000048417c5 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/home/david/llvm-concepts/build/bin/clang-10+0x48417c5)
#13 0x000000000482fa9f clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/home/david/llvm-concepts/build/bin/clang-10+0x482fa9f)
#14 0x000000000482d8a1 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/home/david/llvm-concepts/build/bin/clang-10+0x482d8a1)
#15 0x00000000047e29f4 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x47e29f4)
#16 0x00000000047e22df clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x47e22df)
#17 0x00000000047e1106 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/home/david/llvm-concepts/build/bin/clang-10+0x47e1106)
#18 0x00000000047dee0d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x47dee0d)
#19 0x00000000047da324 clang::ParseAST(clang::Sema&, bool, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x47da324)
#20 0x000000000398903f clang::FrontendAction::Execute() (/home/david/llvm-concepts/build/bin/clang-10+0x398903f)
#21 0x00000000038e7ed8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/david/llvm-concepts/build/bin/clang-10+0x38e7ed8)
#22 0x0000000003a33b57 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/david/llvm-concepts/build/bin/clang-10+0x3a33b57)
#23 0x0000000001fd23ee cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/david/llvm-concepts/build/bin/clang-10+0x1fd23ee)
#24 0x0000000001fd0168 main (/home/david/llvm-concepts/build/bin/clang-10+0x1fd0168)
#25 0x00007fe26f607f1b __libc_start_main (/lib64/libc.so.6+0x23f1b)
#26 0x0000000001fcd02a _start (/home/david/llvm-concepts/build/bin/clang-10+0x1fcd02a)
clang-10: fatal error: unable to execute command: Aborted (core dumped)
clang version 10.0.0 (git@github.com:saarraz/clang-concepts-monorepo.git 327743ab29bb0e458cfc4a0eab3bea946b72c938)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/david/llvm-concepts/build/bin
davidstone commented 5 years ago

Here is a simpler reproduction:

struct s {
    int x;
};

decltype(s()) f();

int x = f().x;
clang-10: /home/david/llvm-concepts/clang/lib/Sema/SemaExprMember.cpp:510: clang::ExprResult clang::Sema::ActOnDependentMemberExpr(clang::Expr *, clang::QualType, bool, clang::SourceLocation, const clang::CXXScopeSpec &, clang::SourceLocation, clang::NamedDecl *, const clang::DeclarationNameInfo &, const clang::TemplateArgumentListInfo *): Assertion `BaseType->isDependentType() || (BaseExpr && BaseExpr->isTypeDependent()) || NameInfo.getName().isDependentName() || isDependentScopeSpecifier(SS)' failed.
Stack dump:
0.  Program arguments: /home/david/llvm-concepts/build/bin/clang-10 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /dev/null.gcno -resource-dir /home/david/llvm-concepts/build/lib/clang/10.0.0 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9 -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/x86_64-pc-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/backward -internal-isystem /usr/local/include -internal-isystem /home/david/llvm-concepts/build/lib/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++2a -fdeprecated-macro -fdebug-compilation-dir /home/david/test -ferror-limit 19 -fmessage-length 0 -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -fconcepts-ts -o /dev/null -x c++ source/main.cpp 
1.  source/main.cpp:7:14: current parser token ';'
 #0 0x0000000003048d1d PrintStackTraceSignalHandler(void*) (.llvm.4153284813334431990) (/home/david/llvm-concepts/build/bin/clang-10+0x3048d1d)
 #1 0x00000000030464a0 llvm::sys::RunSignalHandlers() (/home/david/llvm-concepts/build/bin/clang-10+0x30464a0)
 #2 0x00000000030491b8 SignalHandler(int) (/home/david/llvm-concepts/build/bin/clang-10+0x30491b8)
 #3 0x00007f1c8646f660 __restore_rt (/lib64/libpthread.so.0+0x14660)
 #4 0x00007f1c85e80d21 raise (/lib64/libc.so.6+0x38d21)
 #5 0x00007f1c85e6a535 abort (/lib64/libc.so.6+0x22535)
 #6 0x00007f1c85e6a40f _nl_load_domain.cold (/lib64/libc.so.6+0x2240f)
 #7 0x00007f1c85e78712 (/lib64/libc.so.6+0x30712)
 #8 0x0000000004d3356e clang::Sema::ActOnDependentMemberExpr(clang::Expr*, clang::QualType, bool, clang::SourceLocation, clang::CXXScopeSpec const&, clang::SourceLocation, clang::NamedDecl*, clang::DeclarationNameInfo const&, clang::TemplateArgumentListInfo const*) (/home/david/llvm-concepts/build/bin/clang-10+0x4d3356e)
 #9 0x0000000004d3af9f clang::Sema::ActOnMemberAccessExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, clang::tok::TokenKind, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, clang::Decl*) (/home/david/llvm-concepts/build/bin/clang-10+0x4d3af9f)
#10 0x00000000048449fa clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/home/david/llvm-concepts/build/bin/clang-10+0x48449fa)
#11 0x0000000004847702 clang::Parser::ParseCastExpression(clang::Parser::CastParseOption, bool, bool&, clang::Parser::TypeCastState, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x4847702)
#12 0x00000000048417c5 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/home/david/llvm-concepts/build/bin/clang-10+0x48417c5)
#13 0x000000000482fa9f clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/home/david/llvm-concepts/build/bin/clang-10+0x482fa9f)
#14 0x000000000482d8a1 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/home/david/llvm-concepts/build/bin/clang-10+0x482d8a1)
#15 0x00000000047e29f4 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x47e29f4)
#16 0x00000000047e22df clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/home/david/llvm-concepts/build/bin/clang-10+0x47e22df)
#17 0x00000000047e1106 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/home/david/llvm-concepts/build/bin/clang-10+0x47e1106)
#18 0x00000000047dee0d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x47dee0d)
#19 0x00000000047da324 clang::ParseAST(clang::Sema&, bool, bool) (/home/david/llvm-concepts/build/bin/clang-10+0x47da324)
#20 0x000000000398903f clang::FrontendAction::Execute() (/home/david/llvm-concepts/build/bin/clang-10+0x398903f)
#21 0x00000000038e7ed8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/david/llvm-concepts/build/bin/clang-10+0x38e7ed8)
#22 0x0000000003a33b57 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/david/llvm-concepts/build/bin/clang-10+0x3a33b57)
#23 0x0000000001fd23ee cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/david/llvm-concepts/build/bin/clang-10+0x1fd23ee)
#24 0x0000000001fd0168 main (/home/david/llvm-concepts/build/bin/clang-10+0x1fd0168)
#25 0x00007f1c85e6bf1b __libc_start_main (/lib64/libc.so.6+0x23f1b)
#26 0x0000000001fcd02a _start (/home/david/llvm-concepts/build/bin/clang-10+0x1fcd02a)
clang-10: error: unable to execute command: Aborted (core dumped)
clang-10: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 10.0.0 (git@github.com:saarraz/clang-concepts-monorepo.git 327743ab29bb0e458cfc4a0eab3bea946b72c938)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/david/llvm-concepts/build/bin
clang-10: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang-10: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-10: note: diagnostic msg: /tmp/main-c45d1c.cpp
clang-10: note: diagnostic msg: /tmp/main-c45d1c.sh
clang-10: note: diagnostic msg: 

********************
davidstone commented 5 years ago

Introduced by a6ab0a1ee541adfe1a0376f19a564a7a5e4a4431