From b33735fe20bcf0b8497169932a1498deff867fd4 Mon Sep 17 00:00:00 2001 From: Jasmine Tang Date: Mon, 27 Oct 2025 15:16:49 -0700 Subject: [PATCH 1/4] Fix formatting for frontendaction/ --- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 430 +++++++++--------- 1 file changed, 215 insertions(+), 215 deletions(-) diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index b6a31032de4b..bc08052729d7 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -61,24 +61,24 @@ using namespace cir; using namespace clang; -static std::string sanitizePassOptions(llvm::StringRef o) { - if (o.empty()) +static std::string sanitizePassOptions(llvm::StringRef O) { + if (O.empty()) return ""; - std::string opts{o}; + std::string Opts{O}; // MLIR pass options are space separated, but we use ';' in clang since // space aren't well supported, switch it back. - for (unsigned i = 0, e = opts.size(); i < e; ++i) - if (opts[i] == ';') - opts[i] = ' '; + for (unsigned I = 0, E = Opts.size(); I < E; ++I) + if (Opts[I] == ';') + Opts[I] = ' '; // If arguments are surrounded with '"', trim them off - return llvm::StringRef(opts).trim('"').str(); + return llvm::StringRef(Opts).trim('"').str(); } namespace cir { static BackendAction -getBackendActionFromOutputType(CIRGenAction::OutputType action) { - switch (action) { +getBackendActionFromOutputType(CIRGenAction::OutputType Action) { + switch (Action) { case CIRGenAction::OutputType::EmitAssembly: return BackendAction::Backend_EmitAssembly; case CIRGenAction::OutputType::EmitBC: @@ -93,79 +93,79 @@ getBackendActionFromOutputType(CIRGenAction::OutputType action) { } static std::unique_ptr lowerFromCIRToLLVMIR( - const clang::FrontendOptions &feOptions, mlir::ModuleOp mlirMod, - std::unique_ptr mlirCtx, llvm::LLVMContext &llvmCtx, - bool disableVerifier = false, bool disableCCLowering = false, - bool disableDebugInfo = false) { - if (feOptions.ClangIRDirectLowering) + const clang::FrontendOptions &FeOptions, mlir::ModuleOp MlirMod, + std::unique_ptr MlirCtx, llvm::LLVMContext &LlvmCtx, + bool DisableVerifier = false, bool DisableCcLowering = false, + bool DisableDebugInfo = false) { + if (FeOptions.ClangIRDirectLowering) return direct::lowerDirectlyFromCIRToLLVMIR( - mlirMod, llvmCtx, disableVerifier, disableCCLowering, disableDebugInfo); + MlirMod, LlvmCtx, DisableVerifier, DisableCcLowering, DisableDebugInfo); else - return lowerFromCIRToMLIRToLLVMIR(mlirMod, std::move(mlirCtx), llvmCtx); + return lowerFromCIRToMLIRToLLVMIR(MlirMod, std::move(MlirCtx), LlvmCtx); } class CIRGenConsumer : public clang::ASTConsumer { virtual void anchor(); - CIRGenAction::OutputType action; + CIRGenAction::OutputType Action; - CompilerInstance &compilerInstance; - DiagnosticsEngine &diagnosticsEngine; - [[maybe_unused]] const HeaderSearchOptions &headerSearchOptions; - CodeGenOptions &codeGenOptions; - [[maybe_unused]] const TargetOptions &targetOptions; - [[maybe_unused]] const LangOptions &langOptions; - const FrontendOptions &feOptions; + CompilerInstance &CompilerInstance; + DiagnosticsEngine &DiagnosticsEngine; + [[maybe_unused]] const HeaderSearchOptions &HeaderSearchOptions; + CodeGenOptions &CodeGenOptions; + [[maybe_unused]] const TargetOptions &TargetOptions; + [[maybe_unused]] const LangOptions &LangOptions; + const FrontendOptions &FeOptions; - std::unique_ptr outputStream; + std::unique_ptr OutputStream; - ASTContext *astContext{nullptr}; + ASTContext *AstContext{nullptr}; IntrusiveRefCntPtr FS; - std::unique_ptr gen; + std::unique_ptr Gen; public: - CIRGenConsumer(CIRGenAction::OutputType action, - CompilerInstance &compilerInstance, - DiagnosticsEngine &diagnosticsEngine, + CIRGenConsumer(CIRGenAction::OutputType Action, + class CompilerInstance &CompilerInstance, + class DiagnosticsEngine &DiagnosticsEngine, IntrusiveRefCntPtr VFS, - const HeaderSearchOptions &headerSearchOptions, - CodeGenOptions &codeGenOptions, - const TargetOptions &targetOptions, - const LangOptions &langOptions, - const FrontendOptions &feOptions, - std::unique_ptr os) - : action(action), compilerInstance(compilerInstance), - diagnosticsEngine(diagnosticsEngine), - headerSearchOptions(headerSearchOptions), - codeGenOptions(codeGenOptions), targetOptions(targetOptions), - langOptions(langOptions), feOptions(feOptions), - outputStream(std::move(os)), FS(VFS), - gen(std::make_unique(diagnosticsEngine, std::move(VFS), - codeGenOptions)) {} - - void Initialize(ASTContext &ctx) override { - assert(!astContext && "initialized multiple times"); - - astContext = &ctx; - - gen->Initialize(ctx); + const class HeaderSearchOptions &HeaderSearchOptions, + class CodeGenOptions &CodeGenOptions, + const class TargetOptions &TargetOptions, + const class LangOptions &LangOptions, + const FrontendOptions &FeOptions, + std::unique_ptr Os) + : Action(Action), CompilerInstance(CompilerInstance), + DiagnosticsEngine(DiagnosticsEngine), + HeaderSearchOptions(HeaderSearchOptions), + CodeGenOptions(CodeGenOptions), TargetOptions(TargetOptions), + LangOptions(LangOptions), FeOptions(FeOptions), + OutputStream(std::move(Os)), FS(VFS), + Gen(std::make_unique(DiagnosticsEngine, std::move(VFS), + CodeGenOptions)) {} + + void Initialize(ASTContext &Ctx) override { + assert(!AstContext && "initialized multiple times"); + + AstContext = &Ctx; + + Gen->Initialize(Ctx); } bool HandleTopLevelDecl(DeclGroupRef D) override { PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(), - astContext->getSourceManager(), + AstContext->getSourceManager(), "LLVM IR generation of declaration"); - gen->HandleTopLevelDecl(D); + Gen->HandleTopLevelDecl(D); return true; } void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *VD) override { - gen->HandleCXXStaticMemberVarInstantiation(VD); + Gen->HandleCXXStaticMemberVarInstantiation(VD); } void HandleInlineFunctionDefinition(FunctionDecl *D) override { - gen->HandleInlineFunctionDefinition(D); + Gen->HandleInlineFunctionDefinition(D); } void HandleInterestingDecl(DeclGroupRef D) override { @@ -173,57 +173,57 @@ class CIRGenConsumer : public clang::ASTConsumer { } void HandleTranslationUnit(ASTContext &C) override { - llvm::TimeTraceScope scope("CIR Gen"); + llvm::TimeTraceScope Scope("CIR Gen"); // Note that this method is called after `HandleTopLevelDecl` has already // ran all over the top level decls. Here clang mostly wraps defered and // global codegen, followed by running CIR passes. - gen->HandleTranslationUnit(C); + Gen->HandleTranslationUnit(C); - if (!feOptions.ClangIRDisableCIRVerifier) - if (!gen->verifyModule()) { + if (!FeOptions.ClangIRDisableCIRVerifier) + if (!Gen->verifyModule()) { llvm::report_fatal_error( "CIR codegen: module verification error before running CIR passes"); return; } - auto mlirMod = gen->getModule(); - auto mlirCtx = gen->takeContext(); + auto MlirMod = Gen->getModule(); + auto MlirCtx = Gen->takeContext(); - auto setupCIRPipelineAndExecute = [&] { + auto SetupCirPipelineAndExecute = [&] { // Sanitize passes options. MLIR uses spaces between pass options // and since that's hard to fly in clang, we currently use ';'. - std::string lifetimeOpts, idiomRecognizerOpts, libOptOpts; - if (feOptions.ClangIRLifetimeCheck) - lifetimeOpts = sanitizePassOptions(feOptions.ClangIRLifetimeCheckOpts); - if (feOptions.ClangIRIdiomRecognizer) - idiomRecognizerOpts = - sanitizePassOptions(feOptions.ClangIRIdiomRecognizerOpts); - if (feOptions.ClangIRLibOpt) - libOptOpts = sanitizePassOptions(feOptions.ClangIRLibOptOpts); - - bool enableCCLowering = - feOptions.ClangIRCallConvLowering && - !(action == CIRGenAction::OutputType::EmitMLIR && - feOptions.MLIRTargetDialect == frontend::MLIR_CIR); - bool flattenCIR = - action == CIRGenAction::OutputType::EmitMLIR && - feOptions.MLIRTargetDialect == clang::frontend::MLIR_CIR_FLAT; + std::string LifetimeOpts, IdiomRecognizerOpts, LibOptOpts; + if (FeOptions.ClangIRLifetimeCheck) + LifetimeOpts = sanitizePassOptions(FeOptions.ClangIRLifetimeCheckOpts); + if (FeOptions.ClangIRIdiomRecognizer) + IdiomRecognizerOpts = + sanitizePassOptions(FeOptions.ClangIRIdiomRecognizerOpts); + if (FeOptions.ClangIRLibOpt) + LibOptOpts = sanitizePassOptions(FeOptions.ClangIRLibOptOpts); + + bool EnableCcLowering = + FeOptions.ClangIRCallConvLowering && + !(Action == CIRGenAction::OutputType::EmitMLIR && + FeOptions.MLIRTargetDialect == frontend::MLIR_CIR); + bool FlattenCir = + Action == CIRGenAction::OutputType::EmitMLIR && + FeOptions.MLIRTargetDialect == clang::frontend::MLIR_CIR_FLAT; // Setup and run CIR pipeline. - std::string passOptParsingFailure; + std::string PassOptParsingFailure; if (runCIRToCIRPasses( - mlirMod, mlirCtx.get(), C, !feOptions.ClangIRDisableCIRVerifier, - feOptions.ClangIRLifetimeCheck, lifetimeOpts, - feOptions.ClangIRIdiomRecognizer, idiomRecognizerOpts, - feOptions.ClangIRLibOpt, libOptOpts, passOptParsingFailure, - codeGenOptions.OptimizationLevel > 0, flattenCIR, - !feOptions.ClangIRDirectLowering, enableCCLowering, - feOptions.ClangIREnableMem2Reg) + MlirMod, MlirCtx.get(), C, !FeOptions.ClangIRDisableCIRVerifier, + FeOptions.ClangIRLifetimeCheck, LifetimeOpts, + FeOptions.ClangIRIdiomRecognizer, IdiomRecognizerOpts, + FeOptions.ClangIRLibOpt, LibOptOpts, PassOptParsingFailure, + CodeGenOptions.OptimizationLevel > 0, FlattenCir, + !FeOptions.ClangIRDirectLowering, EnableCcLowering, + FeOptions.ClangIREnableMem2Reg) .failed()) { - if (!passOptParsingFailure.empty()) - diagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing) - << feOptions.ClangIRLifetimeCheckOpts; + if (!PassOptParsingFailure.empty()) + DiagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing) + << FeOptions.ClangIRLifetimeCheckOpts; else llvm::report_fatal_error("CIR codegen: MLIR pass manager fails " "when running CIR passes!"); @@ -231,71 +231,71 @@ class CIRGenConsumer : public clang::ASTConsumer { } }; - if (!feOptions.ClangIRDisablePasses) { + if (!FeOptions.ClangIRDisablePasses) { // Handle source manager properly given that lifetime analysis // might emit warnings and remarks. - auto &clangSourceMgr = C.getSourceManager(); - FileID MainFileID = clangSourceMgr.getMainFileID(); + auto &ClangSourceMgr = C.getSourceManager(); + FileID MainFileID = ClangSourceMgr.getMainFileID(); std::unique_ptr FileBuf = llvm::MemoryBuffer::getMemBuffer( - clangSourceMgr.getBufferOrFake(MainFileID)); + ClangSourceMgr.getBufferOrFake(MainFileID)); - llvm::SourceMgr mlirSourceMgr; - mlirSourceMgr.AddNewSourceBuffer(std::move(FileBuf), llvm::SMLoc()); + llvm::SourceMgr MlirSourceMgr; + MlirSourceMgr.AddNewSourceBuffer(std::move(FileBuf), llvm::SMLoc()); - if (feOptions.ClangIRVerifyDiags) { - mlir::SourceMgrDiagnosticVerifierHandler sourceMgrHandler( - mlirSourceMgr, mlirCtx.get()); - mlirCtx->printOpOnDiagnostic(false); - setupCIRPipelineAndExecute(); + if (FeOptions.ClangIRVerifyDiags) { + mlir::SourceMgrDiagnosticVerifierHandler SourceMgrHandler( + MlirSourceMgr, MlirCtx.get()); + MlirCtx->printOpOnDiagnostic(false); + SetupCirPipelineAndExecute(); // Verify the diagnostic handler to make sure that each of the // diagnostics matched. - if (sourceMgrHandler.verify().failed()) { + if (SourceMgrHandler.verify().failed()) { // FIXME: we fail ungracefully, there's probably a better way // to communicate non-zero return so tests can actually fail. llvm::sys::RunInterruptHandlers(); exit(1); } } else { - mlir::SourceMgrDiagnosticHandler sourceMgrHandler(mlirSourceMgr, - mlirCtx.get()); - setupCIRPipelineAndExecute(); + mlir::SourceMgrDiagnosticHandler SourceMgrHandler(MlirSourceMgr, + MlirCtx.get()); + SetupCirPipelineAndExecute(); } } - auto emitMLIR = [&](mlir::Operation *mlirMod, bool verify) { - assert(mlirMod && + auto EmitMlir = [&](mlir::Operation *MlirMod, bool Verify) { + assert(MlirMod && "MLIR module does not exist, but lowering did not fail?"); - assert(outputStream && "Why are we here without an output stream?"); + assert(OutputStream && "Why are we here without an output stream?"); // FIXME: we cannot roundtrip prettyForm=true right now. - mlir::OpPrintingFlags flags; - flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); - if (!verify) - flags.assumeVerified(); - mlirMod->print(*outputStream, flags); + mlir::OpPrintingFlags Flags; + Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); + if (!Verify) + Flags.assumeVerified(); + MlirMod->print(*OutputStream, Flags); }; - switch (action) { + switch (Action) { case CIRGenAction::OutputType::EmitMLIR: { - switch (feOptions.MLIRTargetDialect) { + switch (FeOptions.MLIRTargetDialect) { case clang::frontend::MLIR_CORE: // case for direct lowering is already checked in compiler invocation // no need to check here - emitMLIR(lowerFromCIRToMLIR(mlirMod, mlirCtx.get()), false); + EmitMlir(lowerFromCIRToMLIR(MlirMod, MlirCtx.get()), false); break; case clang::frontend::MLIR_LLVM: { - mlir::ModuleOp loweredMLIRModule = - feOptions.ClangIRDirectLowering - ? direct::lowerDirectlyFromCIRToLLVMDialect(mlirMod) - : lowerFromCIRToMLIRToLLVMDialect(mlirMod, mlirCtx.get()); - emitMLIR(loweredMLIRModule, false); + mlir::ModuleOp LoweredMlirModule = + FeOptions.ClangIRDirectLowering + ? direct::lowerDirectlyFromCIRToLLVMDialect(MlirMod) + : lowerFromCIRToMLIRToLLVMDialect(MlirMod, MlirCtx.get()); + EmitMlir(LoweredMlirModule, false); break; } case clang::frontend::MLIR_CIR: case clang::frontend::MLIR_CIR_FLAT: - emitMLIR(mlirMod, feOptions.ClangIRDisableCIRVerifier); + EmitMlir(MlirMod, FeOptions.ClangIRDisableCIRVerifier); break; } break; @@ -304,20 +304,20 @@ class CIRGenConsumer : public clang::ASTConsumer { case CIRGenAction::OutputType::EmitBC: case CIRGenAction::OutputType::EmitObj: case CIRGenAction::OutputType::EmitAssembly: { - llvm::LLVMContext llvmCtx; - bool disableDebugInfo = - codeGenOptions.getDebugInfo() == llvm::codegenoptions::NoDebugInfo; - auto llvmModule = lowerFromCIRToLLVMIR( - feOptions, mlirMod, std::move(mlirCtx), llvmCtx, - feOptions.ClangIRDisableCIRVerifier, - !feOptions.ClangIRCallConvLowering, disableDebugInfo); + llvm::LLVMContext LlvmCtx; + bool DisableDebugInfo = + CodeGenOptions.getDebugInfo() == llvm::codegenoptions::NoDebugInfo; + auto LlvmModule = lowerFromCIRToLLVMIR( + FeOptions, MlirMod, std::move(MlirCtx), LlvmCtx, + FeOptions.ClangIRDisableCIRVerifier, + !FeOptions.ClangIRCallConvLowering, DisableDebugInfo); - BackendAction backendAction = getBackendActionFromOutputType(action); + BackendAction BackendAction = getBackendActionFromOutputType(Action); - emitBackendOutput(compilerInstance, codeGenOptions, + emitBackendOutput(CompilerInstance, CodeGenOptions, C.getTargetInfo().getDataLayoutString(), - llvmModule.get(), backendAction, FS, - std::move(outputStream)); + LlvmModule.get(), BackendAction, FS, + std::move(OutputStream)); break; } case CIRGenAction::OutputType::None: @@ -327,17 +327,17 @@ class CIRGenConsumer : public clang::ASTConsumer { void HandleTagDeclDefinition(TagDecl *D) override { PrettyStackTraceDecl CrashInfo(D, SourceLocation(), - astContext->getSourceManager(), + AstContext->getSourceManager(), "CIR generation of declaration"); - gen->HandleTagDeclDefinition(D); + Gen->HandleTagDeclDefinition(D); } void HandleTagDeclRequiredDefinition(const TagDecl *D) override { - gen->HandleTagDeclRequiredDefinition(D); + Gen->HandleTagDeclRequiredDefinition(D); } void CompleteTentativeDefinition(VarDecl *D) override { - gen->CompleteTentativeDefinition(D); + Gen->CompleteTentativeDefinition(D); } void CompleteExternalDeclaration(DeclaratorDecl *D) override { @@ -348,15 +348,15 @@ class CIRGenConsumer : public clang::ASTConsumer { llvm_unreachable("NYI"); } - void HandleVTable(CXXRecordDecl *RD) override { gen->HandleVTable(RD); } + void HandleVTable(CXXRecordDecl *RD) override { Gen->HandleVTable(RD); } }; } // namespace cir void CIRGenConsumer::anchor() {} -CIRGenAction::CIRGenAction(OutputType act, mlir::MLIRContext *_MLIRContext) - : mlirContext(_MLIRContext ? _MLIRContext : new mlir::MLIRContext), - action(act) {} +CIRGenAction::CIRGenAction(OutputType Act, mlir::MLIRContext *MlirContext) + : mlirContext(MlirContext ? MlirContext : new mlir::MLIRContext), + action(Act) {} CIRGenAction::~CIRGenAction() { mlirModule.reset(); } @@ -370,19 +370,19 @@ void CIRGenAction::EndSourceFileAction() { } static std::unique_ptr -getOutputStream(CompilerInstance &ci, StringRef inFile, - CIRGenAction::OutputType action) { - switch (action) { +getOutputStream(CompilerInstance &Ci, StringRef InFile, + CIRGenAction::OutputType Action) { + switch (Action) { case CIRGenAction::OutputType::EmitAssembly: - return ci.createDefaultOutputFile(false, inFile, "s"); + return Ci.createDefaultOutputFile(false, InFile, "s"); case CIRGenAction::OutputType::EmitMLIR: - return ci.createDefaultOutputFile(false, inFile, "mlir"); + return Ci.createDefaultOutputFile(false, InFile, "mlir"); case CIRGenAction::OutputType::EmitLLVM: - return ci.createDefaultOutputFile(false, inFile, "ll"); + return Ci.createDefaultOutputFile(false, InFile, "ll"); case CIRGenAction::OutputType::EmitBC: - return ci.createDefaultOutputFile(true, inFile, "bc"); + return Ci.createDefaultOutputFile(true, InFile, "bc"); case CIRGenAction::OutputType::EmitObj: - return ci.createDefaultOutputFile(true, inFile, "o"); + return Ci.createDefaultOutputFile(true, InFile, "o"); case CIRGenAction::OutputType::None: return nullptr; } @@ -391,21 +391,21 @@ getOutputStream(CompilerInstance &ci, StringRef inFile, } std::unique_ptr -CIRGenAction::CreateASTConsumer(CompilerInstance &ci, StringRef inputFile) { - auto out = ci.takeOutputStream(); - if (!out) - out = getOutputStream(ci, inputFile, action); +CIRGenAction::CreateASTConsumer(CompilerInstance &Ci, StringRef InputFile) { + auto Out = Ci.takeOutputStream(); + if (!Out) + Out = getOutputStream(Ci, InputFile, action); auto Result = std::make_unique( - action, ci, ci.getDiagnostics(), &ci.getVirtualFileSystem(), - ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), ci.getTargetOpts(), - ci.getLangOpts(), ci.getFrontendOpts(), std::move(out)); + action, Ci, Ci.getDiagnostics(), &Ci.getVirtualFileSystem(), + Ci.getHeaderSearchOpts(), Ci.getCodeGenOpts(), Ci.getTargetOpts(), + Ci.getLangOpts(), Ci.getFrontendOpts(), std::move(Out)); cgConsumer = Result.get(); // Enable generating macro debug info only when debug info is not disabled and // also macrod ebug info is enabled - if (ci.getCodeGenOpts().getDebugInfo() != llvm::codegenoptions::NoDebugInfo && - ci.getCodeGenOpts().MacroDebugInfo) { + if (Ci.getCodeGenOpts().getDebugInfo() != llvm::codegenoptions::NoDebugInfo && + Ci.getCodeGenOpts().MacroDebugInfo) { llvm_unreachable("NYI"); } @@ -413,11 +413,11 @@ CIRGenAction::CreateASTConsumer(CompilerInstance &ci, StringRef inputFile) { } mlir::OwningOpRef -CIRGenAction::loadModule(llvm::MemoryBufferRef mbRef) { - auto module = - mlir::parseSourceString(mbRef.getBuffer(), mlirContext); - assert(module && "Failed to parse ClangIR module"); - return module; +CIRGenAction::loadModule(llvm::MemoryBufferRef MbRef) { + auto Module = + mlir::parseSourceString(MbRef.getBuffer(), mlirContext); + assert(Module && "Failed to parse ClangIR module"); + return Module; } void CIRGenAction::ExecuteAction() { @@ -429,17 +429,17 @@ void CIRGenAction::ExecuteAction() { // If this is a CIR file we have to treat it specially. // TODO: This could be done more logically. This is just modeled at the moment // mimicing CodeGenAction but this is clearly suboptimal. - auto &ci = getCompilerInstance(); - std::unique_ptr outstream = - getOutputStream(ci, getCurrentFile(), action); - if (action != OutputType::None && !outstream) + auto &Ci = getCompilerInstance(); + std::unique_ptr Outstream = + getOutputStream(Ci, getCurrentFile(), action); + if (action != OutputType::None && !Outstream) return; - auto &sourceManager = ci.getSourceManager(); - auto fileID = sourceManager.getMainFileID(); - auto mainFile = sourceManager.getBufferOrNone(fileID); + auto &SourceManager = Ci.getSourceManager(); + auto FileId = SourceManager.getMainFileID(); + auto MainFile = SourceManager.getBufferOrNone(FileId); - if (!mainFile) + if (!MainFile) return; mlirContext->getOrLoadDialect(); @@ -449,94 +449,94 @@ void CIRGenAction::ExecuteAction() { // TODO: unwrap this -- this exists because including the `OwningModuleRef` in // CIRGenAction's header would require linking the Frontend against MLIR. // Let's avoid that for now. - auto mlirModule = loadModule(*mainFile); - if (!mlirModule) + auto MlirModule = loadModule(*MainFile); + if (!MlirModule) return; // FIXME(cir): This compilation path does not account for some flags. - llvm::LLVMContext llvmCtx; - bool disableDebugInfo = - ci.getCodeGenOpts().getDebugInfo() == llvm::codegenoptions::NoDebugInfo; - auto llvmModule = lowerFromCIRToLLVMIR( - ci.getFrontendOpts(), mlirModule.release(), - std::unique_ptr(mlirContext), llvmCtx, - /*disableVerifier=*/false, /*disableCCLowering=*/true, disableDebugInfo); - - if (outstream) - llvmModule->print(*outstream, nullptr); + llvm::LLVMContext LlvmCtx; + bool DisableDebugInfo = + Ci.getCodeGenOpts().getDebugInfo() == llvm::codegenoptions::NoDebugInfo; + auto LlvmModule = lowerFromCIRToLLVMIR( + Ci.getFrontendOpts(), MlirModule.release(), + std::unique_ptr(mlirContext), LlvmCtx, + /*disableVerifier=*/false, /*disableCCLowering=*/true, DisableDebugInfo); + + if (Outstream) + LlvmModule->print(*Outstream, nullptr); } namespace cir { void EmitAssemblyAction::anchor() {} -EmitAssemblyAction::EmitAssemblyAction(mlir::MLIRContext *_MLIRContext) - : CIRGenAction(OutputType::EmitAssembly, _MLIRContext) {} +EmitAssemblyAction::EmitAssemblyAction(mlir::MLIRContext *MlirContext) + : CIRGenAction(OutputType::EmitAssembly, MlirContext) {} void EmitCIROnlyAction::anchor() {} -EmitCIROnlyAction::EmitCIROnlyAction(mlir::MLIRContext *_MLIRContext) - : CIRGenAction(OutputType::None, _MLIRContext) {} +EmitCIROnlyAction::EmitCIROnlyAction(mlir::MLIRContext *MlirContext) + : CIRGenAction(OutputType::None, MlirContext) {} void EmitMLIRAction::anchor() {} -EmitMLIRAction::EmitMLIRAction(mlir::MLIRContext *_MLIRContext) - : CIRGenAction(OutputType::EmitMLIR, _MLIRContext) {} +EmitMLIRAction::EmitMLIRAction(mlir::MLIRContext *MlirContext) + : CIRGenAction(OutputType::EmitMLIR, MlirContext) {} void EmitLLVMAction::anchor() {} -EmitLLVMAction::EmitLLVMAction(mlir::MLIRContext *_MLIRContext) - : CIRGenAction(OutputType::EmitLLVM, _MLIRContext) {} +EmitLLVMAction::EmitLLVMAction(mlir::MLIRContext *MlirContext) + : CIRGenAction(OutputType::EmitLLVM, MlirContext) {} void EmitBCAction::anchor() {} -EmitBCAction::EmitBCAction(mlir::MLIRContext *_MLIRContext) - : CIRGenAction(OutputType::EmitBC, _MLIRContext) {} +EmitBCAction::EmitBCAction(mlir::MLIRContext *MlirContext) + : CIRGenAction(OutputType::EmitBC, MlirContext) {} void EmitObjAction::anchor() {} -EmitObjAction::EmitObjAction(mlir::MLIRContext *_MLIRContext) - : CIRGenAction(OutputType::EmitObj, _MLIRContext) {} +EmitObjAction::EmitObjAction(mlir::MLIRContext *MlirContext) + : CIRGenAction(OutputType::EmitObj, MlirContext) {} } // namespace cir // Used for -fclangir-analysis-only: use CIR analysis but still use original // LLVM codegen path void AnalysisOnlyActionBase::anchor() {} -AnalysisOnlyActionBase::AnalysisOnlyActionBase(unsigned _Act, - llvm::LLVMContext *_VMContext) - : clang::CodeGenAction(_Act, _VMContext) {} +AnalysisOnlyActionBase::AnalysisOnlyActionBase(unsigned Act, + llvm::LLVMContext *VmContext) + : clang::CodeGenAction(Act, VmContext) {} std::unique_ptr -AnalysisOnlyActionBase::CreateASTConsumer(clang::CompilerInstance &ci, - llvm::StringRef inFile) { +AnalysisOnlyActionBase::CreateASTConsumer(clang::CompilerInstance &Ci, + llvm::StringRef InFile) { std::vector> Consumers; - Consumers.push_back(clang::CodeGenAction::CreateASTConsumer(ci, inFile)); + Consumers.push_back(clang::CodeGenAction::CreateASTConsumer(Ci, InFile)); Consumers.push_back(std::make_unique( - CIRGenAction::OutputType::None, ci, ci.getDiagnostics(), - &ci.getVirtualFileSystem(), ci.getHeaderSearchOpts(), ci.getCodeGenOpts(), - ci.getTargetOpts(), ci.getLangOpts(), ci.getFrontendOpts(), nullptr)); + CIRGenAction::OutputType::None, Ci, Ci.getDiagnostics(), + &Ci.getVirtualFileSystem(), Ci.getHeaderSearchOpts(), Ci.getCodeGenOpts(), + Ci.getTargetOpts(), Ci.getLangOpts(), Ci.getFrontendOpts(), nullptr)); return std::make_unique(std::move(Consumers)); } void AnalysisOnlyAndEmitAssemblyAction::anchor() {} AnalysisOnlyAndEmitAssemblyAction::AnalysisOnlyAndEmitAssemblyAction( - llvm::LLVMContext *_VMContext) - : AnalysisOnlyActionBase(Backend_EmitAssembly, _VMContext) {} + llvm::LLVMContext *VmContext) + : AnalysisOnlyActionBase(Backend_EmitAssembly, VmContext) {} void AnalysisOnlyAndEmitBCAction::anchor() {} AnalysisOnlyAndEmitBCAction::AnalysisOnlyAndEmitBCAction( - llvm::LLVMContext *_VMContext) - : AnalysisOnlyActionBase(Backend_EmitBC, _VMContext) {} + llvm::LLVMContext *VmContext) + : AnalysisOnlyActionBase(Backend_EmitBC, VmContext) {} void AnalysisOnlyAndEmitLLVMAction::anchor() {} AnalysisOnlyAndEmitLLVMAction::AnalysisOnlyAndEmitLLVMAction( - llvm::LLVMContext *_VMContext) - : AnalysisOnlyActionBase(Backend_EmitLL, _VMContext) {} + llvm::LLVMContext *VmContext) + : AnalysisOnlyActionBase(Backend_EmitLL, VmContext) {} void AnalysisOnlyAndEmitLLVMOnlyAction::anchor() {} AnalysisOnlyAndEmitLLVMOnlyAction::AnalysisOnlyAndEmitLLVMOnlyAction( - llvm::LLVMContext *_VMContext) - : AnalysisOnlyActionBase(Backend_EmitNothing, _VMContext) {} + llvm::LLVMContext *VmContext) + : AnalysisOnlyActionBase(Backend_EmitNothing, VmContext) {} void AnalysisOnlyAndEmitCodeGenOnlyAction::anchor() {} AnalysisOnlyAndEmitCodeGenOnlyAction::AnalysisOnlyAndEmitCodeGenOnlyAction( - llvm::LLVMContext *_VMContext) - : AnalysisOnlyActionBase(Backend_EmitMCNull, _VMContext) {} + llvm::LLVMContext *VmContext) + : AnalysisOnlyActionBase(Backend_EmitMCNull, VmContext) {} void AnalysisOnlyAndEmitObjAction::anchor() {} AnalysisOnlyAndEmitObjAction::AnalysisOnlyAndEmitObjAction( - llvm::LLVMContext *_VMContext) - : AnalysisOnlyActionBase(Backend_EmitObj, _VMContext) {} + llvm::LLVMContext *VmContext) + : AnalysisOnlyActionBase(Backend_EmitObj, VmContext) {} From b10e77fe92d9edf907204a734f587fbc2cae3757 Mon Sep 17 00:00:00 2001 From: Jasmine Tang Date: Tue, 11 Nov 2025 10:48:12 -0800 Subject: [PATCH 2/4] Add extra parenthesis for msvc --- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index bc08052729d7..12d2e0c13b8a 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -222,7 +222,7 @@ class CIRGenConsumer : public clang::ASTConsumer { FeOptions.ClangIREnableMem2Reg) .failed()) { if (!PassOptParsingFailure.empty()) - DiagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing) + DiagnosticsEngine.Report((diag::err_drv_cir_pass_opt_parsing)) << FeOptions.ClangIRLifetimeCheckOpts; else llvm::report_fatal_error("CIR codegen: MLIR pass manager fails " From 074c0d8da8f71a4e7f0ee9b4cff7a952d69cce4f Mon Sep 17 00:00:00 2001 From: Jasmine Tang Date: Tue, 11 Nov 2025 15:23:53 -0800 Subject: [PATCH 3/4] Split << on seperate statements --- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index 12d2e0c13b8a..44fe4b515ed0 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -221,9 +221,10 @@ class CIRGenConsumer : public clang::ASTConsumer { !FeOptions.ClangIRDirectLowering, EnableCcLowering, FeOptions.ClangIREnableMem2Reg) .failed()) { - if (!PassOptParsingFailure.empty()) - DiagnosticsEngine.Report((diag::err_drv_cir_pass_opt_parsing)) - << FeOptions.ClangIRLifetimeCheckOpts; + if (!PassOptParsingFailure.empty()) { + auto D = DiagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing); + D << FeOptions.ClangIRLifetimeCheckOpts; + } else llvm::report_fatal_error("CIR codegen: MLIR pass manager fails " "when running CIR passes!"); From d7d48a6fc9cfc0067539343349c47a6eb5f2fdb4 Mon Sep 17 00:00:00 2001 From: Jasmine Tang Date: Tue, 11 Nov 2025 22:52:26 -0800 Subject: [PATCH 4/4] Reformatting --- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index 44fe4b515ed0..0a366a0142aa 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -224,8 +224,7 @@ class CIRGenConsumer : public clang::ASTConsumer { if (!PassOptParsingFailure.empty()) { auto D = DiagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing); D << FeOptions.ClangIRLifetimeCheckOpts; - } - else + } else llvm::report_fatal_error("CIR codegen: MLIR pass manager fails " "when running CIR passes!"); return;