Skip to content

Conversation

@mmha
Copy link
Contributor

@mmha mmha commented Oct 31, 2025

This enables clang to print out diagnostics that point to both the C++ source in the error and the incorrect CIR in the notes.

This enables clang to print out diagnostics that point to both the C++ source in the error and the incorrect CIR in the notes.
@mmha mmha requested a review from erichkeane October 31, 2025 08:38
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Oct 31, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2025

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Morris Hafner (mmha)

Changes

This enables clang to print out diagnostics that point to both the C++ source in the error and the incorrect CIR in the notes.


Full diff: https://github.com/llvm/llvm-project/pull/165838.diff

1 Files Affected:

  • (modified) clang/lib/CIR/FrontendAction/CIRGenAction.cpp (+12-3)
diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp
index 67bb5657d4001..ae244d785631b 100644
--- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp
+++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp
@@ -95,6 +95,18 @@ class CIRGenConsumer : public clang::ASTConsumer {
   void HandleTranslationUnit(ASTContext &C) override {
     Gen->HandleTranslationUnit(C);
 
+    mlir::ModuleOp MlirModule = Gen->getModule();
+    mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
+
+    SourceManager &ClangSourceMgr = C.getSourceManager();
+    FileID MainFileID = ClangSourceMgr.getMainFileID();
+    std::unique_ptr<llvm::MemoryBuffer> FileBuf =
+        llvm::MemoryBuffer::getMemBuffer(
+            ClangSourceMgr.getBufferOrFake(MainFileID));
+    llvm::SourceMgr MlirSourceMgr;
+    MlirSourceMgr.AddNewSourceBuffer(std::move(FileBuf), llvm::SMLoc());
+    mlir::SourceMgrDiagnosticHandler DiagnosticHandler(MlirSourceMgr, &MlirCtx);
+
     if (!FEOptions.ClangIRDisableCIRVerifier) {
       if (!Gen->verifyModule()) {
         CI.getDiagnostics().Report(
@@ -105,9 +117,6 @@ class CIRGenConsumer : public clang::ASTConsumer {
       }
     }
 
-    mlir::ModuleOp MlirModule = Gen->getModule();
-    mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
-
     if (!FEOptions.ClangIRDisablePasses) {
       // Setup and run CIR pipeline.
       if (runCIRToCIRPasses(MlirModule, MlirCtx, C,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants