@@ -411,22 +411,26 @@ class OSSExprInfoGathering
411
411
// Get the inner expr
412
412
const Expr *TmpE = E;
413
413
// First come OSSArraySection
414
+ bool FoundPointer = false ;
414
415
while (const OSSArraySectionExpr *ASE = dyn_cast<OSSArraySectionExpr>(TmpE->IgnoreParenImpCasts ())) {
415
416
// Stop in the innermost ArrayToPointerDecay
416
417
TmpE = ASE->getBase ();
417
- // If we see a Pointer we must to add one dimension and done
418
+ // If we see a Pointer we must add one dimension and done
418
419
if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ()) {
419
420
AddDimStartEnd ();
421
+ FoundPointer = true ;
420
422
break ;
421
423
}
422
424
}
423
- while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(TmpE->IgnoreParenImpCasts ())) {
424
- // Stop in the innermost ArrayToPointerDecay
425
- TmpE = ASE->getBase ();
426
- // If we see a Pointer we must to add one dimension and done
427
- if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ()) {
428
- AddDimStartEnd ();
429
- break ;
425
+ if (!FoundPointer) {
426
+ while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(TmpE->IgnoreParenImpCasts ())) {
427
+ // Stop in the innermost ArrayToPointerDecay
428
+ TmpE = ASE->getBase ();
429
+ // If we see a Pointer we must add one dimension and done
430
+ if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ()) {
431
+ AddDimStartEnd ();
432
+ break ;
433
+ }
430
434
}
431
435
}
432
436
RetTypes.insert (RetTypes.begin (), TmpE->getType ());
@@ -645,6 +649,7 @@ class OSSDependVisitor
645
649
// Get the inner expr
646
650
const Expr *TmpE = E;
647
651
// First come OSSArraySection
652
+ bool FoundPointer = false ;
648
653
while (const OSSArraySectionExpr *ASE = dyn_cast<OSSArraySectionExpr>(TmpE->IgnoreParenImpCasts ())) {
649
654
// Stop in the innermost ArrayToPointerDecay
650
655
TmpE = ASE->getBase ();
@@ -709,22 +714,25 @@ class OSSDependVisitor
709
714
if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ()) {
710
715
assert (LengthUpper && " Sema should have forbidden unspecified sizes in pointers" );
711
716
Dims.push_back (CGF.Builder .CreateSExt (CGF.EmitScalarExpr (LengthUpper), OSSArgTy));
717
+ FoundPointer = true ;
712
718
break ;
713
719
}
714
720
}
715
- while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(TmpE->IgnoreParenImpCasts ())) {
716
- // Stop in the innermost ArrayToPointerDecay
717
- TmpE = ASE->getBase ();
718
- // Add indexes
719
- llvm::Value *Idx = CGF.EmitScalarExpr (ASE->getIdx ());
720
- Idx = CGF.Builder .CreateSExt (Idx, OSSArgTy);
721
- llvm::Value *IdxEnd = CGF.Builder .CreateAdd (Idx, llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
722
- Starts.push_back (Idx);
723
- Ends.push_back (IdxEnd);
724
- // If we see a Pointer we must to add one dimension and done
725
- if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ()) {
726
- Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
727
- break ;
721
+ if (!FoundPointer) {
722
+ while (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(TmpE->IgnoreParenImpCasts ())) {
723
+ // Stop in the innermost ArrayToPointerDecay
724
+ TmpE = ASE->getBase ();
725
+ // Add indexes
726
+ llvm::Value *Idx = CGF.EmitScalarExpr (ASE->getIdx ());
727
+ Idx = CGF.Builder .CreateSExt (Idx, OSSArgTy);
728
+ llvm::Value *IdxEnd = CGF.Builder .CreateAdd (Idx, llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
729
+ Starts.push_back (Idx);
730
+ Ends.push_back (IdxEnd);
731
+ // If we see a Pointer we must to add one dimension and done
732
+ if (TmpE->IgnoreParenImpCasts ()->getType ()->isPointerType ()) {
733
+ Dims.push_back (llvm::ConstantInt::getSigned (OSSArgTy, 1 ));
734
+ break ;
735
+ }
728
736
}
729
737
}
730
738
0 commit comments