Adds memory allocation analysis functions#1041
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
... and 2 files with indirect coverage changes
🚀 New features to boost your workflow:
|
| return llvm::isa_and_nonnull<clang::FunctionProtoType>(T); | ||
| } | ||
|
|
||
| static AllocType handleNew(const clang::CXXNewExpr* CNE) { |
There was a problem hiding this comment.
warning: no header providing "Cpp::AllocType" is directly included [misc-include-cleaner]
(T);
^| } | ||
|
|
||
| static AllocType handleCall(const clang::CallExpr* CE) { | ||
| if (auto* FD = CE->getDirectCallee()) { |
There was a problem hiding this comment.
warning: 'auto *FD' can be declared as 'const auto *FD' [readability-qualified-auto]
| if (auto* FD = CE->getDirectCallee()) { | |
| * CE) {const |
| return it->second; | ||
| return AllocType::None; | ||
| } else { | ||
| // FIXME: BindingDecl, NonTypeTemplateParmDecl are not handled |
There was a problem hiding this comment.
warning: do not use 'else' after 'return' [llvm-else-after-return]
else {
^this fix will not be applied because it overlaps with another fix
| } | ||
| }; | ||
| RetStmtVisitor Visitor; | ||
| Visitor.TraverseStmt(const_cast<CompoundStmt*>(CS)); |
There was a problem hiding this comment.
warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]
isitor;
^| } | ||
| }; | ||
| VarVisitor Visitor; | ||
| Visitor.TraverseStmt(const_cast<CompoundStmt*>(CS)); |
There was a problem hiding this comment.
warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]
isitor;
^6aed8ff to
9b5d77a
Compare
… for different branches
75948c0 to
4f9b70f
Compare
Vipul-Cariappa
left a comment
There was a problem hiding this comment.
Minor code quality related comments:
| bool VisitVarDecl(VarDecl* VD) { | ||
| Expr* expr = VD->getInit(); | ||
| if (expr) | ||
| varMap[VD] = handleExpr(expr, varMap); |
There was a problem hiding this comment.
Does the handleExpr here cause it to be run 2 times on the same input, because we also have it in VisitBinaryOperator?
There was a problem hiding this comment.
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
Does not support detection for multiple branches, that is another milestone will be done after discussed.