[netcf-devel] [PATCH] * src/ref.h (ref_make_ref): prevent inlining
David Lutterkort
lutter at redhat.com
Fri Aug 14 00:31:33 UTC 2009
The assignment to '*(void **) ptrptr' makes gcc think it breaks strict
aliasing, and produces a compilation error when ref_make_ref is inlined.
---
src/internal.h | 4 ++++
src/ref.h | 6 +++++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/src/internal.h b/src/internal.h
index a11648b..3e1603a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -70,11 +70,15 @@
#endif
#endif
+#ifndef ATTRIBUTE_NOINLINE
+#define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
+#endif
#else
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_FORMAT(...)
#define ATTRIBUTE_PURE
#define ATTRIBUTE_RETURN_CHECK
+#define ATTRIBUTE_NOINLINE
#endif /* __GNUC__ */
/* This needs ATTRIBUTE_RETURN_CHECK */
diff --git a/src/ref.h b/src/ref.h
index f9faab7..3a84df9 100644
--- a/src/ref.h
+++ b/src/ref.h
@@ -44,7 +44,11 @@
typedef unsigned int ref_t;
-ATTRIBUTE_UNUSED ATTRIBUTE_RETURN_CHECK
+/* Prevent this function from being inlined; the compiler thinks that the
+ * assignment to PTRPTR breaks strict aliasing - it does not since we know
+ * that ptrptr is already of type (T **)
+ */
+ATTRIBUTE_UNUSED ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NOINLINE
static int ref_make_ref(void *ptrptr, size_t size, size_t ref_ofs) {
*(void**) ptrptr = calloc(1, size);
if (*(void **)ptrptr == NULL) {
--
1.6.2.5
More information about the netcf-devel
mailing list