clad icon indicating copy to clipboard operation
clad copied to clipboard

Fix segmentation fault when processing assert statements

Open mohsinm-dev opened this issue 5 months ago • 24 comments

Resolves issue #1442 where Clad would crash with a segfault when differentiating functions containing assert statements. The crash occurred in ReferencesUpdater::updateType() when processing SourceLocExpr nodes that return null QualType values.

Changes:

  • Add null checks in ReferencesUpdater::VisitStmt() before calling updateType()
  • Add defensive null check in ReferencesUpdater::VisitDeclRefExpr() for consistency
  • Add test case to prevent regression

Fixes #1442

mohsinm-dev avatar Jul 27 '25 07:07 mohsinm-dev

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 27 '25 11:07 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 27 '25 13:07 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 27 '25 13:07 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 28 '25 05:07 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 28 '25 10:07 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 29 '25 19:07 github-actions[bot]

@mohsinm-dev, it seems we are almost ready to go. We need to capture the warning that comes with the test cases as an expected warning...

vgvassilev avatar Jul 30 '25 10:07 vgvassilev

@mohsinm-dev, it seems we are almost ready to go. We need to capture the warning that comes with the test cases as an expected warning...

Yes, are these warnings the reason for failed workflows? Let me know what we have to do. I'll look into it.

mohsinm-dev avatar Jul 30 '25 11:07 mohsinm-dev

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jul 31 '25 18:07 github-actions[bot]

@mohsinm-dev, it seems we are almost ready to go. We need to capture the warning that comes with the test cases as an expected warning...

Yes, are these warnings the reason for failed workflows? Let me know what we have to do. I'll look into it.

I've adjusted the test for osx, however, it looks like the current fix is not enough for ubuntu. Can you take a look?

vgvassilev avatar Jul 31 '25 19:07 vgvassilev

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 01 '25 06:08 github-actions[bot]

Your last push undid the changes I made to your branch to fix osx.

vgvassilev avatar Aug 01 '25 06:08 vgvassilev

Your last push undid the changes I made to your branch to fix osx.

Yes, I was trying something. I am working on it. Will push the updates soon. Hopefully that will resolve it.

mohsinm-dev avatar Aug 01 '25 06:08 mohsinm-dev

Your last push undid the changes I made to your branch to fix osx.

Yes, I was trying something. I am working on it. Will push the updates soon. Hopefully that will resolve it.

If you need to debug the runners here is how: https://clad.readthedocs.io/en/latest/user/DevelopersDocumentation.html#debugging-github-runners

vgvassilev avatar Aug 01 '25 07:08 vgvassilev

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 01 '25 07:08 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 01 '25 07:08 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 01 '25 07:08 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 01 '25 15:08 github-actions[bot]

Your last push undid the changes I made to your branch to fix osx.

Yes, I was trying something. I am working on it. Will push the updates soon. Hopefully, that will resolve it.

If you need to debug the runners here is how: https://clad.readthedocs.io/en/latest/user/DevelopersDocumentation.html#debugging-github-runners

Can you guide me a bit? I tried running the debugger, but was unable to connect. I guess there might be some internal fixes that need to be done. I am looking into that and debugging it. Probably will try to wrap up this weekend.

mohsinm-dev avatar Aug 01 '25 23:08 mohsinm-dev

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 02 '25 07:08 github-actions[bot]

Ok, we are getting there. Newer versions fail because it seems we might not be handling properly the PredefinedExpr expression kind. Perhaps you can build locally a newer version of clang and debug?

vgvassilev avatar Aug 02 '25 07:08 vgvassilev

Ok, we are getting there. Newer versions fail because it seems we might not be handling properly the PredefinedExpr expression kind. Perhaps you can build locally a newer version of clang and debug?

You're right about the PredefinedExpr issue. I found that __func__, __FUNCTION__, and __PRETTY_FUNCTION__ return null QualType values, causing segfaults in CloneType(). Fixed by adding null check, also updated the test to cover PredefinedExpr cases.

mohsinm-dev avatar Aug 02 '25 10:08 mohsinm-dev

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 02 '25 19:08 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Aug 03 '25 06:08 github-actions[bot]