Commit Graph

66 Commits

Author SHA1 Message Date
Douglas Yung efebe76e93 Remove redundant test that was causing intermittent build bot failures.
Patch by Fred Grim!

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D104295
2021-06-15 12:46:03 -07:00
Fred Grim 673c5ba584 [clang-format] Adds a formatter for aligning arrays of structs
This adds a new formatter to arrange array of struct initializers into
neat columns.

Differential Revision: https://reviews.llvm.org/D101868
2021-06-13 21:14:37 +02:00
Abhina Sreeskantharajan e59d336e75 [test] Use host platform specific error message substitution in lit tests - continued
On z/OS, other error messages are not matched correctly in lit tests.

```
EDC5121I Invalid argument.
EDC5111I Permission denied.
```

This patch adds a lit substitution to fix it.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D95808
2021-02-03 09:53:22 -05:00
Albertas Vyšniauskas 60bf5826cf [clang-format] PR16518 Add flag to suppress empty line insertion before access modifier
Add new option called InsertEmptyLineBeforeAccessModifier. Empty line
before access modifier is inerted if this option is set to true (which
is the default value, because clang-format always inserts empty lines
before access modifiers), otherwise empty lines are removed.

Fixes issue #16518.

Differential Revision: https://reviews.llvm.org/D93846
2021-01-25 21:02:41 +01:00
Nathan James eb9483b210
[format] Add overload to parseConfiguration that accept llvm::MemoryBufferRef
This overload should be used for better diagnostics when parsing configurations.
Now a failure to parse will list the filename (or <command-line>) instead of just `YAML`.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D93633
2020-12-23 12:08:29 +00:00
Joachim Meyer c755e41c33 Fix -Wno-error= parsing in clang-format.
As noted in https://reviews.llvm.org/D86137#2460135 parsing of
the clang-format parameter -Wno-error=unknown fails.
This currently is done by having `-Wno-error=unknown` as an option.
In this patch this is changed to make `-Wno-error=` parse an enum into a bit set.
This way the parsing is fixed and also we can possibly add new options easily.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D93459
2020-12-17 22:23:42 +01:00
Alex Richardson e0ff5a8410 [clang-format] Add a test showing the current config file list parsing
Currently clang-format starts overriding the default values at index 0
(keeping the existing values) instead of appending or replacing all values.
This patch simply checks the current (IMO surprising) behaviour and does
not attempt to change it.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D86941
2020-09-04 16:57:46 +01:00
Paul Hoad 6a1f7d6c9f [clang-format] Proposal for clang-format to give compiler style warnings
relanding {D68554} with fixed lit tests, checked on Windows and MacOS

llvm-svn: 374720
2019-10-13 14:51:45 +00:00
Nico Weber e95d1ca1e2 Revert r374663 "[clang-format] Proposal for clang-format to give compiler style warnings"
The test fails on macOS and looks a bit wrong, see comments on the review.

Also revert follow-up r374686.

llvm-svn: 374688
2019-10-12 22:58:34 +00:00
Paul Hoad 1f20bc17d0 [clang-format] Proposal for clang-format to give compiler style warnings
Summary:
Related somewhat to {D29039}

On seeing a quote on twitter by @invalidop

> If it's not formatted with clang-format it's a build error.

This made me want to change the way I use clang-format into a tool that could optionally show me where my source code violates clang-format syle.

When I'm making a change to clang-format itself, one thing I like to do to test the change is to ensure I didn't cause a huge wave of changes, what I want to do is simply run this on a known formatted directory and see if any new differences arrive in a manner I'm used to.

This started me thinking that we should allow build systems to run clang-format on a whole tree and emit compiler style warnings about files that fail clang-format in a form that would make them as a warning in most build systems and because those build systems range in their construction I don't think its unreasonable to NOT expect them to have to do the directory searching or parsing the output replacements themselves, but simply transform that into an error code when there are changes required.

I am starting this by suggesing adding a -n or -dry-run command line argument which would emit a warning/error of the form

Support for various common compiler command line argumuments like '-Werror' and '-ferror-limit' could make this very flexible to be integrated into build systems and CI systems.

```
> $ /usr/bin/clang-format --dry-run ClangFormat.cpp -ferror-limit=3 -fcolor-diagnostics
> ClangFormat.cpp:54:29: warning: code should be clang-formatted [-Wclang-format-violations]
> static cl::list<std::string>
>                             ^
> ClangFormat.cpp:55:20: warning: code should be clang-formatted [-Wclang-format-violations]
> LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n"
>                    ^
> ClangFormat.cpp:55:77: warning: code should be clang-formatted [-Wclang-format-violations]
> LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n"
>                                                                             ^
```

Reviewers: mitchell-stellar, klimek, owenpan

Reviewed By: klimek

Subscribers: mgorny, cfe-commits

Tags: #clang-format, #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D68554

llvm-svn: 374663
2019-10-12 15:36:05 +00:00
Reid Kleckner 38e033bf33 Re-land Remove REQUIRES:shell from tests that pass for me on Windows
This reverts r371497 (git commit 3d7e9ab7b9)

Reorder `not` with `env` in these two tests so they pass:
  Driver/rewrite-map-in-diagnostics.c
  Index/crash-recovery-modules.m.

This will not be necessary after D66531 lands.

llvm-svn: 371552
2019-09-10 20:15:45 +00:00
James Henderson 3d7e9ab7b9 Revert Remove REQUIRES:shell from tests that pass for me on Windows
This reverts r371478 (git commit a9980f60ce)

llvm-svn: 371497
2019-09-10 08:48:33 +00:00
Reid Kleckner a9980f60ce Remove REQUIRES:shell from tests that pass for me on Windows
I see in the history for some of these tests REQUIRES:shell was used as
a way to disable tests on Windows because they are flaky there. I tried
not to re-enable such tests, but it's possible that I missed some and
this will re-enable flaky tests on Windows. If so, we should disable
them with UNSUPPORTED:system-windows and add a comment that they are
flaky there. So far as I can tell, the lit internal shell is capable of
running all of these tests, and we shouldn't use REQUIRES:shell as a
proxy for Windows.

llvm-svn: 371478
2019-09-10 00:50:32 +00:00
Rafael Stahl f625a8a250 [clang-format][tests] Explicitly specify style in some tests
Summary: This fixes broken tests when doing an out-of-source build that picks up a random .clang-format on the file system due to the default "file" style.

Reviewers: djasper, klimek, MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay

Subscribers: lebedev.ri, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61001

llvm-svn: 365909
2019-07-12 15:56:18 +00:00
Ben Hamilton 6845dec917 [clang-format] Fix bug where -dump-config failed on ObjC header
Summary:
`clang-format -dump-config path/to/file.h` never passed
anything for the Code parameter to clang::format::getStyle().

This meant the logic to guess Objective-C from the contents
of a .h file never worked, because LibFormat didn't have the
code to work with.

With this fix, we now correctly read in the contents of the
file if possible with -dump-config.

I had to update the lit config for test/Format/ because
the default config ignores .h files.

Test Plan: make -j12 check-clang

Reviewers: jolesiak, krasimir

Reviewed By: jolesiak, krasimir

Subscribers: Wizard, klimek, cfe-commits, djasper

Differential Revision: https://reviews.llvm.org/D42395

llvm-svn: 323668
2018-01-29 17:36:43 +00:00
Kuba Mracek 5b57633a45 [clang] Get rid of "%T" expansions
The %T lit expansion expands to a common directory shared between all the tests in the same directory, which is unexpected and unintuitive, and more importantly, it's been a source of subtle race conditions and flaky tests. In https://reviews.llvm.org/D35396, it was agreed that it would be best to simply ban %T and only keep %t, which is unique to each test. When a test needs a temporary directory, it can just create one using mkdir %t.

This patch removes %T in clang.

Differential Revision: https://reviews.llvm.org/D36437

llvm-svn: 310950
2017-08-15 19:47:06 +00:00
Sylvestre Ledru d23dd6c633 clang-format: add an option -verbose to list the files being processed
Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D34824

llvm-svn: 310778
2017-08-12 15:15:10 +00:00
Krasimir Georgiev bcda54b69d [clang-format] Replace IncompleteFormat by a struct with Line
Summary: This patch replaces the boolean IncompleteFormat that is used to notify the client if an unrecoverable syntax error occurred by a struct that also contains a line number.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D32298

llvm-svn: 300985
2017-04-21 14:35:20 +00:00
NAKAMURA Takumi d6fc6730ce clang/test/Format/inplace.cpp: Avoid using wildcard.
MSYS' tools don't do globbing.

llvm-svn: 296460
2017-02-28 10:05:56 +00:00
Haojian Wu 44038f176b [clang-format] Fix test failure caused by "rm" on some buildbots.
The begining command "rm" will return 1 when there is not such file to
delete.

This patch is to remove it, as it's not needed for the test.

llvm-svn: 296453
2017-02-28 09:03:07 +00:00
Nico Weber 65da45763e clang-format: Don't leave behind temp files in -i mode on Windows, PR26125, reloaded
Second attempt after http://llvm.org/viewvc/llvm-project?rev=296166&view=rev

In the first attempt, Code (the memory buffer backing the input file) was reset
before overwriteChangedFiles() was called, but overwriteChangedFiles() still
reads from it.  This time, load the whole input file into memory instead of
using mmap when formatting in-place.

(Since the test is identical to what was in the repo before chapuni's revert,
svn diff doesn't show it – see the above link for the test.)

https://reviews.llvm.org/D30385

llvm-svn: 296408
2017-02-27 22:59:58 +00:00
NAKAMURA Takumi d274dc3896 Revert r296166, "clang-format: Don't leave behind temp files in -i mode on Windows, PR26125", and r296171.
(MemoryBuffer)Code.reset() was too early.

  ==26912== Invalid read of size 1
  ==26912==    at 0x437E1D: llvm::MemoryBuffer::init(char const*, char const*, bool) (MemoryBuffer.cpp:47)
  ==26912==    by 0x438013: (anonymous namespace)::MemoryBufferMem::MemoryBufferMem(llvm::StringRef, bool) (MemoryBuffer.cpp:86)
  ==26912==    by 0x438128: llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, llvm::StringRef, bool) (MemoryBuffer.cpp:112)
  ==26912==    by 0x4E189D: clang::vfs::detail::(anonymous namespace)::InMemoryFileAdaptor::getBuffer(llvm::Twine const&, long, bool, bool) (VirtualFileSystem.cpp:443)
  ==26912==    by 0x4DF5BA: clang::vfs::FileSystem::getBufferForFile(llvm::Twine const&, long, bool, bool) (VirtualFileSystem.cpp:94)
  ==26912==    by 0x4B72EC: clang::FileManager::getBufferForFile(clang::FileEntry const*, bool, bool) (FileManager.cpp:443)
  ==26912==    by 0x4C1F81: clang::SrcMgr::ContentCache::getBuffer(clang::DiagnosticsEngine&, clang::SourceManager const&, clang::SourceLocation, bool*) const (SourceManager.cpp:98)
  ==26912==    by 0x4C50E5: clang::SourceManager::getBufferData(clang::FileID, bool*) const (SourceManager.cpp:689)
  ==26912==    by 0x58E794: clang::Rewriter::getEditBuffer(clang::FileID) (Rewriter.cpp:230)
  ==26912==    by 0x407297: clang::format::format(llvm::StringRef) (ClangFormat.cpp:311)
  ==26912==    by 0x4078D7: main (ClangFormat.cpp:363)

llvm-svn: 296237
2017-02-25 03:45:49 +00:00
Nico Weber 0760360dcc Try to unbreak tests after r296166
Looks like %T isn't per-test but per-test-directory, and
the rm was deleting temp files written by other tests in
test/Format.  Limit the rm's scope a bit.

llvm-svn: 296171
2017-02-24 21:01:43 +00:00
Nico Weber cc0573b03f clang-format: Don't leave behind temp files in -i mode on Windows, PR26125
Fix and analysis by Wei Mao <weimao1@gmail.com> (see bug), test by me.

llvm-svn: 296166
2017-02-24 20:49:00 +00:00
Antonio Maiorano ae834047a4 clang-format: remove tests that assume no config file will be found as this is not always the case
These tests fail for developers who place their build directories under the
llvm root directory because llvm's own .clang-format file will be found.
Anyway these cases are covered by FormatStyle.GetStyleOfFile tests
(FormatTest.cpp).

Differential Revision: https://reviews.llvm.org/D28983

llvm-svn: 292787
2017-01-23 13:20:23 +00:00
Krasimir Georgiev 69cb6ce7fb [clang-format] Remove redundant test in style-on-command-line.cpp
Summary:
rL292562 added a fix to always format if the fallback style is set to "none".
In test/Format/style-on-command-line.cpp:19 is redundant, since -fallback-style
has a default value of LLVM set in ClangFormat.cpp:72.

@amaiorano: I believe that the rest of the test cases still cover your change in
case the fallback style is explicitly set to "none". Please, if this is not the
case, initiate a discussion.

Reviewers: ioeric, bkramer

Reviewed By: ioeric

Subscribers: cfe-commits, klimek, amaiorano

Differential Revision: https://reviews.llvm.org/D28943

llvm-svn: 292604
2017-01-20 12:39:05 +00:00
Antonio Maiorano 7eb7507aeb clang-format: fix fallback style set to "none" not always formatting
This fixes clang-format not formatting if fallback-style is explicitly set to
"none", and either a config file is found or YAML is passed in without a
"BasedOnStyle". With this change, passing "none" in these cases will have no
affect, and LLVM style will be used as the base style.

Differential Revision: https://reviews.llvm.org/D28844

llvm-svn: 292562
2017-01-20 01:22:42 +00:00
Antonio Maiorano 3adfb6a3ee clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyle
Change the contract of GetStyle so that it returns an error when an error occurs
(i.e. when it writes to stderr), and only returns the fallback style when it
can't find a configuration file.

Differential Revision: https://reviews.llvm.org/D28081

llvm-svn: 292174
2017-01-17 00:12:27 +00:00
Eric Liu a992afe809 Make clang-format remove duplicate headers when sorting #includes.
Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes.

Reviewers: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D23274

llvm-svn: 278206
2016-08-10 09:32:23 +00:00
Daniel Jasper 7048edb104 Fix clang-format test. I believe that the new behavior is better.
llvm-svn: 253861
2015-11-23 08:50:52 +00:00
Daniel Jasper da44677082 clang-format: Enable #include sorting by default.
This has seen quite some usage and I am not aware of any issues. Also
add a style option to enable/disable include sorting. The existing
command line flag can from now on be used to override whatever is set
in the style.

llvm-svn: 253202
2015-11-16 12:38:56 +00:00
Daniel Jasper a1036e5d08 clang-format: When a line is formatted, also format subsequence lines if their indent is off.
Summary: This is especially important so that if a change is solely inserting a block around a few statements, clang-format-diff.py will still clean up and add indentation to the inner parts.

Reviewers: klimek

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D14105

llvm-svn: 251474
2015-10-28 01:08:22 +00:00
Nico Weber 3cb667edaa clang-format: Use pipes instead of temporary files for most lit tests.
This makes the format tests look more like most other FileCheck tests in clang.

The multiple-inputs tests still use temp files, to make sure that the file
input code in clang-format stays tested.

Stop stripping out the comment lines in style-on-command-line.cpp as they don't
get in the way and it makes the test simpler. Also remove 2>&1s on the tests in
that file that don't need it.

http://reviews.llvm.org/D13852

llvm-svn: 250706
2015-10-19 16:21:29 +00:00
Daniel Jasper 148f32925f clang-format: Add test for (properly escaped) XML output.
llvm-svn: 250629
2015-10-17 22:44:19 +00:00
Reid Kleckner f8439940ef Disable style-on-command-line test on Windows
llvm-svn: 239416
2015-06-09 17:47:59 +00:00
Benjamin Kramer fea47d418a Remove rm invocations where the file is immediately rewritten later.
This may or may not help making this test less flaky on windows. There's
a race condition in lit somewhere.

llvm-svn: 239402
2015-06-09 12:41:02 +00:00
Manuel Klimek 21b4117a12 Remove error message when using the fallback style.
llvm-svn: 238822
2015-06-02 11:52:15 +00:00
Daniel Jasper 622c72ded5 Reapply r236854 and fixed r236867.
Makes emacs show a different message when clang-format encountered a
syntax error.

llvm-svn: 236943
2015-05-10 07:47:19 +00:00
Tobias Grosser a704600295 Revert "Make emacs show when clang-format encountered a syntax error."
This reverts commit 236854, which caused clang-format to always print
'{ "IncompleteFormat": false }' at the top of an incompletely formatted file.
This output causes problems e.g. in Polly's automatic formatting checks. Daniel
tried to fix this in 236867, but this fix had to be reverted due to buildbot
failures. I revert this change as well for now as it is Friday night and
unlikely to be fixed immediately.

llvm-svn: 236908
2015-05-08 21:34:09 +00:00
Renato Golin 82fbfe684e Revert "clang-format: Only output IncompleteFormat if -cursor is given."
This reverts commit r236867, as it was breaking multiple buildbots. Daniel
will look into it later.

llvm-svn: 236882
2015-05-08 17:05:24 +00:00
Daniel Jasper e44e5665d4 clang-format: Only output IncompleteFormat if -cursor is given.
This is only for editor integrations.

llvm-svn: 236867
2015-05-08 15:36:30 +00:00
Manuel Klimek 3dfe4a87c8 Make emacs show when clang-format encountered a syntax error.
Propagate the 'incomplete-format' state back through clang-format's command
line interace and adapt the emacs integration to show a better result.

llvm-svn: 236854
2015-05-08 13:59:15 +00:00
Alp Toker a3c494f0db Revert "clang/test/Driver/crash-report.c: This requires rewriter for -frewrite-includes. [PR20321]"
We've decided to make the core rewriter class and PP rewriters mandatory.
They're only a few hundred lines of code in total and not worth supporting as a
distinct build configuration, especially since doing so disables key compiler
features.

This reverts commit r213150.

Revert "clang/test: Introduce the feature "rewriter" for --enable-clang-rewriter."

This reverts commit r213148.

Revert "Move clang/test/Frontend/rewrite-*.c to clang/test/Frontend/Rewriter/"

This reverts commit r213146.

llvm-svn: 213159
2014-07-16 15:12:48 +00:00
NAKAMURA Takumi 692d6bb544 clang/test: Introduce the feature "rewriter" for --enable-clang-rewriter.
llvm-svn: 213148
2014-07-16 13:36:39 +00:00
Daniel Jasper 553d4878da clang-format: Introduce style with spaces on both sides of */&.
Patch by Janusz Sobczak (slightly extended).
This fixes llvm.org/19929.

llvm-svn: 211098
2014-06-17 12:40:34 +00:00
Rafael Espindola 374597abfc Allow lowercase messages in this test again.
I misunderstood where the message was being converted.

llvm-svn: 210774
2014-06-12 12:40:04 +00:00
Rafael Espindola d0136707a9 Give clang-format its own error category.
The posix errno values are probably to the best thing to use for
describing parse errors.

This should also fix the mingw build.

llvm-svn: 210739
2014-06-12 02:50:04 +00:00
Rafael Espindola a8aef53849 Accomodate for message differences on windows.
llvm-svn: 210722
2014-06-11 23:53:06 +00:00
Daniel Jasper 94ea5bb115 clang-format: Add basic test for -style=none.
llvm-svn: 209447
2014-05-22 15:13:48 +00:00
Daniel Jasper e1d9141433 clang-format: Explicitly set fallback style that is tested.
llvm-svn: 196213
2013-12-03 06:48:41 +00:00