diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -487,6 +487,11 @@ } } +static bool actionRequiresCodeGen(BackendAction Action) { + return Action != Backend_EmitNothing && Action != Backend_EmitBC && + Action != Backend_EmitLL; +} + static bool initTargetOptions(DiagnosticsEngine &Diags, llvm::TargetOptions &Options, const CodeGenOptions &CodeGenOpts, @@ -977,9 +982,7 @@ setCommandLineOpts(CodeGenOpts); - bool UsesCodeGen = (Action != Backend_EmitNothing && - Action != Backend_EmitBC && - Action != Backend_EmitLL); + bool UsesCodeGen = actionRequiresCodeGen(Action); CreateTargetMachine(UsesCodeGen); if (UsesCodeGen && !TM) @@ -1006,6 +1009,12 @@ CreatePasses(PerModulePasses, PerFunctionPasses); + // Add a verifier pass if requested. We don't have to do this if the action + // requires code generation because there will already be a verifier pass in + // the code-generation pipeline. + if (!UsesCodeGen && CodeGenOpts.VerifyModule) + PerModulePasses.add(createVerifierPass()); + legacy::PassManager CodeGenPasses; CodeGenPasses.add( createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); @@ -1425,6 +1434,13 @@ MPM.addPass(ModuleMemProfilerPass()); } } + + // Add a verifier pass if requested. We don't have to do this if the action + // requires code generation because there will already be a verifier pass in + // the code-generation pipeline. + if (!actionRequiresCodeGen(Action) && CodeGenOpts.VerifyModule) + MPM.addPass(VerifierPass()); + switch (Action) { case Backend_EmitBC: if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) { @@ -1514,8 +1530,7 @@ TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime : nullptr); setCommandLineOpts(CodeGenOpts); - bool RequiresCodeGen = (Action != Backend_EmitNothing && - Action != Backend_EmitBC && Action != Backend_EmitLL); + bool RequiresCodeGen = actionRequiresCodeGen(Action); CreateTargetMachine(RequiresCodeGen); if (RequiresCodeGen && !TM) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5034,7 +5034,7 @@ llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); llvm::Type *ResolverTy = llvm::GlobalIFunc::getResolverFunctionType(DeclTy); llvm::Constant *Resolver = - GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, GD, + GetOrCreateLLVMFunction(IFA->getResolver(), ResolverTy, {}, /*ForVTable=*/false); llvm::GlobalIFunc *GIF = llvm::GlobalIFunc::create(DeclTy, 0, llvm::Function::ExternalLinkage, diff --git a/clang/test/CodeGen/lto-newpm-pipeline.c b/clang/test/CodeGen/lto-newpm-pipeline.c --- a/clang/test/CodeGen/lto-newpm-pipeline.c +++ b/clang/test/CodeGen/lto-newpm-pipeline.c @@ -32,6 +32,8 @@ // CHECK-FULL-O0-NEXT: Running pass: CoroCleanupPass // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass +// CHECK-FULL-O0-NEXT: Running pass: VerifierPass +// CHECK-FULL-O0-NEXT: Running analysis: VerifierAnalysis // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass // CHECK-THIN-O0: Running pass: AlwaysInlinerPass @@ -40,6 +42,8 @@ // CHECK-THIN-O0: Running pass: CoroCleanupPass // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass +// CHECK-THIN-O0-NEXT: Running pass: VerifierPass +// CHECK-THIN-O0-NEXT: Running analysis: VerifierAnalysis // CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass // TODO: The LTO pre-link pipeline currently invokes