[PATCH] D37700: Fix recording preamble's conditional stack in skipped PP branches.

Nikolai Kosjar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 12 00:45:24 PDT 2017


nik added a comment.

Fixes the reported issue, thanks!

I still run into another case that is not yet properly covered. The reported issue was extracted from the following case. If you prefer, I'll create a separate report for the remaining issues.

The follow code outlines the problems in the comments:

  #ifdef MYCPLUSPLUS
  extern "C" { // On parse this is skipped as expected. On reparse, this is surprisingly not skipped anymore.
  #endif
  
  #ifdef MYCPLUSPLUS
  }
  #endif
  
  int main()
  {
      return 0;
  } // On reparse a diagnostic is added here: "expected '}' to match this '{' (line 2)"

Here are some c-index-test invocations for this to make this testable/reproducible ($FILE does not contain the above comments):

Do a parse and save the tokens:

  % ./c-index-test -test-annotate-tokens=$FILE:1:1:7:1 $FILE > /tmp/1

No diagnostics are emitted as expected.

Do a parse and reparse and save also the tokens:

  % CINDEXTEST_EDITING=1 ./c-index-test -test-annotate-tokens=$FILE:1:1:7:1 $FILE > /tmp/2
  $FILE:12:2: error: expected '}'
  Number FIX-ITs = 0
  $FILE:2:12: note: to match this '{'
  Number FIX-ITs = 0
   

Note that a new diagnostic is emitted on reparse at the bottom of the file (issue1).
Also, the first skipped source range is not skipped anymore on reparse (issue2):

  % diff -u /tmp/{1,2}
  --- /tmp/1	2017-09-12 09:33:42.210204021 +0200
  +++ /tmp/2	2017-09-12 09:33:51.458334870 +0200
  @@ -1,4 +1,3 @@
  -Skipping: [1:2 - 3:7]
   Skipping: [5:2 - 7:7]
   Punctuation: "#" [1:1 - 1:2] preprocessing directive=
   Identifier: "ifdef" [1:2 - 1:7] preprocessing directive=
  zsh: exit 1     colordiff -u /tmp/{1,2}
  %


https://reviews.llvm.org/D37700





More information about the cfe-commits mailing list