OSDN Git Service

* gcc.dg/simulate-thread/simulate-thread.gdb: Call
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / pr43402.c
1 /* { dg-do run } */
2 /* { dg-options "-O1 -fno-inline" } */
3 /* { dg-require-effective-target int32plus } */
4
5 extern void abort (void);
6
7 static int something;
8
9 static int * converterData[2]={
10     &something, &something,
11 };
12
13 static struct {
14   const char *name;
15   int type;
16 } const cnvNameType[] = {
17   { "bocu1", 1 },
18   { "utf7", 1 },
19   { "utf8", 1 }
20 };
21
22
23 const int * getAlgorithmicTypeFromName(const char *realName);
24 const int *
25 getAlgorithmicTypeFromName(const char *realName)
26 {
27     unsigned mid, start, limit;
28     unsigned lastMid;
29     int result;
30     start = 0;
31     limit = sizeof(cnvNameType)/sizeof(cnvNameType[0]);
32     mid = limit;
33     lastMid = 0xffffffff;
34
35     for (;;) {
36         mid = (start + limit) / 2;
37         if (lastMid == mid) {   /* Have we moved? */
38             break;  /* We haven't moved, and it wasn't found. */
39         }
40         lastMid = mid;
41         result = __builtin_strcmp(realName, cnvNameType[mid].name);
42
43         if (result < 0) {
44             limit = mid;
45         } else if (result > 0) {
46             start = mid;
47         } else {
48             return converterData[cnvNameType[mid].type];
49         }
50     }
51
52     return 0;
53 }
54
55 int main (void)
56 {
57   if (!getAlgorithmicTypeFromName ("utf8"))
58     abort ();
59   return 0;
60 }