[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:
Justin Holewinski 2014-06-27 18:36:01 +00:00
parent 773ca40f5d
commit 549c773619
2 changed files with 23 additions and 7 deletions

View File

@ -1502,13 +1502,24 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
// Ptx allows variable initilization only for constant and global state
// spaces.
if (((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
(PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) &&
GVar->hasInitializer()) {
const Constant *Initializer = GVar->getInitializer();
if (!Initializer->isNullValue()) {
O << " = ";
printScalarConstant(Initializer, O);
if (GVar->hasInitializer()) {
if ((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
(PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) {
const Constant *Initializer = GVar->getInitializer();
// 'undef' is treated as there is no value spefied.
if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
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 {

View File

@ -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