[PATCH] D120824: [clang][ASTImporter] Fix a bug when importing CXXDefaultInitExpr.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 9 02:24:14 PST 2022
balazske added a comment.
In D120824#3369407 <https://reviews.llvm.org/D120824#3369407>, @martong wrote:
> So, my understanding is that the issue stems from the fact that `hasInClassInitializer()` gave inconsistent results with `getInClassInitializer()` for previously imported nodes.
Not really the API is the problem. The real problem was that to create a `CXXDefaultInitExpr` the field should have a "in-class initializer". `CXXDefaultInitExpr` has a pointer to the field that is initialized at that place. The field has an "in-class initializer", this is the used expression to initialize the field (`CXXDefaultInitExpr` is a separate object that is replicated for every initialization in constructors and initializer-list). The in-class initializer expression is not always stored in the AST, in the `ToTU` it is missing initially. The field has the flag set that it contains in-class initializer but the actual expression is not set yet (probably because the code parser works this way). This expression should be imported before a `CXXDefaultInitExpr` can be created.
The other code change (at lines 3650-60) is needed because `setInClassInitializer` can be called only if the value is not set already, otherwise it will assert.
================
Comment at: clang/unittests/AST/ASTImporterTest.cpp:536-547
+TEST_P(ImportExpr, ImportCXXDefaultInitExpr) {
+ MatchVerifier<Decl> Verifier;
+ testImport("class declToImport { int DefInit = 5; }; declToImport X;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ cxxRecordDecl(hasDescendant(cxxConstructorDecl(
+ hasAnyConstructorInitializer(cxxCtorInitializer(
+ withInitializer(cxxDefaultInitExpr())))))));
----------------
martong wrote:
> So these tests failed with the baseline?
This test was added only because there was no test for `CXXDefaultInitExpr`. Probably this test does not fail without the fix. The failing test is only the added lit test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120824/new/
https://reviews.llvm.org/D120824
More information about the cfe-commits
mailing list