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.
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.
*** Bug 17117 has been marked as a duplicate of this bug. ***
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.
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
Which version of clang-format were you using? Alp landed a patch related to this area in r194250. Can that have fixed it?
(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.
I'd been using r194000, so I hadn't picked up the fix. Thanks!
I've just finished setting up windows for clang development to fix it myself, but Alp was faster ;) Alp, thanks for fixing this!
(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.