[all-commits] [llvm/llvm-project] a37734: [ASTImporter] Prevent the ASTImporter from creatin...

Raphael Isemann via All-commits all-commits at lists.llvm.org
Mon Feb 17 23:37:47 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: a37734f643fbac04ce6d7f2f6b1c8dcd3c4d5e0e
      https://github.com/llvm/llvm-project/commit/a37734f643fbac04ce6d7f2f6b1c8dcd3c4d5e0e
  Author: Raphael Isemann <teemperor at gmail.com>
  Date:   2020-02-18 (Tue, 18 Feb 2020)

  Changed paths:
    M clang/lib/AST/ASTImporter.cpp
    M clang/unittests/AST/ASTImporterTest.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list