Skip to content

[SYCL][PostLink] Fix Coverity issues in SYCLPostLink.cpp#21573

Open
hchilama wants to merge 19 commits intointel:syclfrom
hchilama:fix/sycl-postlink-coverity-issues
Open

[SYCL][PostLink] Fix Coverity issues in SYCLPostLink.cpp#21573
hchilama wants to merge 19 commits intointel:syclfrom
hchilama:fix/sycl-postlink-coverity-issues

Conversation

@hchilama
Copy link
Contributor

@hchilama hchilama commented Mar 20, 2026

The below summary is generated by Claud but I followed the human in the middle policy to review each and every step that AI made.

Summary

This PR fixes critical Coverity static analysis issues in SYCLPostLink.cpp:

Issues Fixed

  1. Memory Leak - Fixed resource leak in performPostLinkProcessing

    • Removed unnecessary MD.release() call at line 184 that was leaking ModuleDesc pointer
    • The unique_ptr now properly manages memory cleanup automatically
  2. Uninitialized Properties - Fixed uninitialized data access in saveModuleDesc

    • Initialize SplitModule with {} for proper value-initialization

Changes Made

  • lib/SYCLPostLink/SYCLPostLink.cpp:
    • Line 52: Changed SM; to SM{}; for explicit initialization
    • Line 183: Removed MD.release(); that was causing memory leak

Test Plan

  • ✅ Built successfully using python buildbot/compile.py
  • ✅ No compilation errors or warnings
  • ✅ All 3984 build steps completed successfully
  • ✅ Code properly deployed to toolchain

Assisted-by: Claude AI

@hchilama hchilama requested a review from a team as a code owner March 20, 2026 00:55
This commit addresses critical Coverity static analysis issues:

1. Fixed memory leak in performPostLinkProcessing:
   - Removed unnecessary MD.release() call that was leaking ModuleDesc
   - The unique_ptr now properly manages memory cleanup

2. Fixed uninitialized data in saveModuleDesc:
   - Initialize SplitModule with {} for proper value-initialization

These changes prevent potential memory leaks and undefined behavior.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@hchilama hchilama force-pushed the fix/sycl-postlink-coverity-issues branch from 0b0ff45 to 0afc179 Compare March 20, 2026 01:02
@hchilama hchilama requested a review from maksimsab March 20, 2026 01:06
Copy link
Contributor

@YuriPlyakhin YuriPlyakhin left a comment

Choose a reason for hiding this comment

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

I'm wondering was any AI tool used to prepare this PR?

@hchilama
Copy link
Contributor Author

hchilama commented Mar 20, 2026

Yes @YuriPlyakhin I just started using Claude and thought to try it on Coverity issues and it worked.

@YuriPlyakhin
Copy link
Contributor

Yes @YuriPlyakhin I just started using Claude and thought to try it on Coverity issues and it worked.

@hchilama , could you, please, follow https://llvm.org/docs/AIToolPolicy.html

if (!SplitImageOrErr)
return SplitImageOrErr.takeError();

MD.release();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can agree. release() function just returns the pointer so that a caller is responsible to destroy the resource which is obviously not happen here. The best solution would be to do:

MD.reset();

This way unique_ptr would destroy the object.
In overall, this is done this way because IRs are fat and we want to release used RAM as soon as possible.

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 thought deleting the object when the pointer goes out of scope would be the safest if there is any early returns. But sure I can make sure the pointer to release sooner with reset() .

llvm::sycl_post_link::saveModuleDesc(module_split::ModuleDesc &MD,
std::string Prefix, bool OutputAssembly) {
module_split::SplitModule SM;
module_split::SplitModule SM{};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't agree. Coverity complains about the problem with NumBuckets being uninitialized in destructor which is true. I am not sure that your change resolves the problem.

It looks like the problem was introduced recently while DenseMap has been changing over last several months. It can be tracked in git blame or here llvm/llvm-project#168255

I think this is better to raise this concern to appropriate folks in LLVM by github issue or, probably, email to some author that has been doing that work recently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, may be we can do that. I usually follow the Coverity BKM rules and make this as a "False Positive" in the scan. while the Coverity flags this as a uninitialized, but the members are safely initialized by the constructor. If that is ok, I can update the comments in the scan.

@hchilama
Copy link
Contributor Author

Yes @YuriPlyakhin I just started using Claude and thought to try it on Coverity issues and it worked.

@hchilama , could you, please, follow https://llvm.org/docs/AIToolPolicy.html

Thanks @YuriPlyakhin . I reviewed the document and edit the commit. Please take a look.

@hchilama hchilama requested a review from maksimsab March 20, 2026 17:34
Copy link
Contributor

@YuriPlyakhin YuriPlyakhin left a comment

Choose a reason for hiding this comment

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

I'm ok with the fix, but I'll let @maksimsab to approve, as he was working on this code.

please, see below

return SplitImageOrErr.takeError();

MD.release();
Md.reset();
Copy link
Contributor

@YuriPlyakhin YuriPlyakhin Mar 20, 2026

Choose a reason for hiding this comment

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

Does this compile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, sorry typo.

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.

3 participants