forked from OSchip/llvm-project
[NVPTX] Error out if initializer is given for variable in an address space that does not support initialization
llvm-svn: 211943
This commit is contained in:
parent
773ca40f5d
commit
549c773619
|
@ -1502,13 +1502,24 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
|
||||||
|
|
||||||
// Ptx allows variable initilization only for constant and global state
|
// Ptx allows variable initilization only for constant and global state
|
||||||
// spaces.
|
// spaces.
|
||||||
if (((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
|
if (GVar->hasInitializer()) {
|
||||||
(PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) &&
|
if ((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
|
||||||
GVar->hasInitializer()) {
|
(PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) {
|
||||||
const Constant *Initializer = GVar->getInitializer();
|
const Constant *Initializer = GVar->getInitializer();
|
||||||
if (!Initializer->isNullValue()) {
|
// 'undef' is treated as there is no value spefied.
|
||||||
O << " = ";
|
if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
|
||||||
printScalarConstant(Initializer, O);
|
O << " = ";
|
||||||
|
printScalarConstant(Initializer, O);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// The frontend adds zero-initializer to variables that don't have an
|
||||||
|
// initial value, so skip warning for this case.
|
||||||
|
if (!GVar->getInitializer()->isNullValue()) {
|
||||||
|
std::string warnMsg = "initial value of '" + GVar->getName().str() +
|
||||||
|
"' is not allowed in addrspace(" +
|
||||||
|
llvm::utostr_32(PTy->getAddressSpace()) + ")";
|
||||||
|
report_fatal_error(warnMsg.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
|
||||||
|
|
||||||
|
; Error out if initializer is given for address spaces that do not support initializers
|
||||||
|
; XFAIL: *
|
||||||
|
@g0 = addrspace(3) global i32 42
|
Loading…
Reference in New Issue