<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - ExecutionEngine fails to get constant value when BlockAddress is passed into the function parameter"
href="https://bugs.llvm.org/show_bug.cgi?id=45917">45917</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ExecutionEngine fails to get constant value when BlockAddress is passed into the function parameter
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Generic Execution Engine Support
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>tlawodn94@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>1101.debian@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=23486" name="attach_23486" title="Interpreter bug related to ExecutionEngine">attachment 23486</a> <a href="attachment.cgi?id=23486&action=edit" title="Interpreter bug related to ExecutionEngine">[details]</a></span>
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;
...</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>