Skip to content

fix SynthesizingCodeRAII for clang-repl#819

Merged
Vipul-Cariappa merged 2 commits intocompiler-research:mainfrom
Vipul-Cariappa:dev/RAII-clang
Feb 24, 2026
Merged

fix SynthesizingCodeRAII for clang-repl#819
Vipul-Cariappa merged 2 commits intocompiler-research:mainfrom
Vipul-Cariappa:dev/RAII-clang

Conversation

@Vipul-Cariappa
Copy link
Copy Markdown
Collaborator

Description

This was a problem with the state of the IntermentalParser in clang.
If the TranslationUnit has some problems, then it is not passed to Execute, and I believe it is not pushed into PTUs.
This is the minimum change that was required to get the tests to pass, in CppInterOp as well as cppyy.
I don't know if we will have problems later when using PCHs and modules.

Maybe we should consider upstreaming this?

Fixes # (issue)

Regression introduced by #787, that cases test_leakcheck.py cppyy test to fail after running for an hour.

Please tick all options which are relevant.

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

Please describe the test(s) that you added and ran to verify your changes.

Checklist

  • I have read the contribution guide recently

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.56%. Comparing base (70e15fd) to head (33241a6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #819   +/-   ##
=======================================
  Coverage   79.56%   79.56%           
=======================================
  Files          11       11           
  Lines        4012     4012           
=======================================
  Hits         3192     3192           
  Misses        820      820           
Files with missing lines Coverage Δ
lib/CppInterOp/Compatibility.h 86.95% <ø> (-0.44%) ⬇️
lib/CppInterOp/CppInterOp.cpp 87.86% <100.00%> (+0.02%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/Compatibility.h 86.95% <ø> (-0.44%) ⬇️
lib/CppInterOp/CppInterOp.cpp 87.86% <100.00%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@vgvassilev
Copy link
Copy Markdown
Contributor

If the TranslationUnit has some problems, then it is not passed to Execute, and I believe it is not pushed into PTUs

That should be the correct behavior. If there is a syntax error, the AST is broken and what code we are expected to jit?

@Vipul-Cariappa
Copy link
Copy Markdown
Collaborator Author

If there is a syntax error, the AST is broken and what code we are expected to jit?

Broken AST is not sent to JIT. So, in theory, the JIT is not in a broken state. Only good ASTs (TranslationUnit) are JITed.

@vgvassilev
Copy link
Copy Markdown
Contributor

If there is a syntax error, the AST is broken and what code we are expected to jit?

Broken AST is not sent to JIT. So, in theory, the JIT is not in a broken state. Only good ASTs (TranslationUnit) are JITed.

Why do we need to reset the diagnostics, if everything was fine?

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@Vipul-Cariappa Vipul-Cariappa force-pushed the dev/RAII-clang branch 2 times, most recently from 7a6af96 to 78241c8 Compare February 23, 2026 10:48
@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

getSema().InstantiateFunctionDefinition(SourceLocation(), FD,
/*Recursive=*/true,
/*DefinitionRequired=*/true);
clang::DiagnosticsEngine& Diags = getSema().getDiagnostics();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need a fixme to move this in a raii.

Copy link
Copy Markdown
Collaborator Author

@Vipul-Cariappa Vipul-Cariappa Feb 23, 2026

Choose a reason for hiding this comment

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

This is the only code path that requires this. Why create a RAII object for a one-off case?

Also, from the last meeting, what I understood is: The SynthesizingCodeRAII class should tackle failures at the JIT level. And to create a new RAII object for this (errors at the parser level). If the "diagnostics reset" is required in other code paths at that point, we should add a new RAII object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think such a raii already exists in Sema.

auto Symbol = compat::getSymbolAddress(I, linker_mangled_name);
llvm::orc::LLJIT& Jit = *compat::getExecutionEngine(I);
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession();
// FIXME: for getMainJITDylib
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This should not be here. Did not plan to commit this. Note to self: remove this.

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Copy Markdown
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Lgtm! Consider squash in merge.

@Vipul-Cariappa Vipul-Cariappa merged commit 33a5ba5 into compiler-research:main Feb 24, 2026
36 checks passed
@Vipul-Cariappa Vipul-Cariappa deleted the dev/RAII-clang branch February 24, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants