llvm.org GIT mirror llvm / 3c81367
[NVPTX] Error out if initializer is given for variable in an address space that does not support initialization git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211943 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Holewinski 5 years ago
2 changed file(s) with 23 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
15011501
15021502 // Ptx allows variable initilization only for constant and global state
15031503 // spaces.
1504 if (((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
1505 (PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) &&
1506 GVar->hasInitializer()) {
1507 const Constant *Initializer = GVar->getInitializer();
1508 if (!Initializer->isNullValue()) {
1509 O << " = ";
1510 printScalarConstant(Initializer, O);
1504 if (GVar->hasInitializer()) {
1505 if ((PTy->getAddressSpace() == llvm::ADDRESS_SPACE_GLOBAL) ||
1506 (PTy->getAddressSpace() == llvm::ADDRESS_SPACE_CONST)) {
1507 const Constant *Initializer = GVar->getInitializer();
1508 // 'undef' is treated as there is no value spefied.
1509 if (!Initializer->isNullValue() && !isa(Initializer)) {
1510 O << " = ";
1511 printScalarConstant(Initializer, O);
1512 }
1513 } else {
1514 // The frontend adds zero-initializer to variables that don't have an
1515 // initial value, so skip warning for this case.
1516 if (!GVar->getInitializer()->isNullValue()) {
1517 std::string warnMsg = "initial value of '" + GVar->getName().str() +
1518 "' is not allowed in addrspace(" +
1519 llvm::utostr_32(PTy->getAddressSpace()) + ")";
1520 report_fatal_error(warnMsg.c_str());
1521 }
15111522 }
15121523 }
15131524 } else {
0 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
1
2 ; Error out if initializer is given for address spaces that do not support initializers
3 ; XFAIL: *
4 @g0 = addrspace(3) global i32 42