On Mon, Oct 11, 2010 at 17:17, Chris Lattner <[email protected]> wrote:
>
> On Oct 11, 2010, at 4:57 PM, Matt Beaumont-Gay wrote:
>
>> Here's an updated patch to address Windows portability concerns.
>
> Thanks Matt, this fails a regression test though:
Oops, thanks for catching that. Updated patch attached.
-Matt
>
> FAIL: Clang :: Headers/x86-intrinsics-headers.c (1181 of 2601)
> ******************** TEST 'Clang :: Headers/x86-intrinsics-headers.c' FAILED
> ********************
> Script:
> --
> /Volumes/Projects/cvs/llvm/Debug+Asserts/bin/clang -fsyntax-only
> /Volumes/Projects/cvs/llvm/tools/clang/test/Headers/x86-intrinsics-headers.c
> /Volumes/Projects/cvs/llvm/Debug+Asserts/bin/clang -fsyntax-only
> -fno-lax-vector-conversions
> /Volumes/Projects/cvs/llvm/tools/clang/test/Headers/x86-intrinsics-headers.c
> /Volumes/Projects/cvs/llvm/Debug+Asserts/bin/clang -ccc-clang-cxx -ccc-cxx
> -fsyntax-only -x c++
> /Volumes/Projects/cvs/llvm/tools/clang/test/Headers/x86-intrinsics-headers.c
> --
> Exit Code: 1
> Command Output (stderr):
> --
> In file included from
> /Volumes/Projects/cvs/llvm/tools/clang/test/Headers/x86-intrinsics-headers.c:8:
> /Volumes/Projects/cvs/llvm/Debug+Asserts/lib/clang/2.9/include/mm_malloc.h:35:16:
> error: exception specification in declaration does not match previous
> declaration
> extern "C" int posix_memalign(void **memptr, size_t alignment, size_t size)
> ^
> In file included from
> /Volumes/Projects/cvs/llvm/tools/clang/test/Headers/x86-intrinsics-headers.c:8:
> In file included from
> /Volumes/Projects/cvs/llvm/Debug+Asserts/lib/clang/2.9/include/mm_malloc.h:27:
> /usr/include/stdlib.h:173:7: note: previous declaration is here
> int posix_memalign(void **, size_t, size_t);
> ^
>
>
Index: lib/Headers/mm_malloc.h
===================================================================
--- lib/Headers/mm_malloc.h (revision 116430)
+++ lib/Headers/mm_malloc.h (working copy)
@@ -24,39 +24,48 @@
#ifndef __MM_MALLOC_H
#define __MM_MALLOC_H
-#include <errno.h>
#include <stdlib.h>
-static __inline__ void *__attribute__((__always_inline__, __nodebug__))
+#ifdef _WIN32
+#include <malloc.h>
+#else
+#ifndef __cplusplus
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
+#else
+// Some systems (e.g. those with GNU libc) declare posix_memalign with an
+// exception specifier. Via an "egregious workaround" in
+// Sema::CheckEquivalentExceptionSpec, Clang accepts the following as a valid
+// redeclaration of glibc's declaration.
+extern "C" int posix_memalign(void **memptr, size_t alignment, size_t size);
+#endif
+#endif
+
+static __inline__ void *__attribute__((__always_inline__, __nodebug__,
+ __malloc__))
_mm_malloc(size_t size, size_t align)
{
- if (align & (align - 1)) {
- errno = EINVAL;
- return 0;
+ if (align == 1) {
+ return malloc(size);
}
- if (!size)
- return 0;
+ if (!(align & (align - 1)) && align < sizeof(void *))
+ align = sizeof(void *);
- if (align < 2 * sizeof(void *))
- align = 2 * sizeof(void *);
-
- void *mallocedMemory = malloc(size + align);
- if (!mallocedMemory)
+ void *mallocedMemory;
+#ifdef _WIN32
+ mallocedMemory = _aligned_malloc(size, align);
+#else
+ if (posix_memalign(&mallocedMemory, align, size))
return 0;
+#endif
- void *alignedMemory =
- (void *)(((size_t)mallocedMemory + align) & ~((size_t)align - 1));
- ((void **)alignedMemory)[-1] = mallocedMemory;
-
- return alignedMemory;
+ return mallocedMemory;
}
static __inline__ void __attribute__((__always_inline__, __nodebug__))
_mm_free(void *p)
{
- if (p)
- free(((void **)p)[-1]);
+ free(p);
}
#endif /* __MM_MALLOC_H */
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits