Skip to content

Support function try-catch blocks in AnalyzeAllocType and AnalyzeDeallocType - #1186

Open
sumitsaraswat362 wants to merge 3 commits into
compiler-research:mainfrom
sumitsaraswat362:fix-1061-support-try-catch-in-alloc-analyzers
Open

sumitsaraswat362 wants to merge 3 commits into
compiler-research:mainfrom
sumitsaraswat362:fix-1061-support-try-catch-in-alloc-analyzers

Conversation

@sumitsaraswat362

Copy link
Copy Markdown

Description

Traverse function body statements directly instead of requiring a CompoundStmt, allowing function-level try-catch blocks to be properly analyzed for allocation and deallocation behavior.

Fixes #1061

Type of change

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

Updated existing func16 test in unittests/CppInterOp/FunctionReflectionTest.cpp to expect New instead of Unknown, and added func46 to verify deallocation within a function try-block.

Checklist

  • I have read the contribution guide recently

…locType

Traverse function body statements directly instead of requiring a CompoundStmt, allowing function-level try-catch blocks to be properly analyzed for allocation and deallocation.

@github-actions github-actions Bot left a comment

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.

clang-tidy made some suggestions

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
for (auto* parm : Fn->parameters())
Traverser.VisitVarDecl(parm);
Traverser.TraverseStmt(const_cast<clang::CompoundStmt*>(CmpStmt));
Traverser.TraverseStmt(const_cast<clang::Stmt*>(fnBody));

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.

warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]

VisitVarDecl(parm);
                                             ^

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
valPerParam.assign(numParam, DeallocType::None);
DeallocationTraverser Traverser(valPerParam, visitedFuncs);
Traverser.TraverseStmt(const_cast<CompoundStmt*>(CmpStmt));
Traverser.TraverseStmt(const_cast<Stmt*>(S));

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.

warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]

ram, visitedFuncs);
                                             ^

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.85%. Comparing base (3ab124a) to head (8858d05).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1186      +/-   ##
==========================================
- Coverage   88.86%   88.85%   -0.02%     
==========================================
  Files          24       24              
  Lines        7014     7006       -8     
==========================================
- Hits         6233     6225       -8     
  Misses        781      781              
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 91.21% <100.00%> (-0.02%) ⬇️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 91.21% <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! 👍"

This branch has not been deployed

No deployments
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.

[Bug]: AnalyzeAllocType does not analyze try catch blocks

1 participant