This is an archive of the discontinued LLVM Phabricator instance.

[clang][ASTImporter] Fix import of recursive field initializer.
ClosedPublic

Authored by balazske on Jul 18 2023, 3:29 AM.

Details

Summary

Import of field initializers with circular reference was not working,
this is fixed now.

Fixes issue #63120

Diff Detail

Event Timeline

balazske created this revision.Jul 18 2023, 3:29 AM
Herald added a reviewer: shafik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
balazske requested review of this revision.Jul 18 2023, 3:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 3:29 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Jul 18 2023, 4:13 AM
balazske updated this revision to Diff 542383.Jul 20 2023, 2:16 AM

using clang-format

danix800 added inline comments.
clang/lib/AST/ASTImporter.cpp
3936–3937

Initializer could indirectly depends on this field and set the initializer while importing.
setInClassInitializer() asserts that initializer should not be set more than once:

static int ref_A();
static int ref_B();
struct A {
  int a = ref_B();
};
struct B {
  int b = ref_A();
};
int ref_B() { B b; return b.b; }
int ref_A() { A a; return a.a; }
balazske added inline comments.Jul 26 2023, 4:31 AM
clang/lib/AST/ASTImporter.cpp
3936–3937

This example code really causes problems. But import of Expr is not checked for recursion, the assertion in the new code fails for this test.

Why do you want to use such code? It looks to cause infinite loop when executed. Even code like class A { int b{b}; }; is probably not correct.

danix800 added inline comments.Jul 26 2023, 5:39 AM
clang/lib/AST/ASTImporter.cpp
3936–3937

Like int a{a}; this testcase is minimized to just show what might cause the problem.

balazske updated this revision to Diff 544371.Jul 26 2023, 7:51 AM

Added check for duplicate import of initializer.
Added more tests.