[AST] Do not reorder non-constant operands#962
Conversation
...even for commutative opcodes. Doing so breaks short-circuit evaluation of logical expressions, and can also cause side effects to occur out of order.
|
@bryanpkc Fortran does not guarantee short-circuit evaluation. This is a feature likely to come in the next revision of the standard using explicit keywords ANDTHEN, ORELSE. See the proposals below. |
|
@kiranchandramohan Thanks for the link! I read "10.1.7 Evaluation of operands" of the Fortran 2018 standard and understood it as allowing short-circuit evaluation, but I was not aware that the language standard allowed operand evaluation in any order. |
|
The |
|
We can discuss this today. |
|
As a side note, I've checked that although cp2k and some other of workloads we're testing do use |
|
@pawosm-arm Yes, I have noticed that too. The failing example that we found came from a program written by a customer, who was perhaps used to gfortran's behaviour. |
Do not reorder non-constant operands, even for commutative opcodes. Doing so breaks short-circuit evaluation
of logical expressions, and can also cause side effects to occur out of order.
This PR includes a reproducer which, when compiled without the patch, would access an optional dummy argument before confirming its presence, leading to a segmentation fault.