4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Licensed under the Open Software License version 1.1
9 * expand constant expressions.
27 #include "expression.h"
29 /* Random cost numbers */
30 #define SIDE_EFFECTS 10000 /* The expression has side effects */
31 #define UNSAFE 100 /* The expression may be "infinitely costly" due to exceptions */
32 #define SELECT_COST 20 /* Cut-off for turning a conditional into a select */
33 #define BRANCH_COST 10 /* Cost of a conditional branch */
35 static int expand_expression(struct expression
*);
36 static int expand_statement(struct statement
*);
38 static int expand_symbol_expression(struct expression
*expr
)
40 struct symbol
*sym
= expr
->symbol
;
42 if (sym
== &zero_int
) {
43 if (Wundefined_preprocessor
)
44 warning(expr
->pos
, "undefined preprocessor identifier '%s'", show_ident(expr
->symbol_name
));
45 expr
->type
= EXPR_VALUE
;
49 /* The cost of a symbol expression is lower for on-stack symbols */
50 return (sym
->ctype
.modifiers
& (MOD_STATIC
| MOD_EXTERN
)) ? 2 : 1;
53 static long long get_longlong(struct expression
*expr
)
55 int no_expand
= expr
->ctype
->ctype
.modifiers
& MOD_UNSIGNED
;
56 long long mask
= 1ULL << (expr
->ctype
->bit_size
- 1);
57 long long value
= expr
->value
;
58 long long ormask
, andmask
;
62 andmask
= mask
| (mask
-1);
66 return (value
& andmask
) | ormask
;
69 void cast_value(struct expression
*expr
, struct symbol
*newtype
,
70 struct expression
*old
, struct symbol
*oldtype
)
72 int old_size
= oldtype
->bit_size
;
73 int new_size
= newtype
->bit_size
;
74 long long value
, mask
, signmask
;
75 long long oldmask
, oldsignmask
, dropped
;
77 if (newtype
->ctype
.base_type
== &fp_type
||
78 oldtype
->ctype
.base_type
== &fp_type
)
81 // For pointers and integers, we can just move the value around
82 expr
->type
= EXPR_VALUE
;
83 if (old_size
== new_size
) {
84 expr
->value
= old
->value
;
88 // expand it to the full "long long" value
89 value
= get_longlong(old
);
92 // Truncate it to the new size
93 signmask
= 1ULL << (new_size
-1);
94 mask
= signmask
| (signmask
-1);
95 expr
->value
= value
& mask
;
97 // Check if we dropped any bits..
98 oldsignmask
= 1ULL << (old_size
-1);
99 oldmask
= oldsignmask
| (oldsignmask
-1);
100 dropped
= oldmask
& ~mask
;
102 // Ok if the bits were (and still are) purely sign bits
103 if (value
& dropped
) {
104 if (!(value
& oldsignmask
) || !(value
& signmask
) || (value
& dropped
) != dropped
)
105 warning(old
->pos
, "cast truncates bits from constant value (%llx becomes %llx)",
112 if (newtype
->ctype
.base_type
!= &fp_type
) {
113 value
= (long long)old
->fvalue
;
114 expr
->type
= EXPR_VALUE
;
118 if (oldtype
->ctype
.base_type
!= &fp_type
)
119 expr
->fvalue
= (long double)get_longlong(old
);
121 expr
->fvalue
= old
->value
;
123 if (!(newtype
->ctype
.modifiers
& MOD_LONGLONG
)) {
124 if ((newtype
->ctype
.modifiers
& MOD_LONG
))
125 expr
->fvalue
= (double)expr
->fvalue
;
127 expr
->fvalue
= (float)expr
->fvalue
;
129 expr
->type
= EXPR_FVALUE
;
132 static int check_shift_count(struct expression
*expr
, struct symbol
*ctype
, unsigned int count
)
134 if (count
>= ctype
->bit_size
) {
135 warning(expr
->pos
, "shift too big (%u) for type %s", count
, show_typename(ctype
));
136 count
&= ctype
->bit_size
-1;
142 * CAREFUL! We need to get the size and sign of the
145 #define CONVERT(op,s) (((op)<<1)+(s))
146 #define SIGNED(op) CONVERT(op, 1)
147 #define UNSIGNED(op) CONVERT(op, 0)
148 static int simplify_int_binop(struct expression
*expr
, struct symbol
*ctype
)
150 struct expression
*left
= expr
->left
, *right
= expr
->right
;
151 unsigned long long v
, l
, r
, mask
;
152 signed long long sl
, sr
;
155 if (right
->type
!= EXPR_VALUE
)
158 if (expr
->op
== SPECIAL_LEFTSHIFT
|| expr
->op
== SPECIAL_RIGHTSHIFT
) {
159 r
= check_shift_count(expr
, ctype
, r
);
162 if (left
->type
!= EXPR_VALUE
)
164 l
= left
->value
; r
= right
->value
;
165 is_signed
= !(ctype
->ctype
.modifiers
& MOD_UNSIGNED
);
166 mask
= 1ULL << (ctype
->bit_size
-1);
168 if (is_signed
&& (sl
& mask
))
170 if (is_signed
&& (sr
& mask
))
173 switch (CONVERT(expr
->op
,is_signed
)) {
210 if (l
== mask
&& sr
== -1)
231 case SIGNED(SPECIAL_LEFTSHIFT
):
232 case UNSIGNED(SPECIAL_LEFTSHIFT
):
236 case SIGNED(SPECIAL_RIGHTSHIFT
):
240 case UNSIGNED(SPECIAL_RIGHTSHIFT
):
247 mask
= mask
| (mask
-1);
248 expr
->value
= v
& mask
;
249 expr
->type
= EXPR_VALUE
;
252 warning(expr
->pos
, "division by zero");
255 warning(expr
->pos
, "constant integer operation overflow");
259 static int simplify_cmp_binop(struct expression
*expr
, struct symbol
*ctype
)
261 struct expression
*left
= expr
->left
, *right
= expr
->right
;
262 unsigned long long l
, r
, mask
;
263 signed long long sl
, sr
;
265 if (left
->type
!= EXPR_VALUE
|| right
->type
!= EXPR_VALUE
)
267 l
= left
->value
; r
= right
->value
;
268 mask
= 1ULL << (ctype
->bit_size
-1);
275 case '<': expr
->value
= sl
< sr
; break;
276 case '>': expr
->value
= sl
> sr
; break;
277 case SPECIAL_LTE
: expr
->value
= sl
<= sr
; break;
278 case SPECIAL_GTE
: expr
->value
= sl
>= sr
; break;
279 case SPECIAL_EQUAL
: expr
->value
= l
== r
; break;
280 case SPECIAL_NOTEQUAL
: expr
->value
= l
!= r
; break;
281 case SPECIAL_UNSIGNED_LT
:expr
->value
= l
< r
; break;
282 case SPECIAL_UNSIGNED_GT
:expr
->value
= l
> r
; break;
283 case SPECIAL_UNSIGNED_LTE
:expr
->value
= l
<= r
; break;
284 case SPECIAL_UNSIGNED_GTE
:expr
->value
= l
>= r
; break;
286 expr
->type
= EXPR_VALUE
;
290 static int simplify_float_binop(struct expression
*expr
)
292 struct expression
*left
= expr
->left
, *right
= expr
->right
;
293 unsigned long mod
= expr
->ctype
->ctype
.modifiers
;
294 long double l
, r
, res
;
296 if (left
->type
!= EXPR_FVALUE
|| right
->type
!= EXPR_FVALUE
)
302 if (mod
& MOD_LONGLONG
) {
304 case '+': res
= l
+ r
; break;
305 case '-': res
= l
- r
; break;
306 case '*': res
= l
* r
; break;
307 case '/': if (!r
) goto Div
;
311 } else if (mod
& MOD_LONG
) {
313 case '+': res
= (double) l
+ (double) r
; break;
314 case '-': res
= (double) l
- (double) r
; break;
315 case '*': res
= (double) l
* (double) r
; break;
316 case '/': if (!r
) goto Div
;
317 res
= (double) l
/ (double) r
; break;
322 case '+': res
= (float)l
+ (float)r
; break;
323 case '-': res
= (float)l
- (float)r
; break;
324 case '*': res
= (float)l
* (float)r
; break;
325 case '/': if (!r
) goto Div
;
326 res
= (float)l
/ (float)r
; break;
330 expr
->type
= EXPR_FVALUE
;
334 warning(expr
->pos
, "division by zero");
338 static int simplify_float_cmp(struct expression
*expr
, struct symbol
*ctype
)
340 struct expression
*left
= expr
->left
, *right
= expr
->right
;
343 if (left
->type
!= EXPR_FVALUE
|| right
->type
!= EXPR_FVALUE
)
349 case '<': expr
->value
= l
< r
; break;
350 case '>': expr
->value
= l
> r
; break;
351 case SPECIAL_LTE
: expr
->value
= l
<= r
; break;
352 case SPECIAL_GTE
: expr
->value
= l
>= r
; break;
353 case SPECIAL_EQUAL
: expr
->value
= l
== r
; break;
354 case SPECIAL_NOTEQUAL
: expr
->value
= l
!= r
; break;
356 expr
->type
= EXPR_VALUE
;
360 static int expand_binop(struct expression
*expr
)
364 cost
= expand_expression(expr
->left
);
365 cost
+= expand_expression(expr
->right
);
366 if (simplify_int_binop(expr
, expr
->ctype
))
368 if (simplify_float_binop(expr
))
373 static int expand_logical(struct expression
*expr
)
375 struct expression
*left
= expr
->left
;
376 struct expression
*right
;
379 /* Do immediate short-circuiting ... */
380 cost
= expand_expression(left
);
381 if (left
->type
== EXPR_VALUE
) {
382 if (expr
->op
== SPECIAL_LOGICAL_AND
) {
384 expr
->type
= EXPR_VALUE
;
390 expr
->type
= EXPR_VALUE
;
398 rcost
= expand_expression(right
);
399 if (left
->type
== EXPR_VALUE
&& right
->type
== EXPR_VALUE
) {
401 * We know the left value doesn't matter, since
402 * otherwise we would have short-circuited it..
404 expr
->type
= EXPR_VALUE
;
405 expr
->value
= right
->value
!= 0;
410 * If the right side is safe and cheaper than a branch,
411 * just avoid the branch and turn it into a regular binop
414 if (rcost
< BRANCH_COST
) {
415 expr
->type
= EXPR_BINOP
;
416 rcost
-= BRANCH_COST
- 1;
419 return cost
+ BRANCH_COST
+ rcost
;
422 static int expand_comma(struct expression
*expr
)
426 cost
= expand_expression(expr
->left
);
427 cost
+= expand_expression(expr
->right
);
428 if (expr
->left
->type
== EXPR_VALUE
|| expr
->left
->type
== EXPR_FVALUE
)
429 *expr
= *expr
->right
;
433 #define MOD_IGN (MOD_VOLATILE | MOD_CONST)
435 static int compare_types(int op
, struct symbol
*left
, struct symbol
*right
)
439 return !type_difference(left
, right
, MOD_IGN
, MOD_IGN
);
440 case SPECIAL_NOTEQUAL
:
441 return type_difference(left
, right
, MOD_IGN
, MOD_IGN
) != NULL
;
443 return left
->bit_size
< right
->bit_size
;
445 return left
->bit_size
> right
->bit_size
;
447 return left
->bit_size
<= right
->bit_size
;
449 return left
->bit_size
>= right
->bit_size
;
454 static int expand_compare(struct expression
*expr
)
456 struct expression
*left
= expr
->left
, *right
= expr
->right
;
459 cost
= expand_expression(left
);
460 cost
+= expand_expression(right
);
462 /* Type comparison? */
463 if (left
&& right
&& left
->type
== EXPR_TYPE
&& right
->type
== EXPR_TYPE
) {
465 expr
->type
= EXPR_VALUE
;
466 expr
->value
= compare_types(op
, left
->symbol
, right
->symbol
);
469 if (simplify_cmp_binop(expr
, left
->ctype
))
471 if (simplify_float_cmp(expr
, left
->ctype
))
476 static int expand_conditional(struct expression
*expr
)
478 struct expression
*cond
= expr
->conditional
;
479 struct expression
*true = expr
->cond_true
;
480 struct expression
*false = expr
->cond_false
;
483 cond_cost
= expand_expression(cond
);
484 if (cond
->type
== EXPR_VALUE
) {
490 return expand_expression(expr
);
493 cost
= expand_expression(true);
494 cost
+= expand_expression(false);
496 if (cost
< SELECT_COST
) {
497 expr
->type
= EXPR_SELECT
;
498 cost
-= BRANCH_COST
- 1;
501 return cost
+ cond_cost
+ BRANCH_COST
;
504 static int expand_assignment(struct expression
*expr
)
506 expand_expression(expr
->left
);
507 expand_expression(expr
->right
);
511 static int expand_addressof(struct expression
*expr
)
513 return expand_expression(expr
->unop
);
516 static int expand_dereference(struct expression
*expr
)
518 struct expression
*unop
= expr
->unop
;
520 expand_expression(unop
);
523 * NOTE! We get a bogus warning right now for some special
524 * cases: apparently I've screwed up the optimization of
525 * a zero-offset derefence, and the ctype is wrong.
527 * Leave the warning in anyway, since this is also a good
528 * test for me to get the type evaluation right..
530 if (expr
->ctype
->ctype
.modifiers
& MOD_NODEREF
)
531 warning(unop
->pos
, "dereference of noderef expression");
533 if (unop
->type
== EXPR_SYMBOL
) {
534 struct symbol
*sym
= unop
->symbol
;
536 /* Const symbol with a constant initializer? */
537 if (!(sym
->ctype
.modifiers
& (MOD_ASSIGNED
| MOD_ADDRESSABLE
))) {
538 struct expression
*value
= sym
->initializer
;
540 if (value
->type
== EXPR_VALUE
) {
541 expr
->type
= EXPR_VALUE
;
542 expr
->value
= value
->value
;
544 } else if (value
->type
== EXPR_FVALUE
) {
545 expr
->type
= EXPR_FVALUE
;
546 expr
->fvalue
= value
->fvalue
;
552 /* Direct symbol dereference? Cheap and safe */
553 return (sym
->ctype
.modifiers
& (MOD_STATIC
| MOD_EXTERN
)) ? 2 : 1;
558 static int simplify_preop(struct expression
*expr
)
560 struct expression
*op
= expr
->unop
;
561 unsigned long long v
, mask
;
563 if (op
->type
!= EXPR_VALUE
)
566 mask
= 1ULL << (expr
->ctype
->bit_size
-1);
571 if (v
== mask
&& !(expr
->ctype
->ctype
.modifiers
& MOD_UNSIGNED
))
575 case '!': v
= !v
; break;
576 case '~': v
= ~v
; break;
579 mask
= mask
| (mask
-1);
580 expr
->value
= v
& mask
;
581 expr
->type
= EXPR_VALUE
;
585 warning(expr
->pos
, "constant integer operation overflow");
589 static int simplify_float_preop(struct expression
*expr
)
591 struct expression
*op
= expr
->unop
;
594 if (op
->type
!= EXPR_FVALUE
)
599 case '-': v
= -v
; break;
603 expr
->type
= EXPR_FVALUE
;
608 * Unary post-ops: x++ and x--
610 static int expand_postop(struct expression
*expr
)
612 expand_expression(expr
->unop
);
616 static int expand_preop(struct expression
*expr
)
622 return expand_dereference(expr
);
625 return expand_addressof(expr
);
627 case SPECIAL_INCREMENT
:
628 case SPECIAL_DECREMENT
:
630 * From a type evaluation standpoint the pre-ops are
631 * the same as the postops
633 return expand_postop(expr
);
638 cost
= expand_expression(expr
->unop
);
640 if (simplify_preop(expr
))
642 if (simplify_float_preop(expr
))
647 static int expand_arguments(struct expression_list
*head
)
650 struct expression
*expr
;
652 FOR_EACH_PTR (head
, expr
) {
653 cost
+= expand_expression(expr
);
654 } END_FOR_EACH_PTR(expr
);
658 static int expand_cast(struct expression
*expr
)
661 struct expression
*target
= expr
->cast_expression
;
663 cost
= expand_expression(target
);
665 /* Simplify normal integer casts.. */
666 if (target
->type
== EXPR_VALUE
|| target
->type
== EXPR_FVALUE
) {
667 cast_value(expr
, expr
->ctype
, target
, target
->ctype
);
673 /* The arguments are constant if the cost of all of them is zero */
674 int expand_constant_p(struct expression
*expr
, int cost
)
676 expr
->type
= EXPR_VALUE
;
681 /* The arguments are safe, if their cost is less than SIDE_EFFECTS */
682 int expand_safe_p(struct expression
*expr
, int cost
)
684 expr
->type
= EXPR_VALUE
;
685 expr
->value
= (cost
< SIDE_EFFECTS
);
690 * expand a call expression with a symbol. This
691 * should expand builtins.
693 static int expand_symbol_call(struct expression
*expr
, int cost
)
695 struct expression
*fn
= expr
->fn
;
696 struct symbol
*ctype
= fn
->ctype
;
698 if (fn
->type
!= EXPR_PREOP
)
701 if (ctype
->op
&& ctype
->op
->expand
)
702 return ctype
->op
->expand(expr
, cost
);
707 static int expand_call(struct expression
*expr
)
711 struct expression
*fn
= expr
->fn
;
713 cost
= expand_arguments(expr
->args
);
716 error(expr
->pos
, "function has no type");
719 if (sym
->type
== SYM_NODE
)
720 return expand_symbol_call(expr
, cost
);
725 static int expand_expression_list(struct expression_list
*list
)
728 struct expression
*expr
;
730 FOR_EACH_PTR(list
, expr
) {
731 cost
+= expand_expression(expr
);
732 } END_FOR_EACH_PTR(expr
);
737 * We can simplify nested position expressions if
738 * this is a simple (single) positional expression.
740 static int expand_pos_expression(struct expression
*expr
)
742 struct expression
*nested
= expr
->init_expr
;
743 unsigned long offset
= expr
->init_offset
;
744 int nr
= expr
->init_nr
;
747 switch (nested
->type
) {
749 offset
+= nested
->init_offset
;
751 expr
->init_offset
= offset
;
755 case EXPR_INITIALIZER
: {
756 struct expression
*reuse
= nested
, *entry
;
758 FOR_EACH_PTR(expr
->expr_list
, entry
) {
759 if (entry
->type
== EXPR_POS
) {
760 entry
->init_offset
+= offset
;
764 * This happens rarely, but it can happen
765 * with bitfields that are all at offset
768 reuse
= alloc_expression(entry
->pos
, EXPR_POS
);
770 reuse
->type
= EXPR_POS
;
771 reuse
->ctype
= entry
->ctype
;
772 reuse
->init_offset
= offset
;
774 reuse
->init_expr
= entry
;
775 REPLACE_CURRENT_PTR(entry
, reuse
);
778 } END_FOR_EACH_PTR(entry
);
787 return expand_expression(nested
);
790 static int compare_expressions(const void *_a
, const void *_b
)
792 const struct expression
*a
= _a
;
793 const struct expression
*b
= _b
;
796 r
= (b
->type
!= EXPR_POS
) - (a
->type
!= EXPR_POS
);
799 if (a
->init_offset
< b
->init_offset
)
801 if (a
->init_offset
> b
->init_offset
)
803 /* Check bitfield offset.. */
807 if (a
->ctype
&& b
->ctype
) {
808 if (a
->ctype
->bit_offset
< b
->ctype
->bit_offset
)
816 static void sort_expression_list(struct expression_list
**list
)
818 sort_list((struct ptr_list
**)list
, compare_expressions
);
821 static int expand_expression(struct expression
*expr
)
828 switch (expr
->type
) {
835 return expand_symbol_expression(expr
);
837 return expand_binop(expr
);
840 return expand_logical(expr
);
843 return expand_comma(expr
);
846 return expand_compare(expr
);
848 case EXPR_ASSIGNMENT
:
849 return expand_assignment(expr
);
852 return expand_preop(expr
);
855 return expand_postop(expr
);
858 case EXPR_IMPLIED_CAST
:
859 return expand_cast(expr
);
862 return expand_call(expr
);
865 warning(expr
->pos
, "we should not have an EXPR_DEREF left at expansion time");
869 case EXPR_CONDITIONAL
:
870 return expand_conditional(expr
);
872 case EXPR_STATEMENT
: {
873 struct statement
*stmt
= expr
->statement
;
874 int cost
= expand_statement(stmt
);
876 if (stmt
->type
== STMT_EXPRESSION
&& stmt
->expression
)
877 *expr
= *stmt
->expression
;
884 case EXPR_INITIALIZER
:
885 sort_expression_list(&expr
->expr_list
);
886 return expand_expression_list(expr
->expr_list
);
888 case EXPR_IDENTIFIER
:
895 return expand_expression(expr
->base
) + 1;
898 return expand_pos_expression(expr
);
903 warning(expr
->pos
, "internal front-end error: sizeof in expansion?");
909 static void expand_const_expression(struct expression
*expr
, const char *where
)
912 expand_expression(expr
);
913 if (expr
->type
!= EXPR_VALUE
)
914 warning(expr
->pos
, "Expected constant expression in %s", where
);
918 void expand_symbol(struct symbol
*sym
)
920 struct symbol
*base_type
;
924 base_type
= sym
->ctype
.base_type
;
928 expand_expression(sym
->initializer
);
929 /* expand the body of the symbol */
930 if (base_type
->type
== SYM_FN
) {
932 expand_statement(base_type
->stmt
);
936 static void expand_return_expression(struct statement
*stmt
)
938 expand_expression(stmt
->expression
);
941 static int expand_if_statement(struct statement
*stmt
)
943 struct expression
*expr
= stmt
->if_conditional
;
945 if (!expr
|| !expr
->ctype
)
948 expand_expression(expr
);
950 /* This is only valid if nobody jumps into the "dead" side */
952 /* Simplify constant conditionals without even evaluating the false side */
953 if (expr
->type
== EXPR_VALUE
) {
954 struct statement
*simple
;
955 simple
= expr
->value
? stmt
->if_true
: stmt
->if_false
;
959 stmt
->type
= STMT_NONE
;
962 expand_statement(simple
);
967 expand_statement(stmt
->if_true
);
968 expand_statement(stmt
->if_false
);
973 * Expanding a compound statement is really just
974 * about adding up the costs of each individual
977 * We also collapse a simple compound statement:
978 * this would trigger for simple inline functions,
979 * except we would have to check the "return"
980 * symbol usage. Next time.
982 static int expand_compound(struct statement
*stmt
)
985 struct statement
*s
, *last
;
986 int cost
, symbols
, statements
;
989 FOR_EACH_PTR(stmt
->syms
, sym
) {
992 } END_FOR_EACH_PTR(sym
);
996 expand_symbol(stmt
->ret
);
1002 FOR_EACH_PTR(stmt
->stmts
, s
) {
1005 cost
+= expand_statement(s
);
1006 } END_FOR_EACH_PTR(s
);
1008 if (!symbols
&& statements
== 1)
1014 static int expand_statement(struct statement
*stmt
)
1019 switch (stmt
->type
) {
1021 expand_return_expression(stmt
);
1022 return SIDE_EFFECTS
;
1024 case STMT_EXPRESSION
:
1025 return expand_expression(stmt
->expression
);
1028 return expand_compound(stmt
);
1031 return expand_if_statement(stmt
);
1034 expand_expression(stmt
->iterator_pre_condition
);
1035 expand_expression(stmt
->iterator_post_condition
);
1036 expand_statement(stmt
->iterator_pre_statement
);
1037 expand_statement(stmt
->iterator_statement
);
1038 expand_statement(stmt
->iterator_post_statement
);
1039 return SIDE_EFFECTS
;
1042 expand_expression(stmt
->switch_expression
);
1043 expand_statement(stmt
->switch_statement
);
1044 return SIDE_EFFECTS
;
1047 expand_const_expression(stmt
->case_expression
, "case statement");
1048 expand_const_expression(stmt
->case_to
, "case statement");
1049 expand_statement(stmt
->case_statement
);
1050 return SIDE_EFFECTS
;
1053 expand_statement(stmt
->label_statement
);
1054 return SIDE_EFFECTS
;
1057 expand_expression(stmt
->goto_expression
);
1058 return SIDE_EFFECTS
;
1063 /* FIXME! Do the asm parameter evaluation! */
1066 expand_expression(stmt
->expression
);
1069 expand_expression(stmt
->range_expression
);
1070 expand_expression(stmt
->range_low
);
1071 expand_expression(stmt
->range_high
);
1074 return SIDE_EFFECTS
;
1077 long long get_expression_value(struct expression
*expr
)
1079 long long value
, mask
;
1080 struct symbol
*ctype
;
1084 ctype
= evaluate_expression(expr
);
1086 warning(expr
->pos
, "bad constant expression type");
1089 expand_expression(expr
);
1090 if (expr
->type
!= EXPR_VALUE
) {
1091 warning(expr
->pos
, "bad constant expression");
1095 value
= expr
->value
;
1096 mask
= 1ULL << (ctype
->bit_size
-1);
1099 while (ctype
->type
!= SYM_BASETYPE
)
1100 ctype
= ctype
->ctype
.base_type
;
1101 if (!(ctype
->ctype
.modifiers
& MOD_UNSIGNED
))
1102 value
= value
| mask
| ~(mask
-1);