Skip to content

Adds memory allocation analysis functions#1041

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

Adds memory allocation analysis functions#1041
keremsahn wants to merge 3 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

❌ Patch coverage is 98.78049% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.83%. Comparing base (f86ad09) to head (f9a9feb).

Files with missing lines Patch % Lines
lib/CppInterOp/CppInterOp.cpp 98.78% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1041      +/-   ##
==========================================
+ Coverage   86.53%   86.83%   +0.29%     
==========================================
  Files          23       23              
  Lines        5608     5690      +82     
==========================================
+ Hits         4853     4941      +88     
+ Misses        755      749       -6     
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOpTypes.h 96.73% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 89.80% <98.78%> (+0.25%) ⬆️

... and 2 files with indirect coverage changes

Files with missing lines Coverage Δ
include/CppInterOp/CppInterOpTypes.h 96.73% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 89.80% <98.78%> (+0.25%) ⬆️

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

@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
bool VisitVarDecl(VarDecl* VD) {
Expr* expr = VD->getInit();
if (expr)
varMap[VD] = handleExpr(expr, varMap);

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.

Does the handleExpr here cause it to be run 2 times on the same input, because we also have it in VisitBinaryOperator?

@keremsahn keremsahn Jun 25, 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.

These two functions handle different situations.

int* x = new int(n);

AST of this statement:

-DeclStmt <line:16:5, col:24>
|   | `-VarDecl <col:5, col:23> col:10 used x 'int *' cinit
|   |   `-CXXNewExpr <col:14, col:23> 'int *' Function 0x4a8e6ff0 'operator new' 'void *(std::size_t)'
|   |     `-ImplicitCastExpr <col:22> 'int' <LValueToRValue>
|   |       `-DeclRefExpr <col:22> 'int' lvalue ParmVar 0x4a999868 'n' 'int'
y=x;

AST of this:

-BinaryOperator <line:18:5, col:7> 'int *' lvalue '='
|   | |-DeclRefExpr <col:5> 'int *' lvalue Var 0x4a999b10 'y' 'int *'
|   | `-ImplicitCastExpr <col:7> 'int *' <LValueToRValue>
|   |   `-DeclRefExpr <col:7> 'int *' lvalue Var 0x4a9999c8 'x' 'int *'

So basically in variable declarations there is no BinaryOperator node, hence the intersection

@keremsahn keremsahn requested a review from Vipul-Cariappa June 25, 2026 17:49
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