1 /* PR tree-optimization/78450 - strlen(s) return value can be assumed 2 to be less than the size of s 3 { dg-do compile } 4 { dg-options "-O2 -fdump-tree-optimized" } */ 5 6 #include "strlenopt.h" 7 8 extern char ax[]; 9 10 struct MemArray7 { char a7[7]; }; 11 struct MemArray6 { char a6[6]; }; 12 struct MemArray5 { char a5[5]; }; 13 struct MemArray4 { char a4[4]; }; 14 struct MemArray3 { char a3[3]; }; 15 struct MemArray2 { char a2[2]; }; 16 struct MemArray1 { char a1[1]; }; 17 struct MemArray0 { int n; char a0[0]; }; 18 struct MemArrayX { int n; char ax[]; }; 19 20 struct MemArrays 21 { 22 struct MemArray7 *ma7; 23 struct MemArray6 *ma6; 24 struct MemArray5 *ma5; 25 struct MemArray4 *ma4; 26 struct MemArray3 *ma3; 27 struct MemArray2 *ma2; 28 struct MemArray1 *ma1; 29 struct MemArray0 *ma0; 30 struct MemArrayX *max; 31 }; 32 33 extern void if_stmt_on_line (int); 34 extern void else_stmt_on_line (int); 35 36 #define T(expr) \ 37 (!!(expr) ? if_stmt_on_line (__LINE__) : else_stmt_on_line (__LINE__)) 38 test_memarray_lt(struct MemArrays * p)39void test_memarray_lt (struct MemArrays *p) 40 { 41 T (strlen (p->ma7->a7) < sizeof p->ma7->a7); 42 T (strlen (p->ma6->a6) < sizeof p->ma6->a6); 43 T (strlen (p->ma5->a5) < sizeof p->ma5->a5); 44 T (strlen (p->ma4->a4) < sizeof p->ma4->a4); 45 T (strlen (p->ma3->a3) < sizeof p->ma3->a3); 46 T (strlen (p->ma2->a2) < sizeof p->ma2->a2); 47 T (strlen (p->ma1->a1) < sizeof p->ma1->a1); 48 49 T (strlen (p->ma0->a0) < 1); 50 T (strlen (p->max->ax) < 1); 51 } 52 test_memarray_eq(struct MemArrays * p)53void test_memarray_eq (struct MemArrays *p) 54 { 55 T (strlen (p->ma7->a7) == sizeof p->ma7->a7); 56 T (strlen (p->ma6->a6) == sizeof p->ma6->a6); 57 T (strlen (p->ma5->a5) == sizeof p->ma5->a5); 58 T (strlen (p->ma4->a4) == sizeof p->ma4->a4); 59 T (strlen (p->ma3->a3) == sizeof p->ma3->a3); 60 T (strlen (p->ma2->a2) == sizeof p->ma2->a2); 61 T (strlen (p->ma1->a1) == sizeof p->ma1->a1); 62 63 T (strlen (p->ma0->a0) == 1); 64 T (strlen (p->max->ax) == 1); 65 } 66 test_memarray_gt(struct MemArrays * p)67void test_memarray_gt (struct MemArrays *p) 68 { 69 T (strlen (p->ma7->a7) > sizeof p->ma7->a7); 70 T (strlen (p->ma6->a6) > sizeof p->ma6->a6); 71 T (strlen (p->ma5->a5) > sizeof p->ma5->a5); 72 T (strlen (p->ma4->a4) > sizeof p->ma4->a4); 73 T (strlen (p->ma3->a3) > sizeof p->ma3->a3); 74 T (strlen (p->ma2->a2) > sizeof p->ma2->a2); 75 T (strlen (p->ma1->a1) > sizeof p->ma1->a1); 76 77 T (strlen (p->ma0->a0) > 1); 78 T (strlen (p->max->ax) > 1); 79 } 80 81 /* Verify that no if or else statements have been eliminated. 82 { dg-final { scan-tree-dump-times "if_stmt_on_line" 27 "optimized" } } 83 { dg-final { scan-tree-dump-times "else_stmt_on_line" 27 "optimized" } } */ 84