@@ -236,7 +236,7 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) {
236
236
// / If the specified expr is a simple decay from an array to pointer,
237
237
// / return the array subexpression.
238
238
// / FIXME: this could be abstracted into a common AST helper.
239
- static const Expr *isSimpleArrayDecayOperand (const Expr *e) {
239
+ static const Expr *getSimpleArrayDecayOperand (const Expr *e) {
240
240
// If this isn't just an array->pointer decay, bail out.
241
241
const auto *castExpr = dyn_cast<CastExpr>(e);
242
242
if (!castExpr || castExpr->getCastKind () != CK_ArrayToPointerDecay)
@@ -279,18 +279,12 @@ static QualType getFixedSizeElementType(const ASTContext &astContext,
279
279
return eltType;
280
280
}
281
281
282
- static mlir::Value
283
- emitArraySubscriptPtr (CIRGenFunction &cgf, mlir::Location beginLoc,
284
- mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy,
285
- ArrayRef<mlir::Value> indices, bool inbounds,
286
- bool signedIndices, bool shouldDecay,
287
- const llvm::Twine &name = " arrayidx" ) {
288
- if (indices.size () > 1 ) {
289
- cgf.cgm .errorNYI (" emitArraySubscriptPtr: handle multiple indices" );
290
- return {};
291
- }
292
-
293
- const mlir::Value idx = indices.back ();
282
+ static mlir::Value emitArraySubscriptPtr (CIRGenFunction &cgf,
283
+ mlir::Location beginLoc,
284
+ mlir::Location endLoc, mlir::Value ptr,
285
+ mlir::Type eltTy, mlir::Value idx,
286
+ bool inbounds, bool signedIndices,
287
+ bool shouldDecay) {
294
288
CIRGenModule &cgm = cgf.getCIRGenModule ();
295
289
// TODO(cir): LLVM codegen emits in bound gep check here, is there anything
296
290
// that would enhance tracking this later in CIR?
@@ -300,12 +294,11 @@ emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc,
300
294
shouldDecay);
301
295
}
302
296
303
- static Address emitArraySubscriptPtr (
304
- CIRGenFunction &cgf, mlir::Location beginLoc, mlir::Location endLoc,
305
- Address addr, ArrayRef<mlir::Value> indices, QualType eltType,
306
- bool inbounds, bool signedIndices, mlir::Location loc, bool shouldDecay,
307
- QualType *arrayType = nullptr , const Expr *base = nullptr ,
308
- const llvm::Twine &name = " arrayidx" ) {
297
+ static Address
298
+ emitArraySubscriptPtr (CIRGenFunction &cgf, mlir::Location beginLoc,
299
+ mlir::Location endLoc, Address addr, QualType eltType,
300
+ mlir::Value idx, bool inbounds, mlir::Location loc,
301
+ bool shouldDecay, QualType *arrayType, const Expr *base) {
309
302
310
303
// Determine the element size of the statically-sized base. This is
311
304
// the thing that the indices are expressed in terms of.
@@ -317,14 +310,16 @@ static Address emitArraySubscriptPtr(
317
310
// We can use that to compute the best alignment of the element.
318
311
const CharUnits eltSize = cgf.getContext ().getTypeSizeInChars (eltType);
319
312
const CharUnits eltAlign =
320
- getArrayElementAlign (addr.getAlignment (), indices. back () , eltSize);
313
+ getArrayElementAlign (addr.getAlignment (), idx , eltSize);
321
314
322
315
mlir::Value eltPtr;
323
- const mlir::IntegerAttr lastIndex = getConstantIndexOrNull (indices.back ());
324
- if (!lastIndex) {
325
- eltPtr = emitArraySubscriptPtr (cgf, beginLoc, endLoc, addr.getPointer (),
326
- addr.getElementType (), indices, inbounds,
327
- signedIndices, shouldDecay, name);
316
+ const mlir::IntegerAttr index = getConstantIndexOrNull (idx);
317
+ if (!index) {
318
+ eltPtr = emitArraySubscriptPtr (
319
+ cgf, beginLoc, endLoc, addr.getPointer (), addr.getElementType (), idx,
320
+ inbounds, idx.getType ().isSignlessIntOrIndex (), shouldDecay);
321
+ } else {
322
+ cgf.cgm .errorNYI (" emitArraySubscriptExpr: Non Constant Index" );
328
323
}
329
324
const mlir::Type elementType = cgf.convertTypeForMem (eltType);
330
325
return Address (eltPtr, elementType, eltAlign);
@@ -335,35 +330,32 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
335
330
if (e->getBase ()->getType ()->isVectorType () &&
336
331
!isa<ExtVectorElementExpr>(e->getBase ())) {
337
332
cgm.errorNYI (e->getSourceRange (), " emitArraySubscriptExpr: VectorType" );
338
- return {} ;
333
+ return LValue::makeAddr ( Address::invalid (), e-> getType ()) ;
339
334
}
340
335
341
336
if (isa<ExtVectorElementExpr>(e->getBase ())) {
342
337
cgm.errorNYI (e->getSourceRange (),
343
338
" emitArraySubscriptExpr: ExtVectorElementExpr" );
344
- return {} ;
339
+ return LValue::makeAddr ( Address::invalid (), e-> getType ()) ;
345
340
}
346
341
347
342
if (getContext ().getAsVariableArrayType (e->getType ())) {
348
343
cgm.errorNYI (e->getSourceRange (),
349
344
" emitArraySubscriptExpr: VariableArrayType" );
350
- return {} ;
345
+ return LValue::makeAddr ( Address::invalid (), e-> getType ()) ;
351
346
}
352
347
353
348
if (e->getType ()->getAs <ObjCObjectType>()) {
354
349
cgm.errorNYI (e->getSourceRange (), " emitArraySubscriptExpr: ObjCObjectType" );
355
- return {} ;
350
+ return LValue::makeAddr ( Address::invalid (), e-> getType ()) ;
356
351
}
357
352
358
353
// The index must always be an integer, which is not an aggregate. Emit it
359
354
// in lexical order (this complexity is, sadly, required by C++17).
360
355
assert ((e->getIdx () == e->getLHS () || e->getIdx () == e->getRHS ()) &&
361
356
" index was neither LHS nor RHS" );
362
357
const mlir::Value idx = emitScalarExpr (e->getIdx ());
363
- const QualType idxTy = e->getIdx ()->getType ();
364
- const bool signedIndices = idxTy->isSignedIntegerOrEnumerationType ();
365
-
366
- if (const Expr *array = isSimpleArrayDecayOperand (e->getBase ())) {
358
+ if (const Expr *array = getSimpleArrayDecayOperand (e->getBase ())) {
367
359
LValue arrayLV;
368
360
if (const auto *ase = dyn_cast<ArraySubscriptExpr>(array))
369
361
arrayLV = emitArraySubscriptExpr (ase);
@@ -374,10 +366,9 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
374
366
QualType arrayType = array->getType ();
375
367
const Address addr = emitArraySubscriptPtr (
376
368
*this , cgm.getLoc (array->getBeginLoc ()), cgm.getLoc (array->getEndLoc ()),
377
- arrayLV.getAddress (), {idx}, e->getType (),
378
- !getLangOpts ().isSignedOverflowDefined (), signedIndices,
379
- cgm.getLoc (e->getExprLoc ()), /* shouldDecay=*/ true , &arrayType,
380
- e->getBase ());
369
+ arrayLV.getAddress (), e->getType (), idx,
370
+ !getLangOpts ().isSignedOverflowDefined (), cgm.getLoc (e->getExprLoc ()),
371
+ /* shouldDecay=*/ true , &arrayType, e->getBase ());
381
372
382
373
return LValue::makeAddr (addr, e->getType ());
383
374
}
0 commit comments