[llvm-bugs] [Bug 45917] New: ExecutionEngine fails to get constant value when BlockAddress is passed into the function parameter

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 13 18:53:19 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45917

            Bug ID: 45917
           Summary: ExecutionEngine fails to get constant value when
                    BlockAddress is passed into the function parameter
           Product: libraries
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Generic Execution Engine Support
          Assignee: unassignedbugs at nondot.org
          Reporter: tlawodn94 at gmail.com
                CC: 1101.debian at gmail.com, llvm-bugs at lists.llvm.org

Created attachment 23486
  --> https://bugs.llvm.org/attachment.cgi?id=23486&action=edit
Interpreter bug related to ExecutionEngine

Overview:

    ExecutionEngine::getConstantValue() in
lib/ExecutionEngine/ExecutionEngine.cpp fails to obtain constant pointer value
when BlockAddress is passed into the function parameter.

Steps to Reproduce:

    1) Copy & Paste the ll code below, and save it as "bug.ll"

; ModuleID = './bug.c'
source_filename = "./bug.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: noinline nounwind optnone uwtable
define void @bug(i8*) #0 {
  ; There can be some code related to the parameter
  ; But they're not important in this issue
  ret void
}

; Function Attrs: noinline nounwind optnone uwtable
define i32 @main(i32, i8**, i8**) #0 {
entry:
  call void @bug(i8* blockaddress(@main,%entry))
  ret i32 0
}

attributes #0 = { noinline nounwind optnone uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "min-legal-vector-width"="0"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }



    2) Activate ExecutionEngine using lli's interpreter mode
       $ lli -force-interpreter -O0 bug.ll


Actual Results:

    The ExecutionEngine raises "Unknown constant pointer type!" exception and
the execution crashes.

Expected Results:

    1. ExecutionEngine should get the appropriate constant address for
BlockAddress(Especially the basicblock)
    2. The application should not crash.

Build Date & Hardware:

    Build 2020-05-14 on Ubuntu Linux 18.04

Additional Builds and Platforms:

    Occur On Build 2020-05-14 on macOS Catalina

Additional Information:

    In ExecutionEngine::getConstantValue() in
lib/ExecutionEngine/ExecutionEngine.cpp, there is a code to process constant
pointer.

// Otherwise, we have a simple constant.
...
case Type::PointerTyID:
  while (auto *A = dyn_cast<GlobalAlias>(C)) {
    C = A->getAliasee();
  }
  if (isa<ConstantPointerNull>(C))
    Result.PointerVal = nullptr;
  else if (const Function *F = dyn_cast<Function>(C))
    Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
  else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
    Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
  else
    llvm_unreachable("Unknown constant pointer type!");
  break;
...

    It seems like there is no check for the BlockAddress, so there can be a
patch like the following code or similar.

// Otherwise, we have a simple constant.
...
case Type::PointerTyID:
  while (auto *A = dyn_cast<GlobalAlias>(C)) {
    C = A->getAliasee();
  }
  if (isa<ConstantPointerNull>(C))
    Result.PointerVal = nullptr;
  else if (const Function *F = dyn_cast<Function>(C))
    Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
  else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
    Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
  else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C))
    Result = PTOGV(BA->getBasicBlock());
  else
    llvm_unreachable("Unknown constant pointer type!");
  break;
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200514/cd0951e4/attachment.html>


More information about the llvm-bugs mailing list