2 * Copyright (C) 2006,2008 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * The simplest type of condition is
22 * The next simplest kind of conditions is
24 * In that case 'a' is true when we get to 'b' and both are true
27 * Or's are a little more complicated.
29 * We know 'a' is not true when we get to 'b' but it may be true
32 * If we mix and's and or's that's even more complicated.
33 * if (a && b && c || a && d) { d ;
34 * 'a' is true when we evaluate 'b', and 'd'.
35 * 'b' is true when we evaluate 'c' but otherwise we don't.
37 * The other thing that complicates matters is if we negate
40 * Smatch has passes the un-negated version to the client and flip
41 * the true and false values internally. This makes it easier
44 * And negations can be part of a compound.
45 * if (a && !(b || c)) { d;
46 * In that situation we multiply the negative through to simplify
47 * stuff so that we can remove the parens like this:
48 * if (a && !b && !c) { d;
50 * One other thing is that:
52 * that's basically the same as testing for just 'a' and we simplify
53 * comparisons with zero before passing it to the script.
58 #include "smatch_slist.h"
59 #include "smatch_extra.h"
60 #include "smatch_expression_stacks.h"
62 extern int __expr_stmt_count
;
64 struct expression_list
*big_condition_stack
;
66 static void split_conditions(struct expression
*expr
, int *known_tf
);
68 static int negate_tf(int known_tf
)
75 static int is_logical_and(struct expression
*expr
)
77 if (expr
->op
== SPECIAL_LOGICAL_AND
)
82 static int handle_zero_comparisons(struct expression
*expr
, int *known_tf
)
84 struct expression
*tmp
= NULL
;
85 struct expression
*zero
;
87 // if left is zero or right is zero
88 if (expr_is_zero(expr
->left
)) {
89 zero
= strip_expr(expr
->left
);
90 if (zero
->type
!= EXPR_VALUE
)
91 __split_expr(expr
->left
);
93 } else if (expr_is_zero(expr
->right
)) {
94 zero
= strip_expr(expr
->left
);
95 if (zero
->type
!= EXPR_VALUE
)
96 __split_expr(expr
->right
);
102 // "if (foo != 0)" is the same as "if (foo)"
103 if (expr
->op
== SPECIAL_NOTEQUAL
) {
104 split_conditions(tmp
, known_tf
);
108 // "if (foo == 0)" is the same as "if (!foo)"
109 if (expr
->op
== SPECIAL_EQUAL
) {
110 split_conditions(tmp
, known_tf
);
111 *known_tf
= negate_tf(*known_tf
);
112 __negate_cond_stacks();
120 * This function is for handling calls to likely/unlikely
123 static int ignore_builtin_expect(struct expression
*expr
, int *known_tf
)
125 // TODO: move this into the caller
126 if (sym_name_is("__builtin_expect", expr
->fn
)) {
127 split_conditions(first_ptr_list((struct ptr_list
*) expr
->args
), known_tf
);
134 * handle_compound_stmt() is for: foo = ({blah; blah; blah; 1})
137 static void handle_compound_stmt(struct statement
*stmt
, int *known_tf
)
139 struct expression
*expr
= NULL
;
140 struct statement
*last
;
143 last
= last_ptr_list((struct ptr_list
*)stmt
->stmts
);
144 if (last
->type
== STMT_LABEL
) {
145 if (last
->label_statement
&&
146 last
->label_statement
->type
== STMT_EXPRESSION
)
147 expr
= last
->label_statement
->expression
;
150 } else if (last
->type
!= STMT_EXPRESSION
) {
153 expr
= last
->expression
;
156 FOR_EACH_PTR(stmt
->stmts
, s
) {
159 } END_FOR_EACH_PTR(s
);
160 if (last
&& last
->type
== STMT_LABEL
)
161 __split_label_stmt(last
);
162 split_conditions(expr
, known_tf
);
165 static int handle_preop(struct expression
*expr
, int *known_tf
)
167 struct statement
*stmt
;
169 if (expr
->op
== '!') {
170 split_conditions(expr
->unop
, known_tf
);
171 *known_tf
= negate_tf(*known_tf
);
172 __negate_cond_stacks();
175 stmt
= get_expression_statement(expr
);
177 handle_compound_stmt(stmt
, known_tf
);
183 static void handle_logical(struct expression
*expr
, int *known_tf
)
185 int left_tf
= -1, right_tf
= -1;
188 * If we come to an "and" expr then:
189 * We split the left side.
190 * We keep all the current states.
191 * We split the right side.
192 * We keep all the states from both true sides.
194 * If it's an "or" expr then:
195 * We save the current slist.
196 * We split the left side.
197 * We use the false states for the right side.
198 * We split the right side.
199 * We save all the states that are the same on both sides.
202 split_conditions(expr
->left
, &left_tf
);
204 if (is_logical_and(expr
))
205 __use_cond_true_states();
207 __use_cond_false_states();
209 __push_cond_stacks();
211 __save_pre_cond_states();
212 split_conditions(expr
->right
, &right_tf
);
213 __discard_pre_cond_states();
215 if (is_logical_and(expr
))
220 __use_cond_true_states();
222 if (is_logical_and(expr
)) {
223 if (left_tf
== true && right_tf
== true)
225 if (left_tf
== false || right_tf
== false)
228 if (left_tf
== true || right_tf
== true)
230 if (left_tf
== false && right_tf
== false)
235 static struct stree
*combine_strees(struct stree
*orig
, struct stree
*fake
, struct stree
*new)
237 struct stree
*ret
= NULL
;
239 overwrite_stree(orig
, &ret
);
240 overwrite_stree(fake
, &ret
);
241 overwrite_stree(new, &ret
);
249 * if ((aaa()?bbb():ccc())) { ...
251 * This is almost the same as:
252 * if ((aaa() && bbb()) || (!aaa() && ccc())) { ...
254 * It's a bit complicated because we shouldn't pass aaa()
255 * to the clients more than once.
258 static void handle_select(struct expression
*expr
, int *known_tf
)
260 struct stree
*a_T
= NULL
;
261 struct stree
*a_F
= NULL
;
262 struct stree
*a_T_b_T
= NULL
;
263 struct stree
*a_T_b_F
= NULL
;
264 struct stree
*a_T_b_fake
= NULL
;
265 struct stree
*a_F_c_T
= NULL
;
266 struct stree
*a_F_c_F
= NULL
;
267 struct stree
*a_F_c_fake
= NULL
;
270 int cond_tf
= -1, true_tf
= -1, false_tf
= -1;
273 * Imagine we have this: if (a ? b : c) { ...
275 * The condition is true if "a" is true and "b" is true or
276 * "a" is false and "c" is true. It's false if "a" is true
277 * and "b" is false or "a" is false and "c" is false.
279 * The variable name "a_T_b_T" stands for "a true b true" etc.
281 * But if we know "b" is true then we can simpilify things.
282 * The condition is true if "a" is true or if "a" is false and
283 * "c" is true. The only way the condition can be false is if
284 * "a" is false and "c" is false.
286 * The remaining thing is the "a_T_b_fake". When we simplify
287 * the equations we have to take into consideration that other
288 * states may have changed that don't play into the true false
289 * equation. Take the following example:
291 * (flags) = __raw_local_irq_save();
292 * _spin_trylock(lock) ? 1 :
293 * ({ raw_local_irq_restore(flags); 0; });
295 * Smatch has to record that the irq flags were restored on the
300 __save_pre_cond_states();
302 split_conditions(expr
->conditional
, &cond_tf
);
304 a_T
= __copy_cond_true_states();
305 a_F
= __copy_cond_false_states();
307 __use_cond_true_states();
309 __push_cond_stacks();
310 __push_fake_cur_stree();
311 split_conditions(expr
->cond_true
, &true_tf
);
312 __process_post_op_stack();
313 a_T_b_fake
= __pop_fake_cur_stree();
314 a_T_b_T
= combine_strees(a_T
, a_T_b_fake
, __pop_cond_true_stack());
315 a_T_b_F
= combine_strees(a_T
, a_T_b_fake
, __pop_cond_false_stack());
317 __use_cond_false_states();
319 __push_cond_stacks();
320 __push_fake_cur_stree();
321 split_conditions(expr
->cond_false
, &false_tf
);
322 a_F_c_fake
= __pop_fake_cur_stree();
323 a_F_c_T
= combine_strees(a_F
, a_F_c_fake
, __pop_cond_true_stack());
324 a_F_c_F
= combine_strees(a_F
, a_F_c_fake
, __pop_cond_false_stack());
326 /* We have to restore the pre condition states so that
327 implied_condition_true() will use the right cur_stree */
328 __use_pre_cond_states();
330 if (implied_condition_true(expr
->cond_true
)) {
331 free_stree(&a_T_b_T
);
332 free_stree(&a_T_b_F
);
333 a_T_b_T
= clone_stree(a_T
);
334 overwrite_stree(a_T_b_fake
, &a_T_b_T
);
336 if (implied_condition_false(expr
->cond_true
)) {
337 free_stree(&a_T_b_T
);
338 free_stree(&a_T_b_F
);
339 a_T_b_F
= clone_stree(a_T
);
340 overwrite_stree(a_T_b_fake
, &a_T_b_F
);
342 if (implied_condition_true(expr
->cond_false
)) {
343 free_stree(&a_F_c_T
);
344 free_stree(&a_F_c_F
);
345 a_F_c_T
= clone_stree(a_F
);
346 overwrite_stree(a_F_c_fake
, &a_F_c_T
);
348 if (implied_condition_false(expr
->cond_false
)) {
349 free_stree(&a_F_c_T
);
350 free_stree(&a_F_c_F
);
351 a_F_c_F
= clone_stree(a_F
);
352 overwrite_stree(a_F_c_fake
, &a_F_c_F
);
355 merge_stree(&a_T_b_T
, a_F_c_T
);
356 merge_stree(&a_T_b_F
, a_F_c_F
);
358 tmp
= __pop_cond_true_stack();
360 tmp
= __pop_cond_false_stack();
363 __push_cond_stacks();
364 FOR_EACH_SM(a_T_b_T
, sm
) {
365 __set_true_false_sm(sm
, NULL
);
366 } END_FOR_EACH_SM(sm
);
367 FOR_EACH_SM(a_T_b_F
, sm
) {
368 __set_true_false_sm(NULL
, sm
);
369 } END_FOR_EACH_SM(sm
);
372 free_stree(&a_T_b_fake
);
373 free_stree(&a_F_c_fake
);
374 free_stree(&a_F_c_T
);
375 free_stree(&a_F_c_F
);
376 free_stree(&a_T_b_T
);
377 free_stree(&a_T_b_F
);
381 if (cond_tf
== true && true_tf
== true)
383 if (cond_tf
== false && false_tf
== false)
387 static void handle_comma(struct expression
*expr
, int *known_tf
)
389 __split_expr(expr
->left
);
390 split_conditions(expr
->right
, known_tf
);
393 static int make_op_unsigned(int op
)
397 return SPECIAL_UNSIGNED_LT
;
399 return SPECIAL_UNSIGNED_LTE
;
401 return SPECIAL_UNSIGNED_GT
;
403 return SPECIAL_UNSIGNED_GTE
;
408 static void hackup_unsigned_compares(struct expression
*expr
)
410 if (expr
->type
!= EXPR_COMPARE
)
413 if (type_unsigned(get_type(expr
)))
414 expr
->op
= make_op_unsigned(expr
->op
);
417 static bool handle_expr_statement_conditions(struct expression
*expr
, int *known_tf
)
419 struct statement
*last_stmt
, *stmt
;
420 struct expression
*last_expr
;
422 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '(')
424 if (expr
->type
!= EXPR_STATEMENT
)
427 stmt
= expr
->statement
;
428 if (stmt
->type
!= STMT_COMPOUND
)
431 last_stmt
= last_ptr_list((struct ptr_list
*)stmt
->stmts
);
436 * I don't think this is right, but I'm not sure how to handle other
437 * types of statements.
439 if (last_stmt
->type
== STMT_EXPRESSION
)
440 last_expr
= last_stmt
->expression
;
441 else if (last_stmt
->type
== STMT_LABEL
&&
442 last_stmt
->label_statement
->type
== STMT_EXPRESSION
)
443 last_expr
= last_stmt
->label_statement
->expression
;
448 __push_scope_hooks();
449 FOR_EACH_PTR(stmt
->stmts
, stmt
) {
450 if (stmt
== last_stmt
) {
451 if (stmt
->type
== STMT_LABEL
)
452 __split_label_stmt(stmt
);
453 split_conditions(last_expr
, known_tf
);
457 } END_FOR_EACH_PTR(stmt
);
460 __call_scope_hooks();
466 static void do_condition(struct expression
*expr
)
468 __fold_in_set_states();
469 __push_fake_cur_stree();
470 __pass_to_client(expr
, CONDITION_HOOK
);
471 __fold_in_set_states();
474 static int confidence_implied
;
475 void __set_confidence_implied(void)
477 confidence_implied
++;
480 void __unset_confidence(void)
482 confidence_implied
--;
485 static void split_conditions(struct expression
*expr
, int *known_tf
)
488 char *cond
= expr_to_str(expr
);
490 sm_msg("%d in split_conditions(%s)", get_lineno(), cond
);
494 expr
= strip_expr_set_parent(expr
);
496 __fold_in_set_states();
500 if (handle_expr_statement_conditions(expr
, known_tf
))
504 * On fast paths (and also I guess some people think it's cool) people
505 * sometimes use | instead of ||. It works the same basically except
506 * that || implies a memory barrier between conditions. The easiest way
507 * to handle it is by pretending that | also has a barrier and re-using
508 * all the normal condition code. This potentially hides some bugs, but
509 * people who write code like this should just be careful or they
512 * We could potentially treat boolean bitwise & this way but that seems
513 * too complicated to deal with.
515 if (expr
->type
== EXPR_BINOP
&& expr
->op
== '|') {
516 expr_set_parent_expr(expr
->left
, expr
);
517 expr_set_parent_expr(expr
->right
, expr
);
518 handle_logical(expr
, known_tf
);
522 switch (expr
->type
) {
524 expr_set_parent_expr(expr
->left
, expr
);
525 expr_set_parent_expr(expr
->right
, expr
);
526 __pass_to_client(expr
, LOGIC_HOOK
);
527 handle_logical(expr
, known_tf
);
530 expr_set_parent_expr(expr
->left
, expr
);
531 expr_set_parent_expr(expr
->right
, expr
);
532 hackup_unsigned_compares(expr
);
533 if (handle_zero_comparisons(expr
, known_tf
))
537 if (ignore_builtin_expect(expr
, known_tf
))
541 expr_set_parent_expr(expr
->unop
, expr
);
542 if (handle_preop(expr
, known_tf
))
545 case EXPR_CONDITIONAL
:
547 expr_set_parent_expr(expr
->conditional
, expr
);
548 expr_set_parent_expr(expr
->cond_true
, expr
);
549 expr_set_parent_expr(expr
->cond_false
, expr
);
550 handle_select(expr
, known_tf
);
553 expr_set_parent_expr(expr
->left
, expr
);
554 expr_set_parent_expr(expr
->right
, expr
);
555 handle_comma(expr
, known_tf
);
559 /* fixme: this should be in smatch_flow.c
560 but because of the funny stuff we do with conditions
561 it's awkward to put it there. We would need to
562 call CONDITION_HOOK in smatch_flow as well.
564 push_expression(&big_expression_stack
, expr
);
565 push_expression(&big_condition_stack
, expr
);
567 if (expr
->type
== EXPR_COMPARE
) {
568 if (expr
->left
->type
!= EXPR_POSTOP
)
569 __split_expr(expr
->left
);
570 if (expr
->right
->type
!= EXPR_POSTOP
)
571 __split_expr(expr
->right
);
572 } else if (expr
->type
!= EXPR_POSTOP
) {
576 if (expr
->type
== EXPR_COMPARE
) {
577 if (expr
->left
->type
== EXPR_POSTOP
)
578 __split_expr(expr
->left
);
579 if (expr
->right
->type
== EXPR_POSTOP
)
580 __split_expr(expr
->right
);
581 } else if (expr
->type
== EXPR_POSTOP
) {
585 sm_perror("overwriting known tf. expr='%s' tf=%d",
586 expr_to_str(expr
), *known_tf
);
588 if (confidence_implied
) {
589 if (implied_condition_true(expr
))
591 if (implied_condition_false(expr
))
594 if (known_condition_true(expr
))
596 else if (known_condition_false(expr
))
600 __push_fake_cur_stree();
601 __process_post_op_stack();
602 __fold_in_set_states();
603 pop_expression(&big_condition_stack
);
604 pop_expression(&big_expression_stack
);
607 static int inside_condition
;
608 void __split_whole_condition_tf(struct expression
*expr
, int *known_tf
)
614 __save_pre_cond_states();
615 __push_cond_stacks();
616 /* it's a hack, but it's sometimes handy to have this stuff
617 on the big_expression_stack. */
618 push_expression(&big_expression_stack
, expr
);
619 split_conditions(expr
, known_tf
);
621 __pass_to_client(expr
, WHOLE_CONDITION_HOOK
);
622 pop_expression(&big_expression_stack
);
626 void __split_whole_condition(struct expression
*expr
)
630 __split_whole_condition_tf(expr
, &known_tf
);
633 void __handle_logic(struct expression
*expr
)
638 __save_pre_cond_states();
639 __push_cond_stacks();
640 /* it's a hack, but it's sometimes handy to have this stuff
641 on the big_expression_stack. */
642 push_expression(&big_expression_stack
, expr
);
644 split_conditions(expr
, &known_tf
);
646 __pass_to_client(expr
, WHOLE_CONDITION_HOOK
);
647 pop_expression(&big_expression_stack
);
648 __merge_false_states();
652 int is_condition(struct expression
*expr
)
656 expr
= strip_expr(expr
);
659 if (get_value(expr
, &dummy
))
662 switch (expr
->type
) {
673 int __handle_condition_assigns(struct expression
*expr
)
675 struct expression
*right
;
676 struct stree
*pre_stree
, *true_stree
, *false_stree
, *fake_stree
, *orig
;
682 right
= strip_expr(expr
->right
);
683 if (!is_condition(expr
->right
))
687 * This function handles boolean condition assignments such as:
688 * "equal = (a == b);"
690 * I'm not sure I love the way it's written. It should be possible
691 * to just parse this much more like a normal if statement instead
692 * of doing complicated stree manipulation. But here is the
695 * We parse the condition part. Then we get the true states and false
696 * states. Then we set extra state for each. Then we merge the strees
697 * and we us __set_sm() to overwrite the cur_stree with the merged
698 * states. Then we parse the assignment statement. Parsing the
699 * assignment statement does not overwrite the state in smatch_extra
700 * because smatch_extra handles condition assignments as a special
705 /* parse the condition */
706 pre_stree
= clone_stree(__get_cur_stree());
707 __save_pre_cond_states();
708 __push_cond_stacks();
710 push_expression(&big_expression_stack
, right
);
711 __pass_to_client(right
, WHOLE_CONDITION_HOOK
);
712 pop_expression(&big_expression_stack
);
713 split_conditions(right
, &known_tf
);
716 true_stree
= __get_true_states();
717 false_stree
= __get_false_states();
720 * This is a pretty complicated way to set the extra state in the
721 * &true_stree. There are some other modules which hook into the
722 * extra_mod hooks so those get set as well.
726 __push_fake_cur_stree();
727 set_extra_expr_mod(expr
->left
, alloc_estate_sval(sval_type_val(get_type(expr
->left
), 1)));
728 fake_stree
= __pop_fake_cur_stree();
729 FOR_EACH_SM(fake_stree
, sm
) {
730 overwrite_sm_state_stree(&true_stree
, sm
);
731 } END_FOR_EACH_SM(sm
);
732 free_stree(&fake_stree
);
733 __push_true_states();
735 /* Set the false state in &false_stree. */
736 __use_false_states();
737 __push_fake_cur_stree();
738 set_extra_expr_mod(expr
->left
, alloc_estate_sval(sval_type_val(get_type(expr
->left
), 0)));
739 fake_stree
= __pop_fake_cur_stree();
740 FOR_EACH_SM(fake_stree
, sm
) {
741 overwrite_sm_state_stree(&false_stree
, sm
);
742 } END_FOR_EACH_SM(sm
);
743 free_stree(&fake_stree
);
744 __merge_true_states();
747 * Do the merge, based on the pre_stree and not on the
748 * __merge_true_states() stree. The other important thing to note is
749 * that after merge_fake_stree() &true_stree is a merged stree with
750 * both true and false; not just the true states.
753 orig
= __swap_cur_stree(pre_stree
);
754 merge_fake_stree(&true_stree
, false_stree
);
755 pre_stree
= __swap_cur_stree(orig
);
756 free_stree(&pre_stree
);
758 /* Overwrite cur_stree with the merged states. */
759 FOR_EACH_SM(true_stree
, sm
) {
761 } END_FOR_EACH_SM(sm
);
763 free_stree(&true_stree
);
764 free_stree(&false_stree
);
766 __pass_to_client(expr
, ASSIGNMENT_HOOK
);
771 static int is_select_assign(struct expression
*expr
)
773 struct expression
*right
;
777 right
= strip_expr(expr
->right
);
778 if (right
->type
== EXPR_CONDITIONAL
)
780 if (right
->type
== EXPR_SELECT
)
785 int __handle_select_assigns(struct expression
*expr
)
787 struct expression
*right
, *condition
;
788 struct stree
*final_states
= NULL
;
794 if (!is_select_assign(expr
))
796 right
= strip_expr(expr
->right
);
797 __pass_to_client(right
, SELECT_HOOK
);
799 // FIXME: why is this implied instead of known?
800 is_true
= implied_condition_true(right
->conditional
);
801 is_false
= implied_condition_false(right
->conditional
);
804 * For "x = frob() ?: y;" we only want to parse the frob() call once
805 * so do the assignment and parse the condition in one step.
807 if (right
->cond_true
) {
808 condition
= right
->conditional
;
809 expr_set_parent_expr(condition
, right
);
810 __save_pre_cond_states();
811 __split_whole_condition(condition
);
813 struct expression
*fake_condition
, *fake_assign
;
815 snprintf(buf
, sizeof(buf
), "fake_cond_%p", expr
);
816 fake_condition
= create_fake_assign(buf
, get_type(right
->conditional
), right
->conditional
);
817 if (!fake_condition
) {
818 sm_perror("cannot parse condition");
821 expr_set_parent_expr(fake_condition
, right
);
822 __save_pre_cond_states();
823 __split_whole_condition(fake_condition
);
824 fake_assign
= assign_expression(expr
->left
, expr
->op
, fake_condition
->left
);
825 expr_set_parent_expr(fake_assign
, right
);
826 __split_expr(fake_assign
);
829 if (!is_false
&& right
->cond_true
) {
830 struct expression
*fake_expr
;
832 fake_expr
= assign_expression(expr
->left
, expr
->op
, right
->cond_true
);
833 expr_set_parent_expr(fake_expr
, expr
);
834 __split_expr(fake_expr
);
835 final_states
= clone_stree(__get_cur_stree());
836 } else if (!is_false
) {
837 final_states
= clone_stree(__get_cur_stree());
841 __discard_false_states();
842 merge_stree(&final_states
, __get_cur_stree());
844 struct expression
*fake_expr
;
846 __use_false_states();
847 fake_expr
= assign_expression(expr
->left
, expr
->op
, right
->cond_false
);
848 expr_set_parent_expr(fake_expr
, expr
);
849 __split_expr(fake_expr
);
850 merge_stree(&final_states
, __get_cur_stree());
853 __use_pre_cond_states();
855 FOR_EACH_SM(final_states
, sm
) {
857 } END_FOR_EACH_SM(sm
);
859 free_stree(&final_states
);
864 static struct statement
*split_then_return_last(struct statement
*stmt
)
866 struct statement
*tmp
;
867 struct statement
*last_stmt
;
869 last_stmt
= last_ptr_list((struct ptr_list
*)stmt
->stmts
);
873 __push_scope_hooks();
874 FOR_EACH_PTR(stmt
->stmts
, tmp
) {
875 if (tmp
== last_stmt
) {
876 if (tmp
->type
== STMT_LABEL
) {
877 __split_label_stmt(tmp
);
878 return tmp
->label_statement
;
883 } END_FOR_EACH_PTR(tmp
);
887 static struct expression
*add_casts(struct expression
*cast
, struct expression
*expr
)
891 while (cast
->cast_expression
)
892 cast
= cast
->cast_expression
;
893 cast
->cast_expression
= expr
;
897 int __handle_expr_statement_assigns(struct expression
*expr
)
899 struct expression
*cast
, *right
;
900 struct statement
*stmt
;
902 right
= strip_expr_cast(expr
->right
, &cast
);
903 if (right
->type
== EXPR_PREOP
&& right
->op
== '(')
905 if (right
->type
!= EXPR_STATEMENT
)
909 stmt
= right
->statement
;
910 if (stmt
->type
== STMT_COMPOUND
) {
911 struct statement
*last_stmt
;
912 struct expression
*fake_assign
;
913 struct expression fake_expr_stmt
= { .smatch_flags
= Fake
, };
915 last_stmt
= split_then_return_last(stmt
);
921 fake_expr_stmt
.pos
= last_stmt
->pos
;
922 fake_expr_stmt
.type
= EXPR_STATEMENT
;
923 fake_expr_stmt
.op
= 0;
924 fake_expr_stmt
.statement
= last_stmt
;
926 fake_assign
= assign_expression(expr
->left
, expr
->op
, &fake_expr_stmt
);
927 fake_assign
= add_casts(cast
, fake_assign
);
928 expr_set_parent_expr(fake_assign
, expr
);
929 __split_expr(fake_assign
);
931 __pass_to_client(stmt
, STMT_HOOK_AFTER
);
932 __call_scope_hooks();
933 } else if (stmt
->type
== STMT_EXPRESSION
) {
934 struct expression
*fake_assign
;
936 right
= strip_no_cast(stmt
->expression
);
937 fake_assign
= assign_expression(expr
->left
, expr
->op
, right
);
938 fake_assign
= add_casts(cast
, fake_assign
);
939 expr_set_parent_expr(fake_assign
, expr
);
940 __split_expr(fake_assign
);
949 int in_condition(void)
951 return inside_condition
;