2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / pr54121.c
blob3e2c0e9bb65da45bf81a789fd7d6e1d3075f40b1
1 /* PR target/54121 */
2 /* Reported by Jan Engelhardt <jengelh@inai.de> */
4 /* { dg-do compile { target fpic } } */
5 /* { dg-options "-std=gnu99 -O -fPIC -fprofile-generate" } */
6 /* { dg-require-profiling "-fprofile-generate" } */
8 typedef __SIZE_TYPE__ size_t;
9 typedef unsigned char uint8_t;
11 extern void *memcpy (void *__restrict __dest,
12 __const void *__restrict __src, size_t __n)
13 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
15 typedef enum {
16 LZMA_OK = 0,
17 LZMA_STREAM_END = 1,
18 LZMA_NO_CHECK = 2,
19 LZMA_UNSUPPORTED_CHECK = 3,
20 LZMA_GET_CHECK = 4,
21 LZMA_MEM_ERROR = 5,
22 LZMA_MEMLIMIT_ERROR = 6,
23 LZMA_FORMAT_ERROR = 7,
24 LZMA_OPTIONS_ERROR = 8,
25 LZMA_DATA_ERROR = 9,
26 LZMA_BUF_ERROR = 10,
27 LZMA_PROG_ERROR = 11,
28 } lzma_ret;
30 typedef enum {
31 LZMA_RUN = 0,
32 LZMA_SYNC_FLUSH = 1,
33 LZMA_FULL_FLUSH = 2,
34 LZMA_FINISH = 3
35 } lzma_action;
37 typedef struct {
38 void *( *alloc)(void *opaque, size_t nmemb, size_t size);
39 void ( *free)(void *opaque, void *ptr);
40 void *opaque;
41 } lzma_allocator;
43 typedef struct lzma_coder_s lzma_coder;
45 typedef struct lzma_next_coder_s lzma_next_coder;
47 typedef struct lzma_filter_info_s lzma_filter_info;
49 typedef lzma_ret (*lzma_init_function)(
50 lzma_next_coder *next, lzma_allocator *allocator,
51 const lzma_filter_info *filters);
53 typedef lzma_ret (*lzma_code_function)(
54 lzma_coder *coder, lzma_allocator *allocator,
55 const uint8_t *restrict in, size_t *restrict in_pos,
56 size_t in_size, uint8_t *restrict out,
57 size_t *restrict out_pos, size_t out_size,
58 lzma_action action);
60 typedef void (*lzma_end_function)(
61 lzma_coder *coder, lzma_allocator *allocator);
63 typedef struct {
64 uint8_t *buf;
65 size_t pos;
66 size_t size;
67 } lzma_dict;
69 typedef struct {
70 lzma_coder *coder;
71 lzma_ret (*code)(lzma_coder *restrict coder,
72 lzma_dict *restrict dict, const uint8_t *restrict in,
73 size_t *restrict in_pos, size_t in_size);
74 } lzma_lz_decoder;
76 struct lzma_coder_s {
77 lzma_dict dict;
78 lzma_lz_decoder lz;
81 lzma_ret
82 decode_buffer(lzma_coder *coder,
83 const uint8_t *restrict in, size_t *restrict in_pos,
84 size_t in_size, uint8_t *restrict out, size_t *restrict out_pos)
86 while (1) {
87 const size_t dict_start = coder->dict.pos;
88 const lzma_ret ret
89 = coder->lz.code( coder->lz.coder, &coder->dict, in, in_pos, in_size);
90 const size_t copy_size = coder->dict.pos - dict_start;
91 memcpy(out + *out_pos, coder->dict.buf + dict_start, copy_size);
92 if (ret != LZMA_OK || coder->dict.pos < coder->dict.size)
93 return ret;