Skip to content

Commit 331c4b7

Browse files
fabianbs96MMory
andauthored
LLVM 15 Compatibility (#709)
* 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 <mmo@mail.upb.de>
1 parent 8bdd67c commit 331c4b7

9 files changed

Lines changed: 36 additions & 7 deletions

File tree

cmake/phasar_macros.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ function(generate_ll_file)
7676
set(GEN_C_FLAGS -fno-discard-value-names -emit-llvm -S -w)
7777
set(GEN_CMD_COMMENT "[LL]")
7878

79+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
80+
list(APPEND GEN_CXX_FLAGS -Xclang -no-opaque-pointers)
81+
endif()
82+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
83+
list(APPEND GEN_C_FLAGS -Xclang -no-opaque-pointers)
84+
endif()
85+
7986
if(GEN_LL_MEM2REG)
8087
list(APPEND GEN_CXX_FLAGS -Xclang -disable-O0-optnone)
8188
list(APPEND GEN_C_FLAGS -Xclang -disable-O0-optnone)
@@ -121,7 +128,7 @@ function(generate_ll_file)
121128
add_custom_command(
122129
OUTPUT ${test_code_ll_file}
123130
COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file}
124-
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} opt -mem2reg -S ${test_code_ll_file} -o ${test_code_ll_file}
131+
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} opt -mem2reg -S -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file}
125132
COMMENT ${GEN_CMD_COMMENT}
126133
DEPENDS ${GEN_LL_FILE}
127134
VERBATIM

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/EdgeValue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H
1111
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H
1212

13+
#include "llvm/ADT/APFloat.h"
1314
#include "llvm/ADT/APSInt.h"
1415
#include "llvm/ADT/Twine.h"
1516
#include "llvm/IR/Constant.h"

lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@
2929
#include "phasar/Utils/Logger.h"
3030

3131
#include "llvm/Demangle/Demangle.h"
32+
#include "llvm/IR/Constants.h"
3233
#include "llvm/IR/GlobalVariable.h"
3334
#include "llvm/IR/InstrTypes.h"
3435
#include "llvm/IR/Instructions.h"
3536
#include "llvm/Support/Casting.h"
3637
#include "llvm/Support/raw_ostream.h"
3738

39+
#include <regex>
40+
3841
namespace psr {
3942

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

671674
bool IDEGeneralizedLCA::isStringConstructor(const llvm::Function *F) {
672-
return (ICF->getSpecialMemberFunctionType(F) ==
673-
SpecialMemberFunctionType::Constructor &&
674-
llvm::demangle(F->getName().str())
675-
.find("::allocator<char> >::basic_string") !=
676-
std::string::npos);
675+
if (ICF->getSpecialMemberFunctionType(F) !=
676+
SpecialMemberFunctionType::Constructor) {
677+
return false;
678+
}
679+
680+
static const std::regex StringCtorRex(
681+
"::basic_string<std::allocator<char>[[:space:]]?>\\(",
682+
std::regex::extended | std::regex::nosubs | std::regex::optimize);
683+
684+
auto DName = llvm::demangle(F->getName().str());
685+
return std::regex_search(DName, StringCtorRex);
677686
}
678687

679688
} // namespace psr

lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
1717
#include "phasar/Utils/BitVectorSet.h"
1818

19+
#include "llvm/IR/Constants.h"
1920
#include "llvm/IR/InstrTypes.h"
2021
#include "llvm/IR/Instruction.h"
2122
#include "llvm/IR/Instructions.h"

lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
1818
#include "phasar/Utils/BitVectorSet.h"
1919

20+
#include "llvm/IR/Constants.h"
2021
#include "llvm/IR/Instruction.h"
2122
#include "llvm/IR/Instructions.h"
2223
#include "llvm/IR/Value.h"

lib/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/IR/BasicBlock.h"
2525
#include "llvm/IR/DataLayout.h"
2626
#include "llvm/IR/Function.h"
27+
#include "llvm/IR/InstIterator.h"
2728
#include "llvm/IR/Instruction.h"
2829
#include "llvm/IR/PassManager.h"
2930
#include "llvm/IR/Value.h"

lib/PhasarLLVM/Pointer/external/llvm/CFLGraph.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,13 @@ template <typename CFLAA> class CFLGraphBuilder {
436436
// introduce any aliases.
437437
// TODO: address other common library functions such as realloc(),
438438
// strdup(), etc.
439-
if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI))
439+
if (isMallocOrCallocLikeFn(&Call, &TLI) ||
440+
#if LLVM_VERSION_MAJOR >= 15
441+
getFreedOperand(&Call, &TLI)
442+
#else
443+
isFreeCall(&Call, &TLI)
444+
#endif
445+
)
440446
return;
441447

442448
// TODO: Add support for noalias args/all the other fun function

lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
1717
#include "phasar/Utils/Logger.h"
1818

19+
#include "llvm/BinaryFormat/Dwarf.h"
1920
#include "llvm/IR/DebugInfo.h"
2021
#include "llvm/IR/Function.h"
2122
#include "llvm/IR/InstIterator.h"

lib/PhasarLLVM/Utils/LLVMShorthands.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
#include "llvm/ADT/DenseMap.h"
2323
#include "llvm/ADT/StringRef.h"
24+
#include "llvm/ADT/StringSwitch.h"
2425
#include "llvm/Bitcode/BitcodeReader.h"
2526
#include "llvm/Bitcode/BitcodeWriter.h"
27+
#include "llvm/IR/Constants.h"
2628
#include "llvm/IR/DerivedTypes.h"
2729
#include "llvm/IR/Function.h"
2830
#include "llvm/IR/Instruction.h"

0 commit comments

Comments
 (0)