Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Crash on invalid use of `_Nonnull` attribute through an alias template #50848

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR51881
Status CONFIRMED
Importance P normal
Reported by Chandler Carruth (chandlerc@gmail.com)
Reported on 2021-09-16 11:11:20 -0700
Last modified on 2021-10-18 12:39:52 -0700
Version trunk
Hardware PC All
CC aaron@aaronballman.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk, rjmccall@apple.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

https://compiler-explorer.com/z/EKfcebd97

template <typename T>
using Nonnull = T _Nonnull;

Nonnull<int> x;

From compiler explorer:

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: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -O2 -march=haswell -fsanitize=null -fno-inline <source>
1.  <source>:4:1: at annotation token
 #0 0x000055ebf938a22f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055ebf93880f0 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35880f0)
 #2 0x000055ebf92d8a68 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f02e24143c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x000055ebfb934947 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformAttributedType(clang::TypeLocBuilder&, clang::AttributedTypeLoc) SemaTemplateInstantiate.cpp:0:0
 #5 0x000055ebfb9242cb clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
 #6 0x000055ebfb927a2a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
 #7 0x000055ebfb927b38 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::QualType) SemaTemplateInstantiate.cpp:0:0
 #8 0x000055ebfb92894c clang::Sema::SubstType(clang::QualType, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b2894c)
 #9 0x000055ebfb841180 clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5a41180)
#10 0x000055ebfb842baf clang::Sema::ActOnTemplateIdType(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::OpaquePtr<clang::TemplateName>, clang::IdentifierInfo*, clang::SourceLocation, clang::SourceLocation, llvm::MutableArrayRef<clang::ParsedTemplateArgument>, clang::SourceLocation, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5a42baf)
#11 0x000055ebfb21316d clang::Parser::AnnotateTemplateIdTokenAsType(clang::CXXScopeSpec&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x541316d)
#12 0x000055ebfb17c3c2 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x537c3c2)
#13 0x000055ebfb1515af clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53515af)
#14 0x000055ebfb151e31 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.280) Parser.cpp:0:0
#15 0x000055ebfb157d59 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5357d59)
#16 0x000055ebfb159179 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5359179)
#17 0x000055ebfb14c9d9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x534c9d9)
#18 0x000055ebfa2fa762 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44fa762)
#19 0x000055ebf9c985e1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e985e1)
#20 0x000055ebf9c35942 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e35942)
#21 0x000055ebf9d658e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f658e3)
#22 0x000055ebf70cf6dc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x12cf6dc)
#23 0x000055ebf70cb75d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#24 0x000055ebf9add095 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#25 0x000055ebf92d9053 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x34d9053)
#26 0x000055ebf9adf14e clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cdf14e)
#27 0x000055ebf9ab4b7a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cb4b7a)
#28 0x000055ebf9ab56bf clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cb56bf)
#29 0x000055ebf9abeaf5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cbeaf5)
#30 0x000055ebf6fdfb8e main (/opt/compiler-explorer/clang-trunk/bin/clang+++0x11dfb8e)
#31 0x00007f02e1ec40b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#32 0x000055ebf70cb2da _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x12cb2da)
clang-14: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
Quuxplusone commented 3 years ago
The issue is that we lose the attribute due to a "temporary" measure in
template instantiation that was added in 2009.

https://github.com/llvm/llvm-
project/blob/main/clang/lib/Sema/TreeTransform.h#L4623 is the problematic line.
Calling getTrivialTypeSourceInfo() gets a TypeSourceInfo object that does not
track the Attr * for the attributed type. So when we go to diagnose on
https://github.com/llvm/llvm-
project/blob/main/clang/lib/Sema/TreeTransform.h#L6785 the modifiedType is a
null pointer.

https://github.com/llvm/llvm-
project/commit/550e0c2f0fd655d6946a2e2b6dbbbf2c473a513c is what introduced the
temporary hack.

I think we need the temporary 12 year old hack fixed because otherwise we have
no location information for the attribute. We can get "close enough" by using
one of the nearby locations to solve the immediate crashing problem, but better
to solve this properly by not stripping the attribute from the type source
information.
Quuxplusone commented 3 years ago
(In reply to Aaron Ballman from comment #1)
> I think we need the temporary 12 year old hack fixed because otherwise we
> have no location information for the attribute. We can get "close enough" by
> using one of the nearby locations to solve the immediate crashing problem,
> but better to solve this properly by not stripping the attribute from the
> type source information.

Right.  The proper fix there is to remove TransformType(QualType) so that we
only ever transform a TSI, which of course requires all the call sites to move
to TransformType(TSI), which requires them to preserve a TSI down.