summaryrefslogtreecommitdiff
path: root/src/mongo/platform
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2021-09-22 16:48:31 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-28 02:44:37 +0000
commit7771ad5741a409db9aed5d3da457711d30990cbf (patch)
tree5b6737617b063c82956db2021b03cba17eef5346 /src/mongo/platform
parente5e1f54075866e768d91720d0ec8b584f14f7554 (diff)
downloadmongo-7771ad5741a409db9aed5d3da457711d30990cbf.tar.gz
SERVER-60157 Annotate mongoMalloc and mongoRealloc more aggressively
Diffstat (limited to 'src/mongo/platform')
-rw-r--r--src/mongo/platform/compiler.h21
-rw-r--r--src/mongo/platform/compiler_gcc.h6
-rw-r--r--src/mongo/platform/compiler_msvc.h6
3 files changed, 33 insertions, 0 deletions
diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h
index 0774eb82646..8d03e62250a 100644
--- a/src/mongo/platform/compiler.h
+++ b/src/mongo/platform/compiler.h
@@ -156,6 +156,27 @@
* Tells the compiler that a function returns a value for which consuming the result is
* necessary. Functions thus defined are "must check results" style functions. Preview of the
* `[[nodiscard]]` C++17 attribute.
+ *
+ *
+ * MONGO_COMPILER_RETURNS_NONNULL
+ *
+ * Tells the compiler that the function always returns a non-null value, potentially allowing
+ * additional optimizations at call sites.
+ *
+ *
+ * MONGO_COMPILER_MALLOC
+ *
+ * Tells the compiler that the function is "malloc like", in that the return value points
+ * to uninitialized memory which does not alias any other valid pointers.
+ *
+ *
+ * MONGO_COMPILER_ALLOC_SIZE(varindex)
+ *
+ * Tells the compiler that the parameter indexed by `varindex`
+ * provides the size of the allocated region that a "malloc like"
+ * function will return a pointer to, potentially allowing static
+ * analysis of use of the region when the argument to the
+ * allocation function is a constant expression.
*/
diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h
index 555ea6ccfca..9c1696d415d 100644
--- a/src/mongo/platform/compiler_gcc.h
+++ b/src/mongo/platform/compiler_gcc.h
@@ -95,3 +95,9 @@
#define MONGO_COMPILER_UNREACHABLE __builtin_unreachable()
#define MONGO_COMPILER_NOINLINE [[gnu::noinline]]
+
+#define MONGO_COMPILER_RETURNS_NONNULL [[gnu::returns_nonnull]]
+
+#define MONGO_COMPILER_MALLOC [[gnu::malloc]]
+
+#define MONGO_COMPILER_ALLOC_SIZE(varindex) [[gnu::alloc_size(varindex)]]
diff --git a/src/mongo/platform/compiler_msvc.h b/src/mongo/platform/compiler_msvc.h
index 046cb41e809..1cd0d3bdc9e 100644
--- a/src/mongo/platform/compiler_msvc.h
+++ b/src/mongo/platform/compiler_msvc.h
@@ -70,3 +70,9 @@
#define MONGO_COMPILER_ALWAYS_INLINE __forceinline
#define MONGO_COMPILER_UNREACHABLE __assume(false)
+
+#define MONGO_COMPILER_RETURNS_NONNULL
+
+#define MONGO_COMPILER_MALLOC __declspec(restrict)
+
+#define MONGO_COMPILER_ALLOC_SIZE(varindex)