This is an archive of the discontinued LLVM Phabricator instance.

[ASTImporter] Fix import of VarDecl init
ClosedPublic

Authored by martong on Sep 3 2018, 7:56 AM.

Details

Summary

The init expression of a VarDecl is overwritten in the "To" context if we
import a VarDecl without an init expression (and with a definition). Please
refer to the added tests, especially InitAndDefinitionAreInDifferentTUs. This
patch fixes the malfunction by importing the whole Decl chain similarly as we
did that in case of FunctionDecls. We handle the init expression similarly to
a definition, alas only one init expression will be in the merged ast.

Diff Detail

Repository
rL LLVM

Event Timeline

martong created this revision.Sep 3 2018, 7:56 AM
martong added inline comments.Sep 3 2018, 8:01 AM
unittests/AST/ASTImporterTest.cpp
3763 ↗(On Diff #163719)

This hunk has nothing to do with this change, but previously we forgot to instantiate these test cases :(

Hi Gabor,
The change looks mostly fine but the difference with ASTReader approach disturbs me a bit.

lib/AST/ASTImporter.cpp
1441 ↗(On Diff #163719)

I see that this is only a code move but I realized that ASTReader and ASTImporter handle this case differently. ASTReader code says:

if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
  EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
  Eval->CheckedICE = true;
  Eval->IsICE = Val == 3;
}

but ASTimporter sets these bits only if isInitKnownICE() is true. This looks strange.

3190 ↗(On Diff #163719)

have (same below)

unittests/AST/ASTImporterTest.cpp
3312 ↗(On Diff #163719)

Formatting of comma is broken. Same below.

martong marked 3 inline comments as done.Sep 12 2018, 2:22 AM
martong added inline comments.
lib/AST/ASTImporter.cpp
1441 ↗(On Diff #163719)

The comment in ASTReader seems to be wrong and misleading.
I checked the correspondent code in ASTWriter:

Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));

Thus, the comment in ASTReader should be:

if (Val > 1) { // IsInitNOTKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3

So, Val > 1 means that the original init expression written by the ASTWriter had the ICE-ness already determined.
Thus the ASTImporter code seems correct to me.

martong updated this revision to Diff 165039.Sep 12 2018, 2:22 AM
martong marked an inline comment as done.
  • Fix formatting and typo
a_sidorin accepted this revision.Sep 15 2018, 3:10 PM
a_sidorin added inline comments.
lib/AST/ASTImporter.cpp
1441 ↗(On Diff #163719)

Thank you for checking this!
The reason I was worrying about this code is that ASTReader/Writer are used in XTU as well so a mismatch between them and ASTImporter can cost us some annoying debug in the future.

This revision is now accepted and ready to land.Sep 15 2018, 3:10 PM
This revision was automatically updated to reflect the committed changes.