Skip to content

Commit 34df10c

Browse files
committed
Fix getReceiverType() for functions returning large or non-trivially movable structs
1 parent d0a36f2 commit 34df10c

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "llvm/IR/Constants.h"
2121
#include "llvm/IR/DerivedTypes.h"
2222
#include "llvm/IR/InstrTypes.h"
23+
#include "llvm/IR/Instructions.h"
24+
#include "llvm/Support/Casting.h"
2325

2426
#include "phasar/DB/ProjectIRDB.h"
2527
#include "phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h"
@@ -51,15 +53,29 @@ std::optional<unsigned> getVFTIndex(const llvm::CallBase *CallSite) {
5153
}
5254

5355
const llvm::StructType *getReceiverType(const llvm::CallBase *CallSite) {
54-
if (!CallSite->arg_empty()) {
55-
const auto *Receiver = CallSite->getArgOperand(0);
56-
if (Receiver->getType()->isPointerTy()) {
57-
if (const auto *ReceiverTy = llvm::dyn_cast<llvm::StructType>(
58-
Receiver->getType()->getPointerElementType())) {
59-
return ReceiverTy;
60-
}
61-
}
56+
if (CallSite->arg_empty() ||
57+
(CallSite->hasStructRetAttr() && CallSite->arg_size() < 2)) {
58+
return nullptr;
59+
}
60+
61+
const auto *Receiver =
62+
CallSite->getArgOperand(unsigned(CallSite->hasStructRetAttr()));
63+
64+
if (!Receiver->getType()->isPointerTy()) {
65+
return nullptr;
6266
}
67+
68+
if (Receiver->getType()->isOpaquePointerTy()) {
69+
llvm::errs() << "WARNING: The IR under analysis uses opaque pointers, "
70+
"which are not supported by phasar yet!\n";
71+
return nullptr;
72+
}
73+
74+
if (const auto *ReceiverTy = llvm::dyn_cast<llvm::StructType>(
75+
Receiver->getType()->getPointerElementType())) {
76+
return ReceiverTy;
77+
}
78+
6379
return nullptr;
6480
}
6581

0 commit comments

Comments
 (0)