diff --git a/CMakeLists.txt b/CMakeLists.txt index 68f2dc8380..e1dabb9361 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,12 @@ if (DEFINED LLVM_MAIN_SRC_DIR) endif() if (NOT PHASAR_IN_TREE) - project (phasar) - set(CMAKE_PROJECT_NAME "phasar") + project (phasar + LANGUAGES C CXX + DESCRIPTION "A LLVM-based static analysis framework." + ) endif () +set(PHASAR_VERSION 2403) # NOTE: When we require cmake >= 3.21, we can use PROJECT_IS_TOP_LEVEL instead if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) @@ -492,7 +495,7 @@ configure_package_config_file( write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake - VERSION 2403 + VERSION ${PHASAR_VERSION} COMPATIBILITY SameMajorVersion ) diff --git a/Config.cmake.in b/Config.cmake.in index adc1a9a6ca..107efdb2d9 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -1,4 +1,4 @@ -set(PHASAR_VERSION 2403) +set(PHASAR_VERSION @PHASAR_VERSION@) @PACKAGE_INIT@ set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") diff --git a/config.h.in b/config.h.in index 253f05f861..97b0e8a9f6 100644 --- a/config.h.in +++ b/config.h.in @@ -2,6 +2,8 @@ #define PHASAR_CONFIG_CONFIG_H #define PHASAR_CONFIG_DIR "@PHASAR_CONFIG_INSTALL_DIR@" +#define PHASAR_VERSION @PHASAR_VERSION@ +#define PHASAR_VERSION_STRING "v@PHASAR_VERSION@" #cmakedefine PAMM_CORE #cmakedefine PAMM_FULL diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index dbf9245f07..aa681ea795 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -38,7 +38,7 @@ PROJECT_NAME = "Phasar" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.1 +PROJECT_NUMBER = @PHASAR_VERSION@ # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/include/phasar/Config.h b/include/phasar/Config.h index 81df120eb8..bf78a9ae25 100644 --- a/include/phasar/Config.h +++ b/include/phasar/Config.h @@ -11,6 +11,6 @@ #define PHASAR_CONFIG_H #include "phasar/Config/Configuration.h" -#include "phasar/Config/Version.h" +#include "phasar/Config/phasar-config.h" #endif // PHASAR_CONFIG_H diff --git a/include/phasar/Config/Configuration.h b/include/phasar/Config/Configuration.h index 86528c3386..1d0f91b789 100644 --- a/include/phasar/Config/Configuration.h +++ b/include/phasar/Config/Configuration.h @@ -17,13 +17,10 @@ #ifndef PHASAR_CONFIG_CONFIGURATION_H_ #define PHASAR_CONFIG_CONFIGURATION_H_ -#include "phasar/Config/Version.h" - #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/MemoryBuffer.h" -#include #include #include #include @@ -32,7 +29,8 @@ namespace psr { class PhasarConfig { public: - /// Current Phasar version + /// Current Phasar version. Same as the preprocessor-symbol + /// PHASAR_VERSION_STRING // NOLINTNEXTLINE(readability-identifier-naming) [[nodiscard]] static llvm::StringRef PhasarVersion() noexcept; @@ -66,27 +64,30 @@ class PhasarConfig { [[nodiscard]] std::optional readConfigFileAsTextOrNull(const llvm::Twine &FileName); - /// Specifies the directory in which Phasar is located. + /// Specifies the directory in which Phasar's sources are located. // NOLINTNEXTLINE(readability-identifier-naming) [[nodiscard]] static llvm::StringRef PhasarDirectory() noexcept; /// Name of the file storing all standard header search paths used for /// compilation. - [[nodiscard]] static constexpr llvm::StringRef + [[nodiscard, deprecated("This ancient API is broken and should not be used " + "anymore")]] static constexpr llvm::StringRef // NOLINTNEXTLINE(readability-identifier-naming) HeaderSearchPathsFileName() noexcept { return "standard_header_paths.conf"; } /// Name of the compile_commands.json file (in case we wish to rename) - [[nodiscard]] static constexpr llvm::StringRef + [[nodiscard, deprecated("This ancient API is broken and should not be used " + "anymore")]] static constexpr llvm::StringRef // NOLINTNEXTLINE(readability-identifier-naming) CompileCommandsJson() noexcept { return "compile_commands.json"; } /// Default Source- and Sink-Functions path - [[nodiscard]] static llvm::StringRef + [[nodiscard, deprecated("This ancient API is broken and should not be used " + "anymore")]] static llvm::StringRef // NOLINTNEXTLINE(readability-identifier-naming) DefaultSourceSinkFunctionsPath() noexcept; @@ -142,24 +143,7 @@ class PhasarConfig { private: PhasarConfig(); - bool loadConfigFileInto(llvm::StringRef FileName, - std::set &Lines); - - void loadGlibcSpecialFunctionNames(); - void loadLLVMSpecialFunctionNames(); - std::set SpecialFuncNames; - - /// Name of the file storing all glibc function names. - static constexpr llvm::StringLiteral GLIBCFunctionListFileName = - "glibc_function_list_v1-04.05.17.conf"; - - /// Name of the file storing all LLVM intrinsic function names. - static constexpr llvm::StringLiteral LLVMIntrinsicFunctionListFileName = - "llvm_intrinsics_function_list_v1-04.05.17.conf"; - - /// Log file directory - static constexpr llvm::StringLiteral LogFileDirectory = "log/"; }; } // namespace psr diff --git a/include/phasar/Config/Version.h b/include/phasar/Config/Version.h index 4f595ee968..c5017b860b 100644 --- a/include/phasar/Config/Version.h +++ b/include/phasar/Config/Version.h @@ -1,6 +1,12 @@ #ifndef PHASAR_CONFIG_VERSION_H #define PHASAR_CONFIG_VERSION_H -#define PHASAR_VERSION v2403 +/// Note: This header is only left for backward compatibility and may be removed +/// in the future + +#pragma GCC warning( \ + "The header Version.h is deprecated. Use 'phasar/Config/phasar-config.h' instead") + +#include "phasar/Config/phasar-config.h" #endif diff --git a/lib/Config/Configuration.cpp b/lib/Config/Configuration.cpp index 9d383aaea3..11a36279e3 100644 --- a/lib/Config/Configuration.cpp +++ b/lib/Config/Configuration.cpp @@ -28,19 +28,23 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include #include #include #include -#define XSTR(S) STR(S) -#define STR(S) #S - using namespace psr; namespace psr { +/// Name of the file storing all glibc function names. +static constexpr llvm::StringLiteral GLIBCFunctionListFileName = + "glibc_function_list_v1-04.05.17.conf"; + +/// Name of the file storing all LLVM intrinsic function names. +static constexpr llvm::StringLiteral LLVMIntrinsicFunctionListFileName = + "llvm_intrinsics_function_list_v1-04.05.17.conf"; + llvm::StringRef PhasarConfig::PhasarVersion() noexcept { - return XSTR(PHASAR_VERSION); + return PHASAR_VERSION_STRING; } llvm::StringRef PhasarConfig::GlobalConfigurationDirectory() noexcept { @@ -55,9 +59,51 @@ llvm::StringRef PhasarConfig::DefaultSourceSinkFunctionsPath() noexcept { return PHASAR_SRC_DIR "/config/phasar-source-sink-function.json"; } +static bool loadConfigFileInto(PhasarConfig &PC, llvm::StringRef FileName, + std::set &Lines) { + auto ConfigFile = PC.readConfigFileAsTextOrErr(FileName); + if (!ConfigFile) { + if (ConfigFile.getError() != std::errc::no_such_file_or_directory) { + PHASAR_LOG_LEVEL(WARNING, "Could not open config file '" + << FileName << "': " + << ConfigFile.getError().message()); + } + + return false; + } + + llvm::SmallVector ConfigLines; + llvm::SplitString(*ConfigFile, ConfigLines, "\n"); + + llvm::transform( + ConfigLines, std::inserter(Lines, Lines.end()), [](llvm::StringRef Str) { + if (auto Comment = Str.find("//"); Comment != llvm::StringRef::npos) { + Str = Str.slice(0, Comment); + } + return Str.trim().str(); + }); + return true; +} + +static void loadGlibcSpecialFunctionNames(PhasarConfig &PC, + std::set &Into) { + if (!loadConfigFileInto(PC, GLIBCFunctionListFileName, Into)) { + // Add default glibc function names + Into.insert({"_exit"}); + } +} + +static void loadLLVMSpecialFunctionNames(PhasarConfig &PC, + std::set &Into) { + if (!loadConfigFileInto(PC, LLVMIntrinsicFunctionListFileName, Into)) { + // Add default LLVM function names + Into.insert({"llvm.va_start"}); + } +} + PhasarConfig::PhasarConfig() { - loadGlibcSpecialFunctionNames(); - loadLLVMSpecialFunctionNames(); + loadGlibcSpecialFunctionNames(*this, SpecialFuncNames); + loadLLVMSpecialFunctionNames(*this, SpecialFuncNames); // Insert allocation operators SpecialFuncNames.insert({"_Znwm", "_Znam", "_ZdlPv", "_ZdaPv"}); @@ -120,47 +166,6 @@ PhasarConfig::readConfigFileAsTextOrNull(const llvm::Twine &FileName) { return std::nullopt; } -bool PhasarConfig::loadConfigFileInto(llvm::StringRef FileName, - std::set &Lines) { - auto ConfigFile = readConfigFileAsTextOrErr(FileName); - if (!ConfigFile) { - if (ConfigFile.getError() != std::errc::no_such_file_or_directory) { - PHASAR_LOG_LEVEL(WARNING, "Could not open config file '" - << FileName << "': " - << ConfigFile.getError().message()); - } - - return false; - } - - llvm::SmallVector ConfigLines; - llvm::SplitString(*ConfigFile, ConfigLines, "\n"); - - llvm::transform( - ConfigLines, std::inserter(Lines, Lines.end()), [](llvm::StringRef Str) { - if (auto Comment = Str.find("//"); Comment != llvm::StringRef::npos) { - Str = Str.slice(0, Comment); - } - return Str.trim().str(); - }); - return true; -} - -void PhasarConfig::loadGlibcSpecialFunctionNames() { - if (!loadConfigFileInto(GLIBCFunctionListFileName, SpecialFuncNames)) { - // Add default glibc function names - SpecialFuncNames.insert({"_exit"}); - } -} - -void PhasarConfig::loadLLVMSpecialFunctionNames() { - if (!loadConfigFileInto(LLVMIntrinsicFunctionListFileName, - SpecialFuncNames)) { - // Add default LLVM function names - SpecialFuncNames.insert({"llvm.va_start"}); - } -} - PhasarConfig &PhasarConfig::getPhasarConfig() { static PhasarConfig PC{}; return PC;