Skip to content

Commit

Permalink
LLVM 15 Compatibility (#709)
Browse files Browse the repository at this point in the history
* Make phasar compile and run with LLVM 14 and 15 (still using typed pointers)

* Make phasar compile with clang 15

* minor

* fix attempt for clang-14 build

* another fix attempt

---------

Co-authored-by: Martin Mory <[email protected]>
  • Loading branch information
fabianbs96 and MMory authored Apr 25, 2024
1 parent 8bdd67c commit 331c4b7
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
9 changes: 8 additions & 1 deletion cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function(generate_ll_file)
set(GEN_C_FLAGS -fno-discard-value-names -emit-llvm -S -w)
set(GEN_CMD_COMMENT "[LL]")

if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
list(APPEND GEN_CXX_FLAGS -Xclang -no-opaque-pointers)
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
list(APPEND GEN_C_FLAGS -Xclang -no-opaque-pointers)
endif()

if(GEN_LL_MEM2REG)
list(APPEND GEN_CXX_FLAGS -Xclang -disable-O0-optnone)
list(APPEND GEN_C_FLAGS -Xclang -disable-O0-optnone)
Expand Down Expand Up @@ -121,7 +128,7 @@ function(generate_ll_file)
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 ${CMAKE_CXX_COMPILER_LAUNCHER} opt -mem2reg -S -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file}
COMMENT ${GEN_CMD_COMMENT}
DEPENDS ${GEN_LL_FILE}
VERBATIM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H

#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constant.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
#include "phasar/Utils/Logger.h"

#include "llvm/Demangle/Demangle.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"

#include <regex>

namespace psr {

using namespace glca;
Expand Down Expand Up @@ -669,11 +672,17 @@ bool IDEGeneralizedLCA::isEntryPoint(const std::string &Name) const {
}

bool IDEGeneralizedLCA::isStringConstructor(const llvm::Function *F) {
return (ICF->getSpecialMemberFunctionType(F) ==
SpecialMemberFunctionType::Constructor &&
llvm::demangle(F->getName().str())
.find("::allocator<char> >::basic_string") !=
std::string::npos);
if (ICF->getSpecialMemberFunctionType(F) !=
SpecialMemberFunctionType::Constructor) {
return false;
}

static const std::regex StringCtorRex(
"::basic_string<std::allocator<char>[[:space:]]?>\\(",
std::regex::extended | std::regex::nosubs | std::regex::optimize);

auto DName = llvm::demangle(F->getName().str());
return std::regex_search(DName, StringCtorRex);
}

} // namespace psr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
#include "phasar/Utils/BitVectorSet.h"

#include "llvm/IR/Constants.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
#include "phasar/Utils/BitVectorSet.h"

#include "llvm/IR/Constants.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Value.h"
Expand Down
1 change: 1 addition & 0 deletions lib/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Value.h"
Expand Down
8 changes: 7 additions & 1 deletion lib/PhasarLLVM/Pointer/external/llvm/CFLGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,13 @@ template <typename CFLAA> class CFLGraphBuilder {
// introduce any aliases.
// TODO: address other common library functions such as realloc(),
// strdup(), etc.
if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI))
if (isMallocOrCallocLikeFn(&Call, &TLI) ||
#if LLVM_VERSION_MAJOR >= 15
getFreedOperand(&Call, &TLI)
#else
isFreeCall(&Call, &TLI)
#endif
)
return;

// TODO: Add support for noalias args/all the other fun function
Expand Down
1 change: 1 addition & 0 deletions lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
#include "phasar/Utils/Logger.h"

#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
Expand Down
2 changes: 2 additions & 0 deletions lib/PhasarLLVM/Utils/LLVMShorthands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
Expand Down

0 comments on commit 331c4b7

Please sign in to comment.