Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion Config.cmake.in
Original file line number Diff line number Diff line change
@@ -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@")
Expand Down
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 9 additions & 25 deletions include/phasar/Config/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filesystem>
#include <optional>
#include <set>
#include <string>
Expand All @@ -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;

Expand Down Expand Up @@ -66,27 +64,30 @@ class PhasarConfig {
[[nodiscard]] std::optional<std::string>
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;

Expand Down Expand Up @@ -142,24 +143,7 @@ class PhasarConfig {
private:
PhasarConfig();

bool loadConfigFileInto(llvm::StringRef FileName,
std::set<std::string> &Lines);

void loadGlibcSpecialFunctionNames();
void loadLLVMSpecialFunctionNames();

std::set<std::string> 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
Expand Down
8 changes: 7 additions & 1 deletion include/phasar/Config/Version.h
Original file line number Diff line number Diff line change
@@ -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
101 changes: 53 additions & 48 deletions lib/Config/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"

#include <algorithm>
#include <cstdlib>
#include <iterator>
#include <system_error>

#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 {
Expand All @@ -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<std::string> &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<llvm::StringRef, 0> 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<std::string> &Into) {
if (!loadConfigFileInto(PC, GLIBCFunctionListFileName, Into)) {
// Add default glibc function names
Into.insert({"_exit"});
}
}

static void loadLLVMSpecialFunctionNames(PhasarConfig &PC,
std::set<std::string> &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"});
Expand Down Expand Up @@ -120,47 +166,6 @@ PhasarConfig::readConfigFileAsTextOrNull(const llvm::Twine &FileName) {
return std::nullopt;
}

bool PhasarConfig::loadConfigFileInto(llvm::StringRef FileName,
std::set<std::string> &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<llvm::StringRef, 0> 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;
Expand Down