This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix readability-braces-around-statements assert failure
Needs RevisionPublic

Authored by mattsta on Dec 28 2015, 10:17 AM.

Details

Reviewers
None
Summary

What: clang-tidy fails to complete on some source files with always-braces fixup enabled.

Why: Failure check is after findRParenLoc() already asserted on error and crashed.

Fix: Check for invalid location before findRParenLoc() instead of after.

Removes error:

Assertion failed: (CondEndLoc.isValid()), function findRParenLoc, file ../llvm/tools/clang/tools/extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp, line 183.

Diff Detail

Repository
rL LLVM

Event Timeline

mattsta updated this revision to Diff 43697.Dec 28 2015, 10:17 AM
mattsta retitled this revision from to [clang-tidy] Fix readability-braces-around-statements assert failure.
mattsta updated this object.
mattsta set the repository for this revision to rL LLVM.
mattsta updated this object.
alexfh edited edge metadata.Dec 28 2015, 10:51 PM

Please add a test that crashes without the patch and passes with it.

mattsta updated this revision to Diff 43748.Dec 29 2015, 10:32 AM
mattsta edited edge metadata.

Updated to include fix for:

Assertion failed: (InitialLoc.isValid()), function checkStmt, file ../llvm/tools/clang/tools/extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp, line 226.

It's difficult to track down *why* the invalid locations are happening because by the time we get to an invalid location, all source location information is lost. The best I've been able to come up with is fixing the early return conditions (which were previously impossible to reach due to asserts catching the invalid conditions first).

It's easy to have these happen on any large codebase (e.g. try to recursively clang-tidy the erlang source tree with readability-braces-around-statements).

It's difficult to track down *why* the invalid locations are happening because by the time we get to an invalid location, all source location information is lost. The best I've been able to come up with is fixing the early return conditions (which were previously impossible to reach due to asserts catching the invalid conditions first).

It's easy to have these happen on any large codebase (e.g. try to recursively clang-tidy the erlang source tree with readability-braces-around-statements).

I'd still like to add a test for this (and I have a different idea on how to fix this, namely return an invalid location from findRParenLoc instead of asserting). If you can't come up with a test case, I'll try to find one myself by running on some files, but we absolutely have to add a test to avoid regressions when this code is changed again.

Yeah, I fully understand the need to make sure it doesn't break again (or that this actually fixes it properly), but these changes are about the limit of my LLVM+Tidy internals understanding. (What's missing from this diff is the 20 hours across 4-6 months where I tried to fix it "properly" but could never figure out how things were getting to an Invalid state to begin with.)

I'll leave this in more capable hands than my own at this point. It's easy to reproduce the assert failures on large source dirs (a freebsd checkout, an erlang checkout, etc), but I couldn't narrow down what triggers the failures.

An alternative fix has recently been committed. Can you run clang-tidy built after r260505 on your code?

alexfh requested changes to this revision.Feb 25 2016, 4:25 AM
alexfh edited edge metadata.
This revision now requires changes to proceed.Feb 25 2016, 4:25 AM