Skip to content

Failed module imports: "fatal error: malformed or corrupted precompiled file" #158321

@kamrann

Description

@kamrann

As of some point after clang 20 I've been unable to compile my modules project with clang due to various errors, but this one appears to be the main blocker on latest trunk:

fatal error: malformed or corrupted precompiled file: 'Expected TU local lookup table block'

It's occurring when compiling one interface partition that imports another. I've debugged it and appears to be finding DECL_CONTEXT_MODULE_LOCAL_VISIBLE when it's expecting DECL_CONTEXT_TU_LOCAL_VISIBLE.

I will try to reduce at some stage but I'm not sure when I'll find the time, so just logging the issue in case the problem is obvious, or if anyone can give pointers on what might trigger it which could help with reducing a repro.

Stack trace for reference:

>	clang++.exe!clang::ASTReader::ReadVisibleDeclContextStorage(clang::serialization::ModuleFile & M, llvm::BitstreamCursor & Cursor, unsigned __int64 Offset, clang::GlobalDeclID ID, clang::ASTReader::VisibleDeclContextStorageKind VisibleKind) Line 1550	C++
 	clang++.exe!clang::ASTReader::ReadDeclRecord(clang::GlobalDeclID ID) Line 4259	C++
 	clang++.exe!clang::ASTReader::GetDecl(clang::GlobalDeclID ID) Line 8411	C++
 	[Inline Frame] clang++.exe!clang::ASTReader::ReadDecl(clang::serialization::ModuleFile & F, const llvm::SmallVectorImpl<unsigned long long> & R, unsigned int & I) Line 2176	C++
 	[Inline Frame] clang++.exe!clang::ASTRecordReader::readDecl() Line 189	C++
 	[Inline Frame] clang++.exe!clang::ASTDeclReader::readDecl() Line 187	C++
 	clang++.exe!clang::ASTDeclReader::VisitRedeclarable<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl> * D) Line 2826	C++
 	clang++.exe!clang::ASTDeclReader::VisitNamespaceDecl(clang::NamespaceDecl * D) Line 1854	C++
 	clang++.exe!clang::ASTDeclReader::Visit(clang::Decl * D) Line 531	C++
 	[Inline Frame] clang++.exe!llvm::function_ref<void ()>::operator()() Line 69	C++
 	[Inline Frame] clang++.exe!clang::runWithSufficientStackSpace(llvm::function_ref<void ()>) Line 49	C++
 	clang++.exe!clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation Loc, llvm::function_ref<void ()> Fn) Line 20	C++
 	clang++.exe!clang::Sema::runWithSufficientStackSpace(clang::SourceLocation Loc, llvm::function_ref<void ()> Fn) Line 629	C++
 	clang++.exe!clang::ASTReader::runWithSufficientStackSpace(clang::SourceLocation Loc, llvm::function_ref<void ()> Fn) Line 10247	C++
 	clang++.exe!clang::ASTReader::ReadDeclRecord(clang::GlobalDeclID ID) Line 4236	C++
 	clang++.exe!clang::ASTReader::GetDecl(clang::GlobalDeclID ID) Line 8411	C++
 	[Inline Frame] clang++.exe!clang::ASTReader::FindExternalVisibleDeclsByName::<lambda_13>::operator()(clang::serialization::MultiOnDiskHashTable<clang::serialization::reader::ASTDeclContextNameLookupTrait> & Table, clang::DeclarationName & Key) Line 8703	C++
 	clang++.exe!clang::ASTReader::FindExternalVisibleDeclsByName(const clang::DeclContext * DC, clang::DeclarationName Name, const clang::DeclContext * OriginalDC) Line 8715	C++
 	clang++.exe!clang::DeclContext::lookupImpl(clang::DeclarationName Name, const clang::DeclContext * OriginalLookupDC) Line 1923	C++
 	clang++.exe!clang::DeclContext::lookup(clang::DeclarationName Name) Line 1885	C++
 	clang++.exe!LookupDirect(clang::Sema & S, clang::LookupResult & R, const clang::DeclContext * DC) Line 1140	C++
 	clang++.exe!clang::Sema::LookupQualifiedName(clang::LookupResult & R, clang::DeclContext * LookupCtx, bool InUnqualifiedLookup) Line 2479	C++
 	clang++.exe!clang::Sema::ActOnStartNamespaceDef(clang::Scope * NamespcScope, clang::SourceLocation InlineLoc, clang::SourceLocation NamespaceLoc, clang::SourceLocation IdentLoc, clang::IdentifierInfo * II, clang::SourceLocation LBrace, const clang::ParsedAttributesView & AttrList, clang::UsingDirectiveDecl * & UD, bool IsNested) Line 11848	C++
 	clang++.exe!clang::Parser::ParseNamespace(clang::DeclaratorContext Context, clang::SourceLocation & DeclEnd, clang::SourceLocation InlineLoc) Line 205	C++
 	[Inline Frame] clang++.exe!clang::Parser::ObjCDeclContextSwitch::ObjCDeclContextSwitch(clang::Parser & p) Line 5388	C++
 	clang++.exe!clang::Parser::ParseDeclaration(clang::DeclaratorContext Context, clang::SourceLocation & DeclEnd, clang::ParsedAttributes & DeclAttrs, clang::ParsedAttributes & DeclSpecAttrs, clang::SourceLocation * DeclSpecStart) Line 1882	C++
 	clang++.exe!clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes & Attrs, clang::ParsedAttributes & DeclSpecAttrs, clang::ParsingDeclSpec * DS) Line 0	C++
 	clang++.exe!clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef> & Result, clang::Sema::ModuleImportState & ImportState) Line 745	C++
 	clang++.exe!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 169	C++
 	clang++.exe!clang::FrontendAction::Execute() Line 1314	C++
 	clang++.exe!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act) Line 1016	C++
 	clang++.exe!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang) Line 302	C++
 	clang++.exe!cc1_main(llvm::ArrayRef<const char *> Argv, const char * Argv0, void * MainAddr) Line 297	C++
 	clang++.exe!ExecuteCC1Tool(llvm::SmallVectorImpl<const char *> & ArgV, const llvm::ToolContext & ToolContext) Line 223	C++
 	[Inline Frame] clang++.exe!llvm::function_ref<int (llvm::SmallVectorImpl<const char *> &)>::operator()(llvm::SmallVectorImpl<const char *> & params) Line 69	C++
 	[Inline Frame] clang++.exe!clang::driver::CC1Command::Execute::<lambda>() Line 436	C++
 	clang++.exe!llvm::function_ref<void ()>::callback_fn<`lambda at C:\LLVM\repo\clang\lib\Driver\Job.cpp:436:22'>(__int64 callable) Line 46	C++
 	clang++.exe!llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()> Fn) Line 235	C++
 	clang++.exe!clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>> Redirects, std::string * ErrMsg, bool * ExecutionFailed) Line 436	C++
 	clang++.exe!clang::driver::Compilation::ExecuteCommand(const clang::driver::Command & C, const clang::driver::Command * & FailingCommand, bool LogOnly) Line 196	C++
 	clang++.exe!clang::driver::Compilation::ExecuteJobs(const clang::driver::JobList & Jobs, llvm::SmallVectorImpl<std::pair<int,const clang::driver::Command *>> & FailingCommands, bool LogOnly) Line 246	C++
 	clang++.exe!clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation & C, llvm::SmallVectorImpl<std::pair<int,const clang::driver::Command *>> & FailingCommands) Line 2241	C++
 	clang++.exe!clang_main(int Argc, char * * Argv, const llvm::ToolContext & ToolContext) Line 404	C++
 	clang++.exe!main(int argc, char * * argv) Line 17	C++

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header ModulescrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions