LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 19368 - clang crashes on applying coding standards
Summary: clang crashes on applying coding standards
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Formatter (show other bugs)
Version: trunk
Hardware: PC Windows XP
: P release blocker
Assignee: Alexander Kornienko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-08 08:49 PDT by Marco Servadei
Modified: 2014-04-15 09:54 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
The file that causes the crash (49.65 KB, text/plain)
2014-04-08 08:49 PDT, Marco Servadei
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Servadei 2014-04-08 08:49:04 PDT
Created attachment 12353 [details]
The file that causes the crash

Clang crashes on applying coding standards to a file named StructureTreeCache.cpp (in attachment). OS Windows 8

The error:
Assertion failed: NewRemainingTokenColumns < RemainingTokenColumns, file ..\tools\clang\lib\Format\ContinuationIndenter.cpp, line 876
Traceback (most recent call last):
  File "apply-cs.py", line 54, in <module>
    subprocess.check_call([CLANG_FORMAT,'-i',f,'-style=file'])
  File "C:\Python27\lib\subprocess.py", line 511, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['D:\\git-root\\qt\\cmbuild\\bin\\win32_clang-format', '-i', 'D:\\git-root\\beetrunk\\beecore\\src\\server\\module\\Bee\\Cache\\StructureTreeCache.cpp', '-style=file']' returned non-zero exit status -1073740791

#######################

using the following config data:

# uncomment the following once clang 3.5 is out

Language:        Cpp
CommentPragmas:  '^ IWYU pragma:'

Standard:        Cpp03
TabWidth:        4
UseTab:          Always
BreakBeforeBraces: Allman

# indentation rules
NamespaceIndentation: None
ContinuationIndentWidth: 4
IndentWidth:     4
IndentCaseLabels: true

# spaces in angles and brackets
SpacesInParentheses: true
SpacesInAngles:  false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceBeforeAssignmentOperators: true
SpacesBeforeTrailingComments: 1
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesInAngles: false

# class/constructor related
AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 4
ConstructorInitializerAllOnOneLineOrOnePerLine: false
BreakConstructorInitializersBeforeComma: true

# Function related formatting
IndentFunctionDeclarationAfterType: true
BinPackParameters: false
#AllowShortFunctionsOnASingleLine: true

# control statement formatting
AllowShortLoopsOnASingleLine: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true

AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: false
ColumnLimit:     120

DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
MaxEmptyLinesToKeep: 1

ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: true
Cpp11BracedListStyle: false
Comment 1 Daniel Jasper 2014-04-08 09:00:17 PDT
I can reproduce this, it seems to assert in breakProtrudingToken(). Alex, can you take a look?
Comment 2 Alexander Kornienko 2014-04-08 10:29:29 PDT
I don't see any crashes on the attached file using the style quoted here (and also the llvm style). I build clang-format from r205758.

$ clang-format StructureTreeCache.cpp -style=llvm
... [formatted output]

$ cat .clang-format 
# uncomment the following once clang 3.5 is out

Language:        Cpp
CommentPragmas:  '^ IWYU pragma:'

Standard:        Cpp03
TabWidth:        4
UseTab:          Always
BreakBeforeBraces: Allman

...

$ clang-format StructureTreeCache.cpp -style=file
... [formatted output]

Daniel, how do you reproduce the issue and what symptoms do you observe (the mostly interesting being the stack trace)?
Comment 3 Daniel Jasper 2014-04-09 01:19:48 PDT
With clang-format built from head:

$ bin/clang-format ~/Downloads/StructureTreeCache.cpp 
Can't find usable .clang-format, using LLVM style
clang-format: /usr/local/google/clang/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp:941: unsigned int clang::format::ContinuationIndenter::breakProtrudingToken(const clang::format::FormatToken &, clang::format::LineState &, bool): Assertion `NewRemainingTokenColumns < RemainingTokenColumns' failed.
...
Comment 4 Max Horn 2014-04-09 08:04:13 PDT
In case it helps, I can also reproduce the issue with clang SVN rev 205846 (via git mirror 2f53df4e2), on Mac OS X 10.8.5. I am using a Debug+Assert build, and get this:

clang-format ~/Downloads/StructureTreeCache.cpp
Can't find usable .clang-format, using LLVM style
Assertion failed: (NewRemainingTokenColumns < RemainingTokenColumns), function breakProtrudingToken, file /Users/mhorn/Projekte/foreign/llvm-project/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp, line 941.
0  clang-format      0x00000001092e4e4e llvm::sys::PrintStackTrace(__sFILE*) + 46
1  clang-format      0x00000001092e515b PrintStackTraceSignalHandler(void*) + 27
2  clang-format      0x00000001092e54d8 SignalHandler(int) + 408
3  libsystem_c.dylib 0x00007fff8ffab90a _sigtramp + 26
4  libsystem_c.dylib 0x00007fff56b58be8 _sigtramp + 3334132472
5  clang-format      0x00000001092e518b raise + 27
6  clang-format      0x00000001092e5242 abort + 18
7  clang-format      0x00000001092e5221 __assert_rtn + 129
8  clang-format      0x00000001090b9fb0 clang::format::ContinuationIndenter::breakProtrudingToken(clang::format::FormatToken const&, clang::format::LineState&, bool) + 4704
9  clang-format      0x00000001090b5d12 clang::format::ContinuationIndenter::moveStateToNextToken(clang::format::LineState&, bool, bool) + 7826
10 clang-format      0x00000001090b7948 clang::format::ContinuationIndenter::addTokenToState(clang::format::LineState&, bool, bool, unsigned int) + 520
11 clang-format      0x00000001090c3653 clang::format::(anonymous namespace)::UnwrappedLineFormatter::addNextStateToQueue(unsigned int, clang::format::(anonymous namespace)::UnwrappedLineFormatter::StateNode*, bool, unsigned int*, std::__1::priority_queue<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::UnwrappedLineFormatter::StateNode*>, std::__1::vector<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::UnwrappedLineFormatter::StateNode*>, std::__1::allocator<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::UnwrappedLineFormatter::StateNode*> > >, std::__1::greater<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::UnwrappedLineFormatter::StateNode*> > >*) + 435
12 clang-format      0x00000001090c3211 clang::format::(anonymous namespace)::UnwrappedLineFormatter::analyzeSolutionSpace(clang::format::LineState&, bool) + 4273
13 clang-format      0x00000001090c2135 clang::format::(anonymous namespace)::UnwrappedLineFormatter::format(clang::format::AnnotatedLine const&, unsigned int, bool) + 149
14 clang-format      0x00000001090c0e02 clang::format::(anonymous namespace)::UnwrappedLineFormatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*> const&, bool, int, bool) + 3138
15 clang-format      0x00000001090bf895 clang::format::(anonymous namespace)::Formatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*>&, bool, clang::format::(anonymous namespace)::FormatTokenLexer&) + 693
16 clang-format      0x00000001090bd981 clang::format::(anonymous namespace)::Formatter::format() + 929
17 clang-format      0x00000001090bd554 clang::format::reformat(clang::format::FormatStyle const&, clang::Lexer&, clang::SourceManager&, std::__1::vector<clang::CharSourceRange, std::__1::allocator<clang::CharSourceRange> >) + 100
18 clang-format      0x00000001090a2a07 clang::format::format(llvm::StringRef) + 1735
19 clang-format      0x00000001090a2118 main + 1192
20 libdyld.dylib     0x00007fff91ea07e1 start + 0
21 libdyld.dylib     0x0000000000000002 start + 1846933537
Illegal instruction: 4
Comment 5 Alexander Kornienko 2014-04-15 09:54:30 PDT
Fixed in r206295.