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

clang-format 15 crashes with AllowShortFunctionsOnASingleLine: Inline #54147

Closed
mnil opened this issue Mar 2, 2022 · 7 comments
Closed

clang-format 15 crashes with AllowShortFunctionsOnASingleLine: Inline #54147

mnil opened this issue Mar 2, 2022 · 7 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior clang-format crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@mnil
Copy link

mnil commented Mar 2, 2022

When trying to bump our clang-format version we hit a crash in one of our files.

Reproduced on clang-format version:

Ubuntu clang-format version 15.0.0-++20220218052900+34313583331e-1~exp1~20220218173003.163

I reduced it to this, last return is not needed but makes tmp2 "used":

    auto const foobar = []() {
        // comment
        auto const tmp  = 5U;
        auto const tmp2 = tmp;
        return tmp2;
    };

which formats fine with the Google based config, but changing the following breaks it:

AllowShortFunctionsOnASingleLine: Inline
# or
AllowShortFunctionsOnASingleLine: InlineOnly

Stacktrace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /usr/bin/clang-format -output-replacements-xml -style=file -fallback-style=LLVM -assume-filename=/home/<name>/foo.cpp
 #0 0x00007f33b42b7da1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-15.so.1+0xe64da1)
 #1 0x00007f33b42b5afe llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-15.so.1+0xe62afe)
 #2 0x00007f33b42b82cb (/lib/x86_64-linux-gnu/libLLVM-15.so.1+0xe652cb)
 #3 0x00007f33bd6ce3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #4 0x00007f33bcb0d7cc (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cbe7cc)
 #5 0x00007f33bcb0caa7 clang::format::UnwrappedLineFormatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*> const&, bool, int, bool, unsigned int, unsigned int, unsigned int) (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cbdaa7)
 #6 0x00007f33bcb0f9bc (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cc09bc)
 #7 0x00007f33bcb1061a (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cc161a)
 #8 0x00007f33bcb10144 (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cc1144)
 #9 0x00007f33bcb0ceb8 clang::format::UnwrappedLineFormatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*> const&, bool, int, bool, unsigned int, unsigned int, unsigned int) (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cbdeb8)
#10 0x00007f33bcad3c41 (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2c84c41)
#11 0x00007f33bcafc566 clang::format::TokenAnalyzer::process() (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2cad566)
#12 0x00007f33bcae0e41 (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2c91e41)
#13 0x00007f33bcacbbda clang::format::internal::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2c7cbda)
#14 0x00007f33bcacc9b1 clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/lib/x86_64-linux-gnu/libclang-cpp.so.15+0x2c7d9b1)
#15 0x000000000040aec2 (/usr/bin/clang-format+0x40aec2)
#16 0x00000000004091c5 (/usr/bin/clang-format+0x4091c5)
#17 0x00007f33b2f370b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#18 0x000000000040632e (/usr/bin/clang-format+0x40632e)

Let me know if you need anything else.

@mnil
Copy link
Author

mnil commented Mar 2, 2022

I guess this is an easier way to reproduce:

clang-format --style="{BasedOnStyle: Google, AllowShortFunctionsOnASingleLine: Inline}" foo.cpp

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 2, 2022

@llvm/issue-subscribers-clang-format

@carlosgalvezp carlosgalvezp added the bug Indicates an unexpected problem or unintended behavior label Mar 2, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 2, 2022

@llvm/issue-subscribers-bug

@mkurdej mkurdej added crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Mar 2, 2022
@mkurdej
Copy link
Member

mkurdej commented Mar 3, 2022

Reduced a bit more to:

[] {
  // comment
  ;
  ;
};

and config:

BasedOnStyle: LLVM
AllowShortFunctionsOnASingleLine: Inline

@mkurdej mkurdej self-assigned this Mar 3, 2022
@mkurdej
Copy link
Member

mkurdej commented Mar 3, 2022

There's a failing assertion:

Assertion failed: LastNonComment, file E:\src\llvm-project\clang\lib\Format\UnwrappedLineFormatter.cpp, line 321

@mkurdej mkurdej added the awaiting-review Has pending Phabricator review label Mar 3, 2022
@mkurdej
Copy link
Member

mkurdej commented Mar 3, 2022

Revision URI: https://reviews.llvm.org/D120902

@mkurdej
Copy link
Member

mkurdej commented Mar 3, 2022

For the record, this bug was unearthed in commit ef39235, but introduced actually in 7af1198.

@mkurdej mkurdej closed this as completed in d03e342 Mar 7, 2022
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang-format crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants