r227677 - clang-format: Fix incorrect handling of leading whitespace.

Kostya Serebryany kcc at google.com
Tue Feb 3 15:44:13 PST 2015


clang-format-fuzzer is hitting this assertion on the bot:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer/builds/19/steps/stage2%2Fasan%20run%20clang-format-fuzzer/logs/stdio

I don't yet have a way for extracting individual reproducers when an
assertion happens (this works only for asan-ish bugs),
but you can reproduce this very easily with

cmake $HOME/llvm -GNinja -DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_ASSERTIONS=ON   -DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++ -DLLVM_USE_SANITIZE_COVERAGE=YES
-DLLVM_USE_SANITIZER=Address
ninja clang-format-fuzzer
./bin/clang-format-fuzzer

llvm/tools/clang/lib/Format/ContinuationIndenter.cpp:257: unsigned int
clang::format::ContinuationIndenter::addTokenToState(clang::format::LineState
&, bool, bool, unsigned int): Assertion `EndColumn >= StartColumn' failed.

Meanwhile, I am going to disable assertions on the fuzzer bot.



On Fri, Jan 30, 2015 at 11:05 PM, Daniel Jasper <djasper at google.com> wrote:

> Author: djasper
> Date: Sat Jan 31 01:05:46 2015
> New Revision: 227677
>
> URL: http://llvm.org/viewvc/llvm-project?rev=227677&view=rev
> Log:
> clang-format: Fix incorrect handling of leading whitespace.
>
> Added an assertion that triggered in an existing test case (without
> observable differences) and fixed the code.
>
> Modified:
>     cfe/trunk/lib/Format/ContinuationIndenter.cpp
>
> Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=227677&r1=227676&r2=227677&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
> +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sat Jan 31 01:05:46 2015
> @@ -245,12 +245,18 @@ unsigned ContinuationIndenter::addTokenT
>         (Current.Previous->Tok.getIdentifierInfo() == nullptr ||
>          Current.Previous->Tok.getIdentifierInfo()->getPPKeywordID() ==
>              tok::pp_not_keyword))) {
> -    // FIXME: Is this correct?
> -    int WhitespaceLength = SourceMgr.getSpellingColumnNumber(
> -                               State.NextToken->WhitespaceRange.getEnd())
> -
> -                           SourceMgr.getSpellingColumnNumber(
> -
>  State.NextToken->WhitespaceRange.getBegin());
> -    State.Column += WhitespaceLength;
> +    unsigned EndColumn =
> +
> SourceMgr.getSpellingColumnNumber(Current.WhitespaceRange.getEnd());
> +    if (Current.LastNewlineOffset != 0) {
> +      // If there is a newline within this token, the final column will
> solely
> +      // determined by the current end column.
> +      State.Column = EndColumn;
> +    } else {
> +      unsigned StartColumn =
> +
> SourceMgr.getSpellingColumnNumber(Current.WhitespaceRange.getBegin());
> +      assert(EndColumn >= StartColumn);
> +      State.Column += EndColumn - StartColumn;
> +    }
>      moveStateToNextToken(State, DryRun, /*Newline=*/false);
>      return 0;
>    }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150203/27cb7453/attachment.html>


More information about the cfe-commits mailing list