Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failed: Shift >= 0, file C:\src\llvm_package_303050\llvm\tools\clang\lib\Format\WhitespaceManager.cpp, line 245 #32854

Closed
llvmbot opened this issue Jun 19, 2017 · 15 comments
Labels
bugzilla Issues migrated from bugzilla clang-format

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 19, 2017

Bugzilla Link 33507
Resolution FIXED
Resolved on Aug 25, 2017 13:31
Version trunk
OS Windows NT
Blocks #33196
Reporter LLVM Bugzilla Contributor
CC @zmodem,@donhinton,@krasimir-google

Extended Description

We have a dozen of C++ files with some lambdas that make clang-format crash.

One example is this code:

auto found = range::find_if(vsProducts, [&](auto * aProduct) {
static const Version verVs2017;
return true;
});

If I add this code to another C++ file and try to format (on save), it will crash and create a dump file. (the example code was reduced, but still two lines)

I've trimmed the config file to just these two lines to reproduce the problem:

BasedOnStyle: Mozilla
AlignConsecutiveDeclarations: 'true'

Thanks

@zmodem
Copy link
Collaborator

zmodem commented Aug 8, 2017

I can reproduce with trunk and 5.0 but not 4.0, so this is a regression.

Daniel: is there someone besides yourself who like looking into clang-format bugs? :-)

@zmodem
Copy link
Collaborator

zmodem commented Aug 10, 2017

*** Bug llvm/llvm-bugzilla-archive#34071 has been marked as a duplicate of this bug. ***

@llvmbot
Copy link
Collaborator Author

llvmbot commented Aug 11, 2017

I have made an workaround for me - simply commented out this assert. And it looks quite normal. I don't know why. :)

@llvmbot
Copy link
Collaborator Author

llvmbot commented Aug 22, 2017

Some blame history:

  1. assert added in rev 248999
    [clang-format] Add support of consecutive declarations alignment

  2. rev 295586 the assert was still valid

  3. rev 306282 the assert is NOT valid anymore

This means only four revisions left, most likely rev 298574 by nikola:

Fix issues in clang-format's AlignConsecutive modes.

Indeed, a quick check confirms that rev 5.0.0.300231 is also affected.

@zmodem
Copy link
Collaborator

zmodem commented Aug 22, 2017

+Nikola

@zmodem
Copy link
Collaborator

zmodem commented Aug 23, 2017

krasimir: Maybe you could take a look?

@zmodem
Copy link
Collaborator

zmodem commented Aug 24, 2017

I have made an workaround for me - simply commented out this assert. And it
looks quite normal. I don't know why. :)

It seems to misformat the test case if I do that:

$ cat | bin/clang-format -style="{BasedOnStyle: Mozilla,AlignConsecutiveDeclarations: 'true'}"
auto found = range::find_if(vsProducts, [&](auto * aProduct) {
static const Version verVs2017;
return true;
});
auto found = range::find_if(vsProducts, [&](auto* aProduct) {
static const VersionverVs2017;
return true;
});

Note that it breaks the code by concatenating "Version" and "verVs2017" :-(

@zmodem
Copy link
Collaborator

zmodem commented Aug 24, 2017

Note that it breaks the code by concatenating "Version" and "verVs2017" :-(

Confirmed that both the assert and the concatenation started with r298574.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Aug 25, 2017

Hello, I've sent this patch for review if anyone wants to give it a try: https://reviews.llvm.org/D37137

@donhinton
Copy link
Collaborator

Not sure exactly how to fix it, but here's a minimal example that asserts:

echo "v f( {y x; x;});" | bin/clang-format -style="{AlignConsecutiveDeclarations: 'true'}"

And, interestingly, the following doesn't assert, but as you can see, the formatting is a bit odd:

echo "vvvvvvvvvvvv f( {y x; x;});" | bin/clang-format -style="{AlignConsecutiveDeclarations: 'true'}"
vvvvvvvvvvvv f( {
y x;
x;
});

@donhinton
Copy link
Collaborator

Sorry, didn't see your post/patch before I commented, but I tested it with my test case and it works great...

@zmodem
Copy link
Collaborator

zmodem commented Aug 25, 2017

The patch was committed in r311792. I'll let it bake a little bit and then merge.

@zmodem
Copy link
Collaborator

zmodem commented Aug 25, 2017

Merged in r311800. Thanks for fixing!

@zmodem
Copy link
Collaborator

zmodem commented Nov 26, 2021

mentioned in issue #33196

@zmodem
Copy link
Collaborator

zmodem commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#34071

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-format
Projects
None yet
Development

No branches or pull requests

3 participants