Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

"using I = int" makes Clang crash if "I" is also a name of a constant in another scope. #30136

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR31163
Status NEW
Importance P normal
Reported by Mikhail Kremniov (officesamurai@gmail.com)
Reported on 2016-11-25 10:02:18 -0800
Last modified on 2018-10-25 20:12:03 -0700
Version 3.9
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments ClangCrash.cpp (207 bytes, text/x-c++src)
ClangCrash-7df28d.tar.gz (68173 bytes, application/gzip)
Blocks
Blocked by
See also
The following code makes Clang crash if compiled with -std=c++14

#include <tuple>

template <typename Tuple>
void foo()
{
    constexpr int I = 0;
    std::get<I>(Tuple());
}

int main()
{
    foo<std::tuple<int>>();
}

// Remove this and the crash is gone
using I = int;

Output:

~/tmp$ clang++-3.9 ClangCrash.cpp -std=c++14 -stdlib=libc++

#0 0x000000000157a335 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x157a335)
#1 0x000000000157a996 SignalHandler(int) (/home/brd/soft/clang+llvm-3.9.0-
x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x157a996)
#2 0x00007fbecb4e1330 __restore_rt (/lib/x86_64-linux-
gnu/libpthread.so.0+0x10330)
#3 0x0000000002923870
clang::NestedNameSpecifier::containsUnexpandedParameterPack() const
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x2923870)
#4 0x00000000027cc7f5
clang::ASTContext::getDependentNameType(clang::ElaboratedTypeKeyword,
clang::NestedNameSpecifier*, clang::IdentifierInfo const*, clang::QualType)
const (/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-
3.9+0x27cc7f5)
#5 0x00000000024cced7
clang::Sema::CheckTemplateTypeArgument(clang::TemplateTypeParmDecl*,
clang::TemplateArgumentLoc&, llvm::SmallVectorImpl<clang::TemplateArgument>&)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x24cced7)
#6 0x00000000024cdefd clang::Sema::CheckTemplateArgument(clang::NamedDecl*,
clang::TemplateArgumentLoc&, clang::NamedDecl*, clang::SourceLocation,
clang::SourceLocation, unsigned int,
llvm::SmallVectorImpl<clang::TemplateArgument>&,
clang::Sema::CheckTemplateArgumentKind) (/home/brd/soft/clang+llvm-3.9.0-x86_64-
linux-gnu-ubuntu-14.04/bin/clang-3.9+0x24cdefd)
#7 0x00000000024c61f1
clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*,
clang::SourceLocation, clang::TemplateArgumentListInfo&, bool,
llvm::SmallVectorImpl<clang::TemplateArgument>&) (/home/brd/soft/clang+llvm-
3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x24c61f1)
#8 0x000000000250b5af
clang::Sema::SubstituteExplicitTemplateArguments(clang::FunctionTemplateDecl*,
clang::TemplateArgumentListInfo&,
llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&,
llvm::SmallVectorImpl<clang::QualType>&, clang::QualType*,
clang::sema::TemplateDeductionInfo&) (/home/brd/soft/clang+llvm-3.9.0-x86_64-
linux-gnu-ubuntu-14.04/bin/clang-3.9+0x250b5af)
#9 0x000000000250dbd0
clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x250dbd0)
#10 0x000000000245cccd
clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*,
clang::DeclAccessPair, clang::TemplateArgumentListInfo*,
llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x245cccd)
#11 0x000000000246dfbf
clang::Sema::AddOverloadedCallCandidates(clang::UnresolvedLookupExpr*,
llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x246dfbf)
#12 0x000000000246e180 clang::Sema::buildOverloadedCallSet(clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation,
clang::OverloadCandidateSet*, clang::ActionResult<clang::Expr*, true>*)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x246e180)
#13 0x000000000246e4aa clang::Sema::BuildOverloadedCallExpr(clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool,
bool) (/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-
3.9+0x246e4aa)
#14 0x00000000022c9e42 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool) (/home/brd/soft/clang+llvm-3.9.0-
x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x22c9e42)
#15 0x0000000002547c79 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x2547c79)
#16 0x0000000002541668 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x2541668)
#17 0x0000000002552271 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool) (/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-
3.9+0x2552271)
#18 0x0000000002541611 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&) (/home/brd/soft/clang+llvm-3.9.0-
x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x2541611)
#19 0x000000000256adea
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool) (/home/brd/soft/clang+llvm-3.9.0-x86_64-
linux-gnu-ubuntu-14.04/bin/clang-3.9+0x256adea)
#20 0x0000000002565bcb clang::Sema::PerformPendingInstantiations(bool)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x2565bcb)
#21 0x00000000021121a5 clang::Sema::ActOnEndOfTranslationUnit()
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x21121a5)
#22 0x0000000001f319e5
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x1f319e5)
#23 0x0000000001f2e4f6 clang::ParseAST(clang::Sema&, bool, bool)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x1f2e4f6)
#24 0x0000000001985dcc clang::FrontendAction::Execute()
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x1985dcc)
#25 0x0000000001951fd8
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x1951fd8)
#26 0x00000000019f92d9
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-3.9+0x19f92d9)
#27 0x00000000007a2f0c cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-
3.9+0x7a2f0c)
#28 0x00000000007a178c main (/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-
ubuntu-14.04/bin/clang-3.9+0x7a178c)
#29 0x00007fbeca0bff45 __libc_start_main /build/eglibc-oGUzwX/eglibc-
2.19/csu/libc-start.c:321:0
#30 0x000000000079ee4e _start (/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-
ubuntu-14.04/bin/clang-3.9+0x79ee4e)
Stack dump:
0.  Program arguments: /home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-
14.04/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all
-disable-free -disable-llvm-verifier -discard-value-names -main-file-name
ClangCrash.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-
array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir
/home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-
14.04/bin/../lib/clang/3.9.0 -internal-isystem /home/brd/soft/clang+llvm-3.9.0-
x86_64-linux-gnu-ubuntu-14.04/bin/../include/c++/v1 -internal-isystem
/usr/local/include -internal-isystem /home/brd/soft/clang+llvm-3.9.0-x86_64-
linux-gnu-ubuntu-14.04/bin/../lib/clang/3.9.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-
externc-isystem /usr/include -std=c++14 -fdeprecated-macro -fdebug-compilation-
dir /home/brd/tmp -ferror-limit 19 -fmessage-length 237 -fobjc-runtime=gcc -
fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/ClangCrash-880c8b.o -x c++ ClangCrash.cpp
1.  <eof> parser at end of file
2.  ClangCrash.cpp:4:6: instantiating function definition
'foo<std::__1::tuple<int> >'
clang-3.9: error: unable to execute command: Segmentation fault
clang-3.9: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.9.0 (tags/RELEASE_390/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/brd/soft/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin
clang-3.9: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and
associated run script.
clang-3.9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.9: note: diagnostic msg: /tmp/ClangCrash-7df28d.cpp
clang-3.9: note: diagnostic msg: /tmp/ClangCrash-7df28d.sh
clang-3.9: note: diagnostic msg:
Quuxplusone commented 7 years ago

Attached ClangCrash.cpp (207 bytes, text/x-c++src): test code (also in the text)

Quuxplusone commented 7 years ago

Attached ClangCrash-7df28d.tar.gz (68173 bytes, application/gzip): preprocessed test code