Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107072.c

raw
1 /* { dg-require-effective-target int32plus } */
2 /* { dg-additional-options "-fanalyzer-call-summaries --param analyzer-min-snodes-for-call-summary=0 -Wno-analyzer-symbol-too-complex" } */
3
4 /* There need to be at least two calls to a function for the
5 call-summarization code to be used.
6 TODO: add some kind of test that summarization *was* used. */
7
8 /* Reduced from an example in Emacs in which string_char_and_length
9 was being incorrectly summarized, failing to see the write to *length. */
10
11 typedef long int ptrdiff_t;
12 typedef struct Lisp_X *Lisp_Word;
13 typedef Lisp_Word Lisp_Object;
14 extern _Bool STRING_MULTIBYTE(Lisp_Object str);
15 extern unsigned char *SDATA(Lisp_Object string);
16 enum { MAX_2_BYTE_CHAR = 0x7FF };
17 enum { MAX_3_BYTE_CHAR = 0xFFFF };
18 enum { MAX_4_BYTE_CHAR = 0x1FFFFF };
19 enum { MAX_5_BYTE_CHAR = 0x3FFF7F };
20 extern int make_char_multibyte(int c);
21 static inline int string_char_and_length(unsigned char const *p, int *length) {
22 int c = p[0];
23 if (!(c & 0x80)) {
24 *length = 1;
25 return c;
26 }
27 ((0xC0 <= c) ? (void)0 : __builtin_unreachable());
28 int d = (c << 6) + p[1] - ((0xC0 << 6) + 0x80);
29 if (!(c & 0x20)) {
30 *length = 2;
31 return d + (c < 0xC2 ? 0x3FFF80 : 0);
32 }
33 d = (d << 6) + p[2] - ((0x20 << 12) + 0x80);
34 if (!(c & 0x10)) {
35 *length = 3;
36 ((MAX_2_BYTE_CHAR < d && d <= MAX_3_BYTE_CHAR)
37 ? (void)0
38 : __builtin_unreachable());
39 return d;
40 }
41 d = (d << 6) + p[3] - ((0x10 << 18) + 0x80);
42 if (!(c & 0x08)) {
43 *length = 4;
44 ((MAX_3_BYTE_CHAR < d && d <= MAX_4_BYTE_CHAR)
45 ? (void)0
46 : __builtin_unreachable());
47 return d;
48 }
49 d = (d << 6) + p[4] - ((0x08 << 24) + 0x80);
50 *length = 5;
51 ((MAX_4_BYTE_CHAR < d && d <= MAX_5_BYTE_CHAR)
52 ? (void)0
53 : __builtin_unreachable());
54 return d;
55 }
56 int fetch_string_char_advance(Lisp_Object string,
57 ptrdiff_t *charidx,
58 ptrdiff_t *byteidx) {
59 int output;
60 ptrdiff_t b = *byteidx;
61 unsigned char *chp = SDATA(string) + b;
62 if (STRING_MULTIBYTE(string)) {
63 int chlen;
64 output = string_char_and_length(chp, &chlen);
65 b += chlen;
66 } else {
67 output = *chp;
68 b++;
69 }
70 (*charidx)++;
71 *byteidx = b;
72 return output;
73 }
74 int fetch_string_char_as_multibyte_advance(Lisp_Object string,
75 ptrdiff_t *charidx,
76 ptrdiff_t *byteidx) {
77 int output;
78 ptrdiff_t b = *byteidx;
79 unsigned char *chp = SDATA(string) + b;
80 if (STRING_MULTIBYTE(string)) {
81 int chlen;
82 output = string_char_and_length(chp, &chlen);
83 b += chlen;
84 } else {
85 output = make_char_multibyte(*chp);
86 b++;
87 }
88 (*charidx)++;
89 *byteidx = b;
90 return output;
91 }