llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang-format WhitespaceManager crash

Open tiagomacarios opened this issue 3 years ago • 4 comments

Repro:

file:

static constexpr T v[] {
   { AAAAAAAAAAAAAAAAAAAAAAAAA::aaaaaaaaaaaaaaaaaaa, AAAAAAAAAAAAAAAAAAAAAAAAA::aaaaaaaaaaaaaaaaaaaaaaaa, 1, 0.000000000f, "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
};

.clang-format

AccessModifierOffset: -3
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments:
  Kind: Always
  OverEmptyLines: 2
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveShortCaseStatements:
  Enabled: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
  AfterCaseLabel:         true
  AfterClass:             true
  AfterControlStatement:  true
  AfterEnum:              true
  AfterFunction:          true
  AfterNamespace:         true
  AfterObjCDeclaration:   true
  AfterStruct:            true
  AfterUnion:             false
  BeforeCatch:            true
  BeforeElse:             true
  BeforeLambdaBody:       true
  IndentBraces:           false
  SplitEmptyFunction:     false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers : BeforeColon
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 3
ContinuationIndentWidth: 3
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IndentCaseLabels: true
IndentWidth: 3
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: OuterScope
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PackConstructorInitializers: Never
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 10000
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
Standard: Latest
TabWidth: 3
UseTab: Never

Callstack:

>	clang-format.exe!HandleAbort(int Sig) Line 419	C++
 	[External Code]	
 	clang-format.exe!llvm::SmallVectorTemplateCommon<clang::format::WhitespaceManager::Change,void>::operator[](unsigned __int64 idx) Line 298	C++
 	clang-format.exe!clang::format::WhitespaceManager::getNetWidth<clang::format::WhitespaceManager::CellDescription *>(clang::format::WhitespaceManager::CellDescription * const & Start, clang::format::WhitespaceManager::CellDescription * const & End, unsigned int InitialSpaces) Line 285	C++
 	clang-format.exe!clang::format::WhitespaceManager::getMaximumNetWidth<clang::format::WhitespaceManager::CellDescription *>(clang::format::WhitespaceManager::CellDescription * const & CellStart, clang::format::WhitespaceManager::CellDescription * const & CellStop, unsigned int InitialSpaces, unsigned int CellCount, unsigned int MaxRowCount) Line 324	C++
 	clang-format.exe!clang::format::WhitespaceManager::alignArrayInitializersLeftJustified(clang::format::WhitespaceManager::CellDescriptions && CellDescs) Line 1315	C++
 	clang-format.exe!clang::format::WhitespaceManager::alignArrayInitializers(unsigned int Start, unsigned int End) Line 1222	C++
 	clang-format.exe!clang::format::WhitespaceManager::alignArrayInitializers() Line 1206	C++
 	clang-format.exe!clang::format::WhitespaceManager::generateReplacements() Line 113	C++
 	clang-format.exe!clang::format::`anonymous namespace'::Formatter::analyze(clang::format::TokenAnnotator & Annotator, llvm::SmallVectorImpl<clang::format::AnnotatedLine *> & AnnotatedLines, clang::format::FormatTokenLexer & Tokens) Line 2391	C++
 	clang-format.exe!clang::format::TokenAnalyzer::process(bool SkipAnnotation) Line 132	C++
 	clang-format.exe!clang::format::internal::reformat::__l2::<lambda_10>::operator()(const clang::format::Environment & Env) Line 3673	C++
 	[External Code]	
 	clang-format.exe!clang::format::internal::reformat(const clang::format::FormatStyle & Style, llvm::StringRef Code, llvm::ArrayRef<clang::tooling::Range> Ranges, unsigned int FirstStartColumn, unsigned int NextStartColumn, unsigned int LastStartColumn, llvm::StringRef FileName, clang::format::FormattingAttemptStatus * Status) Line 3688	C++
 	clang-format.exe!clang::format::reformat(const clang::format::FormatStyle & Style, llvm::StringRef Code, llvm::ArrayRef<clang::tooling::Range> Ranges, llvm::StringRef FileName, clang::format::FormattingAttemptStatus * Status) Line 3731	C++
 	clang-format.exe!clang::format::format(llvm::StringRef FileName) Line 499	C++
 	clang-format.exe!main(int argc, const char * * argv) Line 631	C++
 	[External Code]	

tiagomacarios avatar Oct 06 '23 17:10 tiagomacarios

any indication of what version you where using?

mydeveloperday avatar Oct 09 '23 18:10 mydeveloperday

I can't reproduce with 18

mydeveloperday avatar Oct 09 '23 18:10 mydeveloperday

I am able to reproduce this on trunk. The relevant setting is AlignArrayOfStructures: Left and the non-zero ColumnLimit.

I took a quick look at fixing it, but it became very ambiguous how AlignArrayOfStructures should interact with line wrapping, so it wasn't obvious how how to update the code. If anyone is more familiar with the AlignArrayOfStructures I'm happy to discuss and work on a fix.

galenelias avatar Oct 10 '23 16:10 galenelias

Minimized formatting options: clang-format --style="{'AlignArrayOfStructures': 'Left', 'ColumnLimit': '120'}" crash.cpp

galenelias avatar Oct 10 '23 17:10 galenelias