[clangd][module][clang]Crash in SourceManager::overrideFileContents during module build with nested struct default argument
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This input is generated by a fuzzer.
This issue is probably related to https://github.com/llvm/llvm-project/issues/95317, because the stacktrace looks similar. However, it can still be triggered in clang 23.
requests
```
initialize -> initialized -> didOpen -> textDocument/completion->shutdown -> exit
```
It uses almost the same input as https://github.com/llvm/llvm-project/issues/201179, maybe they share similar deeper root causes, I am not sure.
source code
```cxx
// RUN: %clang_cc1 -std=c++14 -fmodules -verify %s -emit-llvm-only
// expected-no-diagnostics
#pragma clang module build A
module A {}
#pragma clang module contents
#pragma clang module begin A
template auto f() { return []{}; }
#pragma clang module end
#pragma clang module endbuild
#pragma clang module build B
struct Outer {
struct Inner {
Inner() {}
Function f = []{};
};
Outer(Inner = Inner());
};
inline void use_nested_2() { Outer o; }
#pragma clang module end
#pragma clang module endbuild
inline auto q() { return []{}; }
inline auto x3() { return q(); }
#pragma clang module import B
#pragma clang module import C
using T = decltype(x1);
using T = decltype(y1);
using U = decltype(x2);
using U = decltype(y2);
using V = decltype(x3);
using V = decltype(y3);
#pragma clang module import A
void (*p)() = f();
void use_nested() {
use_nested_1();
use_nested_2();
}
```
```
location: line = 14, character = 21(0-based)
```
stacktrace
```
#0 0x00005c3c450b18f2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /tmp/llvm-project-main-20260504/llvm/lib/Support/Unix/Signals.inc:884:3
#1 0x00005c3c450ae66c llvm::sys::RunSignalHandlers() /tmp/llvm-project-main-20260504/llvm/lib/Support/Signals.cpp:108:20
#2 0x00005c3c450aeee1 SignalHandler(int, siginfo_t*, void*) /tmp/llvm-project-main-20260504/llvm/lib/Support/Unix/Signals.inc:448:14
#3 0x000075fa39645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00005c3c450da489 llvm::MemoryBuffer::getMemBufferRef() const /tmp/llvm-project-main-20260504/llvm/lib/Support/MemoryBuffer.cpp:620:45
#5 0x00005c3c46c9dc8b clang::SourceManager::overrideFileContents(clang::FileEntryRef, llvm::MemoryBufferRef const&) /tmp/llvm-project-main-20260504/clang/include/clang/Basic/SourceManager.h:998:70
#6 0x00005c3c46c9dc8b InitializeFileRemapping /tmp/llvm-project-main-20260504/clang/lib/Frontend/CompilerInstance.cpp:419:37
#7 0x00005c3c46c9dc8b clang::CompilerInstance::createPreprocessor(clang::TranslationUnitKind) /tmp/llvm-project-main-20260504/clang/lib/Frontend/CompilerInstance.cpp:471:26
#8 0x00005c3c46d231e1 llvm::IntrusiveRefCntPtr::operator bool() const /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:206:43
#9 0x00005c3c46d231e1 clang::CompilerInstance::getDiagnosticClient() const /tmp/llvm-project-main-20260504/clang/include/clang/Frontend/CompilerInstance.h:377:5
#10 0x00005c3c46d231e1 clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) /tmp/llvm-project-main-20260504/clang/lib/Frontend/FrontendAction.cpp:1082:25
#11 0x00005c3c46ca8e24 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /tmp/llvm-project-main-20260504/clang/lib/Frontend/CompilerInstance.cpp:1012:5
#12 0x00005c3c46ca95b6 std::default_delete::operator()(clang::FrontendAction*) const /usr/include/c++/13/bits/unique_ptr.h:99:2
#13 0x00005c3c46ca95b6 std::unique_ptr>::~unique_ptr() /usr/include/c++/13/bits/unique_ptr.h:404:17
#14 0x00005c3c46ca95b6 operator() /tmp/llvm-project-main-20260504/clang/lib/Frontend/CompilerInstance.cpp:1297:7
#15 0x00005c3c46ca95b6 void llvm::function_ref::callback_fn(long) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:52
#16 0x00005c3c450d67be llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) /tmp/llvm-project-main-20260504/llvm/lib/Support/CrashRecoveryContext.cpp:438:10
#17 0x00005c3c450d6808 RunSafelyOnThread_Dispatch(void*) /tmp/llvm-project-main-20260504/llvm/lib/Support/CrashRecoveryContext.cpp:521:16
#18 0x00005c3c450d6513 operator() /usr/include/c++/13/bits/unique_ptr.h:99:2
#19 0x00005c3c450d6513 ~unique_ptr /usr/include/c++/13/bits/unique_ptr.h:404:17
#20 0x00005c3c450d6513 GenericThreadProxy > /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:49:3
#21 0x00005c3c450d6513 void* llvm::thread::ThreadProxy>(void*) /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:62:36
#22 0x000075fa3969caa4 start_thread ./nptl/pthread_create.c:447:8
#23 0x000075fa39729c6c clone3 ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0
```
Contributor guide
Assessment
This issue has not been assessed yet.