| 1 |
// PR target/34403 |
| 2 |
// Origin: Martin Michlmayr <[email protected]> |
| 3 |
|
| 4 |
// { dg-do compile } |
| 5 |
// { dg-options "-O" } |
| 6 |
|
| 7 |
typedef unsigned char uint8_t; |
| 8 |
typedef uint8_t uint8; |
| 9 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 10 |
class csVector2 |
| 11 |
{ |
| 12 |
public:float x; |
| 13 |
}; |
| 14 |
class csBox2 |
| 15 |
{ |
| 16 |
}; |
| 17 |
struct iBase |
| 18 |
{ |
| 19 |
}; |
| 20 |
struct iClipper2D:public virtual iBase |
| 21 |
{ |
| 22 |
}; |
| 23 |
template < class Class > class scfImplementation:public virtual iBase |
| 24 |
{ |
| 25 |
}; |
| 26 |
template < class Class, class I1 > class scfImplementation1:public |
| 27 |
scfImplementation < Class >, |
| 28 |
public I1 |
| 29 |
{ |
| 30 |
}; |
| 31 |
class csClipper:public scfImplementation1 < csClipper, iClipper2D > |
| 32 |
{ |
| 33 |
}; |
| 34 |
class csBoxClipper:public csClipper |
| 35 |
{ |
| 36 |
csBox2 region; |
| 37 |
virtual uint8 Clip (csVector2 * InPolygon, size_t InCount, |
| 38 |
csVector2 * OutPolygon, size_t & OutCount); |
| 39 |
}; |
| 40 |
struct StatusOutputNone |
| 41 |
{ |
| 42 |
}; |
| 43 |
namespace CS |
| 44 |
{ |
| 45 |
template < typename BoxTest, typename StatusOutput > class BoxClipper |
| 46 |
{ |
| 47 |
BoxTest boxTest; |
| 48 |
StatusOutput statOut; |
| 49 |
const csBox2 & region; |
| 50 |
csVector2 *InP; |
| 51 |
size_t InV; |
| 52 |
csVector2 *OutP; |
| 53 |
size_t OutV; |
| 54 |
public: BoxClipper (const BoxTest & boxTest, const StatusOutput & statOut, |
| 55 |
const csBox2 & region, csVector2 * InP, size_t InV, |
| 56 |
csVector2 * OutP):boxTest (boxTest), statOut (statOut), |
| 57 |
region (region), InP (InP), InV (InV), OutP (OutP), OutV (-1) |
| 58 |
{ |
| 59 |
} |
| 60 |
uint8 Clip () |
| 61 |
{ |
| 62 |
// OutV is initialized to SIZE_MAX in the ctor above causing |
| 63 |
// the multiplication below to produce a very large number |
| 64 |
// in excess of the maximum possible object size (SIZE_MAX/2). |
| 65 |
__builtin_memcpy (this->OutP, InP, OutV * sizeof (csVector2)); // { dg-warning "exceeds maximum object size" } |
| 66 |
return 0; |
| 67 |
} |
| 68 |
}; |
| 69 |
} |
| 70 |
struct BoxTestAll |
| 71 |
{ |
| 72 |
}; |
| 73 |
uint8 |
| 74 |
csBoxClipper::Clip (csVector2 * InPolygon, size_t InCount, |
| 75 |
csVector2 * OutPolygon, size_t & OutCount) |
| 76 |
{ |
| 77 |
BoxTestAll b; |
| 78 |
StatusOutputNone n; |
| 79 |
CS::BoxClipper < BoxTestAll, StatusOutputNone > boxClip (b, n, region, |
| 80 |
InPolygon, InCount, |
| 81 |
OutPolygon); |
| 82 |
uint8 Clipped = boxClip.Clip (); |
| 83 |
return 0; |
| 84 |
} |