Skip to content

Adds memory allocation analysis functions#1041

Open
keremsahn wants to merge 5 commits into
compiler-research:mainfrom
keremsahn:alloc-detect
Open

Adds memory allocation analysis functions#1041
keremsahn wants to merge 5 commits into
compiler-research:mainfrom
keremsahn:alloc-detect

Conversation

@keremsahn

Copy link
Copy Markdown
Contributor

Does not support detection for multiple branches, that is another milestone will be done after discussed.

@keremsahn

Copy link
Copy Markdown
Contributor Author

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.92%. Comparing base (91a0c1e) to head (750e0f4).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1041      +/-   ##
==========================================
+ Coverage   86.62%   86.92%   +0.29%     
==========================================
  Files          23       23              
  Lines        5946     6028      +82     
==========================================
+ Hits         5151     5240      +89     
+ Misses        795      788       -7     
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOpTypes.h 96.90% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 89.40% <100.00%> (+0.28%) ⬆️

... and 2 files with indirect coverage changes

Files with missing lines Coverage Δ
include/CppInterOp/CppInterOpTypes.h 96.90% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 89.40% <100.00%> (+0.28%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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

return llvm::isa_and_nonnull<clang::FunctionProtoType>(T);
}

static AllocType handleNew(const clang::CXXNewExpr* CNE) {

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: no header providing "Cpp::AllocType" is directly included [misc-include-cleaner]

(T);
               ^

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
}

static AllocType handleCall(const clang::CallExpr* CE) {
if (auto* FD = CE->getDirectCallee()) {

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: 'auto *FD' can be declared as 'const auto *FD' [readability-qualified-auto]

Suggested change
if (auto* FD = CE->getDirectCallee()) {
* CE) {const

Comment thread lib/CppInterOp/CppInterOp.cpp
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
return it->second;
return AllocType::None;
} else {
// FIXME: BindingDecl, NonTypeTemplateParmDecl are not handled

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 'else' after 'return' [llvm-else-after-return]

 else {
 ^

this fix will not be applied because it overlaps with another fix

Comment thread lib/CppInterOp/CppInterOp.cpp
}
};
RetStmtVisitor Visitor;
Visitor.TraverseStmt(const_cast<CompoundStmt*>(CS));

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]

isitor;
                               ^

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
}
};
VarVisitor Visitor;
Visitor.TraverseStmt(const_cast<CompoundStmt*>(CS));

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]

isitor;
                               ^

@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
@keremsahn keremsahn force-pushed the alloc-detect branch 2 times, most recently from 6aed8ff to 9b5d77a Compare June 23, 2026 14:20
Comment thread lib/CppInterOp/CppInterOp.td Outdated
Comment thread unittests/CppInterOp/FunctionReflectionTest.cpp
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
@keremsahn keremsahn force-pushed the alloc-detect branch 3 times, most recently from 75948c0 to 4f9b70f Compare June 24, 2026 19:26

@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
Comment thread lib/CppInterOp/CppInterOp.cpp
@keremsahn keremsahn requested a review from Vipul-Cariappa June 24, 2026 19:58
@keremsahn keremsahn force-pushed the alloc-detect branch 2 times, most recently from 1d246fc to 207c373 Compare June 25, 2026 11:31

@Vipul-Cariappa Vipul-Cariappa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor code quality related comments:

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp
@keremsahn keremsahn requested a review from Vipul-Cariappa June 25, 2026 17:49

@Vipul-Cariappa Vipul-Cariappa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Small formatting thing. Please rebase so that I can merge.

I have a question:
What happens if we analyse the following:

int* heap_alloc_tail_recr_sum(int n, int acc = 0) {
    if (n)
        return heap_alloc_tail_recr_sum(n - 1, acc + n);
    return new int(acc);
}

If this does not work, please open an issue for it once this PR is merged.

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment on lines +1605 to +1607
if (const auto* CE = dyn_cast<CallExpr>(finExpr)) {
return handleCall(CE);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (const auto* CE = dyn_cast<CallExpr>(finExpr)) {
return handleCall(CE);
}
if (const auto* CE = dyn_cast<CallExpr>(finExpr))
return handleCall(CE);

@keremsahn keremsahn force-pushed the alloc-detect branch 2 times, most recently from 38da0c7 to 6e87954 Compare July 3, 2026 11:46

bool VisitBinaryOperator(clang::BinaryOperator* BO) {
if (BO->getOpcode() != BO_Assign)
return true;

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.

Can we add coverage for this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi Vassil, I added one check the fourth commit. Our first assumption was analyzed function does not leak memory, but i wrote the test this way to point the issue so maybe I can fix it later.

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.

Can we add a comment capturing that intent?

@keremsahn keremsahn Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually I added a FIXME up to the

TESTAC(27, NewArr);

Furthermore, I will open some issues I want to work on when the PR is merged, I can open for this one too. No worries

@keremsahn keremsahn changed the title Adds memory allocation analysis functions Adds memory deallocation analysis functions Jul 6, 2026
@keremsahn keremsahn changed the title Adds memory deallocation analysis functions Adds memory allocation analysis functions Jul 6, 2026
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