This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix <mm_malloc.h> on Linux in C++ code


Hi!

pmm_malloc.h (used for <mm_malloc.h> on x86_64-*-linux and i?86-*-linux)
provides its own posix_memalign prototype, as posix_memalign prototype
is only available with -D_XOPEN_SOURCE=600 or -D_GNU_SOURCE in glibc
<stdlib.h>.  That works well in C code, but in C++ we need to make
it extern "C", as glibc doesn't provide _Z14posix_memalignPPvmm
nor _Z14posix_memalignPPvjj and add throw (), as if the stdlib.h
prototype is visible (ATM always, as g++ predefines _GNU_SOURCE),
the one in stdlib.h has throw () (and always had, since its April, 2000
introduction in glibc stdlib.h) while the one in pmm_malloc.h didn't.

The following patch fixes it, ok for trunk/4.1/4.0?

2005-12-28  Jakub Jelinek  <jakub@redhat.com>

	* config/i386/pmm_malloc.h (posix_memalign): If __cplusplus,
	make the prototype extern "C" and add throw ().

	* g++.dg/other/i386-2.C: New test.

--- gcc/config/i386/pmm_malloc.h.jj	2005-10-28 23:05:41.000000000 +0200
+++ gcc/config/i386/pmm_malloc.h	2005-12-28 18:12:40.000000000 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -31,7 +31,11 @@
 
 /* We can't depend on <stdlib.h> since the prototype of posix_memalign
    may not be visible.  */
+#ifndef __cplusplus
 extern int posix_memalign (void **, size_t, size_t);
+#else
+extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+#endif
 
 static __inline void *
 _mm_malloc (size_t size, size_t alignment)
--- gcc/testsuite/g++.dg/other/i386-2.C.jj	2005-12-28 18:16:43.000000000 +0100
+++ gcc/testsuite/g++.dg/other/i386-2.C	2005-12-28 18:17:20.000000000 +0100
@@ -0,0 +1,12 @@
+/* Test that {,x,e,p}mmintrin.h and mm_malloc.h are
+   usable with -pedantic-errors.  */
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-pedantic-errors -msse3" } */
+
+#include <mmintrin.h>
+#include <xmmintrin.h>
+#include <emmintrin.h>
+#include <pmmintrin.h>
+#include <mm_malloc.h>
+
+int dummy;

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]