This is an archive of the discontinued LLVM Phabricator instance.

[Preprocessor] Don't avoid entering included files after hitting a fatal error.
ClosedPublic

Authored by vsapsai on Nov 29 2018, 4:59 PM.

Details

Summary

Change in r337953 violated the contract for CXTranslationUnit_KeepGoing:

Do not stop processing when fatal errors are encountered.

Use different approach to fix long processing times with multiple
inclusion cycles. Instead of stopping preprocessing for fatal errors, do
this after heuristically detecting an inclusion cycle.

rdar://problem/46108547

Diff Detail

Repository
rL LLVM

Event Timeline

vsapsai created this revision.Nov 29 2018, 4:59 PM
erik.pilkington added inline comments.Dec 4 2018, 2:56 PM
clang/lib/Lex/PPDirectives.cpp
1804–1812 ↗(On Diff #175995)

Why not just always set HasIncludeCycle = true; if we've reached the max allowed include stack depth? Seems like that would always be due to recursive includes. But even if it wasn't caused by recursive includes, we still probably shouldn't descend into more included files anyway, right?

1965 ↗(On Diff #175995)

Nit: may as well just make this if (HasIncludeCycle) now that we don't have to call the function.

vsapsai marked 2 inline comments as done.Dec 4 2018, 5:44 PM
vsapsai added inline comments.
clang/lib/Lex/PPDirectives.cpp
1804–1812 ↗(On Diff #175995)

I wanted to support a use case like

#include "root-of-deep-include-chain.h"
#include "foo.h"

and still enter "foo.h". Setting HasIncludeCycle = true; without cycle checking will prevent it.

After more thinking now I want to support a use case like

#include "cycle.h"
#include "foo.h"

It seems in the spirit of CXTranslationUnit_KeepGoing to process "foo.h" despite a single bad include "cycle.h". And I think it is not too far-fetched to create cycles accidentally during code editing. If tools fail at such moments, it creates bad user experience and tools support is especially useful during erroneous situations.

I have an idea how to implement better cycle-checking (basically llvm::DenseSet<const FileEntry *> FilesCausingCycles), want to try and see if it's not too complicated.

1965 ↗(On Diff #175995)

Good point.

vsapsai updated this revision to Diff 177045.Dec 6 2018, 2:12 PM
  • Keep indexing after include cycle.

That's the approach I had in mind when I was writing about it in code review.
But it turned out to be not my preferred solution. I'll post a different patch
shortly.

vsapsai updated this revision to Diff 177046.Dec 6 2018, 2:12 PM
  • Different approach: don't enter already processed files after reaching max include depth.
erik.pilkington accepted this revision.Dec 6 2018, 2:22 PM

Nice, LGTM!

This revision is now accepted and ready to land.Dec 6 2018, 2:22 PM
vsapsai updated this revision to Diff 177054.Dec 6 2018, 2:25 PM
  • Remove now unnecessary #include "llvm/ADT/DenseSet.h"

Thanks for the review, Erik.

This revision was automatically updated to reflect the committed changes.