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
2 changes: 1 addition & 1 deletion .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: iwyu_tool
run: |
PWD=$(pwd)
iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log
iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --update_comments -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log

- uses: actions/upload-artifact@v3
if: success() || failure()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ test/testsizeof.o: test/testsizeof.cpp lib/addoninfo.h lib/check.h lib/checksize
test/teststl.o: test/teststl.cpp lib/addoninfo.h lib/check.h lib/checkstl.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststl.cpp

test/teststring.o: test/teststring.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
test/teststring.o: test/teststring.cpp lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststring.cpp

test/testsummaries.o: test/testsummaries.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
Expand Down
3 changes: 2 additions & 1 deletion cli/cppcheckexecutorsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <features.h> // __USE_DYNAMIC_STACK_SIZE
#include <map>
#include <string>
#include <unistd.h>
Expand All @@ -48,7 +49,7 @@
# include <ucontext.h>
#endif


// TODO: __USE_DYNAMIC_STACK_SIZE is depedent on the features.h include and not a built-in compiler define, so it might be problematic to depedent on it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like features.h should be included then? Also, 2x typo depedent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to figure out what is actually including this as it seems to be available in all context - I assume that might be caused by the precompiled headers. It is also not available on all platforms so there's a chance it will be breaking some builds (e.g. MacOS does not have it) so it needs some preprocessor checks. I can't be bothered to do any of that right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, 2x typo depedent.

I will fix those in another PR with several other typos.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears features.h is included if you include any system header. __USE_DYNAMIC_STACK_SIZE is defined and set to 1 if _DYNAMIC_STACK_SIZE_SOURCE is defined. That in turn is defined if the user specified _GNU_SOURCE.

features.h documents the following:

__USE_DYNAMIC_STACK_SIZE Define correct (but non compile-time constant)
                         MINSIGSTKSZ, SIGSTKSZ and PTHREAD_STACK_MIN.

But if you look at our code it seems like the check is actually backwards:

#ifdef __USE_DYNAMIC_STACK_SIZE
static const size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer
#else
static const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
#endif

And if you change that code it does not even compile:

cli/cppcheckexecutorsig.cpp:58:13: error: variable length array declaration not allowed at file scope
static char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler
            ^        ~~~~~~~~~~~

Checking the documentation of stack_t where this is being used:
https://www.gnu.org/software/libc/manual/html_node/Signal-Stack.html

size_t ss_size
This is the size (in bytes) of the signal stack which ‘ss_sp’ points to. You should set this to however much space you allocated for the stack.

There are two macros defined in signal.h that you should use in calculating this size:

SIGSTKSZ
This is the canonical size for a signal stack. It is judged to be sufficient for normal uses.

MINSIGSTKSZ
This is the amount of signal stack space the operating system needs just to implement signal delivery. The size of a signal stack must be greater than this.

For most cases, just using SIGSTKSZ for ss_size is sufficient. But if you know how much stack space your program’s signal handlers will need, you may want to use a different size. In this case, you should allocate MINSIGSTKSZ additional bytes for the signal stack and increase ss_size accordingly.

So we are allocating way too much memory for the stack.

https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sigaltstack.2.html shows an example on how to allocate it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also https://reviews.llvm.org/D28265 indicates that using sigaltstack() on MacOS breaks backtrace().

#ifdef __USE_DYNAMIC_STACK_SIZE
static const size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer
#else
Expand Down
1 change: 1 addition & 0 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "common.h"
#include "config.h"
#include "erroritem.h"
#include "errortypes.h"
#include "path.h"
#include "projectfile.h"
#include "report.h"
Expand Down
2 changes: 1 addition & 1 deletion gui/resultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef RESULTSTREE_H
#define RESULTSTREE_H

#include "errortypes.h"
#include "showtypes.h"

#include <QObject>
Expand All @@ -40,6 +39,7 @@ class ThreadHandler;
class QContextMenuEvent;
class QKeyEvent;
class QSettings;
enum class Severity;

/// @addtogroup GUI
/// @{
Expand Down
1 change: 1 addition & 0 deletions gui/showtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "showtypes.h"

#include "common.h"
#include "errortypes.h"

#include <QSettings>

Expand Down
4 changes: 2 additions & 2 deletions gui/showtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef SHOWTYPES_H
#define SHOWTYPES_H

#include "errortypes.h"

#include <QVariant>

enum class Severity;

/// @addtogroup GUI
/// @{

Expand Down
1 change: 1 addition & 0 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//---------------------------------------------------------------------------

#include <functional>
#include <list>
#include <stack>
#include <string>
#include <type_traits>
Expand Down
1 change: 1 addition & 0 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//---------------------------------------------------------------------------
#include "checkio.h"

#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "platform.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/checkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

#include <ostream>
Expand All @@ -34,6 +33,7 @@ class Settings;
class Token;
class Variable;
class ErrorLogger;
enum class Severity;

/// @addtogroup Checks
/// @{
Expand Down
1 change: 1 addition & 0 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "astutils.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "platform.h"
Expand Down
3 changes: 2 additions & 1 deletion lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

#include <list>
Expand All @@ -46,6 +45,8 @@ class Settings;
class Token;
class Variable;
class ErrorLogger;
struct CWE;
enum class Severity;

/// @addtogroup Core
/// @{
Expand Down
1 change: 0 additions & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <set>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions lib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static const std::string emptyString;
#define USE_WINDOWS_SEH
#endif

// TODO: __GLIBC__ is depedent on the features.h include and not a built-in compiler define, so it might be problematic to depedent on it
#if !defined(NO_UNIX_BACKTRACE_SUPPORT) && defined(__GNUC__) && defined(__GLIBC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__NetBSD__) && !defined(__SVR4) && !defined(__QNX__)
#define USE_UNIX_BACKTRACE_SUPPORT
#endif
Expand Down
2 changes: 0 additions & 2 deletions lib/keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include "utils.h"

#include <cassert>

// see https://en.cppreference.com/w/c/keyword

#define C90_KEYWORDS \
Expand Down
2 changes: 1 addition & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "library.h"

#include "astutils.h"
#include "errortypes.h"
#include "mathlib.h"
#include "path.h"
#include "symboldatabase.h"
Expand All @@ -31,7 +32,6 @@
#include <algorithm>
#include <cctype>
#include <climits>
#include <cstddef>
#include <cstring>
#include <list>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion lib/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "config.h"
#include "mathlib.h"
#include "errortypes.h"
#include "standards.h"

#include <map>
Expand All @@ -37,6 +36,7 @@

class Token;
class Settings;
enum class Severity;

namespace tinyxml2 {
class XMLDocument;
Expand Down
1 change: 0 additions & 1 deletion lib/pathanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <algorithm>
#include <string>
#include <tuple>
#include <type_traits>

const Scope* PathAnalysis::findOuterScope(const Scope * scope)
{
Expand Down
1 change: 0 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//---------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <map>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "check.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "platform.h"
Expand Down Expand Up @@ -50,7 +51,6 @@
#include <sstream> // IWYU pragma: keep
#include <stack>
#include <stdexcept>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//---------------------------------------------------------------------------

#include "config.h"
#include "errortypes.h"
#include "tokenlist.h"

#include <cassert>
Expand All @@ -40,6 +39,7 @@ class TemplateSimplifier;
class ErrorLogger;
class Preprocessor;
class VariableMap;
enum class Severity;

namespace simplecpp {
class TokenList;
Expand Down
1 change: 1 addition & 0 deletions lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <limits>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>

struct SelectMapKeys {
Expand Down
3 changes: 2 additions & 1 deletion test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "color.h"
#include "config.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "library.h"
#include "platform.h"
#include "settings.h"
Expand All @@ -39,6 +38,8 @@

class options;
class Tokenizer;
enum class Certainty;
enum class Severity;

class TestFixture : public ErrorLogger {
private:
Expand Down
5 changes: 5 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "cmdlinelogger.h"
#include "cmdlineparser.h"
#include "config.h"
#include "cppcheckexecutor.h"
#include "errortypes.h"
#include "helpers.h"
#include "importproject.h"
#include "platform.h"
#include "redirect.h"
#include "settings.h"
Expand All @@ -33,8 +35,11 @@
#include <cstdint>
#include <cstdio>
#include <list>
#include <memory>
#include <set>
#include <stdexcept>
#include <string>
#include <unordered_set>
#include <vector>

class TestCmdlineParser : public TestFixture {
Expand Down
1 change: 0 additions & 1 deletion test/testprocessexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "library.h"

#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <list>
#include <map>
Expand Down
1 change: 0 additions & 1 deletion test/testsingleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "timer.h"

#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <list>
#include <map>
Expand Down
2 changes: 0 additions & 2 deletions test/teststring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include <string>
#include <vector>

#include <simplecpp.h>

class TestString : public TestFixture {
public:
TestString() : TestFixture("TestString") {}
Expand Down
1 change: 0 additions & 1 deletion test/testthreadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "timer.h"

#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <list>
#include <map>
Expand Down