[cfe-dev] ast_matchers::MatchFinder default constructor segfaults away

Whisperity via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 26 12:31:47 PDT 2018

Dear List,

When trying to instantiate a MatchFinder on my function's local stack,
if I try to use the default constructor, it segfaults.

Relevant code snippet:

  void f()
    MatchFinder finder; // <- SIGSEGV
    // ...

and backtrace:

(gdb) bt  5
#0  0x00007fffeb240f67 in
true>&&) (this=0x7fffdeac3120,
    O=<unknown type in
/large/whisperity/llvm/build/./lib/../lib/libclangASTMatchers.so.7, CU
0x0, DIE 0x20cb21>) at ../../../../../include/llvm/ADT/Optional.h:46
#1  0x00007fffeb237f4d in
atchFinderOptions::Profiling>&&) (this=0x7fffdeac3120, O=<unknown type
in /large/whisperity/llvm/build/./lib/../lib/libclangASTMatchers.so.7,
CU 0x0, DIE 0x2002ac>)
    at ../../../../../include/llvm/ADT/Optional.h:144
#2  0x00007fffeb237f73 in
    this=0x7fffdeac3120) at
#3  0x00007fffeb17fd94 in
clang::ast_matchers::MatchFinder::MatchFinder (this=0x7fffdeac2fe8,
    at ../../../../../../clang/lib/ASTMatchers/ASTMatchFinder.cpp:934

The default constructor's init-list moves from the argument and the
method itself is declared in the header with default argument using a
default constructed instance of Options.
The only use place I could find for this class so far is Clang-Tidy.

I don't want to use the options in any special way in my code, that's
why I tried the default initialiser.

If I explicitly initialise a MatchFinder::MatchFinderOptions and pass
it as an argument, either by copy or move, it works.
Passing a temporary by copy or move results in the same segfault.

  void f()
     MatchFinder::MatchFinderOptions opts;
     MatchFinder finder(opts); // works

I'm not entirely sure what would be the best option to solve this API
inconsistency, as seemingly the error lies two or three types

; Whisperity

More information about the cfe-dev mailing list