llvm-project/clang/unittests/AST
Raphael Isemann a37734f643 [ASTImporter] Prevent the ASTImporter from creating multiple main FileIDs.
Summary:
When importing the main FileID the ASTImporter currently gives it no include location. This means
that any SourceLocations produced for this FileID look to Clang as if they are coming from the
main FileID (as the main FileID has no include location).

Clang seems to expect that there is only one main FileID in one translation unit (which makes sense
during normal compilation), so this behavior leads to several problems when producing diagnostics,
one being that when calling `SourceManager::isBeforeInTranslationUnit` on two SourceLocations
that come from two different ASTContext instances, Clang fails to sort the SourceLocations as
the include chains of the FileIDs don't end up in a single FileID. This causes that Clang crashes
with "Unsortable locations found" in this function.

This patch gives any imported main FileIDs the main FileID of the To ASTContext as its include
location. This allows Clang to sort all imported SourceLocations as now all include chains point
to the main FileID of the To ASTContext. The exact include location is currently set to the start
of the To main file (just because that should always be a valid SourceLocation).

Reviewers: martong, a_sidorin, a.sidorin, shafik, balazske

Reviewed By: martong, a_sidorin, shafik

Subscribers: balazske, rnkovacs, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74542
2020-02-18 08:37:26 +01:00
..
ASTContextParentMapTest.cpp Remove clang::ast_type_traits namespace in favor of clang 2020-02-13 10:46:47 -08:00
ASTImporterFixtures.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
ASTImporterFixtures.h [ASTImporter] Fix name conflict handling with different strategies 2019-08-27 11:36:10 +00:00
ASTImporterGenericRedeclTest.cpp [ASTImporter] Added visibility check for scoped enums. 2020-02-17 14:34:13 +01:00
ASTImporterODRStrategiesTest.cpp [ASTImporter] Added visibility check for scoped enums. 2020-02-17 14:34:13 +01:00
ASTImporterTest.cpp [ASTImporter] Prevent the ASTImporter from creating multiple main FileIDs. 2020-02-18 08:37:26 +01:00
ASTImporterVisibilityTest.cpp [ASTImporter] Added visibility check for scoped enums. 2020-02-17 14:34:13 +01:00
ASTPrint.h [clang][OpeMP] Model OpenMP structured-block in AST (PR40563) 2019-03-20 16:32:36 +00:00
ASTTraverserTest.cpp Remove clang::ast_type_traits namespace in favor of clang 2020-02-13 10:46:47 -08:00
ASTTypeTraitsTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ASTVectorTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CMakeLists.txt Add method to ignore invisible AST nodes 2019-12-18 22:33:23 +00:00
CommentLexer.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CommentParser.cpp [unittests][AST] CommentParser: don't name variable 'DEBUG' 2019-09-02 12:34:21 +00:00
CommentTextTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
DataCollectionTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
DeclMatcher.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
DeclPrinterTest.cpp [clang][DeclPrinter] Implement visitors for {TemplateType,NonTypeTemplate}Parms 2020-02-14 13:20:34 +01:00
DeclTest.cpp Prune include of DataLayout.h from include/clang/Basic/TargetInfo.h. NFC 2019-10-21 17:58:14 +00:00
EvaluateAsRValueTest.cpp [Tooling] Migrated APIs that take ownership of objects to unique_ptr 2019-08-30 09:29:34 +00:00
ExternalASTSourceTest.cpp ArrayRef'ized CompilerInvocation::CreateFromArgs 2019-08-27 22:13:31 +00:00
Language.cpp [ASTImporter] Support functions with placeholder return types ... 2019-12-12 17:49:03 +01:00
Language.h [ASTImporter] Support functions with placeholder return types ... 2019-12-12 17:49:03 +01:00
MatchVerifier.h Remove clang::ast_type_traits namespace in favor of clang 2020-02-13 10:46:47 -08:00
NamedDeclPrinterTest.cpp [ASTMatchers] StringRef'ify hasName 2020-01-29 10:53:08 +01:00
OMPStructuredBlockTest.cpp [AST] OMPStructuredBlockTest: avoid using multiline string literals in macros 2019-03-22 13:40:36 +00:00
RecursiveASTVisitorTest.cpp [Tooling] Migrated APIs that take ownership of objects to unique_ptr 2019-08-30 09:29:34 +00:00
SourceLocationTest.cpp Add FunctionDecl::getParameterSourceRange() 2019-12-03 08:21:55 -05:00
StmtPrinterTest.cpp [ASTMatchers] StringRef'ify hasName 2020-01-29 10:53:08 +01:00
StructuralEquivalenceTest.cpp [AST] AST structural equivalence to work internally with pairs. 2019-09-02 11:01:09 +00:00