Author: adrian Date: Wed Aug 17 18:13:53 2016 New Revision: 279004 URL: http://llvm.org/viewvc/llvm-project?rev=279004&view=rev Log: Support object-file-wrapped modules in clang -module-file-info.
rdar://problem/24504815 Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp cfe/trunk/lib/Frontend/FrontendActions.cpp cfe/trunk/test/Modules/module_file_info.m Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=279004&r1=279003&r2=279004&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/FrontendActions.h (original) +++ cfe/trunk/include/clang/Frontend/FrontendActions.h Wed Aug 17 18:13:53 2016 @@ -138,6 +138,7 @@ class DumpModuleInfoAction : public ASTF protected: std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override; + bool BeginInvocation(CompilerInstance &CI) override; void ExecuteAction() override; public: Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=279004&r1=279003&r2=279004&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original) +++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Wed Aug 17 18:13:53 2016 @@ -314,25 +314,29 @@ ObjectFilePCHContainerWriter::CreatePCHC void ObjectFilePCHContainerReader::ExtractPCH( llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const { - if (auto OF = llvm::object::ObjectFile::createObjectFile(Buffer)) { - auto *Obj = OF.get().get(); - bool IsCOFF = isa<llvm::object::COFFObjectFile>(Obj); + auto OFOrErr = llvm::object::ObjectFile::createObjectFile(Buffer); + if (OFOrErr) { + auto &OF = OFOrErr.get(); + bool IsCOFF = isa<llvm::object::COFFObjectFile>(*OF); // Find the clang AST section in the container. - for (auto &Section : OF->get()->sections()) { + for (auto &Section : OF->sections()) { StringRef Name; Section.getName(Name); - if ((!IsCOFF && Name == "__clangast") || - ( IsCOFF && Name == "clangast")) { + if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) { StringRef Buf; Section.getContents(Buf); - StreamFile.init((const unsigned char *)Buf.begin(), - (const unsigned char *)Buf.end()); - return; + return StreamFile.init((const unsigned char *)Buf.begin(), + (const unsigned char *)Buf.end()); } } } - - // As a fallback, treat the buffer as a raw AST. - StreamFile.init((const unsigned char *)Buffer.getBufferStart(), - (const unsigned char *)Buffer.getBufferEnd()); + handleAllErrors(OFOrErr.takeError(), [&](const llvm::ErrorInfoBase &EIB) { + if (EIB.convertToErrorCode() == + llvm::object::object_error::invalid_file_type) + // As a fallback, treat the buffer as a raw AST. + StreamFile.init((const unsigned char *)Buffer.getBufferStart(), + (const unsigned char *)Buffer.getBufferEnd()); + else + EIB.log(llvm::errs()); + }); } Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=279004&r1=279003&r2=279004&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/FrontendActions.cpp (original) +++ cfe/trunk/lib/Frontend/FrontendActions.cpp Wed Aug 17 18:13:53 2016 @@ -596,6 +596,13 @@ namespace { }; } +bool DumpModuleInfoAction::BeginInvocation(CompilerInstance &CI) { + // The Object file reader also supports raw ast files and there is no point in + // being strict about the module file format in -module-file-info mode. + CI.getHeaderSearchOpts().ModuleFormat = "obj"; + return true; +} + void DumpModuleInfoAction::ExecuteAction() { // Set up the output file. std::unique_ptr<llvm::raw_fd_ostream> OutFile; @@ -608,6 +615,7 @@ void DumpModuleInfoAction::ExecuteAction llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs(); Out << "Information for module file '" << getCurrentFile() << "':\n"; + Preprocessor &PP = getCompilerInstance().getPreprocessor(); DumpModuleInfoListener Listener(Out); HeaderSearchOptions &HSOpts = Modified: cfe/trunk/test/Modules/module_file_info.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/module_file_info.m?rev=279004&r1=279003&r2=279004&view=diff ============================================================================== --- cfe/trunk/test/Modules/module_file_info.m (original) +++ cfe/trunk/test/Modules/module_file_info.m Wed Aug 17 18:13:53 2016 @@ -1,10 +1,13 @@ @import DependsOnModule; -// RUN: rm -rf %t -// RUN: %clang_cc1 -w -Wunused -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE -fmodule-feature myfeature %s +// RUN: rm -rf %t %t-obj +// RUN: %clang_cc1 -w -Wunused -fmodules -fmodule-format=raw -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE -fmodule-feature myfeature %s // RUN: %clang_cc1 -module-file-info %t/DependsOnModule.pcm | FileCheck %s +// RUN: %clang_cc1 -w -Wunused -fmodules -fmodule-format=obj -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-obj -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE -fmodule-feature myfeature %s +// RUN: %clang_cc1 -module-file-info %t-obj/DependsOnModule.pcm | FileCheck %s + // CHECK: Generated by this Clang: // CHECK: Module name: DependsOnModule _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits