Issue 55500
Summary clang ASTImporter infinite loop crash
Labels new issue
Assignees
Reporter balazske
    The following script can be used to reproduce the problem:
(Set CLANG to the correct executable.)
The following commit (and later) contains the bug: 285b39a31ec63a0253fa88c3c61f447712e2f131 `Mon May 9 22:46:34 2022 -0700 "Revert "[NFC][lldb][trace] Use uint64_t when decoding and enconding json"`
```
#/bin/bash

cat > EPoll.cpp << EOF
namespace ns {
struct Foo {
  void wait();
};

template <typename> struct type {};

auto f() {
  auto lambda = [] {};
  return type<decltype(lambda)>{};
}

void Foo::wait() {}
} // namespace ns
EOF

cat > Client.cpp << EOF
namespace ns {
struct Foo {
  void wait();
};

void e(Foo *it) { it->wait(); }
} // namespace ns
EOF

CLANG=clang
EXTDEFTOOL=$CLANG-extdef-mapping

$CLANG -c -x c++ -pedantic -std=c++17 EPoll.cpp -emit-ast -w -o EPoll.cpp.ast

$EXTDEFTOOL EPoll.cpp -- -c -x c++ -pedantic -std=c++17 > externalDefMap.txt
sed -i 's:.cpp:.cpp.ast:g' externalDefMap.txt

$CLANG \
--analyze -Xclang -analyzer-checker=core -Xclang -analyzer-config -Xclang experimental-enable-naive-ctu-analysis=true -Xclang -analyzer-config -Xclang \
ctu-dir=. -pedantic -std=c++17 Client.cpp -fno-crash-diagnostics
```

There is a reference to a declaration inside a function from the function signature at function `f`. The problem is that this reference is hidden inside a template argument in the (computed) return type. This case is not recognized by `ASTImporter` for special handling. Making this work in general case is difficult, an AST visitor or matcher could be used to find such references in every case (see functionn `hasAutoReturnTypeDeclaredInside` in ASTImporter.cpp).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to