[llvm-branch-commits] [llvm] d2a710e - Actually, don't try to use __builtin_strlen in StringRef.h before VS 2019

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 3 08:53:13 PST 2020


Author: Hans Wennborg
Date: 2020-02-03T17:50:03+01:00
New Revision: d2a710ea784eea43c63e3831224de6355f1e4a6f

URL: https://github.com/llvm/llvm-project/commit/d2a710ea784eea43c63e3831224de6355f1e4a6f
DIFF: https://github.com/llvm/llvm-project/commit/d2a710ea784eea43c63e3831224de6355f1e4a6f.diff

LOG: Actually, don't try to use __builtin_strlen in StringRef.h before VS 2019

The fix in b3d7d1061dc375bb5ea725e6597382fcd37f41d6 compiled nicely,
but didn't link because at least the VS 2017 version I use doesn't
have the builtin yet. Instead, make use of the builtin with MSVC
conditional on VS 2019 or later.

(cherry picked from commit ff837aa63cdfadb58f387ca77785ca3ca51c6976)

Added: 
    

Modified: 
    llvm/include/llvm/ADT/StringRef.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 6d75cf8b04e7..7c13b5d17ec7 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -24,7 +24,7 @@
 // Declare the __builtin_strlen intrinsic for MSVC so it can be used in
 // constexpr context.
 #if defined(_MSC_VER)
-extern "C" constexpr size_t __builtin_strlen(const char *);
+extern "C" size_t __builtin_strlen(const char *);
 #endif
 
 namespace llvm {
@@ -77,7 +77,8 @@ namespace llvm {
     static constexpr size_t strLen(const char *Str) {
 #if __cplusplus > 201402L
       return std::char_traits<char>::length(Str);
-#elif __has_builtin(__builtin_strlen) || defined(__GNUC__) || defined(_MSC_VER)
+#elif __has_builtin(__builtin_strlen) || defined(__GNUC__) || \
+    (defined(_MSC_VER) && _MSC_VER >= 1920)
       return __builtin_strlen(Str);
 #else
       const char *Begin = Str;


        


More information about the llvm-branch-commits mailing list