[ASTImporter] Reorder fields after structure import is finished
authorGabor Marton <gabor.marton@ericsson.com>
Thu, 25 Jul 2019 09:07:17 +0000 (09:07 +0000)
committerGabor Marton <gabor.marton@ericsson.com>
Thu, 25 Jul 2019 09:07:17 +0000 (09:07 +0000)
commit48b16e1005df863cf8b6364a6dc3e3e213d7d415
tree029a0b786ba78ddcd73d1ea50c9b8d9980ed9ebf
parent18fa729a39db978a86a96af65c6dc763fcd0175a
[ASTImporter] Reorder fields after structure import is finished

We reorder declarations in RecordDecls because they may have another order
in the "to" context than they have in the "from" context. This may happen
e.g when we import a class like this:
   struct declToImport {
       int a = c + b;
       int b = 1;
       int c = 2;
   };
During the import of `a` we import first the dependencies in sequence,
thus the order would be `c`, `b`, `a`. We will get the normal order by
first removing the already imported members and then adding them in the
order as they apper in the "from" context.

Keeping field order is vital because it determines structure layout.

Reviewers: a_sidorin, shafik

Tags: #clang

Differential Revision: https://reviews.llvm.org/D44100

llvm-svn: 366997
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp