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

Hyperobject containing self-referential template causes infinite recursion #223

Closed
kennyzzhang opened this issue Dec 8, 2023 · 0 comments · Fixed by #224
Closed

Hyperobject containing self-referential template causes infinite recursion #223

kennyzzhang opened this issue Dec 8, 2023 · 0 comments · Fixed by #224
Assignees
Labels
bug Something isn't working

Comments

@kennyzzhang
Copy link

Minimal example:

template <class T>
class A { };

class B {
  A<B> a;
};

void identity(void* view) {}
void reduce(void* l, void* r) {}

B _Hyperobject(identity, reduce) b;

Trying to compile this code gives the following stackdump:

Stack dump:
0.      Program arguments: /home/kzzhang/OpenCilk/build/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -main-file-name bug.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-err
no -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/home/kzzhang/OpenCilk/tutorial -resource-dir /home/kzzhang/O
penCilk/build/lib/clang/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/
c++/12/backward -internal-isystem /home/kzzhang/OpenCilk/build/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -inter
nal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/home/kzzhang/OpenCilk/tutorial -ferror-limit 19 -fopencilk --opencilk-abi-bitcode=/home/kzzhang/OpenCilk/build/lib/clang/16/lib/x86_64-unknown-linux-gnu/libope
ncilk-abi.bc -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/bug-1e516d.o -x c++ bug.cpp
1.      bug.cpp:11:35: current parser token ';'
  #0 0x000055a4d7de9acb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/kzzhang/OpenCilk/build/bin/clang-16+0x2871acb)
  #1 0x000055a4d7de73ab SignalHandler(int) Signals.cpp:0:0
  #2 0x00007f8c265bdfd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
  #3 0x000055a4db0b2655 getInterestingTagDecl(clang::TagDecl*) Type.cpp:0:0
  #4 0x000055a4da9d9205 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
  #5 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
  #6 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
  #7 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
  #8 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
  #9 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
 #10 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
 #11 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
 #12 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
 #13 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
 #14 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
 #15 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
...
#248 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
#249 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
#250 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
#251 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
#252 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
#253 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
#254 0x000055a4da9d9311 DeclContainsHyperobject(clang::RecordDecl const*) SemaType.cpp:0:0
#255 0x000055a4da9d9146 ContainsHyperobject(clang::QualType) SemaType.cpp:0:0
clang-16: error: unable to execute command: Segmentation fault
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 16.0.6 (https://github.com/OpenCilk/opencilk-project 03a724da592c2608e305f5c7f4e500fef2d66c6a)

In the source, ContainsHyperobject has a comment saying that a deep search is done to ensure there are no nested hyperobjects.
In the part of the function that processes template specializations, it seems like all the template arguments are recursively searched for nested hyperobjects, resulting in infinite recursion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants