This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Add support for SEH __try / __except / __finally blocks.
ClosedPublic

Authored by thakis on Feb 3 2015, 11:50 AM.

Details

Reviewers
djasper
Summary

This lets clang-format format

__try {
} __except(0) {
}

and

__try {
} __finally {
}

correctly. try and finally are keywords if LangOpts.MicrosoftExt is set, so this turns this on. This also enables a few other keywords, but it shouldn't overly perturb regular clang-format operation. __except is a context-sensitive keyword, so AdditionalKeywords needs to be passed around to a few more places.

Diff Detail

Event Timeline

thakis updated this revision to Diff 19256.Feb 3 2015, 11:50 AM
thakis retitled this revision from to clang-format: Add support for SEH __try / __except / __finally blocks..
thakis updated this object.
thakis edited the test plan for this revision. (Show Details)
thakis added a reviewer: djasper.
thakis added a subscriber: Unknown Object (MLST).

The only reason I'm sending this out for pre-commit review is the MicrosoftExt bit. I think it should be ok to set this, though.

lib/Format/UnwrappedLineFormatter.cpp
218

Note: The if down here doesn't have any effect, neither for SEH try statements nor for regular try statements, according to the test suite. I added kw___try here because kw_try was here, but maybe this block used to do try formatting and now no longer does.

(All other changes are covered by the tests added in this change.)

djasper edited edge metadata.Feb 3 2015, 11:29 PM

Looks good, thanks. In the commit, mention that this fixes llvm.org/PR22321.

lib/Format/UnwrappedLineFormatter.cpp
218

Please add a FIXME. I'll take a look afterwards.

There are two problems here:

  1. This doesn't get triggered in tests as the tests use LLVM style which has AllowShortBlocksOnASingleLine set to false meaning that the first "if" in this block always fires.
  2. This doesn't work properly, as commonly "catch" (and except and finally) won't be the first token in a line (the line will usually start with "} catch ...".
djasper accepted this revision.Feb 3 2015, 11:29 PM
djasper edited edge metadata.
This revision is now accepted and ready to land.Feb 3 2015, 11:29 PM
thakis closed this revision.Feb 4 2015, 7:30 AM

r228148, thanks!