------- Comment #5 from fxcoudert at gcc dot gnu dot org 2008-02-04 22:51 ------- (In reply to comment #4) > I did not test your patch, but without the common line, the dump contains > "gfhzjf" until you remove the volatile. This saves you from reading assembler.
Thanks! This allowed me to realize that my patch didn't work: I was marking the "fake" variable we create for debugging purposes, not the field of the structure/union. The following patch works, this time: Index: trans-common.c =================================================================== --- trans-common.c (revision 131944) +++ trans-common.c (working copy) @@ -318,6 +318,15 @@ build_field (segment_info *h, tree union GFC_DECL_ASSIGN_ADDR (field) = pushdecl_top_level (addr); } + /* If this field is volatile, mark it. */ + if (h->sym->attr.volatile_) + { + tree new; + TREE_THIS_VOLATILE (field) = 1; + new = build_qualified_type (TREE_TYPE (field), TYPE_QUAL_VOLATILE); + TREE_TYPE (field) = new; + } + h->field = field; } It makes the variable volatile in the following examples (common and equivalence, since they are handled commonly by the codepath I modified): subroutine wait4it () logical event volatile event common /dd/ event event = .false. do if (event) print *, 'gfhzjf' end do end subroutine subroutine wait4it2 () logical event integer i volatile event equivalence(event,i) event = .false. do if (event) print *, 'gfhzjf' end do end subroutine We don't, however, handle the case where we mark volatile the other variable involved in the equivalence: subroutine wait4it3 () logical event integer i volatile i equivalence(event,i) event = .false. do if (event) print *, 'gfhzjf' end do end subroutine Do we need it? I'm not sure. I've checked what other compilers do: Intel and Sun do not optimize out the PRINT statement if variable "i" is marked as volatile; g95 seems to never optimize out variables in equivalences. I've also checked what GCC does for C code, and it is does behave the same as my patch above, ie the following is indeed optimized out: void wait4it () { union { int event; volatile int i; } dd; dd.event = 0; while (1) { if (dd.event) __builtin_puts ("gfhzjf"); } } >From the standard point of view, when you equivalence A and B, you're not supposed to read B after having written to A, so I would think the behaviour I propose here is standard-conforming. I've asked for opinions on c.l.f (http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/9602660696e0170e). -- fxcoudert at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot gnu |fxcoudert at gcc dot gnu dot |dot org |org Status|NEW |ASSIGNED GCC build triplet|i686-pc-cygwin | Keywords| |patch Last reconfirmed|2008-01-31 13:59:37 |2008-02-04 22:51:44 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35037