Gang, worker, vector and collapse all contain optional arguments which may be used during loop expansion. In OpenACC, those expressions could contain variables, but those variables aren't always getting remapped automatically. This patch remaps those variables inside lower_omp_loop.
Note that I didn't need to use a tree walker for more complicated expressions because it's not required. By the time those clauses reach lower_omp_loop, only the result of the expression is available. So the other variables in those expressions get remapped with everything else during omplow. Therefore, the only problematic case is when the the optional expression is just a decl, e.g. gang(static:foo). I've applied this patch to gomp-4_0-branch. Cesar