Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b1b46a8
Number package names to Memory5 and Memory6
jeongsoolee09 Feb 12, 2026
0f5bb42
Add rule package description files
jeongsoolee09 Feb 12, 2026
ebd28d7
Add rule package files
jeongsoolee09 Feb 12, 2026
b416471
Add test case for Memory5 (RULE-21-6-2)
jeongsoolee09 Feb 12, 2026
fd0479d
Add missing stubs
jeongsoolee09 Feb 13, 2026
2c0f579
Prune unneeded stubs
jeongsoolee09 Feb 15, 2026
ad1ddf1
re-export calloc, realloc, aligned_alloc
jeongsoolee09 Feb 15, 2026
b454890
Forward-declare `tuple` in utility.h and define it in tuple.h
jeongsoolee09 Feb 15, 2026
c7e2e87
Format the stub code and add stdlib.h to test
jeongsoolee09 Feb 17, 2026
3e795fa
Checkpoint
jeongsoolee09 Feb 17, 2026
9d525db
Finalize first draft of Rule 21.6.2
jeongsoolee09 Feb 18, 2026
57e3019
Add cases where the addresses of the APIs in question are taken
jeongsoolee09 Feb 18, 2026
9075324
Address `auto` deduction errors because of overloads
jeongsoolee09 Feb 18, 2026
e33e379
Finalize first draft
jeongsoolee09 Feb 18, 2026
71055d3
Add test cases for RULE-21-6-3
jeongsoolee09 Feb 19, 2026
3c7b4c9
Fix error in stubs
jeongsoolee09 Feb 19, 2026
907f40b
Add missing stubs
jeongsoolee09 Feb 19, 2026
69765a6
Checkpoint
jeongsoolee09 Feb 19, 2026
3293d4f
Mark existing class-specific declarations as false-negative and add c…
jeongsoolee09 Feb 20, 2026
5ccc149
Remove false_negative cases
jeongsoolee09 Feb 20, 2026
e67b7af
Fix a bug in the shared library
jeongsoolee09 Feb 20, 2026
bfba947
Clean up code
jeongsoolee09 Feb 20, 2026
d13d596
Add more cases
jeongsoolee09 Feb 20, 2026
e13583f
Minor readability improvement
jeongsoolee09 Feb 20, 2026
ad387ef
Surround stubs in include guards
jeongsoolee09 Feb 23, 2026
ccd0945
Update expected results of AdvancedMemoryManagementUsed
jeongsoolee09 Feb 23, 2026
1a9f0a1
Fine-tune 21.6.2 to exclude placement-new allocation functions
jeongsoolee09 Feb 23, 2026
d25ef97
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Memory5-Memory6
jeongsoolee09 Feb 23, 2026
77cb804
Fix formatting of test case
jeongsoolee09 Feb 23, 2026
daa4afd
Only forward-declare `std::allocator` in <string>
jeongsoolee09 Feb 23, 2026
b49899d
Update line numbers in ImplicitCapturesDisallowedInNonTransientLambda…
jeongsoolee09 Feb 23, 2026
79b679c
Update line numbers in NonTransientLambdaImplicitlyCapturesThis.expec…
jeongsoolee09 Feb 23, 2026
24b9f37
Exclude compiler-generated RAII destructor calls
jeongsoolee09 Feb 23, 2026
5262b89
Fix stubs
jeongsoolee09 Feb 24, 2026
466eb52
Update expected results of Rule 21.6.2
jeongsoolee09 Feb 24, 2026
304479c
Make a base class OperatorNewOrDelete and use that in 21-6-3
jeongsoolee09 Feb 24, 2026
14ecc2b
Rename file to cpp/standardlibrary/Memory.qll
jeongsoolee09 Feb 24, 2026
28d79b2
Change include guard name
jeongsoolee09 Feb 24, 2026
5a82e00
Fix import path and reuse `OperatorNewOrDelete`
jeongsoolee09 Feb 25, 2026
0f7b0aa
Reword alert messages
jeongsoolee09 Feb 25, 2026
cbd972b
Avoid duplicate alerts on `realloc`
jeongsoolee09 Feb 25, 2026
367b677
Reword alert message from `DynamicMemoryManagedManually`
jeongsoolee09 Feb 25, 2026
e20878d
Omit description from alert of RULE-21-6-2
jeongsoolee09 Feb 25, 2026
f6f6f96
Decrease verbosity of alerts from both queries
jeongsoolee09 Feb 25, 2026
2578910
Fix formatting of query
jeongsoolee09 Feb 25, 2026
dfbd0ea
Impose new hierarchy among operator new / delete
jeongsoolee09 Feb 25, 2026
c3ae6e8
Change referenced class by NonStandardNewOrNewArrayOperator and such
jeongsoolee09 Feb 25, 2026
b6fe7b5
Add a set of compliant cases and update test results
jeongsoolee09 Feb 25, 2026
35854cf
Remove unneeded comments
jeongsoolee09 Feb 26, 2026
7af7e8c
Change labels of take_address_of_class_specific_* tests to NON_COMPLI…
jeongsoolee09 Feb 26, 2026
e966b3b
Update descriptions to better reflect rationale
jeongsoolee09 Feb 26, 2026
56bad09
Revert title of Memory6
jeongsoolee09 Feb 26, 2026
f2630d6
Use the title from rules.csv
jeongsoolee09 Feb 26, 2026
832ff90
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Memory5-Memory6
jeongsoolee09 Feb 26, 2026
325c330
Remove duplicate declaration of `allocator`
jeongsoolee09 Feb 26, 2026
2e1637e
Add correctness and maintainability to the @tags property
jeongsoolee09 Feb 27, 2026
0c1521c
Add missing stub <scoped_allocator>
jeongsoolee09 Feb 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Provides models of functions in <memory> that deals with uninitialized memory.
*/

import cpp

abstract class UninitializedMemoryManagementFunction extends Function {
UninitializedMemoryManagementFunction() {
this.getADeclarationLocation().getFile().getShortName() = "memory"
}
}

class UninitializedCopyFunction extends UninitializedMemoryManagementFunction {
UninitializedCopyFunction() { this.hasQualifiedName("std", "uninitialized_copy") }
}

class UninitializedCopyNFunction extends UninitializedMemoryManagementFunction {
UninitializedCopyNFunction() { this.hasQualifiedName("std", "uninitialized_copy_n") }
}

class UninitializedDefaultConstructFunction extends UninitializedMemoryManagementFunction {
UninitializedDefaultConstructFunction() {
this.hasQualifiedName("std", "uninitialized_default_construct")
}
}

class UninitializedDefaultConstructNFunction extends UninitializedMemoryManagementFunction {
UninitializedDefaultConstructNFunction() {
this.hasQualifiedName("std", "uninitialized_default_construct_n")
}
}

class UninitializedValueConstructFunction extends UninitializedMemoryManagementFunction {
UninitializedValueConstructFunction() {
this.hasQualifiedName("std", "uninitialized_value_construct")
}
}

class UninitializedValueConstructNFunction extends UninitializedMemoryManagementFunction {
UninitializedValueConstructNFunction() {
this.hasQualifiedName("std", "uninitialized_value_construct_n")
}
}

class UninitializedMoveFunction extends UninitializedMemoryManagementFunction {
UninitializedMoveFunction() { this.hasQualifiedName("std", "uninitialized_move") }
}

class UninitializedMoveNFunction extends UninitializedMemoryManagementFunction {
UninitializedMoveNFunction() { this.hasQualifiedName("std", "uninitialized_move_n") }
}

class UninitializedFillFunction extends UninitializedMemoryManagementFunction {
UninitializedFillFunction() { this.hasQualifiedName("std", "uninitialized_fill") }
}

class UninitializedFillNFunction extends UninitializedMemoryManagementFunction {
UninitializedFillNFunction() { this.hasQualifiedName("std", "uninitialized_fill_n") }
}

class DestroyFunction extends UninitializedMemoryManagementFunction {
DestroyFunction() { this.hasQualifiedName("std", "destroy") }
}

class DestroyNFunction extends UninitializedMemoryManagementFunction {
DestroyNFunction() { this.hasQualifiedName("std", "destroy_n") }
}

class DestroyAtFunction extends UninitializedMemoryManagementFunction {
DestroyAtFunction() { this.hasQualifiedName("std", "destroy_at") }
}

class LaunderFunction extends UninitializedMemoryManagementFunction {
LaunderFunction() { this.hasQualifiedName("std", "launder") }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ abstract class CustomOperatorNewOrDelete extends Operator {
exists(getFile().getRelativePath()) and
// Not in a file called `new`, which is likely to be a copy of the standard library
// as it is in our tests
not getFile().getBaseName() = "new"
not forall(File file | file = this.getADeclarationLocation().getFile() |
file.getBaseName() = "new"
) and
(
this.getName().regexpMatch("operator new(\\[\\])?") or
this.getName().regexpMatch("operator delete(\\[\\])?")
)
}

/**
Expand Down
26 changes: 26 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory5.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype Memory5Query = TDynamicMemoryManagedManuallyQuery()

predicate isMemory5QueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
// `Query` instance for the `dynamicMemoryManagedManually` query
Memory5Package::dynamicMemoryManagedManuallyQuery() and
queryId =
// `@id` for the `dynamicMemoryManagedManually` query
"cpp/misra/dynamic-memory-managed-manually" and
ruleId = "RULE-21-6-2" and
category = "required"
}

module Memory5Package {
Query dynamicMemoryManagedManuallyQuery() {
//autogenerate `Query` type
result =
// `Query` type for `dynamicMemoryManagedManually` query
TQueryCPP(TMemory5PackageQuery(TDynamicMemoryManagedManuallyQuery()))
}
}
26 changes: 26 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory6.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype Memory6Query = TAdvancedMemoryManagementUsedQuery()

predicate isMemory6QueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
// `Query` instance for the `advancedMemoryManagementUsed` query
Memory6Package::advancedMemoryManagementUsedQuery() and
queryId =
// `@id` for the `advancedMemoryManagementUsed` query
"cpp/misra/advanced-memory-management-used" and
ruleId = "RULE-21-6-3" and
category = "required"
}

module Memory6Package {
Query advancedMemoryManagementUsedQuery() {
//autogenerate `Query` type
result =
// `Query` type for `advancedMemoryManagementUsed` query
TQueryCPP(TMemory6PackageQuery(TAdvancedMemoryManagementUsedQuery()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import Macros
import Memory2
import Memory3
import Memory4
import Memory5
import Memory6
import MoveForward
import Naming
import Naming2
Expand Down Expand Up @@ -123,6 +125,8 @@ newtype TCPPQuery =
TMemory2PackageQuery(Memory2Query q) or
TMemory3PackageQuery(Memory3Query q) or
TMemory4PackageQuery(Memory4Query q) or
TMemory5PackageQuery(Memory5Query q) or
TMemory6PackageQuery(Memory6Query q) or
TMoveForwardPackageQuery(MoveForwardQuery q) or
TNamingPackageQuery(NamingQuery q) or
TNaming2PackageQuery(Naming2Query q) or
Expand Down Expand Up @@ -198,6 +202,8 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
isMemory2QueryMetadata(query, queryId, ruleId, category) or
isMemory3QueryMetadata(query, queryId, ruleId, category) or
isMemory4QueryMetadata(query, queryId, ruleId, category) or
isMemory5QueryMetadata(query, queryId, ruleId, category) or
isMemory6QueryMetadata(query, queryId, ruleId, category) or
isMoveForwardQueryMetadata(query, queryId, ruleId, category) or
isNamingQueryMetadata(query, queryId, ruleId, category) or
isNaming2QueryMetadata(query, queryId, ruleId, category) or
Expand Down
3 changes: 3 additions & 0 deletions cpp/common/test/includes/standard-library/cstdlib
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ using ::atoll;
using ::exit;
using ::free;
using ::malloc;
using ::calloc;
using ::realloc;
using ::aligned_alloc;
using ::quick_exit;
using ::rand;
using ::strtod;
Expand Down
133 changes: 132 additions & 1 deletion cpp/common/test/includes/standard-library/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _GHLIBCPP_MEMORY
#include "exception.h"
#include "stddef.h"
#include "utility.h"

namespace std {

Expand Down Expand Up @@ -128,6 +129,136 @@ class bad_alloc : public exception {
bad_alloc &operator=(const bad_alloc &) noexcept;
virtual const char *what() const noexcept;
};

template <typename T1> struct allocator {
using value_type = T1;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;

constexpr allocator() noexcept = default;
constexpr allocator(const allocator &) noexcept = default;

template <typename T2> constexpr allocator(const allocator<T2> &) noexcept;

~allocator() = default;

T1 *allocate(std::size_t);
void deallocate(T1 *, std::size_t);
};

template <> struct allocator<void> {
using value_type = void;
};

template <typename T1> struct allocator_traits {
using allocator_type = T1;
using value_type = typename T1::value_type;
using pointer = value_type *;
using const_pointer = const value_type *;
using void_pointer = void *;
using const_void_pointer = const void *;
using size_type = typename T1::size_type;
using difference_type = typename T1::difference_type;

template <typename T2> using rebind_alloc = allocator<T2>;

static pointer allocate(T1 &, size_type);
static pointer allocate(T1 &, size_type, const_void_pointer);
static void deallocate(T1 &, pointer, size_type);
};

// uninitialized_default_construct
template <class T1>
void uninitialized_default_construct(T1, T1);

template <class T1, class T2>
void uninitialized_default_construct(T1&&, T2, T2);

// uninitialized_default_construct_n
template <class T1, class T2>
T1 uninitialized_default_construct_n(T1, T2);

template <class T1, class T2, class T3>
T2 uninitialized_default_construct_n(T1&&, T2, T3);

// uninitialized_value_construct
template <class T1>
void uninitialized_value_construct(T1, T1);

template <class T1, class T2>
void uninitialized_value_construct(T1&&, T2, T2);

// uninitialized_value_construct_n
template <class T1, class T2>
T1 uninitialized_value_construct_n(T1, T2);

template <class T1, class T2, class T3>
T2 uninitialized_value_construct_n(T1&&, T2, T3);

// uninitialized_copy
template <class T1, class T2>
T2 uninitialized_copy(T1, T1, T2);

template <class T1, class T2, class T3>
T3 uninitialized_copy(T1&&, T2, T2, T3);

// uninitialized_copy_n
template <class T1, class T2, class T3>
T3 uninitialized_copy_n(T1, T2, T3);

template <class T1, class T2, class T3, class T4>
T4 uninitialized_copy_n(T1&&, T2, T3, T4);

// uninitialized_move
template <class T1, class T2>
T2 uninitialized_move(T1, T1, T2);

template <class T1, class T2, class T3>
T3 uninitialized_move(T1&&, T2, T2, T3);

// uninitialized_move_n
template <class T1, class T2, class T3>
pair<T1, T3> uninitialized_move_n(T1, T2, T3);

template <class T1, class T2, class T3, class T4>
pair<T2, T4> uninitialized_move_n(T1&&, T2, T3, T4);

// uninitialized_fill
template <class T1, class T2>
void uninitialized_fill(T1, T1, const T2&);

template <class T1, class T2, class T3>
void uninitialized_fill(T1&&, T2, T2, const T3&);

// uninitialized_fill_n
template <class T1, class T2, class T3>
T1 uninitialized_fill_n(T1, T2, const T3&);

template <class T1, class T2, class T3, class T4>
T2 uninitialized_fill_n(T1&&, T2, T3, const T4&);

// destroy_at
template <class T1>
void destroy_at(T1*);

// destroy
template <class T1>
void destroy(T1, T1);

template <class T1, class T2>
void destroy(T1&&, T2, T2);

// destroy_n
template <class T1, class T2>
T1 destroy_n(T1, T2);

template <class T1, class T2, class T3>
T2 destroy_n(T1&&, T2, T3);

// launder
template <class T1>
constexpr T1* launder(T1*) noexcept;

} // namespace std

#endif // _GHLIBCPP_MEMORY
#endif // _GHLIBCPP_MEMORY
1 change: 1 addition & 0 deletions cpp/common/test/includes/standard-library/memory_resource
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <memory_resource.h>
Loading
Loading