[LLVMdev] DataLayout missing in isDereferenceablePointer()

Sanjoy Das sanjoy at playingwithpointers.com
Sun Feb 8 23:01:51 PST 2015


Ram,

You need to change MemDerefPrinter to pass in the DataLayout to
isDereferenceablePointer.  The test passes with this change:

(NB: this may not be the right way to solve the problem)

diff --git a/lib/Analysis/MemDerefPrinter.cpp b/lib/Analysis/MemDerefPrinter.cpp
index 64cec18..d239cdf 100644
--- a/lib/Analysis/MemDerefPrinter.cpp
+++ b/lib/Analysis/MemDerefPrinter.cpp
@@ -36,22 +36,23 @@ namespace {
 char MemDerefPrinter::ID = 0;
 INITIALIZE_PASS(MemDerefPrinter, "print-memderefs",
                 "Memory Dereferenciblity of pointers in function", false, true)

 FunctionPass *llvm::createMemDerefPrinter() {
   return new MemDerefPrinter();
 }

 bool MemDerefPrinter::runOnFunction(Function &F) {
+  const DataLayout *DL = F.getDataLayout();
   for (auto &I: inst_range(F)) {
     if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
       Value *PO = LI->getPointerOperand();
-      if (PO->isDereferenceablePointer(nullptr))
+      if (PO->isDereferenceablePointer(DL))
         Vec.push_back(PO);
     }
   }
   return false;
 }

 void MemDerefPrinter::print(raw_ostream &OS, const Module *M) const {
   OS << "The following are dereferenceable:\n";
   for (auto &V: Vec) {
diff --git a/test/Analysis/ValueTracking/memory-dereferenceable.ll
b/test/Analysis/ValueTracking/memory-dereferenceable.ll
index 1ec3fef..f4ca532 100644
--- a/test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ b/test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -1,19 +1,21 @@
 ; RUN: opt -print-memderefs -analyze -S <%s | FileCheck %s

 ; Uses the print-deref (+ analyze to print) pass to run
 ; isDereferenceablePointer() on many load instruction operands

+target datalayout = "e"
+
 declare zeroext i1 @return_i1()

 @globalstr = global [6 x i8] c"hello\00"

-define void @test(i32 addrspace(1)* byval %dparam) {
+define void @test(i32 addrspace(1)* dereferenceable(8) %dparam) {
 ; CHECK: The following are dereferenceable:
 ; CHECK: %globalptr
 ; CHECK: %alloca
 ; CHECK: %dparam
 ; We haven't yet taught it to look through relocations
 ; CHECK-NOT: %relocate
 ; CHECK-NOT: %nparam
 entry:
     %globalptr = getelementptr inbounds [6 x i8]* @globalstr, i32 0, i32 0

On Sun, Feb 8, 2015 at 10:14 PM, Ramkumar Ramachandra
<artagnon at gmail.com> wrote:
> Eric Christopher wrote:
>> How are you trying to call it? Do you have a DataLayout?
>
> In test/Analysis/ValueTracking/memory-dereferenceable.ll, just change
> byval to dereferenceable(8), and %dparam won't match (see
> lib/IR/Value.cpp:521 for the logic that is supposed to fire). How do I
> get it to pass? I tried introducing a target-triple and
> target-datalayout, but it didn't help.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



More information about the llvm-dev mailing list