Bug 1131783 - Optimize away null checks in non-POD Vectors too r=waldo
authorDan Gohman <sunfish@mozilla.com>
Thu, 12 Feb 2015 08:37:01 -0800
changeset 229201 3571f361d77949bf19e77237bc5061010ee22ea3
parent 229200 588d1e20a4bb0f29af8dcdd8e7c75296fd0c5f5d
child 229202 0b376024e3e00d5af9a1e49cc47c673309913e5a
push id28282
push usercbook@mozilla.com
push dateMon, 16 Feb 2015 15:06:35 +0000
treeherdermozilla-central@09f4968d5f42 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1131783
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1131783 - Optimize away null checks in non-POD Vectors too r=waldo
mfbt/Attributes.h
mfbt/Vector.h
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -207,16 +207,32 @@
  *   MOZ_COLD int foo() { return 42; }
  */
 #if defined(__GNUC__) || defined(__clang__)
 #  define MOZ_COLD __attribute__ ((cold))
 #else
 #  define MOZ_COLD
 #endif
 
+/**
+ * MOZ_NONNULL tells the compiler that some of the arguments to a function are
+ * known to be non-null. The arguments are a list of 1-based argument indexes
+ * identifying arguments which are known to be non-null.
+ *
+ * Place this attribute at the very beginning of a function definition. For
+ * example, write
+ *
+ *   MOZ_NONNULL(1, 2) int foo(char *p, char *q);
+ */
+#if defined(__GNUC__) || defined(__clang__)
+#  define MOZ_NONNULL(...) __attribute__ ((nonnull(__VA_ARGS__)))
+#else
+#  define MOZ_NONNULL(...)
+#endif
+
 /*
  * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function
  * declaration, indicates that for the purposes of static analysis, this
  * function does not return.  (The function definition does not need to be
  * annotated.)
  *
  * MOZ_ReportCrash(const char* s, const char* file, int ln)
  *   MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS
--- a/mfbt/Vector.h
+++ b/mfbt/Vector.h
@@ -53,25 +53,27 @@ static bool CapacityHasExcessSpace(size_
  * when the element type is not known to be a POD, as judged by IsPod.
  */
 template<typename T, size_t N, class AP, class ThisVector, bool IsPod>
 struct VectorImpl
 {
   /*
    * Constructs a default object in the uninitialized memory at *aDst.
    */
+  MOZ_NONNULL(1)
   static inline void new_(T* aDst)
   {
     new(aDst) T();
   }
 
   /*
    * Constructs an object in the uninitialized memory at *aDst from aSrc.
    */
   template<typename U>
+  MOZ_NONNULL(1)
   static inline void new_(T* aDst, U&& aU)
   {
     new(aDst) T(Forward<U>(aU));
   }
 
   /* Destroys constructed objects in the range [aBegin, aEnd). */
   static inline void destroy(T* aBegin, T* aEnd)
   {