Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
dnf install -y p7zip-plugins # required as fallback for py7zr in Qt installation
dnf install -y python3-pip # fixes missing pip module in jurplel/install-qt-action
dnf install -y python3-devel # fixes building of wheels for jurplel/install-qt-action
dnf install -y cairo-devel gtk3-devel libcurl-devel lua-devel openssl-devel python3-devel sqlite-devel boost-devel cppunit-devel libsigc++20-devel # for strict cfg checks
dnf install -y iwyu
ln -s iwyu_tool.py /usr/bin/iwyu_tool

Expand Down Expand Up @@ -150,6 +151,16 @@ jobs:
# TODO: remove -stdlib= - it should have been taken from the compilation database
iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --update_comments -stdlib=${{ matrix.stdlib }} ${{ matrix.mapping_file_opt }} ${{ matrix.clang_inc }} > iwyu.log

# TODO: run with all configurations
- name: test/cfg
if: matrix.stdlib == 'libstdc++'
run: |
# TODO: redirect to log
./test/cfg/runtests.sh
env:
IWYU: include-what-you-use
IWYU_CLANG_INC: ${{ matrix.clang_inc }}

- uses: actions/upload-artifact@v4
if: success() || failure()
with:
Expand Down
14 changes: 9 additions & 5 deletions test/cfg/boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@

// cppcheck-suppress-file valueFlowBailout

#include <boost/config.hpp>
#include <cstdio>
#include <new>
#include <tuple>

#include <boost/config.hpp> // IWYU pragma: keep
#include <boost/math/special_functions/round.hpp>
#include <boost/endian/conversion.hpp>
#include <boost/endian/conversion.hpp> // IWYU pragma: keep
#include <boost/bind/bind.hpp>
#include <boost/function.hpp>
#include <boost/function.hpp> // IWYU pragma: keep
#include <boost/smart_ptr/scoped_array.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/mutex.hpp> // IWYU pragma: keep
#include <boost/thread/lock_guard.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test.hpp> // IWYU pragma: keep
#include <boost/core/scoped_enum.hpp>
#include <boost/foreach.hpp>

Expand Down
4 changes: 4 additions & 0 deletions test/cfg/cppunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

// cppcheck-suppress-file valueFlowBailout

#include <string>

#include <cppunit/Exception.h>
#include <cppunit/Portability.h>
#include <cppunit/TestAssert.h>

void cppunit_assert_equal(int x, double y)
Expand Down
6 changes: 4 additions & 2 deletions test/cfg/gnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <netdb.h>
#include <sys/time.h>
#include <sys/types.h>
#include <pwd.h>
#include <sys/mman.h>
Expand All @@ -36,7 +34,11 @@
#include <netdb.h>
#if !defined(__APPLE__)
#include <byteswap.h>
#include <features.h>
#endif
#include <sys/socket.h>
#include <time.h>
#include <stddef.h>

#ifdef __gnu_linux__
void unreachableCode_error(void) // #11197
Expand Down
4 changes: 2 additions & 2 deletions test/cfg/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

#include <stdlib.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gtypes.h>
#include <glib/gi18n.h>


Expand Down
5 changes: 4 additions & 1 deletion test/cfg/libsigc++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

#include <sigc++/sigc++.h>
#include <sigc++/sigc++.h> // IWYU pragma: keep
#include <sigc++/functors/mem_fun.h>
#include <sigc++/functors/slot.h>
#include <sigc++/trackable.h>

struct struct1 : public sigc::trackable {
void func1(int) const {}
Expand Down
4 changes: 3 additions & 1 deletion test/cfg/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
//#include <openssl/types.h>
#include <stdio.h>
#include <string.h>

void valid_code(BIO * bio)
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <stdarg.h>
#include <ctype.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include <strings.h>
#if defined(__APPLE__)
Expand All @@ -47,6 +46,7 @@
#include <wchar.h>
#include <sys/stat.h>
#include <utime.h>
#include <stddef.h>


#if !defined(__APPLE__)
Expand Down
1 change: 1 addition & 0 deletions test/cfg/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h> // should be the first include
#include <stdio.h>
#include <stdlib.h>

void validCode(PyObject * pPyObjArg)
{
Expand Down
12 changes: 10 additions & 2 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <QStack>
#include <QByteArray>
#include <QList>
#include <QLinkedList>
#include <QMap>
#include <QMultiMap>
#include <QQueue>
Expand All @@ -34,6 +33,11 @@
#include <QRegion>
#include <QTransform>

// TODO: this is actually avilable via Core5Compat but I could not get it to work with pkg-config
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QLinkedList>
#endif

#include <cstdio>

int ignoredReturnValue_QSize_height(const QSize &s)
Expand Down Expand Up @@ -323,6 +327,7 @@ QList<int>::iterator QList3()
return it;
}

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
void QLinkedList1()
{
// cppcheck-suppress unreadVariable
Expand Down Expand Up @@ -359,6 +364,7 @@ QLinkedList<int>::iterator QLinkedList3()
// cppcheck-suppress returnDanglingLifetime
return it;
}
#endif

void QStringList1(QStringList stringlistArg)
{
Expand Down Expand Up @@ -569,11 +575,13 @@ void MacroTest2_test()
QByteArray ba = str.toLatin1();
printf(ba.data());

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#ifndef QT_NO_DEPRECATED
str = MacroTest2::trUtf8("test2");
ba = str.toLatin1();
printf(ba.data());
#endif
#endif
}

void MacroTest3()
Expand Down Expand Up @@ -617,7 +625,7 @@ void validCode(int * pIntPtr, QString & qstrArg, double d)
if (qstr1.length() == 1) {}
}
if (qstr1.length() == 1) {} else {
qstr1.remove(1);
qstr1.remove(1, 0);
if (qstr1.length() == 1) {}
}
}
Expand Down
37 changes: 32 additions & 5 deletions test/cfg/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ CXX_OPT=("-fsyntax-only" "-w" "-std=c++2a")
CC=gcc
CC_OPT=("-fsyntax-only" "-w" "-std=c11")

IWYU_OPTS=("-Xiwyu" "--no_fwd_decls" "-Xiwyu" "--update_comments")

function get_pkg_config_cflags {
# TODO: get rid of the error enabling/disabling?
set +e
Expand All @@ -63,16 +65,31 @@ function get_pkg_config_cflags {
echo "$PKGCONFIG"
}

function iwyu_run {
# TODO: convert -I includes provided by pkg-config to -isystem so IWYU does not produce warnings for system headers
${IWYU} "${IWYU_OPTS[@]}" "${IWYU_CLANG_INC}" "$@"
}

function cc_syntax {
${CC} "${CC_OPT[@]}" "$@"
if [ -z "$IWYU" ]; then
${CC} "${CC_OPT[@]}" "$@"
else
iwyu_run "${CC_OPT[@]}" "$@"
fi
}

function cxx_syntax {
${CXX} "${CXX_OPT[@]}" "$@"
if [ -z "$IWYU" ]; then
${CXX} "${CXX_OPT[@]}" "$@"
else
iwyu_run "${CXX_OPT[@]}" "$@"
fi
}

function cppcheck_run {
"${CPPCHECK}" "${CPPCHECK_OPT[@]}" "$@"
if [ -z "$IWYU" ]; then
"${CPPCHECK}" "${CPPCHECK_OPT[@]}" "$@"
fi
}

# posix.c
Expand All @@ -90,10 +107,19 @@ function gnu_fn {
# qt.cpp
function qt_fn {
if [ $HAS_PKG_CONFIG -eq 1 ]; then
QTCONFIG=$(get_pkg_config_cflags Qt5Core Qt5Test Qt5Gui)
if [ -n "$QTCONFIG" ]; then
# TODO: check syntax with Qt5 and Qt6?
QTCONFIG=$(get_pkg_config_cflags Qt6Core Qt6Test Qt6Gui)
if [ -z "$QTCONFIG" ]; then
QTCONFIG=$(get_pkg_config_cflags Qt5Core Qt5Test Qt5Gui)
if [ -n "$QTCONFIG" ]; then
QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt5Core Qt5Test Qt5Gui)
[[ $QTBUILDCONFIG =~ (^|[[:space:]])reduce_relocations($|[[:space:]]) ]] && QTCONFIG="${QTCONFIG} -fPIC"
fi
else
QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt6Core Qt6Test Qt6Gui)
QTCONFIG="${QTCONFIG} -fPIC"
fi
if [ -n "$QTCONFIG" ]; then
# TODO: get rid of the error enabling/disabling?
set +e
echo -e "#include <QString>" | ${CXX} "${CXX_OPT[@]}" ${QTCONFIG} -x c++ -
Expand Down Expand Up @@ -239,6 +265,7 @@ function sqlite3_fn {

# openmp.c
function openmp_fn {
# TODO: omp.h not found with IWYU
# MacOS compiler has no OpenMP by default
if ! command -v sw_vers; then
echo "OpenMP assumed to be present, checking syntax with ${CC} now."
Expand Down
5 changes: 3 additions & 2 deletions test/cfg/std.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <inttypes.h>
#include <float.h>
#include <stdarg.h>
#include <sys/types.h>
#include <assert.h>
#include <alloca.h>
#include <locale.h>
#include <signal.h>
#include <complex.h>
#include <math.h>
#include <stddef.h>

size_t invalidFunctionArgStr_wcslen(void)
{
Expand Down
19 changes: 13 additions & 6 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

// cppcheck-suppress-file valueFlowBailout

#include <algorithm>
#include <algorithm> // IWYU pragma: keep
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
Expand All @@ -27,6 +28,7 @@
#define __STDC_WANT_LIB_EXT1__ 1
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <filesystem>
Expand All @@ -36,26 +38,31 @@
#include <threads.h>
#endif
#include <iomanip>
#include <ios>
#include <ios> // IWYU pragma: keep
#include <iostream>
#include <istream>
#include <istream> // IWYU pragma: keep
#include <iterator>
#include <list>
#include <list> // IWYU pragma: keep
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <numeric>
#include <queue>
#include <set>
#include <streambuf>
#include <sstream>
#include <stdexcept>
#include <streambuf> // IWYU pragma: keep
#include <string>
#include <string_view>
#include <system_error>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <variant>
#include <vector>
#include <version>
#include <version> // IWYU pragma: keep
#ifdef __cpp_lib_span
#include <span>
#endif
Expand Down