Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Analysis/MemDerefPrinter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MemDerefPrinter.cpp - Printer for isDereferenceablePointer ---------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/Analysis/Loads.h"
10
#include "llvm/Analysis/Passes.h"
11
#include "llvm/IR/CallSite.h"
12
#include "llvm/IR/DataLayout.h"
13
#include "llvm/IR/InstIterator.h"
14
#include "llvm/IR/LLVMContext.h"
15
#include "llvm/IR/Module.h"
16
#include "llvm/Support/ErrorHandling.h"
17
#include "llvm/Support/raw_ostream.h"
18
using namespace llvm;
19
20
namespace {
21
  struct MemDerefPrinter : public FunctionPass {
22
    SmallVector<Value *, 4> Deref;
23
    SmallPtrSet<Value *, 4> DerefAndAligned;
24
25
    static char ID; // Pass identification, replacement for typeid
26
1
    MemDerefPrinter() : FunctionPass(ID) {
27
1
      initializeMemDerefPrinterPass(*PassRegistry::getPassRegistry());
28
1
    }
29
1
    void getAnalysisUsage(AnalysisUsage &AU) const override {
30
1
      AU.setPreservesAll();
31
1
    }
32
    bool runOnFunction(Function &F) override;
33
    void print(raw_ostream &OS, const Module * = nullptr) const override;
34
3
    void releaseMemory() override {
35
3
      Deref.clear();
36
3
      DerefAndAligned.clear();
37
3
    }
38
  };
39
}
40
41
char MemDerefPrinter::ID = 0;
42
11.0k
INITIALIZE_PASS_BEGIN(MemDerefPrinter, "print-memderefs",
43
11.0k
                      "Memory Dereferenciblity of pointers in function", false, true)
44
11.0k
INITIALIZE_PASS_END(MemDerefPrinter, "print-memderefs",
45
                    "Memory Dereferenciblity of pointers in function", false, true)
46
47
0
FunctionPass *llvm::createMemDerefPrinter() {
48
0
  return new MemDerefPrinter();
49
0
}
50
51
3
bool MemDerefPrinter::runOnFunction(Function &F) {
52
3
  const DataLayout &DL = F.getParent()->getDataLayout();
53
75
  for (auto &I: instructions(F)) {
54
75
    if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
55
43
      Value *PO = LI->getPointerOperand();
56
43
      if (isDereferenceablePointer(PO, LI->getType(), DL))
57
33
        Deref.push_back(PO);
58
43
      if (isDereferenceableAndAlignedPointer(PO, LI->getType(),
59
43
                                             LI->getAlignment(), DL))
60
24
        DerefAndAligned.insert(PO);
61
43
    }
62
75
  }
63
3
  return false;
64
3
}
65
66
3
void MemDerefPrinter::print(raw_ostream &OS, const Module *M) const {
67
3
  OS << "The following are dereferenceable:\n";
68
33
  for (Value *V: Deref) {
69
33
    V->print(OS);
70
33
    if (DerefAndAligned.count(V))
71
24
      OS << "\t(aligned)";
72
9
    else
73
9
      OS << "\t(unaligned)";
74
33
    OS << "\n\n";
75
33
  }
76
3
}