[llvm-bugs] [Bug 31948] New: NVPTXInferAddressSpaces crashes when rewriting a bitcast instruction.
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Feb 13 08:46:24 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=31948
Bug ID: 31948
Summary: NVPTXInferAddressSpaces crashes when rewriting a
bitcast instruction.
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: PTX
Assignee: unassignedbugs at nondot.org
Reporter: acjacob at us.ibm.com
CC: llvm-bugs at lists.llvm.org
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
--
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/20170213/def345a4/attachment-0001.html>
More information about the llvm-bugs
mailing list