This is an archive of the discontinued LLVM Phabricator instance.

Fix crash when current lexer is nullptr
AbandonedPublic

Authored by yvvan on Aug 8 2017, 4:16 AM.

Details

Summary

caused a crash in <memory> header reparse (msvc kit)

Diff Detail

Event Timeline

yvvan created this revision.Aug 8 2017, 4:16 AM
yvvan added reviewers: bkramer, klimek.
yvvan added a subscriber: cfe-commits.
bkramer edited edge metadata.

Test case?

yvvan added a comment.Aug 8 2017, 4:48 AM

Do you mean the testcase that runs only for windows with ms-extensions flag and msvc includes?
I don't know if clang has that kind of tests. Does it?

yvvan added a comment.Aug 8 2017, 5:27 AM

And if you just meant how to reproduce:

You need to parse and reparse standard <memory> header (my current one is C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory). I can provide the options and a command line that I have if you can't reproduce it with default ones...

Changes like this should come with a small, c-index-test based, test case so we don't reintroduce the same bug in the future.

yvvan added a comment.Aug 9 2017, 5:59 AM
This comment was removed by yvvan.
yvvan updated this revision to Diff 110978.Aug 14 2017, 8:33 AM

I have minimized the crash case and added simple test for it.

I've also stumbled upon this crash. Here is an even simpler repro that crashes for me (does not involve includes):

#ifndef HEADER_GUARD

#define FOO(X) int fhjdfhsdjkfhjkshfjk;
FOO(base)

struct X {
  int a;
};

int test() {
  X v;
  v.
}
#endif
lib/Parse/Parser.cpp
519

This certainly fixes the crash, but aren't we breaking other things if we don't run replayConditionalStack?
I.e. won't we get spurious errors on #endif?

ilya-biryukov added inline comments.Aug 18 2017, 2:36 AM
lib/Parse/Parser.cpp
519

I get a spurious #endif without #if error with your fix. We need to figure out the right place to run replayPreambleConditionalStack.

@erikjv, any ideas?

Here's an alternative fix that moves the replay... call into Preprocessor: https://reviews.llvm.org/D36872.
It also fixes the crash and doesn't add invalid compiler errors about non-matching #ifdefs.

yvvan abandoned this revision.Sep 4 2017, 2:11 AM