[llvm-bugs] [Bug 46859] New: Clang crashed in clang/lib/Sema/SemaTemplate.cpp:7777: bool clang::Sema::CheckTemplateDeclScope(clang::Scope *, clang::TemplateParameterList *): Assertion `Ctx && "Unknown context"' failed

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 27 04:55:37 PDT 2020


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

            Bug ID: 46859
           Summary: Clang crashed in clang/lib/Sema/SemaTemplate.cpp:7777:
                    bool clang::Sema::CheckTemplateDeclScope(clang::Scope
                    *, clang::TemplateParameterList *): Assertion `Ctx &&
                    "Unknown context"' failed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: crash-on-invalid
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Hi, all.

This invalid code makes Clang crashed. All versions from clang-4.0 onwards have
behave the same.

Input:
//small.cc
extern "" template < class > int operator >= ()

Command:
clang++ small.cc

Output:
small.cc:1:8: error: unknown linkage language
extern "" template < class > int operator >= ()
       ^~
clang-12:
/home/tuhaoxin/compilers/llvm-project-0726/clang/lib/Sema/SemaTemplate.cpp:7777:
bool clang::Sema::CheckTemplateDeclScope(clang::Scope *,
clang::TemplateParameterList *): Assertion `Ctx && "Unknown context"' failed.
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:
/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
small.cc -mrelocation-model static -mframe-pointer=all -fmath-errno
-fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64
-fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir
/home/tuhaoxin/compilers/llvm-project-0726/build/lib/clang/12.0.0 -c-isystem
/usr/local/include/csmith-2.3.0 -cxx-isystem /usr/local/include/csmith-2.3.0
-internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward
-internal-isystem /usr/local/include -internal-isystem
/home/tuhaoxin/compilers/llvm-project-0726/build/lib/clang/12.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdeprecated-macro -fdebug-compilation-dir
/home/tuhaoxin/gitee/run-new-scg/comparison/grammarinator/ice-tests/creduce-clang
-ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions
-fcolor-diagnostics -faddrsig -o /tmp/small-ccb73d.o -x c++ small.cc 
1.      <eof> parser at end of file
 #0 0x000000000275ec74 PrintStackTraceSignalHandler(void*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x275ec74)
 #1 0x000000000275c86e llvm::sys::RunSignalHandlers()
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x275c86e)
 #2 0x000000000275ef95 SignalHandler(int)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x275ef95)
 #3 0x00007fa80fedd8a0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #4 0x00007fa80e93bf47 raise
/build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007fa80e93d8b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007fa80e92d42a __assert_fail_base
/build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0
 #7 0x00007fa80e92d4a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2)
 #8 0x000000000470c019 clang::Sema::CheckTemplateDeclScope(clang::Scope*,
clang::TemplateParameterList*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x470c019)
 #9 0x00000000042181bb clang::Sema::ActOnFunctionDeclarator(clang::Scope*,
clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*,
clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>,
bool&)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x42181bb)
#10 0x0000000004214f86 clang::Sema::HandleDeclarator(clang::Scope*,
clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x4214f86)
#11 0x000000000472b7c8 clang::Sema::ActOnTemplateDeclarator(clang::Scope*,
llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Declarator&)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x472b7c8)
#12 0x0000000004006942
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x4006942)
#13 0x0000000004007abb
clang::Parser::ParseDeclarationAfterDeclarator(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x4007abb)
#14 0x0000000004097880
clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext,
clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x4097880)
#15 0x00000000040965a0
clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x40965a0)
#16 0x0000000004095eae
clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x4095eae)
#17 0x0000000003ffff00
clang::Parser::ParseDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&,
clang::SourceLocation*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3ffff00)
#18 0x0000000003fe7aca
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe7aca)
#19 0x0000000004019a89 clang::Parser::ParseLinkage(clang::ParsingDeclSpec&,
clang::DeclaratorContext)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x4019a89)
#20 0x0000000003fe9b81
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe9b81)
#21 0x0000000003fe9635
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe9635)
#22 0x0000000003fe841f
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe841f)
#23 0x0000000003fe648d
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe648d)
#24 0x0000000003fe5cd7
clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe5cd7)
#25 0x0000000003fe189e clang::ParseAST(clang::Sema&, bool, bool)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x3fe189e)
#26 0x0000000002f3b553 clang::FrontendAction::Execute()
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x2f3b553)
#27 0x0000000002ed2193
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x2ed2193)
#28 0x0000000002fe73f2
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x2fe73f2)
#29 0x0000000000989758 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x989758)
#30 0x00000000009877cc ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x9877cc)
#31 0x0000000000987481 main
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x987481)
#32 0x00007fa80e91eb97 __libc_start_main
/build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:344:0
#33 0x000000000098449a _start
(/home/tuhaoxin/compilers/llvm-project-0726/build/bin/clang-12+0x98449a)
clang-12: error: unable to execute command: Aborted (core dumped)
clang-12: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 12.0.0 (https://github.com/llvm/llvm-project.git
d135744c34dc7a6315f1d2d65a969a2791a97534)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/tuhaoxin/compilers/llvm-project-0726/build/bin
clang-12: note: diagnostic msg: 
********************

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

********************

My clang version is
clang version 12.0.0 (https://github.com/llvm/llvm-project.git
d135744c34dc7a6315f1d2d65a969a2791a97534)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/tuhaoxin/compilers/llvm-project-0726/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64

Thanks
Haoxin

-- 
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/20200727/01766fb8/attachment-0001.html>


More information about the llvm-bugs mailing list