Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang][Frontend] Crash on clang::ASTContext::getRawCommentForDeclNoCacheImpl #68524

Closed
bc-lee opened this issue Oct 8, 2023 · 3 comments · Fixed by #78716
Closed

[Clang][Frontend] Crash on clang::ASTContext::getRawCommentForDeclNoCacheImpl #68524

bc-lee opened this issue Oct 8, 2023 · 3 comments · Fixed by #78716
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@bc-lee
Copy link
Contributor

bc-lee commented Oct 8, 2023

LLVM revision: eef35c287ee0

I was trying to build Swift with clang, but clang crashes with the following error.
(Originally, I ran clang with Chromium's clang and got a crash. So I tried to build clang by myself and run it, but it still crashes.)

$ /home/leebc/src/oss/llvm-project/build-clang/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -DSWIFT_THREADING_LINUX -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/lib/AST -I/home/leebc/src/oss/swift/swift/lib/AST -I/home/leebc/src/oss/swift/swift/stdlib/public/SwiftShims -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/include -I/home/leebc/src/oss/swift/swift/include -I/home/leebc/src/oss/swift/llvm-project/llvm/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/include -I/home/leebc/src/oss/swift/llvm-project/clang/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/tools/clang/include -I/home/leebc/src/oss/swift/cmark/src/include -I/home/leebc/src/oss/swift/build/buildbot_linux/cmark-linux-x86_64/src -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O3 -DNDEBUG -std=c++17  -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target x86_64-unknown-linux-gnu -O2 -g0 -march=core2 -MD -MT lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -MF lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o.d -o lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -c /home/leebc/src/oss/swift/swift/lib/AST/ASTContext.cpp
In file included from /home/leebc/src/oss/swift/swift/lib/AST/ASTContext.cpp:17:
In file included from /home/leebc/src/oss/swift/swift/include/swift/AST/ASTContext.h:22:
In file included from /home/leebc/src/oss/swift/swift/include/swift/AST/GenericSignature.h:20:
/home/leebc/src/oss/swift/swift/include/swift/AST/PrintOptions.h:585:33: warning: '\c' command has no word arguments, expected 1 [-Wdocumentation]
  585 |   /// Whether or not to print \c @attached(extension) attributes on
      |                               ~~^
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: /home/leebc/src/oss/llvm-project/build-clang/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -DSWIFT_THREADING_LINUX -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/lib/AST -I/home/leebc/src/oss/swift/swift/lib/AST -I/home/leebc/src/oss/swift/swift/stdlib/public/SwiftShims -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/include -I/home/leebc/src/oss/swift/swift/include -I/home/leebc/src/oss/swift/llvm-project/llvm/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/include -I/home/leebc/src/oss/swift/llvm-project/clang/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/tools/clang/include -I/home/leebc/src/oss/swift/cmark/src/include -I/home/leebc/src/oss/swift/build/buildbot_linux/cmark-linux-x86_64/src -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O3 -DNDEBUG -std=c++17 -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target x86_64-unknown-linux-gnu -O2 -g0 -march=core2 -MD -MT lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -MF lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o.d -o lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -c /home/leebc/src/oss/swift/swift/lib/AST/ASTContext.cpp
1.	<eof> parser at end of file
2.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/Redeclarable.h:189:14: instantiating function definition 'clang::Redeclarable<clang::TranslationUnitDecl>::getNextRedeclaration'
3.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/Redeclarable.h:122:16: instantiating function definition 'clang::Redeclarable<clang::TranslationUnitDecl>::DeclLink::getPrevious'
4.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/ExternalASTSource.h:410:12: instantiating function definition 'clang::LazyGenerationalUpdatePtr<const clang::Decl *, clang::Decl *, &clang::ExternalASTSource::CompleteRedeclChain>::LazyGenerationalUpdatePtr'
5.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/ASTContext.h:3508:57: instantiating function definition 'clang::LazyGenerationalUpdatePtr<const clang::Decl *, clang::Decl *, &clang::ExternalASTSource::CompleteRedeclChain>::makeValue'
 #0 0x00000000045dc372 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/leebc/src/oss/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x00000000045dc7ab PrintStackTraceSignalHandler(void*) /home/leebc/src/oss/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00000000045d9f2e llvm::sys::RunSignalHandlers() /home/leebc/src/oss/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x00000000045dbc5c llvm::sys::CleanupOnSignal(unsigned long) /home/leebc/src/oss/llvm-project/llvm/lib/Support/Unix/Signals.inc:367:31
 #4 0x00000000045138ac (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/leebc/src/oss/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #5 0x0000000004513d3b CrashRecoverySignalHandler(int) /home/leebc/src/oss/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:391:1
 #6 0x00007f5d54d7ebb0 __restore_rt (/lib64/libc.so.6+0x3dbb0)
 #7 0x000000000455a9c5 llvm::StringRef::find_last_of(llvm::StringRef, unsigned long) const /home/leebc/src/oss/llvm-project/llvm/lib/Support/StringRef.cpp:282:44
 #8 0x00000000097c2568 clang::ASTContext::getRawCommentForDeclNoCacheImpl(clang::Decl const*, clang::SourceLocation, std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>> const&) const /home/leebc/src/oss/llvm-project/clang/lib/AST/ASTContext.cpp:353:34
 #9 0x00000000097c3366 clang::ASTContext::attachCommentsToJustParsedDecls(llvm::ArrayRef<clang::Decl*>, clang::Preprocessor const*) /home/leebc/src/oss/llvm-project/clang/lib/AST/ASTContext.cpp:604:44
#10 0x00000000083e7d86 clang::Sema::ActOnDocumentableDecls(llvm::ArrayRef<clang::Decl*>) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaDecl.cpp:14880:42
#11 0x00000000083e7c04 clang::Sema::ActOnDocumentableDecl(clang::Decl*) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaDecl.cpp:14850:1
#12 0x00000000083eb50d clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Decl*, clang::Sema::SkipBodyInfo*, clang::Sema::FnBodyKind) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaDecl.cpp:15658:46
#13 0x000000000912ea46 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5135:51
#14 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#15 0x0000000009186177 clang::Sema::GlobalEagerInstantiationScope::perform() /home/leebc/src/oss/llvm-project/clang/include/clang/Sema/Sema.h:10064:5
#16 0x000000000912edfb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5189:1
#17 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#18 0x0000000009186177 clang::Sema::GlobalEagerInstantiationScope::perform() /home/leebc/src/oss/llvm-project/clang/include/clang/Sema/Sema.h:10064:5
#19 0x000000000912edfb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5189:1
#20 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#21 0x0000000009186177 clang::Sema::GlobalEagerInstantiationScope::perform() /home/leebc/src/oss/llvm-project/clang/include/clang/Sema/Sema.h:10064:5
#22 0x000000000912edfb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5189:1
#23 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#24 0x00000000081506e1 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) /home/leebc/src/oss/llvm-project/clang/lib/Sema/Sema.cpp:1083:3
#25 0x0000000008150a85 clang::Sema::ActOnEndOfTranslationUnit() /home/leebc/src/oss/llvm-project/clang/lib/Sema/Sema.cpp:1124:9
#26 0x0000000007fc1f4c clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/leebc/src/oss/llvm-project/clang/lib/Parse/Parser.cpp:716:12
#27 0x0000000007fbd3cf clang::ParseAST(clang::Sema&, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Parse/ParseAST.cpp:163:37
#28 0x0000000005507d70 clang::ASTFrontendAction::ExecuteAction() /home/leebc/src/oss/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1184:11
#29 0x0000000005f38cd3 clang::CodeGenAction::ExecuteAction() /home/leebc/src/oss/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1208:5
#30 0x00000000055076c1 clang::FrontendAction::Execute() /home/leebc/src/oss/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1074:38
#31 0x0000000005434768 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/leebc/src/oss/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1045:42
#32 0x000000000569994a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/leebc/src/oss/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:38
#33 0x0000000000d69dec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/leebc/src/oss/llvm-project/clang/tools/driver/cc1_main.cpp:294:40
#34 0x0000000000d5ad5e ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/leebc/src/oss/llvm-project/clang/tools/driver/driver.cpp:366:20
#35 0x0000000000d5af4b clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)::operator()(llvm::SmallVectorImpl<char const*>&) const /home/leebc/src/oss/llvm-project/clang/tools/driver/driver.cpp:507:5
#36 0x0000000000d5c547 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:47:3
#37 0x00000000052b4f11 llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::operator()(llvm::SmallVectorImpl<char const*>&) const /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:3
#38 0x00000000052b3c80 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'()::operator()() const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Job.cpp:440:32
#39 0x00000000052b4097 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) /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#40 0x00000000033aad48 llvm::function_ref<void ()>::operator()() const /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#41 0x0000000004513f03 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/leebc/src/oss/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:427:10
#42 0x00000000052b3e6c clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Job.cpp:440:7
#43 0x000000000525825b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Compilation.cpp:199:22
#44 0x0000000005258587 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Compilation.cpp:253:62
#45 0x000000000526a698 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /home/leebc/src/oss/llvm-project/clang/lib/Driver/Driver.cpp:1884:28
#46 0x0000000000d5c0f4 clang_main(int, char**, llvm::ToolContext const&) /home/leebc/src/oss/llvm-project/clang/tools/driver/driver.cpp:542:39
#47 0x0000000000d90d5c main /home/leebc/src/oss/llvm-project/build-clang/tools/clang/tools/driver/clang-driver.cpp:15:58
#48 0x00007f5d54d68b8a __libc_start_call_main (/lib64/libc.so.6+0x27b8a)
#49 0x00007f5d54d68c4b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c4b)
#50 0x0000000000d59325 _start (/home/leebc/src/oss/llvm-project/build-clang/bin/clang+++0xd59325)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git eef35c287ee093b3521c6c2b682d8da538ad28be)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/leebc/src/oss/llvm-project/build-clang/bin
clang++: note: diagnostic msg:
********************

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

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

Link to the diagnostic files: AstContext-0f4f78.zip

If I remove -Wdocumentation flag, it works well.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Oct 8, 2023
bc-lee added a commit to bc-lee/llvm-project that referenced this issue Oct 8, 2023
This commit resolves a crash issue in Clang's frontend caused while using
the `-Wdocumentation` compiler flag.

The flaw was due to the lack of necessary checks before the extraction of
text between the comment and the declaration in the `ASTContext.cpp` file.
Specifically, there was no verification to ensure that the second component
of the declaration location's decomposition is not less than the comment's
end offset.

This could lead to an invalid length being passed to the `StringRef`
constructor, triggering the crash. I have added a check to prevent this
crash from occurring.

Fixes llvm#68524.
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Oct 9, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 9, 2023

@llvm/issue-subscribers-clang-frontend

LLVM revision: [eef35c2](https://github.com/llvm/llvm-project/commit/eef35c287ee093b3521c6c2b682d8da538ad28be)

I was trying to build Swift with clang, but clang crashes with the following error.
(Originally, I ran clang with Chromium's clang and got a crash. So I tried to build clang by myself and run it, but it still crashes.)

$ /home/leebc/src/oss/llvm-project/build-clang/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -DSWIFT_THREADING_LINUX -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/lib/AST -I/home/leebc/src/oss/swift/swift/lib/AST -I/home/leebc/src/oss/swift/swift/stdlib/public/SwiftShims -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/include -I/home/leebc/src/oss/swift/swift/include -I/home/leebc/src/oss/swift/llvm-project/llvm/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/include -I/home/leebc/src/oss/swift/llvm-project/clang/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/tools/clang/include -I/home/leebc/src/oss/swift/cmark/src/include -I/home/leebc/src/oss/swift/build/buildbot_linux/cmark-linux-x86_64/src -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O3 -DNDEBUG -std=c++17  -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target x86_64-unknown-linux-gnu -O2 -g0 -march=core2 -MD -MT lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -MF lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o.d -o lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -c /home/leebc/src/oss/swift/swift/lib/AST/ASTContext.cpp
In file included from /home/leebc/src/oss/swift/swift/lib/AST/ASTContext.cpp:17:
In file included from /home/leebc/src/oss/swift/swift/include/swift/AST/ASTContext.h:22:
In file included from /home/leebc/src/oss/swift/swift/include/swift/AST/GenericSignature.h:20:
/home/leebc/src/oss/swift/swift/include/swift/AST/PrintOptions.h:585:33: warning: '\c' command has no word arguments, expected 1 [-Wdocumentation]
  585 |   /// Whether or not to print \c @<!-- -->attached(extension) attributes on
      |                               ~~^
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: /home/leebc/src/oss/llvm-project/build-clang/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -DSWIFT_THREADING_LINUX -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/lib/AST -I/home/leebc/src/oss/swift/swift/lib/AST -I/home/leebc/src/oss/swift/swift/stdlib/public/SwiftShims -I/home/leebc/src/oss/swift/build/buildbot_linux/swift-linux-x86_64/include -I/home/leebc/src/oss/swift/swift/include -I/home/leebc/src/oss/swift/llvm-project/llvm/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/include -I/home/leebc/src/oss/swift/llvm-project/clang/include -I/home/leebc/src/oss/swift/build/buildbot_linux/llvm-linux-x86_64/tools/clang/include -I/home/leebc/src/oss/swift/cmark/src/include -I/home/leebc/src/oss/swift/build/buildbot_linux/cmark-linux-x86_64/src -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/leebc/src/oss/swift/swift-corelibs-libdispatch -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O3 -DNDEBUG -std=c++17 -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target x86_64-unknown-linux-gnu -O2 -g0 -march=core2 -MD -MT lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -MF lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o.d -o lib/AST/CMakeFiles/swiftAST.dir/ASTContext.cpp.o -c /home/leebc/src/oss/swift/swift/lib/AST/ASTContext.cpp
1.	&lt;eof&gt; parser at end of file
2.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/Redeclarable.h:189:14: instantiating function definition 'clang::Redeclarable&lt;clang::TranslationUnitDecl&gt;::getNextRedeclaration'
3.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/Redeclarable.h:122:16: instantiating function definition 'clang::Redeclarable&lt;clang::TranslationUnitDecl&gt;::DeclLink::getPrevious'
4.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/ExternalASTSource.h:410:12: instantiating function definition 'clang::LazyGenerationalUpdatePtr&lt;const clang::Decl *, clang::Decl *, &amp;clang::ExternalASTSource::CompleteRedeclChain&gt;::LazyGenerationalUpdatePtr'
5.	/home/leebc/src/oss/swift/llvm-project/clang/include/clang/AST/ASTContext.h:3508:57: instantiating function definition 'clang::LazyGenerationalUpdatePtr&lt;const clang::Decl *, clang::Decl *, &amp;clang::ExternalASTSource::CompleteRedeclChain&gt;::makeValue'
 #<!-- -->0 0x00000000045dc372 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /home/leebc/src/oss/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #<!-- -->1 0x00000000045dc7ab PrintStackTraceSignalHandler(void*) /home/leebc/src/oss/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #<!-- -->2 0x00000000045d9f2e llvm::sys::RunSignalHandlers() /home/leebc/src/oss/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #<!-- -->3 0x00000000045dbc5c llvm::sys::CleanupOnSignal(unsigned long) /home/leebc/src/oss/llvm-project/llvm/lib/Support/Unix/Signals.inc:367:31
 #<!-- -->4 0x00000000045138ac (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/leebc/src/oss/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #<!-- -->5 0x0000000004513d3b CrashRecoverySignalHandler(int) /home/leebc/src/oss/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:391:1
 #<!-- -->6 0x00007f5d54d7ebb0 __restore_rt (/lib64/libc.so.6+0x3dbb0)
 #<!-- -->7 0x000000000455a9c5 llvm::StringRef::find_last_of(llvm::StringRef, unsigned long) const /home/leebc/src/oss/llvm-project/llvm/lib/Support/StringRef.cpp:282:44
 #<!-- -->8 0x00000000097c2568 clang::ASTContext::getRawCommentForDeclNoCacheImpl(clang::Decl const*, clang::SourceLocation, std::map&lt;unsigned int, clang::RawComment*, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;unsigned int const, clang::RawComment*&gt;&gt;&gt; const&amp;) const /home/leebc/src/oss/llvm-project/clang/lib/AST/ASTContext.cpp:353:34
 #<!-- -->9 0x00000000097c3366 clang::ASTContext::attachCommentsToJustParsedDecls(llvm::ArrayRef&lt;clang::Decl*&gt;, clang::Preprocessor const*) /home/leebc/src/oss/llvm-project/clang/lib/AST/ASTContext.cpp:604:44
#<!-- -->10 0x00000000083e7d86 clang::Sema::ActOnDocumentableDecls(llvm::ArrayRef&lt;clang::Decl*&gt;) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaDecl.cpp:14880:42
#<!-- -->11 0x00000000083e7c04 clang::Sema::ActOnDocumentableDecl(clang::Decl*) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaDecl.cpp:14850:1
#<!-- -->12 0x00000000083eb50d clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Decl*, clang::Sema::SkipBodyInfo*, clang::Sema::FnBodyKind) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaDecl.cpp:15658:46
#<!-- -->13 0x000000000912ea46 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5135:51
#<!-- -->14 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#<!-- -->15 0x0000000009186177 clang::Sema::GlobalEagerInstantiationScope::perform() /home/leebc/src/oss/llvm-project/clang/include/clang/Sema/Sema.h:10064:5
#<!-- -->16 0x000000000912edfb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5189:1
#<!-- -->17 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#<!-- -->18 0x0000000009186177 clang::Sema::GlobalEagerInstantiationScope::perform() /home/leebc/src/oss/llvm-project/clang/include/clang/Sema/Sema.h:10064:5
#<!-- -->19 0x000000000912edfb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5189:1
#<!-- -->20 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#<!-- -->21 0x0000000009186177 clang::Sema::GlobalEagerInstantiationScope::perform() /home/leebc/src/oss/llvm-project/clang/include/clang/Sema/Sema.h:10064:5
#<!-- -->22 0x000000000912edfb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5189:1
#<!-- -->23 0x00000000091331aa clang::Sema::PerformPendingInstantiations(bool) /home/leebc/src/oss/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6425:32
#<!-- -->24 0x00000000081506e1 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) /home/leebc/src/oss/llvm-project/clang/lib/Sema/Sema.cpp:1083:3
#<!-- -->25 0x0000000008150a85 clang::Sema::ActOnEndOfTranslationUnit() /home/leebc/src/oss/llvm-project/clang/lib/Sema/Sema.cpp:1124:9
#<!-- -->26 0x0000000007fc1f4c clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) /home/leebc/src/oss/llvm-project/clang/lib/Parse/Parser.cpp:716:12
#<!-- -->27 0x0000000007fbd3cf clang::ParseAST(clang::Sema&amp;, bool, bool) /home/leebc/src/oss/llvm-project/clang/lib/Parse/ParseAST.cpp:163:37
#<!-- -->28 0x0000000005507d70 clang::ASTFrontendAction::ExecuteAction() /home/leebc/src/oss/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1184:11
#<!-- -->29 0x0000000005f38cd3 clang::CodeGenAction::ExecuteAction() /home/leebc/src/oss/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1208:5
#<!-- -->30 0x00000000055076c1 clang::FrontendAction::Execute() /home/leebc/src/oss/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1074:38
#<!-- -->31 0x0000000005434768 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) /home/leebc/src/oss/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1045:42
#<!-- -->32 0x000000000569994a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/leebc/src/oss/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:38
#<!-- -->33 0x0000000000d69dec cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) /home/leebc/src/oss/llvm-project/clang/tools/driver/cc1_main.cpp:294:40
#<!-- -->34 0x0000000000d5ad5e ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) /home/leebc/src/oss/llvm-project/clang/tools/driver/driver.cpp:366:20
#<!-- -->35 0x0000000000d5af4b clang_main(int, char**, llvm::ToolContext const&amp;)::'lambda'(llvm::SmallVectorImpl&lt;char const*&gt;&amp;)::operator()(llvm::SmallVectorImpl&lt;char const*&gt;&amp;) const /home/leebc/src/oss/llvm-project/clang/tools/driver/driver.cpp:507:5
#<!-- -->36 0x0000000000d5c547 int llvm::function_ref&lt;int (llvm::SmallVectorImpl&lt;char const*&gt;&amp;)&gt;::callback_fn&lt;clang_main(int, char**, llvm::ToolContext const&amp;)::'lambda'(llvm::SmallVectorImpl&lt;char const*&gt;&amp;)&gt;(long, llvm::SmallVectorImpl&lt;char const*&gt;&amp;) /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:47:3
#<!-- -->37 0x00000000052b4f11 llvm::function_ref&lt;int (llvm::SmallVectorImpl&lt;char const*&gt;&amp;)&gt;::operator()(llvm::SmallVectorImpl&lt;char const*&gt;&amp;) const /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:3
#<!-- -->38 0x00000000052b3c80 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()::operator()() const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Job.cpp:440:32
#<!-- -->39 0x00000000052b4097 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#<!-- -->40 0x00000000033aad48 llvm::function_ref&lt;void ()&gt;::operator()() const /home/leebc/src/oss/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#<!-- -->41 0x0000000004513f03 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) /home/leebc/src/oss/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:427:10
#<!-- -->42 0x00000000052b3e6c clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Job.cpp:440:7
#<!-- -->43 0x000000000525825b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Compilation.cpp:199:22
#<!-- -->44 0x0000000005258587 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const /home/leebc/src/oss/llvm-project/clang/lib/Driver/Compilation.cpp:253:62
#<!-- -->45 0x000000000526a698 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) /home/leebc/src/oss/llvm-project/clang/lib/Driver/Driver.cpp:1884:28
#<!-- -->46 0x0000000000d5c0f4 clang_main(int, char**, llvm::ToolContext const&amp;) /home/leebc/src/oss/llvm-project/clang/tools/driver/driver.cpp:542:39
#<!-- -->47 0x0000000000d90d5c main /home/leebc/src/oss/llvm-project/build-clang/tools/clang/tools/driver/clang-driver.cpp:15:58
#<!-- -->48 0x00007f5d54d68b8a __libc_start_call_main (/lib64/libc.so.6+0x27b8a)
#<!-- -->49 0x00007f5d54d68c4b __libc_start_main@<!-- -->GLIBC_2.2.5 (/lib64/libc.so.6+0x27c4b)
#<!-- -->50 0x0000000000d59325 _start (/home/leebc/src/oss/llvm-project/build-clang/bin/clang+++0xd59325)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git eef35c287ee093b3521c6c2b682d8da538ad28be)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/leebc/src/oss/llvm-project/build-clang/bin
clang++: note: diagnostic msg:
********************

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

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

Link to the diagnostic files: AstContext-0f4f78.zip

If I remove -Wdocumentation flag, it works well.

@VReichelt
Copy link

This is a regression that was introduced by commit 256a0b2 by @tahonermann
which was reviewed here by @cor3ntin :
https://reviews.llvm.org/D64087

Instead of papering over the problem, it's probably better to analyze the root cause for this or revert the offending patch.

@tahonermann tahonermann self-assigned this Oct 17, 2023
@tahonermann
Copy link
Contributor

The same crash has been reported in #67979. I've started looking into it, but have not yet been able to put much time into it. I hope to get back to it this week.

georgestagg added a commit to r-wasm/webr that referenced this issue Dec 7, 2023
Avoids an LLVM crash introduced by upgrading Emscripten to 3.1.47.

See upstream issue llvm/llvm-project#68524 for details.
georgestagg added a commit to r-wasm/webr that referenced this issue Dec 7, 2023
Avoids an LLVM crash introduced by upgrading Emscripten to 3.1.47.

See upstream issue llvm/llvm-project#68524 for details.
georgestagg added a commit to r-wasm/webr that referenced this issue Dec 7, 2023
Avoids an LLVM crash introduced by upgrading Emscripten to 3.1.47.

See upstream issue llvm/llvm-project#68524 for details.
chenshanzhi added a commit to chenshanzhi/llvm-project that referenced this issue Jan 19, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different files.
A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are corrected
in the commit 256a0b2, the variable
`CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source file
rather than the header file for implicit function template instantiation.
Therefore, in the first loop in `ASTContext::attachCommentsToJustParsedDecls`,
`D` should also be adjusted for relevant scenarios like the second loop.

Fixes llvm#67979 llvm#68524 llvm#70550
chenshanzhi added a commit to chenshanzhi/llvm-project that referenced this issue Jan 22, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different files.
A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are corrected
in the commit 256a0b2, the variable
`CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source file
rather than the header file for implicit function template instantiation.
Therefore, in the first loop in `ASTContext::attachCommentsToJustParsedDecls`,
`D` should also be adjusted for relevant scenarios like the second loop.

Fixes llvm#67979 llvm#68524 llvm#70550
@vfdff vfdff closed this as completed in 5f4ee5a Jan 29, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 4, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different
files. A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are
corrected in the commit 256a0b2, the
variable `CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source
file rather than the header file for implicit function template
instantiation. Therefore, in the first loop in
`ASTContext::attachCommentsToJustParsedDecls`, `D` should also be
adjusted for relevant scenarios like the second loop.

Fixes llvm#67979
Fixes llvm#68524
Fixes llvm#70550

(cherry picked from commit 5f4ee5a)
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 8, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different
files. A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are
corrected in the commit 256a0b2, the
variable `CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source
file rather than the header file for implicit function template
instantiation. Therefore, in the first loop in
`ASTContext::attachCommentsToJustParsedDecls`, `D` should also be
adjusted for relevant scenarios like the second loop.

Fixes llvm#67979
Fixes llvm#68524
Fixes llvm#70550

(cherry picked from commit 5f4ee5a)
tstellar pushed a commit to tstellar/llvm-project that referenced this issue Feb 14, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different
files. A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are
corrected in the commit 256a0b2, the
variable `CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source
file rather than the header file for implicit function template
instantiation. Therefore, in the first loop in
`ASTContext::attachCommentsToJustParsedDecls`, `D` should also be
adjusted for relevant scenarios like the second loop.

Fixes llvm#67979
Fixes llvm#68524
Fixes llvm#70550

(cherry picked from commit 5f4ee5a)
tstellar pushed a commit to tstellar/llvm-project that referenced this issue Feb 14, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different
files. A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are
corrected in the commit 256a0b2, the
variable `CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source
file rather than the header file for implicit function template
instantiation. Therefore, in the first loop in
`ASTContext::attachCommentsToJustParsedDecls`, `D` should also be
adjusted for relevant scenarios like the second loop.

Fixes llvm#67979
Fixes llvm#68524
Fixes llvm#70550

(cherry picked from commit 5f4ee5a)
tstellar pushed a commit to tstellar/llvm-project that referenced this issue Feb 14, 2024
This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different
files. A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are
corrected in the commit 256a0b2, the
variable `CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source
file rather than the header file for implicit function template
instantiation. Therefore, in the first loop in
`ASTContext::attachCommentsToJustParsedDecls`, `D` should also be
adjusted for relevant scenarios like the second loop.

Fixes llvm#67979
Fixes llvm#68524
Fixes llvm#70550

(cherry picked from commit 5f4ee5a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
5 participants