Skip to contentSkip to conversation

Fixup clang error messages

PATCH In review Daniel Wagner 2 participants 7 messages Oct 12, 2021 – Oct 15, 2021

lore
Share & tools
lore
#0 lore raw

cover Fixup clang error messages

Based on Emmanuel's patches[1] I tried to get clang to compile ConnMan. -Wcast-align seems a bit too much for clang so I disabled it for clang. The rest are couple of fallouts. Nothing serious. Though I was not able to reproduce the maybe-unitialized warnings.

[1] https://lore.kernel.org/all/MRZP264MB15449CB6E42AF281B16F54FE93D99@MRZP264MB1544.FRAP264.PROD.OUTLOOK.COM/

Daniel Wagner (3):
build: Only enable -Wcast-align for gcc
inet: Remove unused ipv6_addr_advert_mult
gsupplicant: Fix error return type

 acinclude.m4             | 4 +++-
 gsupplicant/supplicant.c | 4 ++--
 src/inet.c               | 7 -------
 3 files changed, 5 insertions(+), 10 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/3 build: Only enable -Wcast-align for gcc

clang -Wcast-align is very unhappy with various alignments of external data structures and access helper such as CMSG_DATA. While its worthwhile to fix these in the long run, let's disable the cast-align warning for the time. This aligns it with iwd.

---
 acinclude.m4 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
acinclude.m4 +3 -1
index 9e8e0dc5e8b2..262465d8085d 100644
@@ -21,7 +21,9 @@ AC_DEFUN([COMPILER_FLAGS], [
 		CFLAGS+=" -Wdeclaration-after-statement"
 		CFLAGS+=" -Wmissing-declarations"
 		CFLAGS+=" -Wredundant-decls"
-		CFLAGS+=" -Wcast-align"
+                if ( $CC -v 2>/dev/null | grep "gcc version" ); then
+                        CFLAGS+=" -Wcast-align"
+                fi
 		CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
 	fi
 ])
Signature · 1 line
2.33.0
#2 lore raw

PATCH 2/3 inet: Remove unused ipv6_addr_advert_mult

In reply to Daniel Wagner

clang complains with

src/inet.c:1839:20: error: unused function 'ipv6_addr_advert_mult' [-Werror,-Wunused-function] static inline void ipv6_addr_advert_mult(const struct in6_addr *addr,

                   ^
Remove the ipv6_addr_advert_mult function.
---
 src/inet.c | 7 -------
 1 file changed, 7 deletions(-)
src/inet.c +0 -7
index df94d1eebaa7..4039a73ca498 100644
@@ -1836,13 +1836,6 @@ int __connman_inet_ipv6_send_rs(int index, int timeout,
 	return 0;
 }
 
-static inline void ipv6_addr_advert_mult(const struct in6_addr *addr,
-					struct in6_addr *advert)
-{
-	ipv6_addr_set(advert, htonl(0xFF020000), 0, htonl(0x2),
-			htonl(0xFF000000) | addr->s6_addr32[3]);
-}
-
 #define MSG_SIZE_SEND 1452
 
 static int inc_len(int len, int inc)
Signature · 1 line
2.33.0
#3 lore raw

PATCH 3/3 gsupplicant: Fix error return type

In reply to Daniel Wagner

clang complains with:

gsupplicant/supplicant.c:1220:10: error: expression which evaluates to zero treated as a null pointer constant of type 'const char *' [-Werror,-Wnon-literal-null-conversion]

                return G_SUPPLICANT_MODE_UNKNOWN;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~
gsupplicant/supplicant.c:1228:10: error: expression which evaluates to zero treated as a null pointer constant of type 'const char *' [-Werror,-Wnon-literal-null-conversion]
                return G_SUPPLICANT_SECURITY_UNKNOWN;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Return NULL instead of the enum. In both cases the enum is 0, so there is no change.

---
 gsupplicant/supplicant.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
gsupplicant/supplicant.c +2 -2
index 8316f48ae0bf..470d99eb36b1 100644
@@ -1217,7 +1217,7 @@ const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
 {
 	if (!network)
-		return G_SUPPLICANT_MODE_UNKNOWN;
+		return NULL;
 
 	return mode2string(network->mode);
 }
@@ -1225,7 +1225,7 @@ const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
 {
 	if (!network)
-		return G_SUPPLICANT_SECURITY_UNKNOWN;
+		return NULL;
 
 	return security2string(network->security);
 }
Signature · 1 line
2.33.0
#4 lore raw
In reply to Daniel Wagner
Quoted 4 lines · Daniel Wagner

Based on Emmanuel's patches[1] I tried to get clang to compile ConnMan. -Wcast-align seems a bit too much for clang so I disabled it for clang. The rest are couple of fallouts. Nothing serious. Though I was not able to reproduce the maybe-unitialized warnings.

Patches applied

#5 lore raw
In reply to Daniel Wagner

Hi Daniel

Quoted 4 lines

Based on Emmanuel's patches[1] I tried to get clang to compile ConnMan.  -Wcast-align seems a bit too much for clang so I disabled it for clang.  The rest are couple of fallouts. Nothing serious. Though I was not able to reproduce the maybe-unitialized warnings.

Strange that you have not faced the same compilation issues. Maybe it is related to the Yocto integration I am using.
Have you tried to activate maybe-uninitialized warning or do you think it is not necessary to check this one before providing patches?

Best Regards,

Emmanuel

#6 lore raw
Quoted 5 lines · VAUTRIN Emmanuel (Canal Plus Prestataire)
Quoted 4 lines

Based on Emmanuel's patches[1] I tried to get clang to compile ConnMan.  -Wcast-align seems a bit too much for clang so I disabled it for clang.  The rest are couple of fallouts. Nothing serious. Though I was not able to reproduce the maybe-unitialized warnings.

Strange that you have not faced the same compilation issues.

This is way it's good not all have the same toolchain running. So I am not completely surprised I don't see it.

Quoted 1 line

Maybe it is related to the Yocto integration I am using.

I am using the clang from my distro (Tubmleweed). Maybe clang can be configured to behave differently. No idea.

Quoted 2 lines

Have you tried to activate maybe-uninitialized warning or do you think it is not necessary to check this one before providing patches?

Yes, I added maybe-uninitialized but still no report from clang. It's totally fine to use different compile flags. But make sure you add them to your commit message. For example the align-cast errors reported by clang is something I'd likely be ignoring. Some of them make sense to address but some are not in our hands, e.g. system include headers.

IIRC, your patch fixes a real problem. I was unhappy on the commit message and all in on patch.