Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infinite recursion on invalid class #104802

Closed
kadircet opened this issue Aug 19, 2024 · 4 comments · Fixed by #104829
Closed

infinite recursion on invalid class #104802

kadircet opened this issue Aug 19, 2024 · 4 comments · Fixed by #104829
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid regression:19 Regression in 19 release

Comments

@kadircet
Copy link
Member

kadircet commented Aug 19, 2024

$ cat prep.cc

class foo {
  foo a;
  virtual int c();
};
$ ~/repos/llvm/build/bin/clang -xc++ -std=c++20 prep.cc
prep.cc:2:7: error: field has incomplete type 'foo'
    2 |   foo a;
      |       ^
prep.cc:1:7: note: definition of 'foo' is not complete until the closing '}'
    1 | class foo {
      |       ^
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/local/google/home/kadircet/repos/llvm/build/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name prep.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/real_inf_Rec -fcoverage-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/real_inf_Rec -resource-dir /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/prep-f2a347.o -x c++ prep.cc
1.      prep.cc:4:2: current parser token ';'
2.      prep.cc:1:1: parsing struct/union/class body 'foo'
  #0 0x0000561ebe915988 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:723:13
  #1 0x0000561ebe91355e llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:106:18
  #2 0x0000561ebe916038 SignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:413:1
  #3 0x00007f29492591a0 (/lib/x86_64-linux-gnu/libc.so.6+0x3d1a0)
  #4 0x0000561ec2041d81 AddInteger /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:355:7
  #5 0x0000561ec2041d81 AddPointer /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:346:5
  #6 0x0000561ec2041d81 Profile /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/DeclarationName.h:69:8
  #7 0x0000561ec2041d81 Profile /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:238:7
  #8 0x0000561ec2041d81 Equals /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:420:3
  #9 0x0000561ec2041d81 llvm::FoldingSet<clang::detail::CXXSpecialNameExtra>::NodeEquals(llvm::FoldingSetBase const*, llvm::FoldingSetBase::Node*, llvm::FoldingSetNodeID const&, unsigned int, llvm::FoldingSetNodeID&) /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:554:12
 #10 0x0000561ebe8860bc llvm::FoldingSetBase::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&, void*&, llvm::FoldingSetBase::FoldingSetInfo const&) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/FoldingSet.cpp:288:9
 #11 0x0000561ec2040f9e clang::DeclarationNameTable::getCXXDestructorName(clang::CanQual<clang::Type>) /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/DeclarationName.cpp:327:13
 #12 0x0000561ec2055bc7 clang::CXXRecordDecl::getDestructor() const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/DeclCXX.cpp:2022:34
 #13 0x0000561ec2055a89 clang::CXXRecordDecl::hasConstexprDestructor() const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/DeclCXX.cpp:602:10
 #14 0x0000561ec13d2ad2 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:7056:13
 #15 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #16 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #17 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #18 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #19 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #20 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&&)::operator()<'lambda'(clang::QualType, auto&&)&>(clang::QualType, auto&&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16

@kadircet kadircet added clang Clang issues not falling into any other category crash-on-invalid labels Aug 19, 2024
@kadircet
Copy link
Member Author

d469794 seems to be the culprit. before that compilation terminates without crashes. cc @Fznamznon

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Aug 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2024

@llvm/issue-subscribers-clang-frontend

Author: kadir çetinkaya (kadircet)

```cpp $ cat prep.cc class foo { foo a; virtual int c(); }; ```
$ ~/repos/llvm/build/bin/clang -xc++ -std=c++20 prep.cc
prep.cc:2:7: error: field has incomplete type 'foo'
    2 |   foo a;
      |       ^
prep.cc:1:7: note: definition of 'foo' is not complete until the closing '}'
    1 | class foo {
      |       ^
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/local/google/home/kadircet/repos/llvm/build/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name prep.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/real_inf_Rec -fcoverage-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/real_inf_Rec -resource-dir /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/prep-f2a347.o -x c++ prep.cc
1.      prep.cc:4:2: current parser token ';'
2.      prep.cc:1:1: parsing struct/union/class body 'foo'
  #<!-- -->0 0x0000561ebe915988 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:723:13
  #<!-- -->1 0x0000561ebe91355e llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:106:18
  #<!-- -->2 0x0000561ebe916038 SignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:413:1
  #<!-- -->3 0x00007f29492591a0 (/lib/x86_64-linux-gnu/libc.so.6+0x3d1a0)
  #<!-- -->4 0x0000561ec2041d81 AddInteger /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:355:7
  #<!-- -->5 0x0000561ec2041d81 AddPointer /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:346:5
  #<!-- -->6 0x0000561ec2041d81 Profile /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/DeclarationName.h:69:8
  #<!-- -->7 0x0000561ec2041d81 Profile /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:238:7
  #<!-- -->8 0x0000561ec2041d81 Equals /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:420:3
  #<!-- -->9 0x0000561ec2041d81 llvm::FoldingSet&lt;clang::detail::CXXSpecialNameExtra&gt;::NodeEquals(llvm::FoldingSetBase const*, llvm::FoldingSetBase::Node*, llvm::FoldingSetNodeID const&amp;, unsigned int, llvm::FoldingSetNodeID&amp;) /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/FoldingSet.h:554:12
 #<!-- -->10 0x0000561ebe8860bc llvm::FoldingSetBase::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&amp;, void*&amp;, llvm::FoldingSetBase::FoldingSetInfo const&amp;) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/FoldingSet.cpp:288:9
 #<!-- -->11 0x0000561ec2040f9e clang::DeclarationNameTable::getCXXDestructorName(clang::CanQual&lt;clang::Type&gt;) /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/DeclarationName.cpp:327:13
 #<!-- -->12 0x0000561ec2055bc7 clang::CXXRecordDecl::getDestructor() const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/DeclCXX.cpp:2022:34
 #<!-- -->13 0x0000561ec2055a89 clang::CXXRecordDecl::hasConstexprDestructor() const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/DeclCXX.cpp:602:10
 #<!-- -->14 0x0000561ec13d2ad2 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:7056:13
 #<!-- -->15 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #<!-- -->16 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #<!-- -->17 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #<!-- -->18 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #<!-- -->19 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16
 #<!-- -->20 0x0000561ec13d2bb1 bool clang::Sema::CheckCompletedCXXClass(clang::Scope*, clang::CXXRecordDecl*)::$_0::operator()(clang::CXXMethodDecl*) const::'lambda'(clang::QualType, auto&amp;&amp;)::operator()&lt;'lambda'(clang::QualType, auto&amp;&amp;)&amp;&gt;(clang::QualType, auto&amp;&amp;) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDeclCXX.cpp:0:16

@shafik
Copy link
Collaborator

shafik commented Aug 19, 2024

Looks like a faults on godbolt: https://godbolt.org/z/v3cr7PsxW

@cor3ntin cor3ntin added the regression:19 Regression in 19 release label Aug 19, 2024
@AaronBallman AaronBallman added the confirmed Verified by a second party label Aug 19, 2024
@AaronBallman
Copy link
Collaborator

I'm testing a potential fix and I think it will be sufficiently safe to make it into Clang 19.x.

AaronBallman added a commit to AaronBallman/llvm-project that referenced this issue Aug 19, 2024
d469794 was fixing an issue with
triggering vtable instantiations, but it accidentally introduced
infinite recursion when the type to be checked is the same as the type
used in a base specifier or field declaration.

Fixes llvm#104802
AaronBallman added a commit that referenced this issue Aug 19, 2024
d469794 was fixing an issue with
triggering vtable instantiations, but it accidentally introduced
infinite recursion when the type to be checked is the same as the type
used in a base specifier or field declaration.

Fixes #104802
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Aug 19, 2024
d469794 was fixing an issue with
triggering vtable instantiations, but it accidentally introduced
infinite recursion when the type to be checked is the same as the type
used in a base specifier or field declaration.

Fixes llvm#104802

(cherry picked from commit 435cb0d)
tru pushed a commit to llvmbot/llvm-project that referenced this issue Aug 20, 2024
d469794 was fixing an issue with
triggering vtable instantiations, but it accidentally introduced
infinite recursion when the type to be checked is the same as the type
used in a base specifier or field declaration.

Fixes llvm#104802

(cherry picked from commit 435cb0d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid regression:19 Regression in 19 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants