aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/clang-format
AgeCommit message (Collapse)AuthorFilesLines
2025-08-26[clang-format] Use proper flags for git diff-tree (#155247)Aiden Grossman1-1/+1
From local testing, git diff-tree does not support three dot diffs correctly, instead expecting the --merge-base flag to be passed along with two commits. From my reading, the documentation (https://git-scm.com/docs/git-diff-tree) also confirms this. This patch updates the git-clang-format script to be correct. I don't think we ever ran into this issue before because we never ended up using it. For the PR code format job I believe we would just explicitly pass the merge base, completely bypassing the problem.
2025-07-31NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)James Y Knight1-5/+3
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs. For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to convenience method `DiagnosticIDs::create()`. Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-07-31NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for ↵James Y Knight1-4/+4
llvm::vfs::FileSystem. (#151407) This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>` instead of `FileSystem*` or `FileSystem&`, when dealing with existing objects. Part of cleanup #151026.
2025-07-14Revert "[clang-format] Fix an off-by-1 bug with -length option (#143302)"Owen Pan1-7/+3
This reverts commit 1fae5918b3d6fbed8ce6d8a2edf31bdf304ca8db because it may break VSCode. Closes #146036
2025-06-13[clang-format] Fix an off-by-1 bug with -length option (#143302)Owen Pan1-3/+7
Also validate the argument value. Fixes #56245
2025-06-12Reland "[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp" (#143477)Owen Pan1-28/+24
Reapply https://github.com/llvm/llvm-project/pull/143236 and fix the bug reported in https://github.com/llvm/llvm-project/pull/143236#issuecomment-2957102180.
2025-06-09Revert "[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (#143236)"Jorge Gorbe Moya1-21/+28
This reverts commit 897ccddcc30cacdfe04ddd622986b50ec963eabc. It introduced a bug when formatting multiple files in one go. When a shorter file is passed after a longer one, a stale length from the previous file seems to be used, triggering an "invalid length (...) is outside the file" error.
2025-06-07[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (#143236)Owen Pan1-28/+21
2025-05-22Reapply "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Jan Svoboda1-4/+4
(#139584)" This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22Revert "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Kazu Hirata1-4/+4
(#139584)" This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c. Multiple builtbot failures have been reported: https://github.com/llvm/llvm-project/pull/139584
2025-05-22[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)Jan Svoboda1-4/+4
The `DiagnosticOptions` class is currently intrusively reference-counted, which makes reasoning about its lifetime very difficult in some cases. For example, `CompilerInvocation` owns the `DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and only exposes an accessor returning `DiagnosticOptions &`. One would think this gives `CompilerInvocation` exclusive ownership of the object, but that's not the case: ```c++ void shareOwnership(CompilerInvocation &CI) { llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions(); // ... } ``` This is a perfectly valid pattern that is being actually used in the codebase. I would like to ensure the ownership of `DiagnosticOptions` by `CompilerInvocation` is guaranteed to be exclusive. This can be leveraged for a copy-on-write optimization later on. This PR changes usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and `lldb` to not be intrusively reference-counted.
2025-05-20[clang-format] Handle raw string literals containing JSON code (#140666)Owen Pan1-2/+2
Fix #65400
2025-05-19[clang-format][NFC] Upgrade SortIncludes option to a struct (#140497)Owen Pan1-3/+2
This allows adding other suboptions e.g. IgnoreExtension in #137840.
2025-04-18[clang-format] Handle spaces in filename paths in clang-format-diff.py (#135779)Selim Keles1-1/+1
This PR resolves an issue in clang-format-diff.py where filenames containing spaces were not correctly extracted from Git diffs. Due to the previous regex implementation, filenames were being truncated, causing the script to fail when processing diffs with such filenames. Fixes #135619.
2025-04-10[clang-format][NFC] Reformat git-clang-formatOwen Pan1-25/+8
2025-04-10Treat ipynb as json (#135137)Tim Clephas3-3/+4
Fixes #110727
2025-04-10[clang-format] Add 'cl' to enable OpenCL kernel file formatting (#134529)Wenju He1-0/+1
There are many .cl files in llvm repo. It would be great that clang-format can support it.
2025-03-16[clang-format] Update the minimum python version requirementOwen Pan1-1/+1
See https://llvm.org/docs/GettingStarted.html#software Fix #131456
2025-02-07[emacs][clang-format] Suppress reference to free variable errors (#126254)Ron Gut1-0/+1
vc-git-program is referenced but not defined -- vc-git provides the definition.
2025-02-04[emacs][clang-format] Add elisp API for clang-format on git diffs (#112792)goldsteinn1-15/+185
New proposed function `clang-format-vc-diff`. It is the same as calling `clang-format-region` on all diffs between the content of a buffer-file and the content of the file at git revision HEAD. This is essentially the same thing as: `git-clang-format -f {filename}` If the current buffer is saved. The motivation is many project (LLVM included) both have code that is non-compliant with there clang-format style and disallow unrelated format diffs in PRs. This means users can't just run `clang-format-buffer` on the buffer they are working on, and need to manually go through all the regions by hand to get them formatted. This is both an error prone and annoying workflow.
2024-12-05[clang-format][NFC] Reformat git-clang-format with `black -l80`Owen Pan1-39/+110
2024-12-05[clang-format] Reformat Python script git-clang-format with blackOwen Pan1-546/+652
2024-12-03[clang-format] Add support for `.cjs` as JavaScript file extension (#118188)Jim B2-2/+2
Node uses `.cjs` as an extension for 'common javascript' modules.
2024-11-26[clang-format] Add mjs to default_extensions in git-clang-format (#117730)루밀LuMir1-2/+4
2024-11-24[clang-format][doc] Minor cleanupOwen Pan1-1/+1
2024-10-30[clang-format] Fix path expansion inside git-clang-format.bat (#114078)Nagy-Egri Máté Ferenc1-1/+1
The trampoline script used on Windows (due to the absence of shebang support) doesn't properly expand the path to the Python script, as it leaves out the drive letter. Functionally equivalent reproducer in action ``` PS C:\Users\mate> gc (gcm git-clang-formatish.bat).Source @ECHO OFF echo "%~pn0" %* PS C:\Users\mate> git-clang-formatish "\Users\mate\git-clang-formatish" ``` Adding `d` to the variable modifiers [as per the docs](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/for) the drive letter is added. Even in the magical cases when it works. (I couldn't reproduce, but I suspect it's only tested from some bash/cygwin variant, where the path becomes `/c/Program Files/...`, but the drive letter is needed. Without it, I also observed cases when used via `git clang-format` (without the inital dash) it tries to infer the drive letter based on the current working directory. In that case it fails to find `D:\Program Files\LLVM\bin\clang-format.exe`, which naturally fails, because `Program Files` is on `C:`)
2024-10-25[clang-format] Print the names of unfound files in error messages (#113640)Owen Pan1-2/+2
Also fix the return status when `-i` is used with reading from stdin. Fixes #113631.
2024-10-25Fix MSVC "signed/unsigned mismatch" warning. NFC.Simon Pilgrim1-1/+1
2024-10-24[clang-format] Fix working -assume-filename with .clang-format-ignore (#113100)kakkoko1-1/+4
Fixes #113099. --------- Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-10-19Add "clang-format-on-save-mode" minor mode to clang-format.el (#104533)Campbell Barton1-0/+57
Add an minor mode which can be optionally used to run clang-format on save. Formatting before saving works well and is convenient to avoid having to remember to manually run clang format. I've written this as it's own package but it's probably better if the functionality is supported by clang-format.el. See: https://github.com/melpa/melpa/pull/8762
2024-10-18[clang-format] Fix a bug that always returns error for JSON (#112839)Owen Pan1-7/+8
Fixes #108556.
2024-09-03[clang-format] Handle spaces in file paths in git-clang-format.bat (#107041)Owen Pan1-1/+1
This patch is provided by @jeliebig. Fixes #107017.
2024-08-31[NFC] Fix typos (#106817)c8ef1-1/+1
Fixes #106761.
2024-08-28Fix clang-format-test.el past 625841c (#106398)Danial Klimkin1-5/+5
2024-08-27[clang-format-diff.py][NFC] Document _stderr as unusedMarcoFalke1-1/+1
The stderr in the result tuple is always None and unused in this context. Document it with an underscore.
2024-08-21[clang-format] Use double hyphen for multiple-letter flags (#100978)magic-akari5-26/+26
- Closes: #100974
2024-08-10[clang-format] Fix a serious bug in `git clang-format -f` (#102629)Owen Pan2-3/+24
With the --force (or -f) option, git-clang-format wipes out input files excluded by a .clang-format-ignore file if they have unstaged changes. This patch adds a hidden clang-format option --list-ignored that lists such excluded files for git-clang-format to filter out. Fixes #102459.
2024-08-02[clang-format] Handle parenthesized list in RemoveParentheses (#100852)Owen Pan1-1/+1
Also, reformat clang-format source to remove redundant parentheses enclosing single list items. Fixes #100768.
2024-06-06[clang-format][NFC] Remove an else after a return statement (#94548)Nour1-2/+1
2024-05-20[clang-format][NFC] Remove redundnat llvm::, clang::, etc.Owen Pan1-12/+10
2024-05-15[clang-format][NFC] Reformat with 18.1.5Owen Pan1-1/+2
2024-05-01[z/OS] treat text files as text files so auto-conversion is done (#90128)Sean Perry1-3/+4
To support auto-conversion on z/OS text files need to be opened as text files. These changes will fix a number of LIT failures due to text files not being converted to the internal code page. update a number of tools so they open the text files as text files add support in the cat.py to open a text file as a text file (Windows will continue to treat all files as binary so new lines are handled correctly) add env var definitions to enable auto-conversion in the lit config file.
2024-04-12Add txtpb to the list of supported TextProto extensions (#88355)Jing Wang1-1/+1
According to https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files, txtpb is the canonical extension Co-authored-by: Jing Wang <99jingw@gmail.com>
2024-03-27[clang-format] Exit clang-format-diff only after all diffs are printed (#86776)Owen Pan1-3/+7
See https://github.com/llvm/llvm-project/pull/70883#issuecomment-2020811077.
2024-03-21[clang-format] Add --fail-on-incomplete-format. (#84346)Roberto Bampi1-4/+9
At the moment clang-format will return exit code 0 on incomplete results. In scripts it would sometimes be useful if clang-format would instead fail in those cases, signalling that there was something wrong with the code being formatted. --------- Co-authored-by: Björn Schäpers <github@hazardy.de> Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-03-19Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"Owen Pan1-0/+6
This reverts commit b92d6dd704d789240685a336ad8b25a9f381b4cc. See github.com/llvm/llvm-project/commit/b92d6dd704d7#commitcomment-139992444 We should use a tool like Visual Studio to clean up the headers.
2024-03-16[clang-format][NFC] Delete 100+ redundant #include lines in .cpp filesOwen Pan1-6/+0
2024-03-16Revert "[clang-format][NFC] Don't use clang-format style in config files"Owen Pan1-6/+1
This reverts commit c69ec700adec315b3daa55742f2ef655242fa297, which has been obsolete since commit dec63221d56e because the clang-format style was added in version 18.
2024-02-07[clang-format] Fix a regression in dumping the config (#80628)Owen Pan1-24/+25
Commit d813af73f70f addressed a regression introduced by commit 3791b3fca6ea but caused `clang-format -dump-config` to "hang". This patch reverts changes to ClangFormat.cpp by both commits and reworks the cleanup. Fixes #80621.
2024-01-23[Format] Fix detection of languages when reading from stdin (#79051)Ben Hamilton (Ben Gertzfield)1-11/+13
The code cleanup in #74794 accidentally broke detection of languages by reading file content from stdin, e.g. via `clang-format -dump-config - < /path/to/filename`. This PR adds unit and integration tests to reproduce the issue and adds a fix. Fixes: #79023