[PATCH] D99905: [OPENMP51]Initial parsing/sema for adjust_args clause for 'declare variant'

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 05:47:59 PDT 2021


ABataev added inline comments.


================
Comment at: clang/lib/Parse/ParseOpenMP.cpp:1447-1448
+    if (IsError) {
+      while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch))
+        ;
+      // Skip the last annot_pragma_openmp_end.
----------------
aaron.ballman wrote:
> ABataev wrote:
> > aaron.ballman wrote:
> > > I know this is code that existed previously, but why the `while` loop? This strikes me as a potential infinite loop because `SkipUntil` returns `false` when the token is not found, so if the token is not found the first time, I'd be surprised if a second pass at it finds the token.
> > It may return early because of parens/braces etc. counting. In this case, it will return `false` while if `annot_pragma_openmp_end` is found, it returns `true`. We need to iterate to the end of the directive here, that's why there is a loop.
> Thank you for the explanation -- that sure sounds like a bug with `SkipUntil` to me, and looking through the code base, the only code that seems to do this dance is OpenMP code. Do you happen to have a code example that requires the loop behavior?
> 
> (Not suggesting a change needs to be made in this patch, I'm mostly wondering if there's a change we can make in a follow-up and remove these loops.)
OpenMP implementation guarantees that the directives are started by `annot_pragma_openmp_begin` and terminated by `annot_pragma_openmp_end`. That's why we always trying to find the terminating `annot_pragma_openmp_end` to recover the parsing errors in OpenMP correctly, so the parser could start parsing regular C/C++ code rather than starting parsing in the middle of the OpenMP directive.
There are some tests in test/OpenMP directory that checks for this but I don't remember which one exactly.
I think `SkipUntil` works correctly for the regular C/C++ code, it is just a special corner case for the pragmas 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99905/new/

https://reviews.llvm.org/D99905



More information about the llvm-commits mailing list