Skip to content

Commit

Permalink
Enable -Wundef by default. (#29582)
Browse files Browse the repository at this point in the history
* Enable -Wundef by default on some platforms.

* Fixes #29216

* Fix a bunch more errors.

* Restrict -Wundef to where it actually passes CI.
  • Loading branch information
bzbarsky-apple authored Oct 5, 2023
1 parent ad65510 commit 8296a75
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 31 deletions.
14 changes: 14 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ config("strict_warnings") {
cflags += [ "-Wconversion" ]
}

# For now we can't enable -Wundef across the board. Enable it where
# we can. Ideally this would be checking chip_device_platform or so
# to be more fine-grained than current_os, but it's not clear that
# we can access that here.
if (current_os != "android" && current_os != "freertos" &&
current_os != "linux" && current_os != "mbed" && current_os != "tizen" &&
current_os != "zephyr" &&
# cmsis-rtos is OpenIOT
current_os != "cmsis-rtos" &&
# cyw30739 is one of the Infineon builds
current_os != "cyw30739") {
cflags += [ "-Wundef" ]
}

if (matter_enable_java_compilation) {
cflags -= [ "-Wshadow" ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#import <os/log.h>

#if DEBUG
#ifdef DEBUG
#define MTR_LOG_DEBUG(format, ...) os_log(OS_LOG_DEFAULT, format, ##__VA_ARGS__)
#define MTR_LOG_ERROR(format, ...) os_log(OS_LOG_DEFAULT, format, ##__VA_ARGS__)
#define MTR_LOG_METHOD_ENTRY() \
Expand Down
4 changes: 1 addition & 3 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ source_set("app-main") {
]
}

if (chip_enable_smoke_co_trigger) {
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_SMOKE_CO_TRIGGER=1" ]
}
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_SMOKE_CO_TRIGGER=${chip_enable_smoke_co_trigger}" ]

public_configs = [ ":app-main-config" ]
}
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/tv-common/src/ZCLCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceConfig.h>

#include "account-login/AccountLoginManager.h"
#include "application-basic/ApplicationBasicManager.h"
Expand Down
2 changes: 2 additions & 0 deletions examples/tv-casting-app/tv-casting-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ config("config") {
]

cflags = [ "-Wconversion" ]

defines = [ "CONFIG_USE_SEPARATE_EVENTLOOP=0" ]
}

chip_data_model("tv-casting-common") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <lib/core/Optional.h>
#include <lib/support/Span.h>
#include <setup_payload/CHIPAdditionalDataPayloadBuildConfig.h>

/**
* @brief Parameters passed to the CastingServer at the time of startup (i.e. init call)
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestDataModelSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void TestDataModelSerialization::DumpBuf()
//
// Enable this once the TLV pretty printer has been checked in.
//
#if ENABLE_TLV_PRINT_OUT
#if defined(ENABLE_TLV_PRINT_OUT) && ENABLE_TLV_PRINT_OUT
TLV::Debug::Print(reader);
#endif
}
Expand Down
8 changes: 8 additions & 0 deletions src/include/platform/CHIPDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1419,3 +1419,11 @@
#ifndef CHIP_DEVICE_CONFIG_ENABLE_NFC
#define CHIP_DEVICE_CONFIG_ENABLE_NFC 0
#endif

/**
* CHIP_DEVICE_ENABLE_PORT_PARAMS enables command-line parameters to set the
* port to use for POSIX example applications.
*/
#ifndef CHIP_DEVICE_ENABLE_PORT_PARAMS
#define CHIP_DEVICE_ENABLE_PORT_PARAMS 0
#endif // CHIP_DEVICE_ENABLE_PORT_PARAMS
6 changes: 3 additions & 3 deletions src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void CloseIOCTLSocket()
}
}

#if __ANDROID__
#ifdef __ANDROID__

static struct if_nameindex * backport_if_nameindex(void);
static void backport_if_freenameindex(struct if_nameindex *);
Expand Down Expand Up @@ -648,7 +648,7 @@ InterfaceIterator::~InterfaceIterator()
{
if (mIntfArray != nullptr)
{
#if __ANDROID__
#ifdef __ANDROID__
backport_if_freenameindex(mIntfArray);
#else
if_freenameindex(mIntfArray);
Expand All @@ -666,7 +666,7 @@ bool InterfaceIterator::Next()
{
if (mIntfArray == nullptr)
{
#if __ANDROID__
#ifdef __ANDROID__
mIntfArray = backport_if_nameindex();
#else
mIntfArray = if_nameindex();
Expand Down
8 changes: 4 additions & 4 deletions src/inet/UDPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ void UDPEndPointImplSockets::HandlePendingIO(System::SocketEvents events)
}
}

#if IP_MULTICAST_LOOP || IPV6_MULTICAST_LOOP
#ifdef IPV6_MULTICAST_LOOP
static CHIP_ERROR SocketsSetMulticastLoopback(int aSocket, bool aLoopback, int aProtocol, int aOption)
{
const unsigned int lValue = static_cast<unsigned int>(aLoopback);
Expand All @@ -707,7 +707,7 @@ static CHIP_ERROR SocketsSetMulticastLoopback(int aSocket, bool aLoopback, int a

return CHIP_NO_ERROR;
}
#endif // IP_MULTICAST_LOOP || IPV6_MULTICAST_LOOP
#endif // IPV6_MULTICAST_LOOP

static CHIP_ERROR SocketsSetMulticastLoopback(int aSocket, IPVersion aIPVersion, bool aLoopback)
{
Expand All @@ -721,11 +721,11 @@ static CHIP_ERROR SocketsSetMulticastLoopback(int aSocket, IPVersion aIPVersion,
lRetval = SocketsSetMulticastLoopback(aSocket, aLoopback, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
break;

#if INET_CONFIG_ENABLE_IPV4
#if INET_CONFIG_ENABLE_IPV4 && defined(IP_MULTICAST_LOOP)
case kIPVersion_4:
lRetval = SocketsSetMulticastLoopback(aSocket, aLoopback, IPPROTO_IP, IP_MULTICAST_LOOP);
break;
#endif // INET_CONFIG_ENABLE_IPV4
#endif // INET_CONFIG_ENABLE_IPV4 && defined(IP_MULTICAST_LOOP)

default:
lRetval = INET_ERROR_WRONG_ADDRESS_TYPE;
Expand Down
5 changes: 3 additions & 2 deletions src/inet/tests/TestInetAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* a class to store and format IPV4 and IPV6 Internet Protocol addresses.
*
*/
#include <lib/core/CHIPConfig.h>

#include <inet/IPAddress.h>

Expand Down Expand Up @@ -1205,7 +1206,7 @@ void CheckFromSocket(nlTestSuite * inSuite, void * inContext)
#if CHIP_SYSTEM_CONFIG_USE_LWIP
(void) inSuite;
// This test is only supported for non LWIP stack.
#else // INET_LWIP
#else // CHIP_SYSTEM_CONFIG_USE_LWIP
const struct TestContext * lContext = static_cast<const struct TestContext *>(inContext);
IPAddressExpandedContextIterator lCurrent = lContext->mIPAddressExpandedContextRange.mBegin;
IPAddressExpandedContextIterator lEnd = lContext->mIPAddressExpandedContextRange.mEnd;
Expand Down Expand Up @@ -1260,7 +1261,7 @@ void CheckFromSocket(nlTestSuite * inSuite, void * inContext)

++lCurrent;
}
#endif // INET_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/inet/tests/TestInetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static void CheckSucceededOrFailed(TestState & aTestState, bool & aOutSucceeded,
{
const TransferStats & lStats = aTestState.mStats;

#if DEBUG
#ifdef DEBUG_TCP_TEST
printf("%u/%u sent, %u/%u received\n", lStats.mTransmit.mActual, lStats.mTransmit.mExpected, lStats.mReceive.mActual,
lStats.mReceive.mExpected);
#endif
Expand Down Expand Up @@ -298,7 +298,7 @@ int main(int argc, char * argv[])

CheckSucceededOrFailed(sTestState, lSucceeded, lFailed);

#if DEBUG
#ifdef DEBUG_TCP_TEST
// clang-format off
printf("%s %s number of expected bytes\n",
((lSucceeded) ? "successfully" :
Expand Down
19 changes: 10 additions & 9 deletions src/inet/tests/TestLwIPDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
*/

#include <inet/InetConfig.h>
#include <lib/core/CHIPConfig.h>

#include <stdint.h>
#include <string.h>

#include <sys/time.h>

#if INET_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/dns.h>
#include <lwip/ip_addr.h>
#endif // INET_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#include <CHIPVersion.h>

Expand All @@ -54,10 +55,10 @@ static bool HandleNonOptionArgs(const char * progName, int argc, char * const ar

// Globals

#if INET_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP
static uint8_t sNumIpAddrs = DNS_MAX_ADDRS_PER_NAME;
static ip_addr_t sIpAddrs[DNS_MAX_ADDRS_PER_NAME];
#endif // INET_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

static const char * sHostname = nullptr;
static const char * sDNSServerAddr = nullptr;
Expand All @@ -76,7 +77,7 @@ static ArgParser::OptionSet * gToolOptionSets[] =
};
// clang-format on

#if INET_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP
static void found_multi(const char * aName, ip_addr_t * aIpAddrs, uint8_t aNumIpAddrs, void * callback_arg)
{
printf("\tfound_multi response\n");
Expand Down Expand Up @@ -205,7 +206,7 @@ static void TestLwIPDNS(void)
printf("\tdns_gethostbyname_multi: %d (expected : ERR_OK)\n", res);
}
}
#endif // INET_LWIP
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

int main(int argc, char * argv[])
{
Expand All @@ -226,11 +227,11 @@ int main(int argc, char * argv[])

InitNetwork();

#if INET_LWIP
#if CHIP_SYSTEM_CONFIG_USE_LWIP
TestLwIPDNS();
#else
fprintf(stderr, "Please assert INET_LWIP to use this test.\n");
#endif // INET_LWIP
fprintf(stderr, "Please assert CHIP_SYSTEM_CONFIG_USE_LWIP to use this test.\n");
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

ShutdownNetwork();

Expand Down
4 changes: 4 additions & 0 deletions src/lib/support/CHIPArgParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <stdio.h>
#include <stdlib.h>

#ifndef CHIP_CONFIG_NON_POSIX_LONG_OPT
#define CHIP_CONFIG_NON_POSIX_LONG_OPT 0
#endif

namespace chip {
namespace ArgParser {

Expand Down
10 changes: 7 additions & 3 deletions src/lib/support/Pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,13 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon<
#ifdef __clang__
#if __has_feature(address_sanitizer)
#define __SANITIZE_ADDRESS__ 1
#endif
#endif
#endif
#else
#define __SANITIZE_ADDRESS__ 0
#endif // __has_feature(address_sanitizer)
#else
#define __SANITIZE_ADDRESS__ 0
#endif // __clang__
#endif // __SANITIZE_ADDRESS__
#if __SANITIZE_ADDRESS__
// Free all remaining objects so that ASAN can catch specific use-after-free cases.
ReleaseAll();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/support/UnitTestRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct

static test_suites_t gs_test_suites;

#if __ZEPHYR__
#ifdef __ZEPHYR__
inline static bool AlreadyExists(UnitTestTriggerFunction tests)
{
for (uint32_t i = 0; i < gs_test_suites.num_test_suites; ++i)
Expand All @@ -50,7 +50,7 @@ CHIP_ERROR RegisterUnitTests(UnitTestTriggerFunction tests)
return CHIP_ERROR_NO_MEMORY;
}

#if __ZEPHYR__
#ifdef __ZEPHYR__
// Not sure yet if it's a Zephyr bug or misconfiguration, but global constructors are called
// twice on native_posix platform - by libc and by Zephyr's main thread initialization code.
// This makes sure tests are not run twice for that reason.
Expand Down
2 changes: 2 additions & 0 deletions src/platform/tests/TestCHIPoBLEStackMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#pragma once

#include <platform/CHIPDeviceConfig.h>

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
int TestCHIPoBLEStackManager();
#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
1 change: 1 addition & 0 deletions src/platform/tests/TestCHIPoBLEStackMgrDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "TestCHIPoBLEStackMgr.h"
#include <platform/CHIPDeviceConfig.h>
#include <stdlib.h>

int main(int argc, char * argv[])
Expand Down
2 changes: 1 addition & 1 deletion src/system/SystemClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ClockBase * gClockBase = &gClockImpl;

#if HAVE_CLOCK_GETTIME

#if HAVE_DECL_CLOCK_BOOTTIME
#if defined(HAVE_DECL_CLOCK_BOOTTIME) && HAVE_DECL_CLOCK_BOOTTIME
// CLOCK_BOOTTIME is a Linux-specific option to clock_gettime for a clock which compensates for system sleep.
#define MONOTONIC_CLOCK_ID CLOCK_BOOTTIME
#define MONOTONIC_RAW_CLOCK_ID CLOCK_MONOTONIC_RAW
Expand Down
4 changes: 4 additions & 0 deletions src/system/SystemPacketBufferInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <lib/core/CHIPConfig.h>
#include <system/SystemConfig.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/opt.h>
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

/**
* CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP
*
Expand Down

0 comments on commit 8296a75

Please sign in to comment.