[PATCH] D74643: [Parse] Consider attributes in `TryParsePtrOperatorSeq`.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 23 06:08:30 PST 2020


aaron.ballman requested changes to this revision.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added inline comments.


================
Comment at: clang/lib/Parse/ParseTentative.cpp:773
+  while (Tok.isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec,
+                     tok::kw_alignas)) {
+    if (Tok.is(tok::l_square)) {
----------------
Do we need to also skip other keyword attributes as well as `alignas`? For instance, `tok::kw__Noreturn` or `tok::kw__Alignas`


================
Comment at: clang/lib/Parse/ParseTentative.cpp:779
+      ConsumeBracket();
+      if (!SkipUntil(tok::r_square) || Tok.isNot(tok::r_square))
+        return false;
----------------
I think this gets the parsing logic wrong when there is a balanced `[]` that is not part of the attribute introducer syntax, such as finding an array in the middle of the attribute argument clause. A test case would be handy, like:
```
constexpr int foo[] = { 2, 4 };
[[gnu::assume_aligned(foo[0])]] int *func() { return nullptr; }
```
You should probably use a `BalancedDelimiterTracker` to handle the brackets.


================
Comment at: clang/lib/Parse/ParseTentative.cpp:789
+      ConsumeParen();
+      if (!SkipUntil(tok::r_paren))
+        return false;
----------------
If we're skipping `__attribute__(())`, this looks to miss the second closing right paren. Also, this logic won't work if we need to skip `_Noreturn`, which has no parens.

This branch is missing test coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74643





More information about the cfe-commits mailing list