[m-rev.] diff: fix inlining macros for clang

Julien Fischer jfischer at opturion.com
Tue Mar 25 14:51:48 AEDT 2014


Branches: master, 14.01

----------------------------


Fix up inlining macros for clang.

Currently we use the C89 definitions of MR_STATIC_INLINE and friends with
clang, which is less than ideal in a couple of ways, firstly we might not get
as much inlining as we would like and secondly, for clang, it causes large
numbers of warnings about unused functions to be generated.

Using GNU C style inlining does not work because we enable the -ansi option
when using clang and the (current) behaviour of the -ansi option with clang is
to enforce strict C89 conformance (i.e. disable any GNU C extensions.).

This change avoids all of the above by (1) adding C99 style definitions of
MR_STATIC_INLINE etc for clang and (2) not passing -ansi to clang (i.e. putting
clang into c99, or technically gnu99, mode).  We fall back on the C89 style
definitions if the user does something odd like setting -ansi or -std=c89
themselves.

runtime/mercury_std.h:
 	Define MR_STATIC_INLINE and friends for clang in the case where clang
 	is in C99 (or equivalent) mode.

configure.ac:
 	Set CFLAGS_FOR_ANSI for clang to empty.  Add an explanation of why
 	we do this.

scripts/mgnuc.in:
 	Don't pass -ansi to clang.

Julien.

diff --git a/configure.ac b/configure.ac
index 27c6f8b..f45bf66 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4649,6 +4649,11 @@ case "$mercury_cv_cc_type" in
          ;;

      clang*)
+
+        # We do not compile with -ansi when using clang because that (currently) puts
+        # clang into C89 mode and we want to use C99's inline keyword with clang.
+        CFLAGS_FOR_ANSI=
+
          # XXX we need go through the warning and optimization options for clang
          # more carefully.
          CFLAGS_FOR_WARNINGS="-w"
diff --git a/runtime/mercury_std.h b/runtime/mercury_std.h
index 0f68690..dcfd96c 100644
--- a/runtime/mercury_std.h
+++ b/runtime/mercury_std.h
@@ -162,14 +162,23 @@ typedef	char		MR_small_bool;
    #define MR_EXTERN_INLINE		inline
    #define MR_OUTLINE_DEFN(DECL,BODY)
  #elif defined(MR_CLANG)
-  /* clang: note that since clang also defines the macro __GNUC__
-  ** we must handle it before we handle the GCC case.
-  ** XXX why don't the C99 definitions work for clang?
-  */
-  #define MR_STATIC_INLINE		static
-  #define MR_INLINE			static
-  #define MR_EXTERN_INLINE		static
-  #define MR_OUTLINE_DEFN(DECL,BODY)
+  #if __STDC_VERSION__ >= 199901
+    /* C99 style inlining. */
+    #define MR_STATIC_INLINE	        static inline
+    #define MR_INLINE			static inline
+    #define MR_EXTERN_INLINE		inline
+    #define MR_OUTLINE_DEFN(DECL,BODY)	extern DECL;
+  #else
+   /*
+   ** C89: note that by default we use clang in C99 mode so this alternative
+   ** will only be used if user explicitly sets -std to use something prior
+   ** to C99.
+   */
+   #define MR_STATIC_INLINE		static
+   #define MR_INLINE			static
+   #define MR_EXTERN_INLINE		static
+   #define MR_OUTLINE_DEFN(DECL,BODY)
+  #endif
  #elif defined(MR_GNUC)
    /* GNU C: in (GNU) C99 or later mode GCC will use C99 style
    ** inline functions; otherwise GNU style inline functions will
diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in
index 42d7041..fc1833b 100644
--- a/scripts/mgnuc.in
+++ b/scripts/mgnuc.in
@@ -72,7 +72,7 @@ case "$C_COMPILER_TYPE" in
          COMPILER=gcc
          ;;
      clang*)
-        ANSI_OPTS="-ansi"
+        ANSI_OPTS=
          CHECK_OPTS="-w"
          OPT_OPTS="@OPT_FLAGS_FOR_CLANG@ $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
          DEBUG_OPT="-g"





More information about the reviews mailing list