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 17216 - clang-format on windows doesn't work on large files
Summary: clang-format on windows doesn't work on large files
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Formatter (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P normal
Assignee: Alexander Kornienko
URL:
Keywords:
: 17117 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-09-12 15:11 PDT by Krzysztof Kowalczyk
Modified: 2013-11-16 12:37 PST (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments
C++ file that causes clang-format to die (16.13 KB, text/plain)
2013-11-15 15:38 PST, Nick Carter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Kowalczyk 2013-09-12 15:11:31 PDT
I tried to run clang-format -style=Google -i on my code base (https://code.google.com/p/sumatrapdf/source/list).

It seems to have a problem with large files. The error message is:
Error while writing file: Error opening output file 'src/AppPrefs.cpp'

I'm only guessing the size is the issue because it does look like it only has problems with files larger than 15-20k bytes.

I ran it both from cmd.exe and cygwin shell.

This is using windows build from http://llvm.org/builds/, SVN r190317.
Comment 1 Alexander Kornienko 2013-10-13 20:14:51 PDT
I've tried this on Windows 7 and Windows 8.1 preview, the file really errors out when using -i option. My error text was:
"Error while writing file: Error opening output file \'1.cpp\': The requested operation cannot be performed on a file with a user-mapped section open"

The problem changes when the file is reduced in size: with certain file size clang-format seems to incorrectly insert line breaks in the first few lines of the file. When the file is even smaller, there seems to be no error.

The "magical size limit" is about 16K bytes.
Comment 2 Alexander Kornienko 2013-11-13 08:39:43 PST
*** Bug 17117 has been marked as a duplicate of this bug. ***
Comment 3 Nick Carter 2013-11-15 15:33:59 PST
I'm seeing this in the Chromium codebase too. Here's a little more characterization.

The problem seems limited to the -i (in-place edit) option to clang-format, and files over 16KB in size. It does not appear to be a recent regression; a build from April 2013 shows the "Error opening output file" failure message.

This does not appear to be a recent regression, but it does appear that the error message changed between r190317 ("Error opening output file") and r191323 ("requested operation cannot be performed on a file with a user-mapped section open").

A workaround, for now, is to avoid using the -i, and to have the calling script (e.g. clang-format-diff.py) buffer stdout and write it back to the target file afterwards.
Comment 4 Nick Carter 2013-11-15 15:38:53 PST
Created attachment 11547 [details]
C++ file that causes clang-format to die

Failing test case, just over 16KB

del fail_.cc && copy fail.cc fail_.cc && clang-format.exe -i fail_.cc
Comment 5 Hans Wennborg 2013-11-15 15:53:11 PST
Which version of clang-format were you using?

Alp landed a patch related to this area in r194250. Can that have fixed it?
Comment 6 Alp Toker 2013-11-15 15:57:49 PST
(In reply to comment #5)
> Which version of clang-format were you using?
> 
> Alp landed a patch related to this area in r194250. Can that have fixed it?

Thanks Hans for spotting this PR!

If you're using Windows clang-format is fixed now, but be aware other facilities like Rewrite/Tooling are still broken for > 16K files. Will open a separate PR for that.

Issue fixed in r194250.
Comment 7 Nick Carter 2013-11-15 17:08:12 PST
I'd been using r194000, so I hadn't picked up the fix. Thanks!
Comment 8 Alexander Kornienko 2013-11-15 17:46:14 PST
I've just finished setting up windows for clang development to fix it myself, but Alp was faster ;)

Alp, thanks for fixing this!
Comment 9 Alp Toker 2013-11-15 18:11:12 PST
(In reply to comment #7)
> I'd been using r194000, so I hadn't picked up the fix. Thanks!

I'm sorry the builds on llvm.org are out of date.

I'm hosting unofficial nightly builds to actually help with debugging on Windows in a meaningful way (instead of the ones on llvm.org wasting our time like this), please ask around if you need the URL, I've been asked not to share it.