<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 - NVPTXInferAddressSpaces crashes when rewriting a bitcast instruction."
href="https://bugs.llvm.org/show_bug.cgi?id=31948">31948</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>NVPTXInferAddressSpaces crashes when rewriting a bitcast instruction.
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>Backend: PTX
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>acjacob@us.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I came across the issue when compiling an OpenMP program for the NVPTX target.
I've written a simple testcase in CUDA that also exposes the crash.
---
typedef struct {
float a;
float *b;
} bar;
__device__ __shared__ bar var1;
__global__ void axpy(float a, float* x, float* y) {
*(var1.b) += 1.0;
int *p = (int *) &(var1.b);
*p = 32;
}
---
Extract of traceback:
---
clang-5.0: llvm/lib/IR/Constants.cpp:1698: static llvm::Constant
*llvm::ConstantExpr::getBitCast(llvm::Constant *, llvm::Type *, bool):
Assertion `CastInst::castIsValid(Instruction::BitCast, C, DstTy) && "Invalid
constantexpr bitcast!"' failed.
...
#9 llvm::ConstantExpr::getBitCast(llvm::Constant*, llvm::Type*, bool)
llvm/lib/IR/Constants.cpp:1697:3
#10 cloneConstantExprWithNewAddressSpace(llvm::ConstantExpr*, unsigned int,
llvm::ValueMap<llvm::Value const*, llvm::WeakVH,
llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false> > >
const&) llvm/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp:347:12
#11 cloneValueWithNewAddressSpace(llvm::Value*, unsigned int,
llvm::ValueMap<llvm::Value const*, llvm::WeakVH,
llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false> > >
const&, llvm::SmallVectorImpl<llvm::Use const*>*)
llvm/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp:416:10
#12 (anonymous
namespace)::NVPTXInferAddressSpaces::rewriteWithNewAddressSpaces(std::vector<llvm::Value*,
std::allocator<llvm::Value*> > const&, llvm::DenseMap<llvm::Value const*,
unsigned int, llvm::DenseMapInfo<llvm::Value const*>,
llvm::detail::DenseMapPair<llvm::Value const*, unsigned int> > const&,
llvm::Function*) llvm/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp:536:34
#13 (anonymous
namespace)::NVPTXInferAddressSpaces::runOnFunction(llvm::Function&)
llvm/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp:450:10
#14 0x0000000011861dcc llvm::FPPassManager::runOnFunction(llvm::Function&)
llvm/lib/IR/LegacyPassManager.cpp:1513:27
---
A quick attempt to understand the code in this file and produce a patch
resulted in the following, but someone who understands the code better should
be able to determine the right fix.
Patch:
---
diff --git a/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp
b/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp
index 60c6d3d..a8451b0 100644
--- a/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp
+++ b/lib/Target/NVPTX/NVPTXInferAddressSpaces.cpp
@@ -343,6 +343,8 @@ static Value *cloneConstantExprWithNewAddressSpace(
assert(CE->getOperand(0)->getType()->getPointerAddressSpace() ==
NewAddrSpace);
return ConstantExpr::getBitCast(CE->getOperand(0), TargetType);
+ } else if (CE->getOpcode() == Instruction::BitCast) {
+ return ConstantExpr::getAddrSpaceCast(CE->getOperand(0), TargetType);
}
// Computes the operands of the new constant expression.
---
Thanks,
Arpith</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>