2013-10-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / pr54121.c
blobb9a208ea84e60e8ec8b8d5b17f1ac91ba1cecbd9
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" } */
7 typedef __SIZE_TYPE__ size_t;
8 typedef unsigned char uint8_t;
10 extern void *memcpy (void *__restrict __dest,
11 __const void *__restrict __src, size_t __n)
12 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
14 typedef enum {
15 LZMA_OK = 0,
16 LZMA_STREAM_END = 1,
17 LZMA_NO_CHECK = 2,
18 LZMA_UNSUPPORTED_CHECK = 3,
19 LZMA_GET_CHECK = 4,
20 LZMA_MEM_ERROR = 5,
21 LZMA_MEMLIMIT_ERROR = 6,
22 LZMA_FORMAT_ERROR = 7,
23 LZMA_OPTIONS_ERROR = 8,
24 LZMA_DATA_ERROR = 9,
25 LZMA_BUF_ERROR = 10,
26 LZMA_PROG_ERROR = 11,
27 } lzma_ret;
29 typedef enum {
30 LZMA_RUN = 0,
31 LZMA_SYNC_FLUSH = 1,
32 LZMA_FULL_FLUSH = 2,
33 LZMA_FINISH = 3
34 } lzma_action;
36 typedef struct {
37 void *( *alloc)(void *opaque, size_t nmemb, size_t size);
38 void ( *free)(void *opaque, void *ptr);
39 void *opaque;
40 } lzma_allocator;
42 typedef struct lzma_coder_s lzma_coder;
44 typedef struct lzma_next_coder_s lzma_next_coder;
46 typedef struct lzma_filter_info_s lzma_filter_info;
48 typedef lzma_ret (*lzma_init_function)(
49 lzma_next_coder *next, lzma_allocator *allocator,
50 const lzma_filter_info *filters);
52 typedef lzma_ret (*lzma_code_function)(
53 lzma_coder *coder, lzma_allocator *allocator,
54 const uint8_t *restrict in, size_t *restrict in_pos,
55 size_t in_size, uint8_t *restrict out,
56 size_t *restrict out_pos, size_t out_size,
57 lzma_action action);
59 typedef void (*lzma_end_function)(
60 lzma_coder *coder, lzma_allocator *allocator);
62 typedef struct {
63 uint8_t *buf;
64 size_t pos;
65 size_t size;
66 } lzma_dict;
68 typedef struct {
69 lzma_coder *coder;
70 lzma_ret (*code)(lzma_coder *restrict coder,
71 lzma_dict *restrict dict, const uint8_t *restrict in,
72 size_t *restrict in_pos, size_t in_size);
73 } lzma_lz_decoder;
75 struct lzma_coder_s {
76 lzma_dict dict;
77 lzma_lz_decoder lz;
80 lzma_ret
81 decode_buffer(lzma_coder *coder,
82 const uint8_t *restrict in, size_t *restrict in_pos,
83 size_t in_size, uint8_t *restrict out, size_t *restrict out_pos)
85 while (1) {
86 const size_t dict_start = coder->dict.pos;
87 const lzma_ret ret
88 = coder->lz.code( coder->lz.coder, &coder->dict, in, in_pos, in_size);
89 const size_t copy_size = coder->dict.pos - dict_start;
90 memcpy(out + *out_pos, coder->dict.buf + dict_start, copy_size);
91 if (ret != LZMA_OK || coder->dict.pos < coder->dict.size)
92 return ret;