From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10618 Path: news.gmane.org!.POSTED!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: Using macro CMSG_NXTHDR generates warnings with CLANG Date: Tue, 11 Oct 2016 16:45:40 +0200 Message-ID: <20161011144540.GA2705@voyager> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1476197173 11506 195.159.176.226 (11 Oct 2016 14:46:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Oct 2016 14:46:13 +0000 (UTC) User-Agent: Mutt/1.5.23 (2014-03-12) To: musl@lists.openwall.com Original-X-From: musl-return-10631-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 11 16:46:06 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1btyJX-0000rd-NG for gllmg-musl@m.gmane.org; Tue, 11 Oct 2016 16:45:55 +0200 Original-Received: (qmail 16073 invoked by uid 550); 11 Oct 2016 14:45:55 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 16055 invoked from network); 11 Oct 2016 14:45:54 -0000 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K0:T16KNnJ8p2+cLpeaQ/OK6nkEMLEUQIi3WGnqM7gUxNgsNQH0Vzn 2dQWVmTnh1EGvjfEaJyA1hKWIXTMdXMojmsST/7tUuzpDgmPPrrL5Gpfkv20FyOiFGCICOi VgPhFUOPY6vnC19fE4kphlzPBwA/GZYE6/BnoJ+LtVaDqD5I1mg7jw4BoZL2hLD/I7M45vN QHQz60FF49TEuplHusbSg== X-UI-Out-Filterresults: notjunk:1;V01:K0:Hum2DZ28IZU=:HHune5ppwDAzYZIcadbffL qqcgW4Uwr8oydLlrYc3CrWEYCGNsy56KV7/JE4cU1x7FhEgGiV6D3K6Dhkq4bIqND9zqBmYkP jPvDr7NT5IbCML6JS26Aunw2kwOglnFA7rgF66wktFYhmWU9Af2tajWlOp4V3OqMLllzFp79y 93/MZI6FFp3VlhwSV092eB79XEjOhsgIVSl61weizypm3D+bU7AMn2q+Fx6qUVAXS6s7QMyrl W133CIyidqksdafT9K44EIClEwkTXctvusHVFdvpvgmW/6y+vBGN6AXOGlDJmdHUTeeN2pdnO W1WCwW3r1ywtOBCyEIwpUlOAppEcsziETAbg9DWXg0JVQ7XJtBagKgh758hyOkhcwHIS58EL8 X3LMPiIBnR9lb8xNFUzlJYT8C+FL6WLPcJ4LuL0vGYxn61TXYGzxZ8QhGrtsXkd9QWBXPoNS8 bpi3eUM8Culvrth/tOtKRTA5yISx0nkcM60GfYwrGTXM50fcc607pIt0wgvUTOnY7T4qDu+K9 JdG402VeRt17y8qzD8g1LY+uudfuxjwSM2OuLKNAhjRtBo1c1xGKe1iYRh76pIP+56r4seUwE whmU0qTEWUm5kT1QMrgfStLfSJ7E2C5ReCAwyyCE3G5KK4hq2+WxkT3kUGLy8YxEWapOkxro2 3zbpLgG/XyHTFVlJTKlRn8lt96+3AtCFlulJ4RxuFmFGDBm15UvY43OT4TJxNaqzjYcx2m7KJ fUh+wmyfIDPlsYwU5P79OHZ2W9yv9oU2vaVbfVyHFh8iqhhcjtZs2XTXNwqXpnrGNFeQzRc+ Xref: news.gmane.org gmane.linux.lib.musl.general:10618 Archived-At: On Mon, Oct 10, 2016 at 10:09:38PM +0000, Jan Vorlicek wrote: > Trying to build a piece of code that uses CMSG_NXTHDR macro using CLANG (tested with CLANG 3.8) with all warnings enabled using -Weverything generates the following warnings: > > clang++ -Weverything ./nettest.cpp -c -o nettest.o > > ./nettest.cpp:5:12: warning: cast from 'unsigned char *' to 'struct cmsghdr *' increases required alignment from 1 to 4 [-Wcast-align] > return CMSG_NXTHDR(mhdr, cmsg); > ^~~~~~~~~~~~~~~~~~~~~~~ > /usr/include/sys/socket.h:270:8: note: expanded from macro 'CMSG_NXTHDR' > ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ./nettest.cpp:5:12: warning: comparison of integers of different signs: 'unsigned long' and 'long' [-Wsign-compare] > return CMSG_NXTHDR(mhdr, cmsg); > ^~~~~~~~~~~~~~~~~~~~~~~ > /usr/include/sys/socket.h:269:44: note: expanded from macro 'CMSG_NXTHDR' > __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 2 warnings generated. > > The testing source is below: > > #include > cmsghdr* GET_CMSG_NXTHDR(msghdr* mhdr, cmsghdr* cmsg); > > cmsghdr* GET_CMSG_NXTHDR(msghdr* mhdr, cmsghdr* cmsg) > { > return CMSG_NXTHDR(mhdr, cmsg); > } > > Would it be possible to fix it so that no warnings are generated? We are building our application with -Weverything and currently we need to disable these two warnings around the CMSG_NXTHDR macro invocation. > Thank you in advance for considering that! > > Jan Both of these appear to be unavoidable if the computation is to be done inline, as it is at the moment. I wondered how glibc does it and they just have a function (__cmsg_nxthdr()) taking care of it. I doubt most contributors here would like to add a function with the sole purpose of calculating a macro, just to shut up the compiler. The first warning is unavoidable because the next control message header can only be reached by skipping over the entire control message, the length of which is recorded in bytes. We do take care of the alignment doing that, but apparently clang is incapable of recognizing that. The second one could be avoided with an explicit type conversion. However, isn't our stance that warnings in system headers are broken, anyway? And warnings resulting from expansions of macros out of system headers just the same. Ciao, Markus