summaryrefslogtreecommitdiffstats
path: root/clang/unittests
Commit message (Collapse)AuthorAgeFilesLines
...
* Reapply [VFS] Ignore broken symlinks in the directory iterator.Juergen Ributzka2017-03-101-0/+74
| | | | | | | | | | | | | | | | | | | Modified the tests to accept any iteration order. The VFS directory iterator and recursive directory iterator behave differently from the LLVM counterparts. Once the VFS iterators hit a broken symlink they immediately abort. The LLVM counterparts allow to recover from this issue by clearing the error code and skipping to the next entry. This change adds the same functionality to the VFS iterators. There should be no change in current behavior in the current CLANG source base, because all clients have loop exit conditions that also check the error code. This fixes rdar://problem/30934619. Differential Revision: https://reviews.llvm.org/D30768 llvm-svn: 297528
* Revert r297510 "[VFS] Ignore broken symlinks in the directory iterator."Juergen Ributzka2017-03-101-83/+0
| | | | | | The tests are failing on one of the bots. llvm-svn: 297517
* [VFS] Ignore broken symlinks in the directory iterator.Juergen Ributzka2017-03-101-0/+83
| | | | | | | | | | | | | | | | | The VFS directory iterator and recursive directory iterator behave differently from the LLVM counterparts. Once the VFS iterators hit a broken symlink they immediately abort. The LLVM counterparts allow to recover from this issue by clearing the error code and skipping to the next entry. This change adds the same functionality to the VFS iterators. There should be no change in current behavior in the current CLANG source base, because all clients have loop exit conditions that also check the error code. This fixes rdar://problem/30934619. Differential Revision: https://reviews.llvm.org/D30768 llvm-svn: 297510
* [clang-format] Add option to break before inheritance separation operator in ↵Andi-Bogdan Postelnicu2017-03-101-0/+12
| | | | | | | | class declaration. Differential Revision: https://reviews.llvm.org/D30487 llvm-svn: 297467
* Add missing implementation for AtomicChange::replace(...)Eric Liu2017-03-081-2/+20
| | | | | | | | | | | | | | Summary: Just realized the implementation is missing... Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30735 llvm-svn: 297289
* [clang-format] Look at NoLineBreak and NoLineBreakInOperand before ↵Krasimir Georgiev2017-03-081-2/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | breakProtrudingToken Summary: This patch makes ContinuationIndenter call breakProtrudingToken only if NoLineBreak and NoLineBreakInOperand is false. Previously, clang-format required two runs to converge on the following example with 24 columns: Note that the second operand shouldn't be splitted according to NoLineBreakInOperand, but the token breaker doesn't take that into account: ``` func(a, "long long long long", c); ``` After first run: ``` func(a, "long long " "long long", c); ``` After second run, where NoLineBreakInOperand is taken into account: ``` func(a, "long long " "long long", c); ``` With the patch, clang-format now obtains in one run: ``` func(a, "long long long" "long", c); ``` which is a better token split overall. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30575 llvm-svn: 297274
* clang-format: Get slightly better at understanding */&.Daniel Jasper2017-03-081-0/+1
| | | | | | | | | | Before: void f() { MACRO(A * const a); } After: void f() { MACRO(A *const a); } llvm-svn: 297268
* [clang-format] Enable comment reflowing in multiline comments containing pragmasKrasimir Georgiev2017-03-081-1/+21
| | | | | | | | | | | | | | | | | Summary: This patch enables comment reflowing of lines not matching the comment pragma regex in multiline comments containing comment pragma lines. Previously, these comments were dumped without being reindented to the result. Reviewers: djasper, mprobst Reviewed By: mprobst Subscribers: klimek, mprobst, cfe-commits Differential Revision: https://reviews.llvm.org/D30697 llvm-svn: 297261
* [clang-format] Followup of D30646 - unbreak the buildAndi-Bogdan Postelnicu2017-03-071-2/+2
| | | | llvm-svn: 297148
* [clang-format] Fixed indent issue when adding a comment at the end of a ↵Andi-Bogdan Postelnicu2017-03-071-0/+5
| | | | | | | | return type in named function declaration. Differential Revision: https://reviews.llvm.org/D30646 llvm-svn: 297143
* [clang-format] Support namespaces ending in semicolonKrasimir Georgiev2017-03-071-1/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds support for namespaces ending in semicolon to the namespace comment fixer. source: ``` namespace A { int i; int j; }; ``` clang-format before: ``` namespace A { int i; int j; } // namespace A; ``` clang-format after: ``` namespace A { int i; int j; }; // namespace A ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30688 llvm-svn: 297140
* [analyzer] Fix crash when building CFG with variable of incomplete typeMartin Bohme2017-03-071-1/+13
| | | | | | | | | | | | | | | | | | Summary: I've included a unit test with a function template containing a variable of incomplete type. Clang compiles this without errors (the standard does not require a diagnostic in this case). Without the fix, this case triggers the crash. Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30636 llvm-svn: 297129
* [clang-format] Add tests for ambiguous namespaces to the comment fixerKrasimir Georgiev2017-03-061-0/+80
| | | | llvm-svn: 297034
* [clang-format] Make NamespaceEndCommentFixer add at most one commentKrasimir Georgiev2017-03-061-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Until now, NamespaceEndCommentFixer was adding missing comments for every run, which results in multiple end comments for: ``` namespace { int i; int j; } #if A int a = 1; #else int a = 2; #endif ``` result before: ``` namespace { int i; int j; }// namespace // namespace #if A int a = 1; #else int a = 2; #endif ``` result after: ``` namespace { int i; int j; }// namespace #if A int a = 1; #else int a = 2; #endif ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30659 llvm-svn: 297028
* [clang-format] Use number of unwrapped lines for short namespaceKrasimir Georgiev2017-03-022-14/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes the namespace comment fixer use the number of unwrapped lines that a namespace spans to detect it that namespace is short, thus not needing end comments to be added. This is needed to ensure clang-format is idempotent. Previously, a short namespace was detected by the original source code lines. This has the effect of requiring two runs for this example: ``` namespace { class A; } ``` after first run: ``` namespace { class A; } ``` after second run: ``` namespace { class A; } // namespace ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30528 llvm-svn: 296736
* clang-format: [JS] Properly format object literals with shorthands.Daniel Jasper2017-03-011-0/+5
| | | | | | | | | | | | | | | | | Before: return { a, b: 'b', c, }; After: return { a, b: 'b', c, }; llvm-svn: 296664
* clang-format: [JS/TS] Properly understand cast expressions.Daniel Jasper2017-03-011-0/+3
| | | | | | | | | | Many things were wrong: - We didn't always allow wrapping after "as", which can be necessary. - We used to Undestand the identifier after "as" as a start of a name. - We didn't properly parse the structure of the expression with "as" having the precedence of relational operators llvm-svn: 296659
* [clang-format] Don't add namespace end comments for unbalanced right braces ↵Krasimir Georgiev2017-03-011-0/+12
| | | | | | after namespace end llvm-svn: 296638
* [clang-format] Add a new flag FixNamespaceComments to FormatStyleKrasimir Georgiev2017-03-011-21/+45
| | | | | | | | | | | | | | | | Summary: This patch enables namespace end comments under a new flag FixNamespaceComments, which is enabled for the LLVM and Google styles. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30405 llvm-svn: 296632
* Introducing clang::tooling::AtomicChange for refactoring tools.Eric Liu2017-03-012-5/+189
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: An AtomicChange is used to create and group a set of source edits, e.g. replacements or header insertions. Edits in an AtomicChange should be related, e.g. replacements for the same type reference and the corresponding header insertion/deletion. An AtomicChange is uniquely identified by a key position and will either be fully applied or not applied at all. The key position should be the location of the key syntactical element that is being changed, e.g. the call to a refactored method. Next step: add a tool that applies AtomicChange. Reviewers: klimek, djasper Reviewed By: klimek Subscribers: alexshap, cfe-commits, djasper, mgorny Differential Revision: https://reviews.llvm.org/D27054 llvm-svn: 296616
* Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.Daniel Jasper2017-03-011-8/+16
| | | | llvm-svn: 296608
* clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.Daniel Jasper2017-03-011-0/+8
| | | | | | | | Those blocks are used if C++ code is SWIG-wrapped (see swig.org) and usually do not contain C++ code. Also cleanup the implementation of for #if 0 and #if false a bit. llvm-svn: 296605
* clang-format: [Java] Fix bug in enum formatting.Daniel Jasper2017-02-281-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Before: public enum VeryLongEnum { ENUM_WITH_MANY_PARAMETERS("aaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb", "ccccccccccccccccccc") , SECOND_ENUM("a", "b", "c"); private VeryLongEnum(String a, String b, String c) {} } After: public enum VeryLongEnum { ENUM_WITH_MANY_PARAMETERS("aaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb", "ccccccccccccccccccc") , SECOND_ENUM("a", "b", "c"); private VeryLongEnum(String a, String b, String c) {} } llvm-svn: 296499
* Blacklist arbitrary @\\w+ JSDoc tags from wrapping.Martin Probst2017-02-281-0/+24
| | | | | | | | | | | | | | | | | | | | Summary: Also limits the blacklisting to only apply when the tag is actually followed by a parameter in curly braces. /** @mods {long.type.must.not.wrap} */ vs /** @const this is a long description that may wrap. */ Reviewers: djasper Subscribers: klimek, krasimir, cfe-commits Differential Revision: https://reviews.llvm.org/D30452 llvm-svn: 296467
* [clang-format] Add a NamespaceEndCommentsFixerKrasimir Georgiev2017-02-272-1/+352
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds a NamespaceEndCommentsFixer TokenAnalyzer for clang-format, which fixes end namespace comments. It currently supports inserting and updating existing wrong comments. Example source: ``` namespace A { int i; } namespace B { int j; } // namespace A ``` after formatting: ``` namespace A { int i; } // namespace A namespace B { int j; } // namespace B ``` Reviewers: klimek, djasper Reviewed By: djasper Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D30269 llvm-svn: 296341
* clang-format: [JS] whitespace after async in arrow functions.Martin Probst2017-02-271-0/+2
| | | | | | | | | | | | | | | | | | | Summary: Async arrow functions should be marked with a whitespace after the async keyword, before the parameter list: x = async () => foo(); Before: x = async() => foo(); This makes it easier to tell apart an async arrow function from a call to a function called async. Reviewers: bkramer Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30399 llvm-svn: 296330
* clang-format: Fix many Objective-C formatting regressions from r289428Nico Weber2017-02-241-0/+7
| | | | | | | | | | | | | | | r289428 added a separate language kind for Objective-C, but kept many "Language == LK_Cpp" checks untouched. This introduced a "IsCpp()" method that returns true for both C++ and Objective-C++, and replaces all comparisons of Language with LK_Cpp with calls to this new method. Also add a lot more test coverge for formatting things in LK_ObjC mode, by having FormatTest's verifyFormat() test for LK_ObjC everything that's being tested for LK_Cpp at the moment. Fixes PR32060 and many other things. llvm-svn: 296160
* clang-format: [JS] Improve line-wrapping behavior of template strings.Daniel Jasper2017-02-201-36/+20
| | | | | | | | Specifically, similar to other blocks, clang-format now wraps both after "${" and before the corresponding "}", if the contained expression spans multiple lines. llvm-svn: 295663
* clang-format: Prevent weird line-wraps in complex lambda introducersDaniel Jasper2017-02-201-4/+14
| | | | | | | | | | | | | | | | | | | Before: aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]() -> ::std:: unordered_set<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> { // }); After: aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]() -> ::std::unordered_set< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> { // }); llvm-svn: 295659
* clang-format: [JS/TS] Improve detection for array subscripts in types.Daniel Jasper2017-02-201-0/+3
| | | | | | | | | | | | Before: var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[ ]).someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[]) .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 295658
* clang-format: Don't remove existing spaces between identifier and ::.Daniel Jasper2017-02-171-0/+2
| | | | | | | | | | | | | | | | | | | | This can lead to bad behavior with macros that are used to annotate functions (e.g. ALWAYS_INLINE). Before, this: ALWAYS_INLINE ::std::string getName() ... was turned into: ALWAYS_INLINE::std::string getName() ... If it turns out that clang-format is failing to clean up a lot of the existing spaces now, we can add more analyses of the identifier. It should not currently. Cases where clang-format breaks nested name specifiers should be fine as clang-format wraps after the "::". Thus, a line getting longer and then shorter again should lead to the same original code. llvm-svn: 295437
* [clang-format] Align block comment decorationsKrasimir Georgiev2017-02-162-8/+196
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements block comment decoration alignment. source: ``` /* line 1 * line 2 */ ``` result before: ``` /* line 1 * line 2 */ ``` result after: ``` /* line 1 * line 2 */ ``` Reviewers: djasper, bkramer, klimek Reviewed By: klimek Subscribers: mprobst, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29943 llvm-svn: 295312
* [clang-format] Remove dead code in FormatTestComments, NFCKrasimir Georgiev2017-02-141-7/+0
| | | | llvm-svn: 295044
* clang-format: don't break code using __has_include, PR31908Nico Weber2017-02-101-0/+5
| | | | llvm-svn: 294772
* [clang-format] Move comment tests to their own file.Krasimir Georgiev2017-02-083-2085/+2177
| | | | | | | | | | | | | | Summary: With a growing suite of comment-related tests, it makes sense to take them out of the main test file. No functional changes. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek, mgorny Differential Revision: https://reviews.llvm.org/D29713 llvm-svn: 294439
* [clang-format] Break before a sequence of line comments aligned with the ↵Krasimir Georgiev2017-02-081-0/+116
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | next line. Summary: Make the comment alignment respect sections of line comments originally alinged with the next token. Until now the decision how to break a continuous sequence of line comments into sections was taken without reference to the next token. source: ``` class A { public: // comment about public // comment about a int a; } ``` format before: ``` class A { public: // comment about public // comment about a int a; } ``` format after: ``` class A { public: // comment about public // comment about a int a; } ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29626 llvm-svn: 294435
* clang-format: Fix bad variable declaration detection.Daniel Jasper2017-02-071-0/+5
| | | | | | | | | | | | Before: LooooooooooooooooongType variable(nullptr, [](A *a) {}); After: LooooooooooooooooongType variable(nullptr, [](A *a) {}); llvm-svn: 294358
* clang-format: [JS] correcly format object literal methods.Martin Probst2017-02-071-0/+12
| | | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, object literals can contain methods: var x = { a() { return 1; }, }; Previously, clang-format always parsed nested {} inside a braced list as further braced lists. Special case this logic for JavaScript to try parsing as a braced list, but fall back to parsing as a child block. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29656 llvm-svn: 294315
* clang-format: [JS] exclaim preceding regex literals.Martin Probst2017-02-071-0/+1
| | | | | | | | | | | | | | | | | | | | Summary: Regex detection would incorrectly classify a trailing `!` operator (nullability cast) followed by a `/` as the start of a regular expression literal. This fixes code such as: var foo = x()! / 10; Which would previously parse a regexp all the way to the end of the source file (or next `/`). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29634 llvm-svn: 294304
* clang-format: [JS] handle parenthesized class expressions.Martin Probst2017-02-071-0/+4
| | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, classes are expressions, so they can appear e.g. in argument lists. var C = foo(class { bar() { return 1; } }; Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29635 llvm-svn: 294302
* clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and ↵Daniel Jasper2017-02-061-0/+38
| | | | | | | | | | | | | | | | AlignAfterOpenBracket Fix for the formatting options combination of BreakBeforeBinaryOperators: All, AlignAfterOpenBracket: AlwaysBreak not handling long templates correctly. This patch allows a break after an opening left parenthesis, TemplateOpener, or bracket when both options are enabled. Patch by Daphne Pfister, thank you! Fixes llvm.org/PR30304. llvm-svn: 294179
* clang-format: [JS] Fix bugs in parsing and aligning template strings.Daniel Jasper2017-02-031-0/+4
| | | | llvm-svn: 294009
* [clang-format] Re-align broken comment lines where appropriate.Krasimir Georgiev2017-02-031-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The comment aligner was skipping over newly broken comment lines. This patch fixes that. source: ``` int ab; // line int a; // long long ``` format with column limit 15 before: ``` int ab; // line int a; // long // long ``` format with column limit 15 after: ``` int ab; // line int a; // long // long ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29486 llvm-svn: 293997
* clang-format: [Proto] Also supports implicit string literal concatenationDaniel Jasper2017-02-031-0/+3
| | | | llvm-svn: 293995
* [clang-format] Don't reflow across comment pragmas.Krasimir Georgiev2017-02-021-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that. source: ``` // long long long long // IWYU pragma: ``` format with column limit = 20 before: ``` // long long long // long IWYU pragma: ``` format with column limit = 20 after: ``` // long long long // long // IWYU pragma: ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29450 llvm-svn: 293898
* [clang-format] Fix breaking of comment sections in unwrapped lines ↵Krasimir Georgiev2017-02-021-1/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | containing newlines. Summary: The breaking of line comment sections was misaligning the case where the first comment line is on an unwrapped line containing newlines. In this case, the breaking column must be based on the source column of the last token that is preceded by a newline, not on the first token of the unwrapped line. source: ``` enum A { a, // line 1 // line 2 }; ``` format before: ``` enum A { a, // line 1 // line 2 }; ``` format after: ``` enum A { a, // line 1 // line 2 }; ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29444 llvm-svn: 293891
* [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.Krasimir Georgiev2017-02-021-0/+24
| | | | | | | | | | | | | | Summary: These lines commonly carry a special meaning. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29396 llvm-svn: 293878
* clang-format: Do not use two-argument/operand special case with no alignmentDaniel Jasper2017-02-021-0/+4
| | | | | | | | | | | | | | | | | Without alignment, there is no clean separation between the arguments, even if there are only two. Before: aaaaaaaaaaaaaa( aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaa(aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 293875
* clang-format: Fix incorrect line breaks after forced operator wraps.Daniel Jasper2017-02-011-0/+9
| | | | | | | | | | | | | | | | | Before: bool x = aaaaa // || bbbbb // || cccc; After: bool x = aaaaa // || bbbbb // || cccc; llvm-svn: 293839
* [clang-format] Fix regression about not aligning trailing comments in case ↵Krasimir Georgiev2017-02-011-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | they were previously aligned, but at different indent. Summary: Comment reflower was adding untouchable tokens in case two consecutive comment lines are aligned in the source code. This disallows the whitespace manager to re-indent them later. source: ``` int i = f(abc, // line 1 d, // line 2 // line 3 b); ``` Since line 2 and line 3 are aligned, the reflower was marking line 3 as untouchable; however the three comment lines need to be re-aligned. output before: ``` int i = f(abc, // line 1 d, // line 2 // line 3 b); ``` output after: ``` int i = f(abc, // line 1 d, // line 2 // line 3 b); ``` Reviewers: djasper Reviewed By: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29383 llvm-svn: 293755
OpenPOWER on IntegriCloud