https://bugs.llvm.org/show_bug.cgi?id=32438

            Bug ID: 32438
           Summary: clang-format: crash in NamespaceEndCommentsFixer
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

Created attachment 18179
  --> https://bugs.llvm.org/attachment.cgi?id=18179&action=edit
Reproducer

I get a SIGSEGV when running
  clang-format a.cpp
on the following creduced a.cpp (attached)

template <int> struct a {};
struct a<bool{}> b() {
}
#define c inline
void d() {
}

The backtrace is as follows:

Program received signal SIGSEGV, Segmentation fault.
(anonymous namespace)::Token::is (this=0x0, 
    K=(anonymous namespace)::(anonymous namespace)::TokenKind::kw_namespace)
    at ../tools/clang/include/clang/Lex/Token.h:94
94        bool is(tok::TokenKind K) const { return Kind == K; }
(gdb) bt
#0  (anonymous namespace)::Token::is (this=0x0, 
    K=(anonymous namespace)::(anonymous namespace)::TokenKind::kw_namespace)
    at ../tools/clang/include/clang/Lex/Token.h:94
#1  0x000000000032be20 in (anonymous namespace)::(anonymous
namespace)::FormatToken::is (this=0x0, 
    Kind=(anonymous namespace)::(anonymous namespace)::TokenKind::kw_namespace)
    at ../tools/clang/lib/Format/FormatToken.h:292
#2  0x000000000032c850 in (anonymous namespace)::(anonymous
namespace)::FormatToken::isNot<clang::tok::TokenKind> (this=0x0,
Kind=(anonymous namespace)::(anonymous namespace)::TokenKind::kw_namespace)
    at ../tools/clang/lib/Format/FormatToken.h:308
#3  0x000000000036808a in (anonymous namespace)::(anonymous
namespace)::NamespaceEndCommentsFixer::analyze (this=0x7fffffffc0e0,
Annotator=..., AnnotatedLines=..., Tokens=...)
    at ../tools/clang/lib/Format/NamespaceEndCommentsFixer.cpp:136
#4  0x00000000003744e5 in (anonymous namespace)::(anonymous
namespace)::TokenAnalyzer::process (
    this=0x7fffffffc0e0) at ../tools/clang/lib/Format/TokenAnalyzer.cpp:110
#5  0x000000000031ab5f in operator() (this=0x7fffffffc838, Fixer=...)
    at ../tools/clang/lib/Format/Format.cpp:1842
#6  0x000000000031a9e0 in (anonymous namespace)::(anonymous
namespace)::reformat (Style=..., Code=..., 
    Ranges=..., FileName=..., IncompleteFormat=0x7fffffffca9f)
    at ../tools/clang/lib/Format/Format.cpp:1860
#7  0x00000000002c8159 in (anonymous namespace)::(anonymous namespace)::format
(FileName=...)
    at ../tools/clang/tools/clang-format/ClangFormat.cpp:280
#8  0x00000000002c75dc in main (argc=2, argv=0x7fffffffddc8)
    at ../tools/clang/tools/clang-format/ClangFormat.cpp:367

In tools/clang/lib/Format/NamespaceEndCommentsFixer.cpp:136, 
NamespaceTok is null. I guess that would be the place to check for it.

I built from SVN, currently at 298877.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to