-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Add MLIR diagnostic handler ahead of verification #165838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This enables clang to print out diagnostics that point to both the C++ source in the error and the incorrect CIR in the notes.
|
@llvm/pr-subscribers-clangir @llvm/pr-subscribers-clang Author: Morris Hafner (mmha) ChangesThis 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:
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,
|
andykaylor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add a test that shows the effect of this change? Perhaps something similar to the invalid CIR tests?
bcardosolopes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending a testcase (either via -verify or FileCheck to workaround any still missing plumbing)
|
The reason I didn't add an explicit test was that there's no way to explicitly trigger an MLIR error from C/C++ source code with clang. The same is true for LLVM errors and OGCG as far as I know. What I think should work and that's what I'm working on now is to enable CIR as a source language in the driver so we can compile and diagnose an invalid .cir file through clang instead of cir-opt. I'll follow up with another PR for that. |
How about |
This enables clang to print out diagnostics that point to both the C++ source in the error and the incorrect CIR in the notes.