compiler: Add PURE_FUNCTION
authorCody P Schafer <dev@codyps.com>
Sat, 21 Jun 2014 00:46:00 +0000 (20:46 -0400)
committerRusty Russell <rusty@rustcorp.com.au>
Sat, 21 Jun 2014 04:47:20 +0000 (14:17 +0930)
CC: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/compiler/compiler.h
tools/configurator/configurator.c

index 651b47cee9dcd611ad7c8513d92ec06ba852bb63..42245646c42ff772bcc6376ffc54ac79a1c1aca1 100644 (file)
 #else
 #define CONST_FUNCTION
 #endif
+
+#ifndef PURE_FUNCTION
+#if HAVE_ATTRIBUTE_PURE
+/**
+ * PURE_FUNCTION - a function is pure
+ *
+ * A pure function is one that has no side effects other than it's return value
+ * and uses no inputs other than it's arguments and global variables.
+ */
+#define PURE_FUNCTION __attribute__((__pure__))
+#else
+#define PURE_FUNCTION
+#endif
+#endif
 #endif
 
 #if HAVE_ATTRIBUTE_UNUSED
index 5ba8cb0bb0c780a54849a8137187d22b647a62da..6fa88e5b071fa6d80faf1fb4cfdeca8565e77b55 100644 (file)
@@ -79,6 +79,8 @@ static struct test tests[] = {
          "static int __attribute__((cold)) func(int x) { return x; }" },
        { "HAVE_ATTRIBUTE_CONST", DEFINES_FUNC, NULL, NULL,
          "static int __attribute__((const)) func(int x) { return x; }" },
+       { "HAVE_ATTRIBUTE_PURE", DEFINES_FUNC, NULL, NULL,
+         "static int __attribute__((pure)) func(int x) { return x; }" },
        { "HAVE_ATTRIBUTE_MAY_ALIAS", OUTSIDE_MAIN, NULL, NULL,
          "typedef short __attribute__((__may_alias__)) short_a;" },
        { "HAVE_ATTRIBUTE_NORETURN", DEFINES_FUNC, NULL, NULL,