| 1 |
/* Detect Clang Version |
| 2 |
* Created by Evan Nemerson <[email protected]> |
| 3 |
* |
| 4 |
* To the extent possible under law, the author(s) have dedicated all |
| 5 |
* copyright and related and neighboring rights to this software to |
| 6 |
* the public domain worldwide. This software is distributed without |
| 7 |
* any warranty. |
| 8 |
* |
| 9 |
* For details, see <http://creativecommons.org/publicdomain/zero/1.0/>. |
| 10 |
* SPDX-License-Identifier: CC0-1.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
/* This file was originally part of SIMDe |
| 14 |
* (<https://github.com/simd-everywhere/simde>). You're free to do with it as |
| 15 |
* you please, but I do have a few small requests: |
| 16 |
* |
| 17 |
* * If you make improvements, please submit them back to SIMDe |
| 18 |
* (at <https://github.com/simd-everywhere/simde/issues>) so others can |
| 19 |
* benefit from them. |
| 20 |
* * Please keep a link to SIMDe intact so people know where to submit |
| 21 |
* improvements. |
| 22 |
* * If you expose it publicly, please change the SIMDE_ prefix to |
| 23 |
* something specific to your project. |
| 24 |
* |
| 25 |
* The version numbers clang exposes (in the ___clang_major__, |
| 26 |
* __clang_minor__, and __clang_patchlevel__ macros) are unreliable. |
| 27 |
* Vendors such as Apple will define these values to their version |
| 28 |
* numbers; for example, "Apple Clang 4.0" is really clang 3.1, but |
| 29 |
* __clang_major__ and __clang_minor__ are defined to 4 and 0 |
| 30 |
* respectively, instead of 3 and 1. |
| 31 |
* |
| 32 |
* The solution is *usually* to use clang's feature detection macros |
| 33 |
* (<https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros>) |
| 34 |
* to determine if the feature you're interested in is available. This |
| 35 |
* generally works well, and it should probably be the first thing you |
| 36 |
* try. Unfortunately, it's not possible to check for everything. In |
| 37 |
* particular, compiler bugs. |
| 38 |
* |
| 39 |
* This file just uses the feature checking macros to detect features |
| 40 |
* added in specific versions of clang to identify which version of |
| 41 |
* clang the compiler is based on. |
| 42 |
* |
| 43 |
* Right now it only goes back to 3.6, but I'm happy to accept patches |
| 44 |
* to go back further. And, of course, newer versions are welcome if |
| 45 |
* they're not already present, and if you find a way to detect a point |
| 46 |
* release that would be great, too! |
| 47 |
*/ |
| 48 |
|
| 49 |
#if !defined(SIMDE_DETECT_CLANG_H) |
| 50 |
#define SIMDE_DETECT_CLANG_H 1 |
| 51 |
|
| 52 |
/* Attempt to detect the upstream clang version number. I usually only |
| 53 |
* worry about major version numbers (at least for 4.0+), but if you |
| 54 |
* need more resolution I'm happy to accept patches that are able to |
| 55 |
* detect minor versions as well. That said, you'll probably have a |
| 56 |
* hard time with detection since AFAIK most minor releases don't add |
| 57 |
* anything we can detect. */ |
| 58 |
|
| 59 |
#if defined(__clang__) && !defined(SIMDE_DETECT_CLANG_VERSION) |
| 60 |
# if __has_warning("-Wformat-insufficient-args") |
| 61 |
# define SIMDE_DETECT_CLANG_VERSION 120000 |
| 62 |
# elif __has_warning("-Wimplicit-const-int-float-conversion") |
| 63 |
# define SIMDE_DETECT_CLANG_VERSION 110000 |
| 64 |
# elif __has_warning("-Wmisleading-indentation") |
| 65 |
# define SIMDE_DETECT_CLANG_VERSION 100000 |
| 66 |
# elif defined(__FILE_NAME__) |
| 67 |
# define SIMDE_DETECT_CLANG_VERSION 90000 |
| 68 |
# elif __has_warning("-Wextra-semi-stmt") || __has_builtin(__builtin_rotateleft32) |
| 69 |
# define SIMDE_DETECT_CLANG_VERSION 80000 |
| 70 |
# elif __has_warning("-Wc++98-compat-extra-semi") |
| 71 |
# define SIMDE_DETECT_CLANG_VERSION 70000 |
| 72 |
# elif __has_warning("-Wpragma-pack") |
| 73 |
# define SIMDE_DETECT_CLANG_VERSION 60000 |
| 74 |
# elif __has_warning("-Wbitfield-enum-conversion") |
| 75 |
# define SIMDE_DETECT_CLANG_VERSION 50000 |
| 76 |
# elif __has_attribute(diagnose_if) |
| 77 |
# define SIMDE_DETECT_CLANG_VERSION 40000 |
| 78 |
# elif __has_warning("-Wcomma") |
| 79 |
# define SIMDE_DETECT_CLANG_VERSION 39000 |
| 80 |
# elif __has_warning("-Wdouble-promotion") |
| 81 |
# define SIMDE_DETECT_CLANG_VERSION 38000 |
| 82 |
# elif __has_warning("-Wshift-negative-value") |
| 83 |
# define SIMDE_DETECT_CLANG_VERSION 37000 |
| 84 |
# elif __has_warning("-Wambiguous-ellipsis") |
| 85 |
# define SIMDE_DETECT_CLANG_VERSION 36000 |
| 86 |
# else |
| 87 |
# define SIMDE_DETECT_CLANG_VERSION 1 |
| 88 |
# endif |
| 89 |
#endif /* defined(__clang__) && !defined(SIMDE_DETECT_CLANG_VERSION) */ |
| 90 |
|
| 91 |
/* The SIMDE_DETECT_CLANG_VERSION_CHECK macro is pretty |
| 92 |
* straightforward; it returns true if the compiler is a derivative |
| 93 |
* of clang >= the specified version. |
| 94 |
* |
| 95 |
* Since this file is often (primarily?) useful for working around bugs |
| 96 |
* it is also helpful to have a macro which returns true if only if the |
| 97 |
* compiler is a version of clang *older* than the specified version to |
| 98 |
* make it a bit easier to ifdef regions to add code for older versions, |
| 99 |
* such as pragmas to disable a specific warning. */ |
| 100 |
|
| 101 |
#if defined(SIMDE_DETECT_CLANG_VERSION) |
| 102 |
# define SIMDE_DETECT_CLANG_VERSION_CHECK(major, minor, revision) (SIMDE_DETECT_CLANG_VERSION >= ((major * 10000) + (minor * 1000) + (revision))) |
| 103 |
# define SIMDE_DETECT_CLANG_VERSION_NOT(major, minor, revision) (SIMDE_DETECT_CLANG_VERSION < ((major * 10000) + (minor * 1000) + (revision))) |
| 104 |
#else |
| 105 |
# define SIMDE_DETECT_CLANG_VERSION_CHECK(major, minor, revision) (0) |
| 106 |
# define SIMDE_DETECT_CLANG_VERSION_NOT(major, minor, revision) (0) |
| 107 |
#endif |
| 108 |
|
| 109 |
#endif /* !defined(SIMDE_DETECT_CLANG_H) */ |