[llvm] r185831 - Use Clang's __has_* macros in Compiler.h to test for features

Reid Kleckner rnk at google.com
Mon Jul 8 09:39:41 PDT 2013


Prospective fix in r185833.

I can't reproduce the bot problem locally when building clang with a
~month-old clang.  Is there anything special about that bot?  Is it
building with a clang from XCode, maybe?

I also didn't receive any mail or IRC notifications about the failure.  Is
that a known issue?


On Mon, Jul 8, 2013 at 12:08 PM, David Dean <david_dean at apple.com> wrote:

> This commit has broken some of the buildbots:
>
>
> http://lab.llvm.org:8013/builders/clang-x86_64-darwin11-nobootstrap-RAincremental/builds/4079
>
> /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin11-nobootstrap-RAincremental/llvm/include/llvm/Support/Compiler.h:204:5:
> error: builtin feature check macro requires a parenthesized identifier
> #if __has_attribute(const) || defined(__GNUC__)
>     ^
> /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin11-nobootstrap-RAincremental/llvm/include/llvm/Support/Compiler.h:204:26:
> error: expected end of line in preprocessor expression
>
> Please fix or revert as soon as you can.
>
> On 8 Jul 2013, at 8:31 AM, Reid Kleckner <reid at kleckner.net> wrote:
>
> > Author: rnk
> > Date: Mon Jul  8 10:31:29 2013
> > New Revision: 185831
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=185831&view=rev
> > Log:
> > Use Clang's __has_* macros in Compiler.h to test for features
> >
> > When targetting Windows, clang does not define __GNUC__, and as a result
> > we don't use our attributes with it.  This leads to warnings about
> > unused functions that are already annotated with LLVM_ATTRIBUTE_UNUSED.
> > Rather than testing for __clang__, we can use its __has_attribute and
> > __has_builtin macros directlty.
> >
> > While I'm here, conditionally define and use __GNUC_PREREQ for gcc
> > version checks.  Spelling the check out with three comparisons is
> > verbose and error prone.
> >
> > Reviewers: aaron.ballman
> >
> > Differential Revision: http://llvm-reviews.chandlerc.com/D1080
> >
> > Modified:
> >    llvm/trunk/include/llvm/Support/Compiler.h
> >
> > Modified: llvm/trunk/include/llvm/Support/Compiler.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=185831&r1=185830&r2=185831&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/Support/Compiler.h (original)
> > +++ llvm/trunk/include/llvm/Support/Compiler.h Mon Jul  8 10:31:29 2013
> > @@ -21,6 +21,25 @@
> > # define __has_feature(x) 0
> > #endif
> >
> > +#ifndef __has_attribute
> > +# define __has_attribute(x) 0
> > +#endif
> > +
> > +#ifndef __has_builtin
> > +# define __has_builtin(x) 0
> > +#endif
> > +
> > +/// \macro __GNUC_PREREQ
> > +/// \brief Defines __GNUC_PREREQ if glibc's features.h isn't available.
> > +#ifndef __GNUC_PREREQ
> > +# if defined(__GNUC__) && defined(__GNUC_MINOR__)
> > +#  define __GNUC_PREREQ(maj, min) \
> > +    ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
> > +# else
> > +#  define __GNUC_PREREQ(maj, min) 0
> > +# endif
> > +#endif
> > +
> > /// \brief Does the compiler support r-value references?
> > /// This implies that <utility> provides the one-argument std::move;  it
> > /// does not imply the existence of any other C++ library features.
> > @@ -146,13 +165,15 @@
> > /// into a shared library, then the class should be private to the
> library and
> > /// not accessible from outside it.  Can also be used to mark variables
> and
> > /// functions, making them private to any shared library they are linked
> into.
> > -#if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
> > +/// On PE/COFF targets, library visibility is the default, so this
> isn't needed.
> > +#if (__has_attribute(visibility) || __GNUC_PREREQ(4, 0)) &&
>        \
> > +    !defined(__MINGW32__) && !defined(__CYGWIN__) &&
> !defined(LLVM_ON_WIN32)
> > #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
> > #else
> > #define LLVM_LIBRARY_VISIBILITY
> > #endif
> >
> > -#if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
> > +#if __has_attribute(used) || __GNUC_PREREQ(3, 1)
> > #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
> > #else
> > #define LLVM_ATTRIBUTE_USED
> > @@ -166,31 +187,35 @@
> > // more portable solution:
> > //   (void)unused_var_name;
> > // Prefer cast-to-void wherever it is sufficient.
> > -#if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
> > +#if __has_attribute(unused) || __GNUC_PREREQ(3, 1)
> > #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
> > #else
> > #define LLVM_ATTRIBUTE_UNUSED
> > #endif
> >
> > -#if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
> > +// FIXME: Provide this for PE/COFF targets.
> > +#if (__has_attribute(weak) || __GNUC_PREREQ(4, 0)) &&
>        \
> > +    (!defined(__MINGW32__) && !defined(__CYGWIN__) &&
> !defined(LLVM_ON_WIN32))
> > #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
> > #else
> > #define LLVM_ATTRIBUTE_WEAK
> > #endif
> >
> > -#ifdef __GNUC__ // aka 'CONST' but following LLVM Conventions.
> > +#if __has_attribute(const) || defined(__GNUC__)
> > +// aka 'CONST' but following LLVM Conventions.
> > #define LLVM_READNONE __attribute__((__const__))
> > #else
> > #define LLVM_READNONE
> > #endif
> >
> > -#ifdef __GNUC__  // aka 'PURE' but following LLVM Conventions.
> > +#if __has_attribute(pure) || defined(__GNUC__)
> > +// aka 'PURE' but following LLVM Conventions.
> > #define LLVM_READONLY __attribute__((__pure__))
> > #else
> > #define LLVM_READONLY
> > #endif
> >
> > -#if (__GNUC__ >= 4)
> > +#if __has_builtin(__builtin_expect) || __GNUC_PREREQ(4, 0)
> > #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
> > #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
> > #else
> > @@ -213,7 +238,7 @@
> >
> > /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to
> do so,
> > /// mark a method "not for inlining".
> > -#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
> > +#if __has_attribute(noinline) || __GNUC_PREREQ(3, 4)
> > #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
> > #elif defined(_MSC_VER)
> > #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
> > @@ -225,7 +250,7 @@
> > /// so, mark a method "always inline" because it is performance
> sensitive. GCC
> > /// 3.4 supported this but is buggy in various cases and produces
> unimplemented
> > /// errors, just use it in GCC 4.0 and later.
> > -#if __GNUC__ > 3
> > +#if __has_attribute(always_inline) || __GNUC_PREREQ(4, 0)
> > #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
> __attribute__((always_inline))
> > #elif defined(_MSC_VER)
> > #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
> > @@ -267,8 +292,7 @@
> > /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
> > /// to an expression which states that it is undefined behavior for the
> > /// compiler to reach this point.  Otherwise is not defined.
> > -#if defined(__clang__) || (__GNUC__ > 4) \
> > - || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
> > +#if __has_builtin(__builtin_unreachable) || __GNUC_PREREQ(4, 5)
> > # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
> > #elif defined(_MSC_VER)
> > # define LLVM_BUILTIN_UNREACHABLE __assume(false)
> > @@ -276,8 +300,7 @@
> >
> > /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an
> expression
> > /// which causes the program to exit abnormally.
> > -#if defined(__clang__) || (__GNUC__ > 4) \
> > - || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
> > +#if __has_builtin(__builtin_trap) || __GNUC_PREREQ(4, 3)
> > # define LLVM_BUILTIN_TRAP __builtin_trap()
> > #else
> > # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
> > @@ -285,11 +308,10 @@
> >
> > /// \macro LLVM_ASSUME_ALIGNED
> > /// \brief Returns a pointer with an assumed alignment.
> > -#if !defined(__clang__) && ((__GNUC__ > 4) \
> > - || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
> > -// FIXME: Enable on clang when it supports it.
> > +#if __has_builtin(__builtin_assume_aligned) && __GNUC_PREREQ(4, 7)
> > # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
> > #elif defined(LLVM_BUILTIN_UNREACHABLE)
> > +// As of today, clang does not support __builtin_assume_aligned.
> > # define LLVM_ASSUME_ALIGNED(p, a) \
> >            (((uintptr_t(p) % (a)) == 0) ? (p) :
> (LLVM_BUILTIN_UNREACHABLE, (p)))
> > #else
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> -David
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130708/63c6a2a6/attachment.html>


More information about the llvm-commits mailing list