Skip to content

Commit 2d8e6a0

Browse files
committed
Get rid of the narrowing conversion in AbstractMemoryLocationFactory
1 parent 41df274 commit 2d8e6a0

2 files changed

Lines changed: 29 additions & 48 deletions

File tree

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AbstractMemoryLocationFactoryBase {
8989
const llvm::DataLayout *DL = nullptr;
9090

9191
const detail::AbstractMemoryLocationImpl *
92-
getOrCreateImpl(const llvm::Value *V, llvm::SmallVectorImpl<ptrdiff_t> &&Offs,
92+
getOrCreateImpl(const llvm::Value *V, llvm::ArrayRef<ptrdiff_t> Offs,
9393
unsigned BOUND);
9494

9595
const detail::AbstractMemoryLocationImpl *

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.cpp

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* Fabian Schiebel and others
88
*****************************************************************************/
99

10-
#include <exception>
1110
#include <limits>
1211
#include <new>
1312

@@ -141,8 +140,7 @@ void AbstractMemoryLocationFactoryBase::setDataLayout(
141140

142141
const AbstractMemoryLocationImpl *
143142
AbstractMemoryLocationFactoryBase::getOrCreateImpl(
144-
const llvm::Value *V, llvm::SmallVectorImpl<ptrdiff_t> &&Offs,
145-
unsigned BOUND) {
143+
const llvm::Value *V, llvm::ArrayRef<ptrdiff_t> Offs, unsigned BOUND) {
146144
llvm::FoldingSetNodeID ID;
147145
detail::AbstractMemoryLocationImpl::MakeProfile(ID, V, Offs, BOUND);
148146
void *Pos;
@@ -157,11 +155,7 @@ AbstractMemoryLocationFactoryBase::getOrCreateImpl(
157155
const AbstractMemoryLocationImpl *
158156
AbstractMemoryLocationFactoryBase::getOrCreateImpl(const llvm::Value *V,
159157
unsigned BOUND) {
160-
161-
llvm::SmallVector<ptrdiff_t, 1> Offs = {0};
162-
const auto *Ret =
163-
getOrCreateImpl(V, std::move(Offs), BOUND == 0 ? 0 : BOUND - 1);
164-
158+
const auto *Ret = getOrCreateImpl(V, {0}, BOUND == 0 ? 0 : BOUND - 1);
165159
return Ret;
166160
}
167161

@@ -233,7 +227,7 @@ AbstractMemoryLocationFactoryBase::createImpl(const llvm::Value *V,
233227
Offs.resize(BOUND);
234228
}
235229

236-
const auto *Mem = getOrCreateImpl(Baseptr, std::move(Offs), Lifetime);
230+
const auto *Mem = getOrCreateImpl(Baseptr, Offs, Lifetime);
237231

238232
#ifdef XTAINT_DIAGNOSTICS
239233
if (IsOverApproximating)
@@ -253,10 +247,12 @@ AbstractMemoryLocationFactoryBase::getOrCreateZeroImpl() const {
253247

254248
const AbstractMemoryLocationImpl *AbstractMemoryLocationFactoryBase::limitImpl(
255249
const AbstractMemoryLocationImpl *AML) {
256-
const auto *Beg = AML->offsets().begin();
257-
const auto *End = AML->offsets().end();
258-
llvm::SmallVector<ptrdiff_t, 8> Offs(Beg, Beg == End ? End : End - 1);
259-
const auto *Ret = getOrCreateImpl(AML->base(), std::move(Offs), 0);
250+
auto Offs = AML->offsets();
251+
if (!Offs.empty()) {
252+
Offs = Offs.drop_back();
253+
}
254+
255+
const auto *Ret = getOrCreateImpl(AML->base(), Offs, 0);
260256

261257
#ifdef XTAINT_DIAGNOSTICS
262258
overApproximatedAMLs.insert(ret);
@@ -299,7 +295,7 @@ AbstractMemoryLocationFactoryBase::withIndirectionOfImpl(
299295
NwLifeTime -= Ind.size();
300296
}
301297

302-
const auto *Ret = getOrCreateImpl(AML->base(), std::move(Offs), NwLifeTime);
298+
const auto *Ret = getOrCreateImpl(AML->base(), Offs, NwLifeTime);
303299

304300
#ifdef XTAINT_DIAGNOSTICS
305301
if (isOverApproximating)
@@ -331,7 +327,7 @@ AbstractMemoryLocationFactoryBase::withOffsetImpl(
331327
AML->offsets().end());
332328
Offs.back() += *GepOffs;
333329

334-
return getOrCreateImpl(AML->base(), std::move(Offs), AML->lifetime());
330+
return getOrCreateImpl(AML->base(), Offs, AML->lifetime());
335331
}
336332
}
337333

@@ -366,8 +362,8 @@ AbstractMemoryLocationFactoryBase::withOffsetsImpl(
366362

367363
OffsCpy.append(std::next(Offs.begin()), Offs.end());
368364

369-
const auto *Ret = getOrCreateImpl(AML->base(), std::move(OffsCpy),
370-
NwLifetime - Offs.size() + 1);
365+
const auto *Ret =
366+
getOrCreateImpl(AML->base(), OffsCpy, NwLifetime - Offs.size() + 1);
371367
#ifdef XTAINT_DIAGNOSTICS
372368
if (isOverApproximating)
373369
overApproximatedAMLs.insert(ret);
@@ -390,40 +386,26 @@ AbstractMemoryLocationFactoryBase::withTransferToImpl(
390386
return Ret;
391387
}
392388

389+
auto [LargerOffs, SmallerOffs] = [&] {
390+
if (AML->offsets().size() >= From->offsets().size()) {
391+
return std::make_pair(AML->offsets(), From->offsets());
392+
}
393+
return std::make_pair(From->offsets(), AML->offsets());
394+
}();
395+
396+
if (!SmallerOffs.empty()) {
397+
LargerOffs = LargerOffs.drop_front(SmallerOffs.size() - 1);
398+
}
399+
393400
// already checked that either offsets() is a prefix of From.offsets() or
394401
// vice versa
395-
llvm::SmallVector<ptrdiff_t, 8> Offs(
396-
[&] {
397-
if (AML->offsets().size() >= From->offsets().size()) {
398-
399-
if (!From->offsets().empty()) {
400-
return std::next(AML->offsets().begin(),
401-
From->offsets().size() -
402-
1); // FIXME @Fabian clang-tidy complains about
403-
// narrowing conversion
404-
}
405-
return AML->offsets().begin();
406-
}
407-
if (!AML->offsets().empty()) {
408-
return std::next(From->offsets().begin(),
409-
AML->offsets().size() -
410-
1); // FIXME @Fabian clang-tidy complains about
411-
// narrowing conversion
412-
}
413-
return From->offsets().begin();
414-
}(),
415-
[&] {
416-
return AML->offsets().size() >= From->offsets().size()
417-
? AML->offsets().end()
418-
: From->offsets().end();
419-
}());
402+
llvm::SmallVector<ptrdiff_t, 8> Offs(LargerOffs.begin(), LargerOffs.end());
420403

421404
if (!Offs.empty()) {
422405
Offs.back() = 0;
423406
}
424407

425-
return getOrCreateImpl(To, std::move(Offs),
426-
std::min(AML->lifetime(), From->lifetime()));
408+
return getOrCreateImpl(To, Offs, std::min(AML->lifetime(), From->lifetime()));
427409
}
428410

429411
const AbstractMemoryLocationImpl *
@@ -462,9 +444,8 @@ AbstractMemoryLocationFactoryBase::withTransferFromImpl(
462444
#endif
463445
}
464446

465-
const auto *Ret =
466-
getOrCreateImpl(To->base(), std::move(Offs),
467-
std::min(AML->lifetime(), MaximumSize - Offs.size()));
447+
const auto *Ret = getOrCreateImpl(
448+
To->base(), Offs, std::min(AML->lifetime(), MaximumSize - Offs.size()));
468449

469450
#ifdef XTAINT_DIAGNOSTICS
470451
if (isOverApproximating)

0 commit comments

Comments
 (0)