|
14 | 14 | import cpp |
15 | 15 | import codingstandards.cpp.misra |
16 | 16 |
|
17 | | -from |
| 17 | +/** |
| 18 | + * A function that has namespace `std` and has name `allocate` or `deallocate`, including but not limited to: |
| 19 | + * - `std::allocator<T>::allocate(std::size_t)` |
| 20 | + * - `std::allocator<T>::dellocate(T*, std::size_t)` |
| 21 | + * - `std::pmr::memory_resource::allocate(std::size_t, std::size_t)` |
| 22 | + * - `std::pmr::memory_resource::allocate(std::size_t, std::size_t)` |
| 23 | + */ |
| 24 | +class AllocateOrDeallocateStdlibMemberFunction extends MemberFunction { |
| 25 | + AllocateOrDeallocateStdlibMemberFunction() { |
| 26 | + this.getName() in ["allocate", "deallocate"] and |
| 27 | + this.getNamespace().getParentNamespace*() instanceof StdNamespace |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * The `std::aligned_alloc` (`<cstdlib>`) or `::aligned_alloc` (`<stdlib.h>`) function. |
| 33 | + */ |
| 34 | +class AlignedAlloc extends Function { |
| 35 | + AlignedAlloc() { this.hasGlobalOrStdName("aligned_alloc") } |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * An expression that wraps `Alloc::isMemoryManagementExpr/0` and adds calls to `aligned_alloc` |
| 40 | + * to the set detected by it. |
| 41 | + */ |
| 42 | +class MemoryManagementExpr extends Expr { |
| 43 | + MemoryManagementExpr() { |
| 44 | + isMemoryManagementExpr(this) or this.(FunctionCall).getTarget() instanceof AlignedAlloc |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +from Expr expr |
18 | 49 | where |
19 | | - not isExcluded(x, Memory5Package::dynamicMemoryManagedManuallyQuery()) and |
20 | | -select |
| 50 | + not isExcluded(expr, Memory5Package::dynamicMemoryManagedManuallyQuery()) and |
| 51 | + ( |
| 52 | + /* ===== 1. The expression is a use of non-placement `new`/ `new[]`, or a `delete`. ===== */ |
| 53 | + /* ===== 2. The expression is a call to malloc / calloc / or to `free`. ===== */ |
| 54 | + expr instanceof MemoryManagementExpr |
| 55 | + or |
| 56 | + /* ===== 3. The expression is a call to a member function named `allocate` or `deallocate` in namespace `std`. ===== */ |
| 57 | + expr.(FunctionCall).getTarget() instanceof AllocateOrDeallocateStdlibMemberFunction |
| 58 | + or |
| 59 | + /* ===== 4. The expression is a ==== */ |
| 60 | + none() |
| 61 | + ) |
| 62 | +select expr, "TODO" |
0 commit comments