From 66b780740311bbfe9f7d93a2b345c68507d76014 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 10 Feb 2016 19:07:47 +0000 Subject: [PATCH] Enable constexpr on Visual Studio 2015, add support for two equivalent attributes Patch by Alexander Riccio This patch enables `constexpr` on Visual Studio 2015 by adding `|| LLVM_MSC_PREREQ(1900)` to the preprocessor `#if` statement. Since VS2013 doesn't support `constexpr`, that's purposely excluded. The `LLVM_CONSTEXPR` macro is used in ~25 places. I also added the MSVC/SAL equivalent of: - `__attribute__((__warn_unused_result__))` as an `LLVM_ATTRIBUTE_UNUSED_RESULT` definition - `__attribute__((returns_nonnull))` as an `LLVM_ATTRIBUTE_RETURNS_NONNULL` definition ...in case anybody ever decides to run `/analyze` on LLVM (probably myself, if anybody) Reviewers: rnk, aaron.ballman Differential Revision: http://reviews.llvm.org/D16751 llvm-svn: 260410 --- llvm/include/llvm/Support/Compiler.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index b3416bb..d28151c 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -17,6 +17,10 @@ #include "llvm/Config/llvm-config.h" +#if defined(_MSC_VER) +#include +#endif + #ifndef __has_feature # define __has_feature(x) 0 #endif @@ -92,7 +96,7 @@ #define LLVM_LVALUE_FUNCTION #endif -#if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__) +#if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__) || LLVM_MSC_PREREQ(1900) # define LLVM_CONSTEXPR constexpr #else # define LLVM_CONSTEXPR @@ -124,6 +128,8 @@ #if __has_attribute(warn_unused_result) || LLVM_GNUC_PREREQ(3, 4, 0) #define LLVM_ATTRIBUTE_UNUSED_RESULT __attribute__((__warn_unused_result__)) +#elif defined(_MSC_VER) +#define LLVM_ATTRIBUTE_UNUSED_RESULT _Check_return_ #else #define LLVM_ATTRIBUTE_UNUSED_RESULT #endif @@ -206,6 +212,8 @@ #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0) #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) +#elif defined(_MSC_VER) +#define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ #else #define LLVM_ATTRIBUTE_RETURNS_NONNULL #endif -- 2.7.4