[llvm] 6c89392 - Use __builtin_strlen in constexpr StringRef ctor with MSVC
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 25 15:54:38 PDT 2019
Author: Reid Kleckner
Date: 2019-10-25T15:53:54-07:00
New Revision: 6c89392592c3eaf174b6f60793b91964297eeb72
URL: https://github.com/llvm/llvm-project/commit/6c89392592c3eaf174b6f60793b91964297eeb72
DIFF: https://github.com/llvm/llvm-project/commit/6c89392592c3eaf174b6f60793b91964297eeb72.diff
LOG: Use __builtin_strlen in constexpr StringRef ctor with MSVC
MSVC supports it. Fixes the major MSVC compile time regression
introduced in r369961. Now
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp compiles in 18s
instead of 7+ minutes.
Fixes PR43369
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 52baab17bede..e87a08f7efff 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -21,6 +21,12 @@
#include <type_traits>
#include <utility>
+// Declare the __builtin_strlen intrinsic for MSVC so it can be used in
+// constexpr context.
+#if defined(_MSC_VER)
+extern "C" size_t __builtin_strlen(const char *);
+#endif
+
namespace llvm {
class APInt;
@@ -71,7 +77,7 @@ 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__)
+#elif __has_builtin(__builtin_strlen) || defined(__GNUC__) || defined(_MSC_VER)
return __builtin_strlen(Str);
#else
const char *Begin = Str;
More information about the llvm-commits
mailing list