From 67ca6e1f887b65fbdac99468b46d416bdfdf7b20 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Mon, 22 May 2017 19:00:19 +0100 Subject: [PATCH] Bug 1365928 - patch 1 - Add a MOZ_NONNULL_RETURN annotation to mfbt/Attributes.h. r=froydnj --- mfbt/Attributes.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index 567f54219d06..d525b26d42ee 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -147,6 +147,21 @@ # define MOZ_NONNULL(...) #endif +/** + * MOZ_NONNULL_RETURN tells the compiler that the function's return value is + * guaranteed to be a non-null pointer, which may enable the compiler to + * optimize better at call sites. + * + * Place this attribute at the end of a function declaration. For example, + * + * char* foo(char *p, char *q) MOZ_NONNULL_RETURN; + */ +#if defined(__GNUC__) || defined(__clang__) +# define MOZ_NONNULL_RETURN __attribute__ ((returns_nonnull)) +#else +# define MOZ_NONNULL_RETURN +#endif + /* * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function * declaration, indicates that for the purposes of static analysis, this