From 48c1824304ac2d8aeaef7b8a55c7d9edc8992f63 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Fri, 20 Jun 2014 20:46:00 -0400 Subject: [PATCH] compiler: Add PURE_FUNCTION CC: Rusty Russell Signed-off-by: Cody P Schafer Signed-off-by: Rusty Russell --- ccan/compiler/compiler.h | 14 ++++++++++++++ tools/configurator/configurator.c | 2 ++ 2 files changed, 16 insertions(+) diff --git a/ccan/compiler/compiler.h b/ccan/compiler/compiler.h index 651b47ce..42245646 100644 --- a/ccan/compiler/compiler.h +++ b/ccan/compiler/compiler.h @@ -75,6 +75,20 @@ #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 diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c index 5ba8cb0b..6fa88e5b 100644 --- a/tools/configurator/configurator.c +++ b/tools/configurator/configurator.c @@ -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, -- 2.39.2