C++ 编译后的堆栈帧大,osx上出现叮当声,导致堆栈溢出

C++ 编译后的堆栈帧大,osx上出现叮当声,导致堆栈溢出,c++,macos,c++11,stack-overflow,clang++,C++,Macos,C++11,Stack Overflow,Clang++,我有两个类似的递归函数: void dfs(const std::vector<std::vector<int64_t>>& tree, int64_t position) { for (int64_t to : tree[position]) { dfs(tree, to); } if (position % 2 == 1) { for (int64_t to : tree[position]) { } } else {

我有两个类似的递归函数:

void dfs(const std::vector<std::vector<int64_t>>& tree, int64_t position) {
  for (int64_t to : tree[position]) {
    dfs(tree, to);
  }

  if (position % 2 == 1) {
    for (int64_t to : tree[position]) {
    }
  } else {
    for (int64_t to : tree[position]) {
    }
  }
}
PS:编译标志: clang++-O0-std=c++11./file.cpp

PSS:我尽量缩小代码。例如,如果我删除其中一个分支中循环的一个空范围,所有内容都将恢复正常


PSSS:如果我用g++-5编译,dfs中的帧大小只有0x50=128字节。同样在Linux上,一切看起来都很好。

旁注:给变量起个更好的名字。@ThomasAyoub谢谢,我已经尝试过修复它们了。太好了。顺便说一句,
dfs
意味着什么?@ThomasAyoub深度优先搜索。
void dfs(const std::vector<std::vector<int64_t>>& tree, int64_t position) {
  for (size_t i = 0; i < tree[position].size(); ++i) {
    int64_t to = tree[position][i];
    dfs(tree, to);
  }

  if (position % 2 == 1) {
    for (size_t i = 0; i < tree[position].size(); ++i) {
      int64_t to = tree[position][i];
    }
  } else {
    for (size_t i = 0; i < tree[position].size(); ++i) {
      int64_t to = tree[position][i];
    }
  }
}
Stack level 1, frame at 0x7fff5fbfebe0:
rip = 0x100000a8c in dfs(std::__1::vector<std::__1::vector<long long, std::__1::allocator<long long> >, std::__1::allocator<std::__1::vector<long long, std::__1::allocator<long long> > > > const&, long long); saved rip = 0x100000a8c
called by frame at 0x7fff5fbfef00, caller of frame at 0x7fff5fbfe8c0
Arglist at 0x7fff5fbfebd0, args: 
Locals at 0x7fff5fbfebd0, Previous frame's sp is 0x7fff5fbfebe0
Saved registers:
rbp at 0x7fff5fbfebd0, rip at 0x7fff5fbfebd8
Stack level 1, frame at 0x7fff5fbff140:
rip = 0x100000d4d in dfs(std::__1::vector<std::__1::vector<long long, std::__1::allocator<long long> >, std::__1::allocator<std::__1::vector<long long, std::__1::allocator<long long> > > > const&, long long); saved rip = 0x100000d4d
called by frame at 0x7fff5fbff240, caller of frame at 0x7fff5fbff040
Arglist at 0x7fff5fbff130, args: 
Locals at 0x7fff5fbff130, Previous frame's sp is 0x7fff5fbff140
Saved registers:
rbp at 0x7fff5fbff130, rip at 0x7fff5fbff138