From 09585d4e4353dd9df83718a9cfd98f01880cab6b Mon Sep 17 00:00:00 2001 From: aadanen Date: Wed, 9 Sep 2026 10:29:04 -0700 Subject: [PATCH 1/4] Add gnu bit operation builtins --- cfg/gnu.cfg | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/cfg/gnu.cfg b/cfg/gnu.cfg index 1c8d1597a7f..f83ed44294a 100644 --- a/cfg/gnu.cfg +++ b/cfg/gnu.cfg @@ -241,16 +241,94 @@ true + + + + + - - + + + + + + + false + + + + + + + + - + + + + + + false + + + + + + 1: + + + + + + + + false + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + From 0c15f202921a03d7ebd743b4dc97cd1af4d6646a Mon Sep 17 00:00:00 2001 From: aadanen Date: Thu, 10 Sep 2026 08:35:12 -0700 Subject: [PATCH 2/4] added tests for gnu.cfg bit op funcs --- test/cfg/gnu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index 14dfcc7700f..33eb78c4af1 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -197,6 +197,29 @@ void knownConditionTrueFalse_ffsll(long long i) if (ffsll(i) == 0) {} } +int uninitvar_popcount() { + unsigned int a; + // cppcheck-suppress uninitvar + int b = __builtin_popcount(a); // popcount requires init arg + return b; +} + +int invalidFunctionArg_clz() { + // cppcheck-suppress invalidFunctionArg + return __builtin_clz(0); +} + +int invalidFunctionArgBool_ctzg(unsigned int a, unsigned int b) { + // cppcheck-suppress invalidFunctionArgBool + return __builtin_ctzg(a, a % b == 0); +} + +int useRetval_stdc_width(size_t n) { + // cppcheck-suppress ignoredReturnValue + __builtin_stdc_bit_width(n); + return 0; +} + #if !defined(__APPLE__) int nullPointer_semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout) { From 48ae282f46f06557b6197dcfc5b134362bb4ddb2 Mon Sep 17 00:00:00 2001 From: aadanen Date: Thu, 10 Sep 2026 08:40:42 -0700 Subject: [PATCH 3/4] rename function --- test/cfg/gnu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index 33eb78c4af1..2f316677885 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -214,7 +214,7 @@ int invalidFunctionArgBool_ctzg(unsigned int a, unsigned int b) { return __builtin_ctzg(a, a % b == 0); } -int useRetval_stdc_width(size_t n) { +int ignoredReturnValue_stdc_width(size_t n) { // cppcheck-suppress ignoredReturnValue __builtin_stdc_bit_width(n); return 0; From b4700fa70e0aa56da725e170aece6a13d9159f6e Mon Sep 17 00:00:00 2001 From: aadanen Date: Thu, 10 Sep 2026 12:44:50 -0700 Subject: [PATCH 4/4] use __GNUC__ for modern builtin --- test/cfg/gnu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index 2f316677885..7b3c6ae5fed 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -214,11 +214,13 @@ int invalidFunctionArgBool_ctzg(unsigned int a, unsigned int b) { return __builtin_ctzg(a, a % b == 0); } +#if __GNUC__ > 14 int ignoredReturnValue_stdc_width(size_t n) { // cppcheck-suppress ignoredReturnValue __builtin_stdc_bit_width(n); return 0; } +#endif #if !defined(__APPLE__) int nullPointer_semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout)