Skip to content

Commit 8e95772

Browse files
committed
improve error messages
1 parent 453c629 commit 8e95772

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

llvm/lib/Target/NVPTX/NVVMReflect.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,47 +159,53 @@ void NVVMReflect::handleReflectFunction(Function *F) {
159159
// to dig deeper to find its initializer with the string we'll use for lookup.
160160

161161
for (User *U : make_early_inc_range(F->users())) {
162-
assert(isa<CallInst>(U) && "Only a call instruction can use _reflect");
162+
if (!isa<CallInst>(U))
163+
report_fatal_error("__nvvm_reflect can only be used in a call instruction");
163164
CallInst *Call = cast<CallInst>(U);
164165

165-
// FIXME: Improve error handling here and elsewhere in this pass.
166-
assert(Call->getNumOperands() == 2 &&
167-
"Wrong number of operands to __nvvm_reflect function");
166+
if (Call->getNumOperands() != 2)
167+
report_fatal_error("__nvvm_reflect requires exactly one argument");
168168

169169
// In cuda 6.5 and earlier, we will have an extra constant-to-generic
170170
// conversion of the string.
171171
const Value *Str = Call->getArgOperand(0);
172172
if (const CallInst *ConvCall = dyn_cast<CallInst>(Str)) {
173173
// Verify this is the constant-to-generic intrinsic
174174
Function *Callee = ConvCall->getCalledFunction();
175-
assert(Callee && Callee->isIntrinsic() &&
176-
Callee->getName().starts_with("llvm.nvvm.ptr.constant.to.gen") &&
177-
"Expected llvm.nvvm.ptr.constant.to.gen intrinsic");
178-
assert(ConvCall->getNumOperands() == 2 && "Expected one argument for ptr conversion");
175+
if (!Callee || !Callee->isIntrinsic() ||
176+
!Callee->getName().starts_with("llvm.nvvm.ptr.constant.to.gen"))
177+
report_fatal_error("Expected llvm.nvvm.ptr.constant.to.gen intrinsic");
178+
if (ConvCall->getNumOperands() != 2)
179+
report_fatal_error("Expected one argument for ptr conversion");
179180
Str = ConvCall->getArgOperand(0);
180181
}
181182
// Pre opaque pointers we have a constant expression wrapping the constant
182183
Str = Str->stripPointerCasts();
183-
assert(isa<Constant>(Str) && "Format of __nvvm_reflect function not recognized");
184+
if (!isa<Constant>(Str))
185+
report_fatal_error("__nvvm_reflect argument must be a constant string");
184186

185187
const Value *Operand = cast<Constant>(Str)->getOperand(0);
186188
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) {
187189
// For CUDA-7.0 style __nvvm_reflect calls, we need to find the operand's
188190
// initializer.
189-
assert(GV->hasInitializer() && "Format of _reflect function not recognized");
191+
if (!GV->hasInitializer())
192+
report_fatal_error("__nvvm_reflect string must have an initializer");
190193
const Constant *Initializer = GV->getInitializer();
191194
Operand = Initializer;
192195
}
193196

194-
assert(isa<ConstantDataSequential>(Operand) &&
195-
"Format of _reflect function not recognized");
196-
assert(cast<ConstantDataSequential>(Operand)->isCString() &&
197-
"Format of _reflect function not recognized");
197+
if (!isa<ConstantDataSequential>(Operand))
198+
report_fatal_error("__nvvm_reflect argument must be a string constant");
199+
if (!cast<ConstantDataSequential>(Operand)->isCString())
200+
report_fatal_error("__nvvm_reflect argument must be a null-terminated string");
198201

199202
StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString();
200203
// Remove the null terminator from the string
201204
ReflectArg = ReflectArg.substr(0, ReflectArg.size() - 1);
202205

206+
if (ReflectArg.empty())
207+
report_fatal_error("__nvvm_reflect argument cannot be empty");
208+
203209
int ReflectVal = 0; // The default value is 0
204210
if (VarMap.contains(ReflectArg)) {
205211
ReflectVal = VarMap[ReflectArg];

0 commit comments

Comments
 (0)