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

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 08:49:45 PST 2020


Author: Hans Wennborg
Date: 2020-02-03T17:49:29+01:00
New Revision: ff837aa63cdfadb58f387ca77785ca3ca51c6976

URL: https://github.com/llvm/llvm-project/commit/ff837aa63cdfadb58f387ca77785ca3ca51c6976
DIFF: https://github.com/llvm/llvm-project/commit/ff837aa63cdfadb58f387ca77785ca3ca51c6976.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.

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 31b0a5c6780f..75a6e1a6b5a8 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -27,7 +27,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 {
@@ -80,7 +80,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-commits mailing list