Skip to content

[CIR] Don't generate ClangIR after an unrecoverable error occured #130971

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

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

mmha
Copy link
Contributor

@mmha mmha commented Mar 12, 2025

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Mar 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2025

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Morris Hafner (mmha)

Changes

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

1 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+2)
diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index 91070eda7d45a..6fa31ab707139 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -43,6 +43,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
 mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }
 
 bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
+  if (diags.hasUnrecoverableErrorOccurred())
+    return true;
 
   for (Decl *decl : group)
     cgm->emitTopLevelDecl(decl);

@@ -43,6 +43,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }

bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
if (diags.hasUnrecoverableErrorOccurred())
return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to let parsing continue here mostly because this is what's being done in other ASTConsumers, but is there a reason to do so?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It honestly doesn't really matter, we currently delay the codegen in clang until parsing/sema is complete anyway (except for REPL). I'd probably leave it for now, as I wouldn't want this to be a changed behavior.

@mmha
Copy link
Contributor Author

mmha commented Mar 12, 2025

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, I don't think we really need a test for it. We have to make sure we get this in EVERY one of the external interfaces unfortunately (as they are added), but LGTM.

@@ -43,6 +43,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }

bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
if (diags.hasUnrecoverableErrorOccurred())
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It honestly doesn't really matter, we currently delay the codegen in clang until parsing/sema is complete anyway (except for REPL). I'd probably leave it for now, as I wouldn't want this to be a changed behavior.

@erichkeane erichkeane merged commit 0f98d1b into llvm:main Mar 14, 2025
14 checks passed
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.

4 participants