[PATCH] D91580: [Frontend] Add flag to allow PCM generation despite compiler errors
This revision was automatically updated to reflect the committed changes. Closed by commit rG5834996fefc9: [Frontend] Add flag to allow PCM generation despite compiler errors (authored by bnbarham, committed by akyrtzi). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91580/new/ https://reviews.llvm.org/D91580 Files: clang/include/clang/Driver/Options.td clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/FrontendActions.h clang/include/clang/Frontend/FrontendOptions.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/FrontendActions.cpp clang/test/Modules/Inputs/error.h clang/test/Modules/Inputs/module.map clang/test/Modules/load-module-with-errors.m clang/tools/c-index-test/core_main.cpp clang/tools/libclang/CIndex.cpp Index: clang/tools/libclang/CIndex.cpp === --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -3476,7 +3476,7 @@ ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); return *out_TU ? CXError_Success : CXError_Failure; Index: clang/tools/c-index-test/core_main.cpp === --- clang/tools/c-index-test/core_main.cpp +++ clang/tools/c-index-test/core_main.cpp @@ -263,7 +263,7 @@ std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/false); if (!AU) { errs() << "failed to create TU for: " << modulePath << '\n'; Index: clang/test/Modules/load-module-with-errors.m === --- /dev/null +++ clang/test/Modules/load-module-with-errors.m @@ -0,0 +1,25 @@ +// RUN: rm -rf %t +// RUN: mkdir %t + +// Write out a module with errors make sure it can be read +// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \ +// RUN: -fmodules-cache-path=%t -x objective-c -emit-module \ +// RUN: -fmodule-name=error %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \ +// RUN: -fmodules-cache-path=%t -x objective-c -I %S/Inputs \ +// RUN: -fimplicit-module-maps -ast-print %s | FileCheck %s + +// allow-pcm-with-compiler-errors should also allow errors in PCH +// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x c++ -emit-pch \ +// RUN: -o %t/check.pch %S/Inputs/error.h + +@import error; + +void test(id x) { + [x method]; +} + +// CHECK: @interface Error +// CHECK-NEXT: - (int)method; +// CHECK-NEXT: @end +// CHECK: void test(id x) Index: clang/test/Modules/Inputs/module.map === --- clang/test/Modules/Inputs/module.map +++ clang/test/Modules/Inputs/module.map @@ -483,3 +483,4 @@ header "template-nontrivial1.h" export * } +module error { header "error.h" } Index: clang/test/Modules/Inputs/error.h === --- /dev/null +++ clang/test/Modules/Inputs/error.h @@ -0,0 +1,8 @@ +@import undefined + +@interface Error +- (int)method; +undefined +@end + +undefined Index: clang/lib/Frontend/FrontendActions.cpp === --- clang/lib/Frontend/FrontendActions.cpp +++ clang/lib/Frontend/FrontendActions.cpp @@ -177,7 +177,8 @@ Consumers.push_back(std::make_unique( CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, - /*AllowASTWithErrors=*/false, + /*AllowASTWithErrors=*/ + +CI.getFrontendOpts().AllowPCMWithCompilerErrors, /*IncludeTimestamps=*/ +CI.getFrontendOpts().BuildingImplicitModule, /*ShouldCacheASTInMemory=*/ @@ -187,6 +188,11 @@ return std::make_unique(std::move(Consumers)); } +bool GenerateModuleAction::shouldEraseOutputFiles() { + return !getCompilerInstance().getFrontendOpts().AllowPCMWithCompilerErrors && + ASTFrontendAction::shouldEraseOutputFiles(); +} + bool GenerateModuleFromModuleMapAction::BeginSourceFileAction( CompilerInstance ) { if (!CI.getLangOpts().Modules) { @@ -339,7 +345,7 @@ CI.getPCHContainerReader(), CI.getFrontendOpts().ModuleFileExtensions, Sysroot.empty() ? "" : Sysroot.c_str(), /*DisableValidation*/ false, -
[PATCH] D91580: [Frontend] Add flag to allow PCM generation despite compiler errors
bnbarham updated this revision to Diff 305914. bnbarham added a comment. Have allow-pcm also set allow-pch + test to make sure that works. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91580/new/ https://reviews.llvm.org/D91580 Files: clang/include/clang/Driver/Options.td clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/FrontendActions.h clang/include/clang/Frontend/FrontendOptions.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/FrontendActions.cpp clang/test/Modules/Inputs/error.h clang/test/Modules/Inputs/module.map clang/test/Modules/load-module-with-errors.m clang/tools/c-index-test/core_main.cpp clang/tools/libclang/CIndex.cpp Index: clang/tools/libclang/CIndex.cpp === --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -3476,7 +3476,7 @@ ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); return *out_TU ? CXError_Success : CXError_Failure; Index: clang/tools/c-index-test/core_main.cpp === --- clang/tools/c-index-test/core_main.cpp +++ clang/tools/c-index-test/core_main.cpp @@ -263,7 +263,7 @@ std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/false); if (!AU) { errs() << "failed to create TU for: " << modulePath << '\n'; Index: clang/test/Modules/load-module-with-errors.m === --- /dev/null +++ clang/test/Modules/load-module-with-errors.m @@ -0,0 +1,25 @@ +// RUN: rm -rf %t +// RUN: mkdir %t + +// Write out a module with errors make sure it can be read +// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \ +// RUN: -fmodules-cache-path=%t -x objective-c -emit-module \ +// RUN: -fmodule-name=error %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \ +// RUN: -fmodules-cache-path=%t -x objective-c -I %S/Inputs \ +// RUN: -fimplicit-module-maps -ast-print %s | FileCheck %s + +// allow-pcm-with-compiler-errors should also allow errors in PCH +// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x c++ -emit-pch \ +// RUN: -o %t/check.pch %S/Inputs/error.h + +@import error; + +void test(id x) { + [x method]; +} + +// CHECK: @interface Error +// CHECK-NEXT: - (int)method; +// CHECK-NEXT: @end +// CHECK: void test(id x) Index: clang/test/Modules/Inputs/module.map === --- clang/test/Modules/Inputs/module.map +++ clang/test/Modules/Inputs/module.map @@ -483,3 +483,4 @@ header "template-nontrivial1.h" export * } +module error { header "error.h" } Index: clang/test/Modules/Inputs/error.h === --- /dev/null +++ clang/test/Modules/Inputs/error.h @@ -0,0 +1,8 @@ +@import undefined + +@interface Error +- (int)method; +undefined +@end + +undefined Index: clang/lib/Frontend/FrontendActions.cpp === --- clang/lib/Frontend/FrontendActions.cpp +++ clang/lib/Frontend/FrontendActions.cpp @@ -177,7 +177,8 @@ Consumers.push_back(std::make_unique( CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, - /*AllowASTWithErrors=*/false, + /*AllowASTWithErrors=*/ + +CI.getFrontendOpts().AllowPCMWithCompilerErrors, /*IncludeTimestamps=*/ +CI.getFrontendOpts().BuildingImplicitModule, /*ShouldCacheASTInMemory=*/ @@ -187,6 +188,11 @@ return std::make_unique(std::move(Consumers)); } +bool GenerateModuleAction::shouldEraseOutputFiles() { + return !getCompilerInstance().getFrontendOpts().AllowPCMWithCompilerErrors && + ASTFrontendAction::shouldEraseOutputFiles(); +} + bool GenerateModuleFromModuleMapAction::BeginSourceFileAction( CompilerInstance ) { if (!CI.getLangOpts().Modules) { @@ -339,7 +345,7 @@ CI.getPCHContainerReader(), CI.getFrontendOpts().ModuleFileExtensions, Sysroot.empty() ? "" : Sysroot.c_str(), /*DisableValidation*/ false, - /*AllowPCHWithCompilerErrors*/ false, + /*AllowASTWithCompilerErrors*/ false, /*AllowConfigurationMismatch*/ true,
[PATCH] D91580: [Frontend] Add flag to allow PCM generation despite compiler errors
akyrtzi added a comment. I'd like if we only had to use one flag (`-fallow-pcm-with-compiler-errors`) and have it handle both modules and PCH. Could you make the flag also work for PCH and/or add a test that verifies it works? You may only have to change Opts.AllowPCHWithCompilerErrors = Args.hasArg(OPT_fallow_pch_with_errors); to Opts.AllowPCHWithCompilerErrors = Args.hasArg(OPT_fallow_pch_with_errors, OPT_fallow_pcm_with_errors); CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91580/new/ https://reviews.llvm.org/D91580 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D91580: [Frontend] Add flag to allow PCM generation despite compiler errors
bnbarham updated this revision to Diff 305622. bnbarham added a comment. Noticed I had left in the `-fdisable-module-hash` flags in the test, removed now. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91580/new/ https://reviews.llvm.org/D91580 Files: clang/include/clang/Driver/Options.td clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/FrontendActions.h clang/include/clang/Frontend/FrontendOptions.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/FrontendActions.cpp clang/test/Modules/Inputs/error.h clang/test/Modules/Inputs/module.map clang/test/Modules/load-module-with-errors.m clang/tools/c-index-test/core_main.cpp clang/tools/libclang/CIndex.cpp Index: clang/tools/libclang/CIndex.cpp === --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -3476,7 +3476,7 @@ ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); return *out_TU ? CXError_Success : CXError_Failure; Index: clang/tools/c-index-test/core_main.cpp === --- clang/tools/c-index-test/core_main.cpp +++ clang/tools/c-index-test/core_main.cpp @@ -263,7 +263,7 @@ std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/false); if (!AU) { errs() << "failed to create TU for: " << modulePath << '\n'; Index: clang/test/Modules/load-module-with-errors.m === --- /dev/null +++ clang/test/Modules/load-module-with-errors.m @@ -0,0 +1,14 @@ +// RUN: rm -rf %t + +// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors -fmodules-cache-path=%t -emit-module -x objective-c -fmodule-name=error %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fallow-pcm-with-compiler-errors -ast-print -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix=CHECK-PRINT %s + +@import error; + +void test(id x) { + [x method]; +} + +// CHECK-PRINT: @interface Error +// CHECK-PRINT-NEXT: - (int)method; +// CHECK-PRINT: void test(id x) Index: clang/test/Modules/Inputs/module.map === --- clang/test/Modules/Inputs/module.map +++ clang/test/Modules/Inputs/module.map @@ -483,3 +483,4 @@ header "template-nontrivial1.h" export * } +module error { header "error.h" } Index: clang/test/Modules/Inputs/error.h === --- /dev/null +++ clang/test/Modules/Inputs/error.h @@ -0,0 +1,8 @@ +@import undefined + +@interface Error +- (int)method; +undefined +@end + +undefined Index: clang/lib/Frontend/FrontendActions.cpp === --- clang/lib/Frontend/FrontendActions.cpp +++ clang/lib/Frontend/FrontendActions.cpp @@ -177,7 +177,8 @@ Consumers.push_back(std::make_unique( CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, - /*AllowASTWithErrors=*/false, + /*AllowASTWithErrors=*/ + +CI.getFrontendOpts().AllowPCMWithCompilerErrors, /*IncludeTimestamps=*/ +CI.getFrontendOpts().BuildingImplicitModule, /*ShouldCacheASTInMemory=*/ @@ -187,6 +188,11 @@ return std::make_unique(std::move(Consumers)); } +bool GenerateModuleAction::shouldEraseOutputFiles() { + return !getCompilerInstance().getFrontendOpts().AllowPCMWithCompilerErrors && + ASTFrontendAction::shouldEraseOutputFiles(); +} + bool GenerateModuleFromModuleMapAction::BeginSourceFileAction( CompilerInstance ) { if (!CI.getLangOpts().Modules) { @@ -339,7 +345,7 @@ CI.getPCHContainerReader(), CI.getFrontendOpts().ModuleFileExtensions, Sysroot.empty() ? "" : Sysroot.c_str(), /*DisableValidation*/ false, - /*AllowPCHWithCompilerErrors*/ false, + /*AllowASTWithCompilerErrors*/ false, /*AllowConfigurationMismatch*/ true, /*ValidateSystemInputs*/ true)); Index: clang/lib/Frontend/CompilerInvocation.cpp === --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -2027,6 +2027,7 @@
[PATCH] D91580: [Frontend] Add flag to allow PCM generation despite compiler errors
bnbarham created this revision. bnbarham added a reviewer: akyrtzi. Herald added subscribers: cfe-commits, dang, arphaman. Herald added a project: clang. bnbarham requested review of this revision. As with precompiled headers, it's useful for indexers to be able to continue through compiler errors in dependent modules. Resolves rdar://69816264 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D91580 Files: clang/include/clang/Driver/Options.td clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/FrontendActions.h clang/include/clang/Frontend/FrontendOptions.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/FrontendActions.cpp clang/test/Modules/Inputs/error.h clang/test/Modules/Inputs/module.map clang/test/Modules/load-module-with-errors.m clang/tools/c-index-test/core_main.cpp clang/tools/libclang/CIndex.cpp Index: clang/tools/libclang/CIndex.cpp === --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -3476,7 +3476,7 @@ ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); return *out_TU ? CXError_Success : CXError_Failure; Index: clang/tools/c-index-test/core_main.cpp === --- clang/tools/c-index-test/core_main.cpp +++ clang/tools/c-index-test/core_main.cpp @@ -263,7 +263,7 @@ std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None, - /*AllowPCHWithCompilerErrors=*/true, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/false); if (!AU) { errs() << "failed to create TU for: " << modulePath << '\n'; Index: clang/test/Modules/load-module-with-errors.m === --- /dev/null +++ clang/test/Modules/load-module-with-errors.m @@ -0,0 +1,14 @@ +// RUN: rm -rf %t + +// RUN: %clang_cc1 -fmodules -fdisable-module-hash -fallow-pcm-with-compiler-errors -fmodules-cache-path=%t -emit-module -x objective-c -fmodule-name=error %S/Inputs/module.map +// RUN: %clang_cc1 -fmodules -fdisable-module-hash -fimplicit-module-maps -fallow-pcm-with-compiler-errors -ast-print -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix=CHECK-PRINT %s + +@import error; + +void test(id x) { + [x method]; +} + +// CHECK-PRINT: @interface Error +// CHECK-PRINT-NEXT: - (int)method; +// CHECK-PRINT: void test(id x) Index: clang/test/Modules/Inputs/module.map === --- clang/test/Modules/Inputs/module.map +++ clang/test/Modules/Inputs/module.map @@ -483,3 +483,4 @@ header "template-nontrivial1.h" export * } +module error { header "error.h" } Index: clang/test/Modules/Inputs/error.h === --- /dev/null +++ clang/test/Modules/Inputs/error.h @@ -0,0 +1,8 @@ +@import undefined + +@interface Error +- (int)method; +undefined +@end + +undefined Index: clang/lib/Frontend/FrontendActions.cpp === --- clang/lib/Frontend/FrontendActions.cpp +++ clang/lib/Frontend/FrontendActions.cpp @@ -177,7 +177,8 @@ Consumers.push_back(std::make_unique( CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, - /*AllowASTWithErrors=*/false, + /*AllowASTWithErrors=*/ + +CI.getFrontendOpts().AllowPCMWithCompilerErrors, /*IncludeTimestamps=*/ +CI.getFrontendOpts().BuildingImplicitModule, /*ShouldCacheASTInMemory=*/ @@ -187,6 +188,11 @@ return std::make_unique(std::move(Consumers)); } +bool GenerateModuleAction::shouldEraseOutputFiles() { + return !getCompilerInstance().getFrontendOpts().AllowPCMWithCompilerErrors && + ASTFrontendAction::shouldEraseOutputFiles(); +} + bool GenerateModuleFromModuleMapAction::BeginSourceFileAction( CompilerInstance ) { if (!CI.getLangOpts().Modules) { @@ -339,7 +345,7 @@ CI.getPCHContainerReader(), CI.getFrontendOpts().ModuleFileExtensions, Sysroot.empty() ? "" : Sysroot.c_str(), /*DisableValidation*/ false, - /*AllowPCHWithCompilerErrors*/ false, + /*AllowASTWithCompilerErrors*/ false, /*AllowConfigurationMismatch*/ true, /*ValidateSystemInputs*/ true)); Index: