Bug 438976

Summary: Clazy crashes when parsing Qt 6.1.0 <QtTest> with old-style-connect check enabled
Product: [Developer tools] clazy Reporter: ts826848+kde
Component: generalAssignee: Unassigned bugs mailing-list <unassigned-bugs>
Status: RESOLVED FIXED    
Severity: crash CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: macOS   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: stderr from crash
Preprocessed LLVM 11 test.cpp
LLVM 11 test.sh crash reproducer
Preprocessed LLVM 12 test.cpp
LLVM 12 test.cpp crash reproducer

Description ts826848+kde 2021-06-21 05:44:40 UTC
Created attachment 139560 [details]
stderr from crash

SUMMARY

Clazy v1.9 compiled against LLVM/Clang 11.1.0 segfaults when parsing <QtTest> from Qt 6.1.0 with old-style-connect check enabled

STEPS TO REPRODUCE

1. Install llvm@11 and qt (currently Qt 6.1.0) from Homebrew
2. Check out tag v1.9 from clazy repo
3. Compile/install clazy using CXX=/usr/local/opt/llvm@11/bin/clang++ and LLVM_ROOT=/usr/local/opt/llvm@11
4. $ export CLANGXX=/usr/local/opt/llvm@11/bin/clang++
5. $ cd /tmp
6. $ echo "#include <QtTest>" > test.cpp
7. $ clazy -std=c++17 -iframework /usr/local/lib -isystem /usr/local/opt/qt/Frameworks/QtTest.framework/Headers -Xclang -plugin-arg-clazy -Xclang  old-style-connect -c test.cpp

OBSERVED RESULT

Clang segfaults; stderr in attachment.

EXPECTED RESULT

Clang successfully compiles test.cpp

SOFTWARE/OS VERSIONS
macOS: 10.15.7
Qt Version: 6.1.0
Comment 1 Sergio Martins 2021-06-21 18:19:45 UTC
can't repro on Linux/llvm-12
Comment 2 ts826848+kde 2021-06-30 00:12:27 UTC
Created attachment 139753 [details]
Preprocessed LLVM 11 test.cpp
Comment 3 ts826848+kde 2021-06-30 00:12:59 UTC
Created attachment 139754 [details]
LLVM 11 test.sh crash reproducer
Comment 4 ts826848+kde 2021-06-30 01:13:01 UTC
I appear to get the same crash with LLVM 12.0.0 from Homebrew if I build either tag v1.9 + a29528ec87474a28258e34e7556fb38c5ba34a96 (Fix build with Clang 12) cherry-picked on top or the tip of the 1.9 branch.

I've attached preprocessed .cpp and .sh files from both LLVM 11 and 12.
Comment 5 ts826848+kde 2021-06-30 01:13:28 UTC
Created attachment 139755 [details]
Preprocessed LLVM 12 test.cpp
Comment 6 ts826848+kde 2021-06-30 01:13:50 UTC
Created attachment 139756 [details]
LLVM 12 test.cpp crash reproducer
Comment 7 Sergio Martins 2021-06-30 22:50:38 UTC
I've reproduced on macOS
Comment 8 Sergio Martins 2021-06-30 23:19:19 UTC
Git commit 19f1254224b69cffd639b4a343866e7db2a469df by Sergio Martins.
Committed on 30/06/2021 at 23:17.
Pushed by smartins into branch 'master'.

old-style-connect: Simplify regexp, which also fixes a crash

Simplification done by Jonathan Marten.

I don't understand why it fixes the crash though, but at least
it's not worse.
Related: bug 435615

M  +1    -1    src/checks/level2/old-style-connect.cpp

https://invent.kde.org/sdk/clazy/commit/19f1254224b69cffd639b4a343866e7db2a469df
Comment 9 ts826848+kde 2021-06-30 23:29:54 UTC
Thank you for the quick fix!