1 /* { dg-options "-fcompare-debug" } */
2
3 enum signop { SIGNED, UNSIGNED };
4 enum tree_code { FOO, BAR };
5 enum tree_code_class { tcc_type, tcc_other };
6 extern enum tree_code_class tree_code_type[];
7
8 struct tree_base {
9 enum tree_code code : 8;
10 unsigned unsigned_flag : 1;
11 };
12
13 struct tree_def {
14 tree_base base;
15 struct {
16 int precision;
17 } type_common;
18 };
19
20 typedef tree_def *tree;
21
22 struct storage_ref
23 {
24 storage_ref (const long *, unsigned int, unsigned int);
25
26 const long *val;
27 unsigned int len;
28 unsigned int precision;
29 };
30
storage_ref(const long * val_in,unsigned int len_in,unsigned int precision_in)31 inline storage_ref::storage_ref (const long *val_in,
32 unsigned int len_in,
33 unsigned int precision_in)
34 : val (val_in), len (len_in), precision (precision_in)
35 {
36 }
37
38 struct hwi_with_prec
39 {
40 long val;
41 unsigned int precision;
42 signop sgn;
43 };
44
45 inline storage_ref
decompose(long * scratch,unsigned int precision,const hwi_with_prec & x)46 decompose (long *scratch, unsigned int precision,
47 const hwi_with_prec &x)
48 {
49 scratch[0] = x.val;
50 if (x.sgn == SIGNED || x.val >= 0 || precision <= sizeof (long) * 8)
51 return storage_ref (scratch, 1, precision);
52 scratch[1] = 0;
53 return storage_ref (scratch, 2, precision);
54 }
55
56 extern void tree_class_check_failed (int) __attribute__ ((__noreturn__));
57
58 inline tree
tree_class_check(tree t,const enum tree_code_class cls,int x)59 tree_class_check (tree t, const enum tree_code_class cls, int x)
60 {
61 if (tree_code_type[t->base.code] != cls)
62 tree_class_check_failed (x);
63 return t;
64 }
65
66 tree wide_int_to_tree (tree, const storage_ref &);
67
68 tree
build_int_cstu(tree type,unsigned long val)69 build_int_cstu (tree type, unsigned long val)
70 {
71 hwi_with_prec x;
72 x.val = val;
73 x.precision = tree_class_check (type, tcc_type, 1)->type_common.precision;
74 x.sgn = (signop) tree_class_check (type, tcc_type, 2)->base.unsigned_flag;
75 long scratch[2];
76 return wide_int_to_tree (type, decompose (scratch, x.precision, x));
77 }
78