Skip to content

Commit

Permalink
Making msvc19 build possible (at least in release mode without IR files
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed Dec 12, 2023
1 parent da38a25 commit ff89763
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 23 deletions.
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ if (NOT MSVC)
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -fno-omit-frame-pointer")
string(APPEND CMAKE_CXX_FLAGS_RELEASE "")
else()
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus /bigobj")
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus /bigobj") # /D_ITERATOR_DEBUG_LEVEL=0 /VERBOSE:LIB
if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
endif()
endif()

option(CMAKE_VISIBILITY_INLINES_HIDDEN "Hide inlined functions from the DSO table (default ON)" ON)
Expand Down Expand Up @@ -168,6 +171,12 @@ option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkag
#option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
option(PHASAR_BUILD_DYNLIB "Build one fat shared library. Requires BUILD_SHARED_LIBS to be turned OFF (default is OFF)" OFF)

if (BUILD_SHARED_LIBS)
message(STATUS "Build shared libraries")
else()
message(STATUS "Build static libraries")
endif()

if(PHASAR_BUILD_DYNLIB AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "PHASAR_BUILD_DYNLIB is incompatible with BUILD_SHARED_LIBS")
endif()
Expand Down Expand Up @@ -283,6 +292,11 @@ add_subdirectory(external/json-schema-validator)
if (NOT PHASAR_IN_TREE)
set(BUILD_GMOCK OFF)
set(INSTALL_GTEST OFF)

if (MSVC AND CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
set(gtest_force_shared_crt ON)
endif()

add_subdirectory(external/googletest EXCLUDE_FROM_ALL)
set(GTEST_INCLUDE_DIR "external/googletest/googletest/include")
else()
Expand Down Expand Up @@ -476,6 +490,12 @@ endif()
# Build all IR test code
if (PHASAR_BUILD_IR)
message("Building IR test code")

message(STATUS "Searching for clang in ${LLVM_BINARY_DIR}")
find_program(CLANG_EXE clang HINTS ${LLVM_BINARY_DIR} REQUIRED)
find_program(CLANGXX_EXE clang++ HINTS ${LLVM_BINARY_DIR} REQUIRED)
find_program(LLVMOPT_EXE opt HINTS ${LLVM_BINARY_DIR} REQUIRED)

add_subdirectory(test)
endif()

Expand Down
6 changes: 3 additions & 3 deletions cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ function(generate_ll_file)

# define .ll file generation command
if(${test_code_file_ext} STREQUAL ".cpp")
set(GEN_CMD ${CMAKE_CXX_COMPILER_LAUNCHER} ${CMAKE_CXX_COMPILER})
set(GEN_CMD ${CLANGXX_EXE})
list(APPEND GEN_CMD ${GEN_CXX_FLAGS})
else()
set(GEN_CMD ${CMAKE_C_COMPILER_LAUNCHER} ${CMAKE_C_COMPILER})
set(GEN_CMD ${CLANG_EXE})
list(APPEND GEN_CMD ${GEN_C_FLAGS})
endif()

if(GEN_LL_MEM2REG)
add_custom_command(
OUTPUT ${test_code_ll_file}
COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file}
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} opt -mem2reg -S ${test_code_ll_file} -o ${test_code_ll_file}
COMMAND ${LLVMOPT_EXE} -mem2reg -S ${test_code_ll_file} -o ${test_code_ll_file}
COMMENT ${GEN_CMD_COMMENT}
DEPENDS ${GEN_LL_FILE}
VERBATIM
Expand Down
1 change: 0 additions & 1 deletion include/phasar/ControlFlow/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "phasar/Utils/ByRef.h"
#include "phasar/Utils/Logger.h"
#include "phasar/Utils/StableVector.h"
#include "phasar/Utils/Utilities.h"

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
Expand Down
4 changes: 2 additions & 2 deletions include/phasar/PhasarLLVM/Utils/LLVMShorthands.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
#ifndef PHASAR_PHASARLLVM_UTILS_LLVMSHORTHANDS_H
#define PHASAR_PHASARLLVM_UTILS_LLVMSHORTHANDS_H

#include "phasar/Utils/Utilities.h"

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"

#include <string>
#include <vector>
Expand All @@ -35,6 +34,7 @@ class StoreInst;
class BranchInst;
class Module;
class CallInst;
class Type;
} // namespace llvm

namespace psr {
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/Utils/DOTGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define PHASAR_UTILS_DOTGRAPH_H

#include "phasar/Config/Configuration.h"
#include "phasar/Utils/Utilities.h"
#include "phasar/Utils/StringIDLess.h"

#include <map>
#include <set>
Expand Down
22 changes: 22 additions & 0 deletions include/phasar/Utils/StringIDLess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/******************************************************************************
* Copyright (c) 2017 Philipp Schubert.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Philipp Schubert and others
*****************************************************************************/

#ifndef PHASAR_UTILS_STRINGIDLESS_H_
#define PHASAR_UTILS_STRINGIDLESS_H_

#include <string>

namespace psr {
struct StringIDLess {
bool operator()(const std::string &LHS, const std::string &RHS) const;
};
} // namespace psr

#endif // PHASAR_UTILS_STRINGIDLESS_H_
9 changes: 4 additions & 5 deletions include/phasar/Utils/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define PHASAR_UTILS_UTILITIES_H_

#include "phasar/Utils/BitVectorSet.h"
#include "phasar/Utils/StringIDLess.h"
#include "phasar/Utils/TypeTraits.h"

#include "llvm/ADT/Hashing.h"
Expand Down Expand Up @@ -153,10 +154,6 @@ void intersectWith(BitVectorSet<T> &Dest, const BitVectorSet<T> &Src) {
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const std::vector<bool> &Bits);

struct StringIDLess {
bool operator()(const std::string &LHS, const std::string &RHS) const;
};

/// See "https://en.cppreference.com/w/cpp/experimental/scope_exit/scope_exit"
template <typename Fn> class scope_exit { // NOLINT
public:
Expand All @@ -179,7 +176,9 @@ template <typename Fn> class scope_exit { // NOLINT
template <typename Fn> scope_exit(Fn) -> scope_exit<Fn>;

// Copied from "https://en.cppreference.com/w/cpp/utility/variant/visit"
template <class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> struct Overloaded : Ts... {
using Ts::operator()...;
};

// explicit deduction guide (not needed as of C++20)
template <class... Ts> Overloaded(Ts...) -> Overloaded<Ts...>;
Expand Down
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_phasar_library(phasar ${PHASAR_DYNLIB_KIND}
phasar_llvm_ifdside
phasar_analysis_strategy
phasar_controller
LINK_PRIVATE
LINK_PUBLIC
${Boost_LIBRARIES}
LLVM_LINK_COMPONENTS
Core
Expand Down
2 changes: 1 addition & 1 deletion lib/Config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ file(GLOB_RECURSE CONFIG_SRC *.h *.cpp)
add_phasar_library(phasar_config
${CONFIG_SRC}
LINKS phasar_utils
LINK_PRIVATE ${Boost_LIBRARIES}
LINK_PUBLIC ${Boost_LIBRARIES}
LLVM_LINK_COMPONENTS Support
)
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ add_phasar_library(phasar_llvm_ifdside
Support
Demangle

LINK_PRIVATE
LINK_PUBLIC
${Boost_LIBRARIES}
)
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ std::string OpenSSLSecureMemoryDescription::getTypeNameOfInterest() const {

set<int>
OpenSSLSecureMemoryDescription::getConsumerParamIdx(llvm::StringRef F) const {
if (const auto *It = llvm::find_if(
// NOTE: On MSVC, the array iterator is no pointer!
if (auto It = llvm::find_if( // NOLINT
ConsumingFuncs, [&F](const auto &Pair) { return F == Pair.first; });
It != ConsumingFuncs.end()) {
return {It->second};
Expand Down
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/Pointer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ add_phasar_library(phasar_llvm_pointer
Passes
Demangle

LINK_PRIVATE
LINK_PUBLIC
${Boost_LIBRARIES}
)
1 change: 1 addition & 0 deletions lib/PhasarLLVM/Pointer/LLVMAliasSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "phasar/Utils/BoxedPointer.h"
#include "phasar/Utils/Logger.h"
#include "phasar/Utils/NlohmannLogging.h"
#include "phasar/Utils/Utilities.h"

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ add_phasar_library(phasar_llvm_typehierarchy
Support
Analysis

LINK_PRIVATE
LINK_PUBLIC
${Boost_LIBRARIES}
)
1 change: 1 addition & 0 deletions lib/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_phasar_library(phasar_utils
${PHASAR_STD_FILESYSTEM}
LINK_PUBLIC
nlohmann_json::nlohmann_json
${Boost_LIBRARIES}
)

set_target_properties(phasar_utils
Expand Down
1 change: 0 additions & 1 deletion lib/Utils/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "phasar/Utils/ErrorHandling.h"
#include "phasar/Utils/Logger.h"
#include "phasar/Utils/Utilities.h"

#include "llvm/ADT/SmallString.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down
4 changes: 4 additions & 0 deletions tools/example-tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ else()
llvm_config(myphasartool ${LLVM_LINK_COMPONENTS})
endif()

if(BUILD_PHASAR_CLANG)
target_link_libraries(myphasartool PRIVATE ${CLANG_LIBRARY})
endif()

install(TARGETS myphasartool
RUNTIME DESTINATION bin
)
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ TEST_F(IDEGeneralizedLCATest, StringTestCpp) {
std::vector<groundTruth_t> GroundTruth;
const auto *LastMainInstruction =
getLastInstructionOf(HA->getProjectIRDB().getFunction("main"));
GroundTruth.push_back({{EdgeValue("Hello, World")},
3U,
std::stoi(getMetaDataID(LastMainInstruction))});
GroundTruth.push_back(
{{EdgeValue("Hello, World")},
3U,
unsigned(std::stoi(getMetaDataID(LastMainInstruction)))});
compareResults(GroundTruth);
}

Expand Down

0 comments on commit ff89763

Please sign in to comment.