[PATCH] D102760: [llvm] Let SmallVector construct from any Iterable

Guillaume Chatelet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 20 04:22:50 PDT 2021


gchatelet added inline comments.


================
Comment at: clang/include/clang/Basic/Module.h:98
 public:
+  Module(const Module &) = default;
+
----------------
fhahn wrote:
> how is this related?
> how is this related?

I'm glad you ask! I'm still investigating the errors that led to this addition (and the one in `llvm/tools/llvm-xray/xray-converter.cpp`) but I suspect this is due to the recursive nature of these classes.
Both `Module` and `StackIdData` contains self-referencing `SmallVector`. It is unclear to me why the compiler is trying to instantiate the newly added `SmallVector` constructor //during// type declaration.

I'll post the compiler errors below the additions.


================
Comment at: clang/include/clang/Basic/Module.h:98
 public:
+  Module(const Module &) = default;
+
----------------
gchatelet wrote:
> fhahn wrote:
> > how is this related?
> > how is this related?
> 
> I'm glad you ask! I'm still investigating the errors that led to this addition (and the one in `llvm/tools/llvm-xray/xray-converter.cpp`) but I suspect this is due to the recursive nature of these classes.
> Both `Module` and `StackIdData` contains self-referencing `SmallVector`. It is unclear to me why the compiler is trying to instantiate the newly added `SmallVector` constructor //during// type declaration.
> 
> I'll post the compiler errors below the additions.
```
FAILED: tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o 
/redacted/build-llvm/download/clang/bin/clang++ --sysroot=/redacted/build-llvm/download/sysroot -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/Lex -I/redacted/git/llvm-project/clang/lib/Lex -I/redacted/git/llvm-project/clang/include -Itools/clang/include -Iinclude -I/redacted/git/llvm-project/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG  -fno-exceptions -fno-rtti -std=c++14 -MD -MT tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o -MF tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o.d -o tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/HeaderSearch.cpp.o -c /redacted/git/llvm-project/clang/lib/Lex/HeaderSearch.cpp
In file included from /redacted/git/llvm-project/clang/lib/Lex/HeaderSearch.cpp:13:
In file included from /redacted/git/llvm-project/clang/include/clang/Lex/HeaderSearch.h:16:
In file included from /redacted/git/llvm-project/clang/include/clang/Basic/SourceLocation.h:19:
/redacted/git/llvm-project/llvm/include/llvm/Support/PointerLikeTypeTraits.h:61:28: error: invalid application of 'alignof' to an incomplete type 'clang::Module'
      detail::ConstantLog2<alignof(T)>::value;
                           ^~~~~~~~~~
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:23:33: note: in instantiation of template class 'llvm::PointerLikeTypeTraits<clang::Module *>' requested here
    std::next(std::declval<I>()),
                                ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:36:39: note: while substituting explicitly-specified template arguments into function template 'is_forward_iterator' 
struct is_forward_iterator : decltype(detail::is_forward_iterator<I>(0)) {};
                                      ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:46:42: note: in instantiation of template class 'llvm::is_forward_iterator<const llvm::PointerIntPair<clang::Module *, 1, bool> *>' requested here
                                         llvm::is_forward_iterator<I>{});
                                         ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:51:37: note: while substituting deduced template arguments into function template 'is_range_iterable' [with T = const llvm::SmallVector<llvm::PointerIntPair<clang::Module *, 1, bool>, 2> &, I = (no value)]
struct is_range_iterable : decltype(detail::is_range_iterable<T>(0)) {};
                                    ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1194:30: note: in instantiation of template class 'llvm::is_range_iterable<const llvm::SmallVector<llvm::PointerIntPair<clang::Module *, 1, bool>, 2> &>' requested here
      std::enable_if_t<llvm::is_range_iterable<Iterable>::value, bool> = true)
                             ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1168:22: note: while substituting deduced template arguments into function template 'SmallVector' [with Iterable = const llvm::SmallVector<llvm::PointerIntPair<clang::Module *, 1, bool>, 2> &]
class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>,
                     ^
/redacted/git/llvm-project/clang/include/clang/Basic/Module.h:96:7: note: while declaring the implicit copy constructor for 'Module'
class Module {
      ^
/redacted/git/llvm-project/clang/include/clang/Basic/Module.h:96:7: note: definition of 'clang::Module' is not complete until the closing '}'
1 error generated.
```


================
Comment at: llvm/tools/llvm-xray/xray-converter.cpp:161
 struct StackIdData {
+  StackIdData(const StackIdData &) = default;
+
----------------
fhahn wrote:
> how is this related?
```
FAILED: tools/llvm-xray/CMakeFiles/llvm-xray.dir/xray-converter.cpp.o 
/redacted/build-llvm/download/clang/bin/clang++ --sysroot=/redacted/build-llvm/download/sysroot -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/llvm-xray -I/redacted/git/llvm-project/llvm/tools/llvm-xray -Iinclude -I/redacted/git/llvm-project/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -fno-rtti -std=c++14 -MD -MT tools/llvm-xray/CMakeFiles/llvm-xray.dir/xray-converter.cpp.o -MF tools/llvm-xray/CMakeFiles/llvm-xray.dir/xray-converter.cpp.o.d -o tools/llvm-xray/CMakeFiles/llvm-xray.dir/xray-converter.cpp.o -c /redacted/git/llvm-project/llvm/tools/llvm-xray/xray-converter.cpp
In file included from /redacted/git/llvm-project/llvm/tools/llvm-xray/xray-converter.cpp:14:
/redacted/git/llvm-project/llvm/tools/llvm-xray/trie-node.h:41:18: error: field has incomplete type '(anonymous namespace)::StackIdData'
  AssociatedData ExtraData;
                 ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:23:33: note: in instantiation of template class 'TrieNode<(anonymous namespace)::StackIdData>' requested here
    std::next(std::declval<I>()),
                                ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:36:39: note: while substituting explicitly-specified template arguments into function template 'is_forward_iterator' 
struct is_forward_iterator : decltype(detail::is_forward_iterator<I>(0)) {};
                                      ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:46:42: note: in instantiation of template class 'llvm::is_forward_iterator<TrieNode<(anonymous namespace)::StackIdData> *const *>' requested here
                                         llvm::is_forward_iterator<I>{});
                                         ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/IterableTraits.h:51:37: note: while substituting deduced template arguments into function template 'is_range_iterable' [with T = const llvm::SmallVector<TrieNode<(anonymous namespace)::StackIdData> *, 4> &, I = (no value)]
struct is_range_iterable : decltype(detail::is_range_iterable<T>(0)) {};
                                    ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1194:30: note: in instantiation of template class 'llvm::is_range_iterable<const llvm::SmallVector<TrieNode<(anonymous namespace)::StackIdData> *, 4> &>' requested here
      std::enable_if_t<llvm::is_range_iterable<Iterable>::value, bool> = true)
                             ^
/redacted/git/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1168:22: note: while substituting deduced template arguments into function template 'SmallVector' [with Iterable = const llvm::SmallVector<TrieNode<(anonymous namespace)::StackIdData> *, 4> &]
class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>,
                     ^
/redacted/git/llvm-project/llvm/tools/llvm-xray/xray-converter.cpp:160:8: note: while declaring the implicit copy constructor for 'StackIdData'
struct StackIdData {
       ^
/redacted/git/llvm-project/llvm/tools/llvm-xray/xray-converter.cpp:160:8: note: definition of '(anonymous namespace)::StackIdData' is not complete until the closing '}'
/redacted/git/llvm-project/llvm/tools/llvm-xray/xray-converter.cpp:225:15: error: no matching member function for call to 'push_front'
    NodeStore.push_front({FuncId, Parent, {}, {(*id_counter)++, {}}});
    ~~~~~~~~~~^~~~~~~~~~
/redacted/build-llvm/download/sysroot/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/bits/forward_list.h:822:7: note: candidate function not viable: cannot convert initializer list argument to 'const TrieNode<(anonymous namespace)::StackIdData>'
      push_front(const _Tp& __val)
      ^
/redacted/build-llvm/download/sysroot/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/bits/forward_list.h:829:7: note: candidate function not viable: cannot convert initializer list argument to 'TrieNode<(anonymous namespace)::StackIdData>'
      push_front(_Tp&& __val)
      ^
/redacted/git/llvm-project/llvm/tools/llvm-xray/xray-converter.cpp:232:13: error: no matching member function for call to 'push_front'
  NodeStore.push_front({FuncId, Parent, {}, {stack_id, std::move(siblings)}});
  ~~~~~~~~~~^~~~~~~~~~
/redacted/build-llvm/download/sysroot/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/bits/forward_list.h:822:7: note: candidate function not viable: cannot convert initializer list argument to 'const TrieNode<(anonymous namespace)::StackIdData>'
      push_front(const _Tp& __val)
      ^
/redacted/build-llvm/download/sysroot/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/bits/forward_list.h:829:7: note: candidate function not viable: cannot convert initializer list argument to 'TrieNode<(anonymous namespace)::StackIdData>'
      push_front(_Tp&& __val)
      ^
3 errors generated.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102760/new/

https://reviews.llvm.org/D102760



More information about the cfe-commits mailing list