Skip to content

Commit 4cbbd97

Browse files
Fix build with MSVC (#1083)
1 parent a09486f commit 4cbbd97

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
1313
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
1414

1515
if (MSVC)
16-
set(CMAKE_CXX_FLAGS "/GL /EHsc /W2 ${CMAKE_CXX_FLAGS}")
16+
set(CMAKE_CXX_FLAGS "/GL /EHsc /W2 /Zc:__cplusplus ${CMAKE_CXX_FLAGS}")
1717
set(CMAKE_CXX_FLAGS_DEBUG "/Od /Zi ${CMAKE_CXX_FLAGS_DEBUG}")
1818
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Oi /Oy /Zc:inline ${CMAKE_CXX_FLAGS_RELEASE}")
1919
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Oi /Zi ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
@@ -130,10 +130,6 @@ set(UTIL_SRCS
130130
util/crc.cpp
131131
util/errors.cpp
132132
util/file.cpp
133-
util/parallel.cpp
134-
util/parallel_fifo.cpp
135-
util/parallel_null.cpp
136-
util/parallel_unrestricted.cpp
137133
util/random.cpp
138134
util/sort.cpp
139135
util/stopwatch.cpp
@@ -142,6 +138,16 @@ set(UTIL_SRCS
142138
util/version.cpp
143139
)
144140

141+
if (BUILD_TV)
142+
set(UTIL_SRCS
143+
${UTIL_SRCS}
144+
util/parallel.cpp
145+
util/parallel_fifo.cpp
146+
util/parallel_null.cpp
147+
util/parallel_unrestricted.cpp
148+
)
149+
endif()
150+
145151
add_library(util STATIC ${UTIL_SRCS})
146152
add_dependencies(util generate_version)
147153

llvm_util/cmd_args_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if (!report_dir_created && !opt_report_dir.empty()) {
6767
if (opt_smt_log) {
6868
fs::path path_z3log = path;
6969
path_z3log.replace_extension("z3_log.txt");
70-
smt::start_logging(path_z3log.c_str());
70+
smt::start_logging(path_z3log.string().c_str());
7171
}
7272
} else if (opt_report_dir.empty()) {
7373
out = &cout;

llvm_util/llvm2alive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ class llvm2alive_ : public llvm::InstVisitor<llvm2alive_, unique_ptr<Instr>> {
19151915
const char *chrs = name.data();
19161916
char *end_ptr;
19171917
auto numeric_id = strtoul(chrs, &end_ptr, 10);
1918-
if (end_ptr != name.end())
1918+
if (end_ptr != &*name.end())
19191919
return M->getGlobalVariable(name, true);
19201920
else {
19211921
auto itr = M->global_begin(), end = M->global_end();

util/compiler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <algorithm>
66
#include <bit>
77

8+
#ifdef _MSC_VER
9+
#include <intrin.h>
10+
#endif
11+
812
using namespace std;
913

1014
#if defined(__clang__) && __clang_major__ < 13 && defined(__apple_build_version__)
@@ -43,6 +47,17 @@ unsigned num_sign_bits(uint64_t n) {
4347
return max(countl_zero(n), countl_one(n)) -1;
4448
}
4549

50+
#ifdef _MSC_VER
51+
uint64_t add_saturate(uint64_t a, uint64_t b) {
52+
unsigned __int64 res;
53+
static_assert(sizeof(res) == sizeof(uint64_t));
54+
return _addcarry_u64(0, a, b, &res) ? UINT64_MAX : res;
55+
}
56+
57+
uint64_t mul_saturate(uint64_t a, uint64_t b) {
58+
return __umulh(a, b) ? UINT64_MAX : a * b;
59+
}
60+
#else
4661
uint64_t add_saturate(uint64_t a, uint64_t b) {
4762
unsigned long long res;
4863
static_assert(sizeof(res) == sizeof(uint64_t));
@@ -54,6 +69,7 @@ uint64_t mul_saturate(uint64_t a, uint64_t b) {
5469
static_assert(sizeof(res) == sizeof(uint64_t));
5570
return __builtin_umulll_overflow(a, b, &res) ? UINT64_MAX : res;
5671
}
72+
#endif
5773

5874
uint64_t divide_up(uint64_t n, uint64_t amount) {
5975
return (n + amount - 1) / amount;

util/file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ string get_random_filename(const string &dir, const char *extension, const char
4141
while (fs::exists(path)) {
4242
path.replace_filename(newname());
4343
}
44-
return path;
44+
return path.string();
4545
}
4646

4747
}

0 commit comments

Comments
 (0)