llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

tidy crashes with readability-duplicate-include #87303

Closed jackua22 closed 5 months ago

jackua22 commented 5 months ago

The crash is the same with llvm 17 and llvm 18. The output looks like

clang-tidy: /.../llvm-v17.0.6d1rh74_lnx86/llvm-project/clang/lib/Basic/SourceManager.cpp:868: clang::FileID clang::SourceManager::getFileIDLoaded(clang::SourceLocation::UIntTy) const: Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /.../llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy --checks=-*,readability-duplicate-include --quiet /.../swfvDB.C -- -fpic -std=c++17 -pthread -stdlib=libc++ -O3 -I. -I.. -I/.../include
1.  /.../ua/include/tbb/internal/_allocator_traits.h:31:2: current parser token 'include'
2.  /.../ua/include/tbb/tbb_profiling.h:126:1: parsing namespace 'tbb'
 #0 0x0000000003f6829b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3f6829b)
 #1 0x0000000003f65b4b llvm::sys::RunSignalHandlers() (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3f65b4b)
 #2 0x0000000003f65c75 SignalHandler(int) Signals.cpp:0:0
 #3 0x00002b7947953630 __restore_rt sigaction.c:0:0
 #4 0x00002b794873c387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00002b794873da78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00002b79487351a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00002b7948735252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000003b22904 (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3b22904)
 #9 0x0000000003b28eb5 clang::SourceManager::getSpellingLineNumber(clang::SourceLocation, bool*) const (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3b28eb5)
#10 0x00000000010ea696 clang::tidy::readability::advanceBeyondCurrentLine(clang::SourceManager const&, clang::SourceLocation, int) DuplicateIncludeCheck.cpp:0:0
#11 0x00000000010eb4b7 clang::tidy::readability::(anonymous namespace)::DuplicateIncludeCallbacks::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang::CharSourceRange, clang::CustomizableOptional<clang::FileEntryRef>, llvm::StringRef, llvm::StringRef, clang::Module const*, clang::SrcMgr::CharacteristicKind) DuplicateIncludeCheck.cpp:0:0
#12 0x0000000003a4635d clang::PPChainedCallbacks::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang::CharSourceRange, clang::CustomizableOptional<clang::FileEntryRef>, llvm::StringRef, llvm::StringRef, clang::Module const*, clang::SrcMgr::CharacteristicKind) (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3a4635d)
#13 0x0000000003a56856 clang::Preprocessor::HandleHeaderIncludeOrImport(clang::SourceLocation, clang::Token&, clang::Token&, clang::SourceLocation, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*)

The first several includes are

#include <vector>
#include <future>
#include <thread>
#include <queue>
#include <atomic>
#include <tbb/concurrent_vector.h>
#include <tbb/parallel_for.h>
llvmbot commented 5 months ago

@llvm/issue-subscribers-clang-tidy

Author: None (jackua22)

The crash is the same with llvm 17 and llvm 18. The output looks like ``` clang-tidy: /.../llvm-v17.0.6d1rh74_lnx86/llvm-project/clang/lib/Basic/SourceManager.cpp:868: clang::FileID clang::SourceManager::getFileIDLoaded(clang::SourceLocation::UIntTy) const: Assertion `0 && "Invalid SLocOffset or bad function choice"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /.../llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy --checks=-*,readability-duplicate-include --quiet /.../swfvDB.C -- -fpic -std=c++17 -pthread -stdlib=libc++ -O3 -I. -I.. -I/.../include 1. /.../ua/include/tbb/internal/_allocator_traits.h:31:2: current parser token 'include' 2. /.../ua/include/tbb/tbb_profiling.h:126:1: parsing namespace 'tbb' #0 0x0000000003f6829b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3f6829b) #1 0x0000000003f65b4b llvm::sys::RunSignalHandlers() (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3f65b4b) #2 0x0000000003f65c75 SignalHandler(int) Signals.cpp:0:0 #3 0x00002b7947953630 __restore_rt sigaction.c:0:0 #4 0x00002b794873c387 raise (/lib64/libc.so.6+0x36387) #5 0x00002b794873da78 abort (/lib64/libc.so.6+0x37a78) #6 0x00002b79487351a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6) #7 0x00002b7948735252 (/lib64/libc.so.6+0x2f252) #8 0x0000000003b22904 (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3b22904) #9 0x0000000003b28eb5 clang::SourceManager::getSpellingLineNumber(clang::SourceLocation, bool*) const (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3b28eb5) #10 0x00000000010ea696 clang::tidy::readability::advanceBeyondCurrentLine(clang::SourceManager const&, clang::SourceLocation, int) DuplicateIncludeCheck.cpp:0:0 #11 0x00000000010eb4b7 clang::tidy::readability::(anonymous namespace)::DuplicateIncludeCallbacks::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang::CharSourceRange, clang::CustomizableOptional<clang::FileEntryRef>, llvm::StringRef, llvm::StringRef, clang::Module const*, clang::SrcMgr::CharacteristicKind) DuplicateIncludeCheck.cpp:0:0 #12 0x0000000003a4635d clang::PPChainedCallbacks::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang::CharSourceRange, clang::CustomizableOptional<clang::FileEntryRef>, llvm::StringRef, llvm::StringRef, clang::Module const*, clang::SrcMgr::CharacteristicKind) (/grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy+0x3a4635d) #13 0x0000000003a56856 clang::Preprocessor::HandleHeaderIncludeOrImport(clang::SourceLocation, clang::Token&, clang::Token&, clang::SourceLocation, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) ``` The first several includes are ``` #include <vector> #include <future> #include <thread> #include <queue> #include <atomic> #include <tbb/concurrent_vector.h> #include <tbb/parallel_for.h> ```
chrchr-github commented 5 months ago

No crash here: https://godbolt.org/z/qrYThsb6P

jackua22 commented 5 months ago

My report is about clang-tidy, not about clang++. But good point. I extracted only these headers, adna ran tidy. Without -I options it takes tbb headers from /usr/include on RHEL 7 and does not crash. With tbb 2020.3, tidy crashes like before /grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy '--checks=readability-duplicate-include' tbb.cpp -- -std=c++17 -stdlib=libc++ -I/.../include

FruitClover commented 5 months ago

My report is about clang-tidy, not about clang++.

You could see tidy report in the bottom half

With tbb 2020.3, tidy crashes like before

include/tbb/internal/_allocator_traits.h:31:2: current parser token 'include' points to the

#include __TBB_STD_SWAP_HEADER

and looks like could be reproduced with

#define INC "t.h"

#include "t.h"
#include INC
FruitClover commented 5 months ago

Candidate patch: https://github.com/llvm/llvm-project/pull/87433

FruitClover commented 5 months ago

reproduced locally at 92eaf036bf22ecc276146cd073208e6a867af8d4 using https://github.com/oneapi-src/oneTBB/releases/tag/v2020.3 includes and

$ cat 87303.cc
#include <tbb/concurrent_vector.h>
$ clang-tidy 87303.cc --checks='-*,readability-duplicate-include' -- -I/tmp/tbb-2020.3-lin/tbb/include
clang-tidy: /home/mike/git/hub/com/llvm-project/clang/lib/Basic/SourceManager.cpp:865: FileID clang::SourceManager::getFileIDLoaded(SourceLocation::UIntTy) const: Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /home/mike/git/hub/com/llvm-project/build/bin/clang-tidy 87303.cc --checks=-*,readability-duplicate-include -- -I/tmp/tbb-2020.3-lin/tbb/include
1.  /tmp/tbb-2020.3-lin/tbb/include/internal/_allocator_traits.h:31:2: current parser token 'include'
2.  /usr/lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/streambuf_iterator.h:39:1: parsing namespace 'std'
 #0 0x000062351ab53f46 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/mike/git/hub/com/llvm-project/build/bin/clang-tidy+0x23adf46)
 #1 0x000062351ab5194e llvm::sys::RunSignalHandlers() (/home/mike/git/hub/com/llvm-project/build/bin/clang-tidy+0x23ab94e)
 #2 0x000062351ab547b4 SignalHandler(int) Signals.cpp:0:0
 #3 0x000072054365a770 (/usr/lib/libc.so.6+0x3c770)
 #4 0x00007205436ab32c (/usr/lib/libc.so.6+0x8d32c)
 #5 0x000072054365a6c8 raise (/usr/lib/libc.so.6+0x3c6c8)
 #6 0x00007205436424b8 abort (/usr/lib/libc.so.6+0x244b8)
 #7 0x00007205436423dc (/usr/lib/libc.so.6+0x243dc)
 #8 0x0000720543652d46 (/usr/lib/libc.so.6+0x34d46)
 #9 0x000062351b2f32ac (/home/mike/git/hub/com/llvm-project/build/bin/clang-tidy+0x2b4d2ac)
#10 0x000062351b2f3e1a clang::SourceManager::getSpellingLineNumber(clang::SourceLocation, bool*) const (/home/mike/git/hub/com/llvm-project/build/bin/clang-tidy+0x2b4de1a)
#11 0x000062351b9db715 clang::tidy::readability::advanceBeyondCurrentLine(clang::SourceManager const&, clang::SourceLocation, int) DuplicateIncludeCheck.cpp:0:0
#12 0x000062351b9db186 clang::tidy::readability::(anonymous namespace)::DuplicateIncludeCallbacks::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang::CharSourceRange, clang::CustomizableOptional<clang::FileEntryRef>, llvm::StringRef, llvm::StringRef, clang::Module const*, clang::SrcMgr::CharacteristicKind) DuplicateIncludeCheck.cpp:0:

and

$ cat t.cc
#define INC "inc.h"

#include "inc.h"
#include INC
$ clang-tidy t.cc --checks='-*,readability-duplicate-include'
clang-tidy: /home/mike/git/hub/com/llvm-project/clang/lib/Basic/SourceManager.cpp:865: FileID clang::SourceManager::getFileIDLoaded(SourceLocation::UIntTy) const: Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /home/mike/git/hub/com/llvm-project/build/bin/clang-tidy t.cc --checks=-*,readability-duplicate-include
1.  /tmp/t.cc:4:2: current parser token 'include'