Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 04 Nov 2011 15:21:21 -0600
From:      Axel Gonzalez <loox@e-shell.net>
To:        freebsd-current@freebsd.org
Cc:        Roman Divacky <rdivacky@freebsd.org>
Subject:   bug in clang printf format | was Re: Strange warning with clang and 9RC1 (ntohs)
Message-ID:  <3103300.opx6oxscCi@moonlight.e-shell.tk>
In-Reply-To: <2104381.NqWTZMXtng@moonlight.e-shell.tk>
References:  <1562351.Ln9lEKl2rv@moonlight.e-shell.tk> <20111101065651.GA27751@freebsd.org> <2104381.NqWTZMXtng@moonlight.e-shell.tk>

next in thread | previous in thread | raw e-mail | index | archive | help

After getting in contact with clang's ml, the determined that this a bug in 
clang's format checker.

Note that this bug affects:
	 printf("%hu\n", ntohs(x));
This happens in 9 that ntohs is defined as a macro using conditinal operator 
(? :)


The discussion is here:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-November/018464.html

The bug in clang is here:
http://llvm.org/bugs/show_bug.cgi?id=11313


Greetings!


On Tuesday 01 November 2011 01:10:36 Axel Gonzalez wrote:
> Here is the output (short version):
> 
> ...
> (snip)
> 
> static __inline __uint16_t
> __bswap16_var(__uint16_t _x)
> {
> 
>  return ((__uint16_t)((_x) << 8 | (_x) >> 8));
> }
> 
> ...
> (snip)
> 
> 
> int main()
> {
>  uint16_t x = (__builtin_constant_p(80) ? (__uint16_t)(((__uint16_t)(80)) <<
> 8
> | ((__uint16_t)(80)) >> 8) : __bswap16_var(80));
> 
>  printf("%hu\n", (uint16_t)(__builtin_constant_p(x) ? (__uint16_t)
> (((__uint16_t)(x)) << 8 | ((__uint16_t)(x)) >> 8) : __bswap16_var(x)));
>  printf("%hu\n", (__builtin_constant_p(x) ? (__uint16_t)(((__uint16_t)(x))
> << 8 | ((__uint16_t)(x)) >> 8) : __bswap16_var(x)));
>  return (0);
> }
> 
> 
> % clang -E ntohs.c > ntohs_.c
> % clang -Wall -o ntohs ntohs_.c
> In file included from ntohs.c:1:
> ntohs.c:8:12: warning: conversion specifies type 'unsigned short' but the
> argument has type
>       'int' [-Wformat]
>   ...%hu\n", (__builtin_constant_p(x) ? (__uint16_t)(((__uint16_t)(x)) << 8
> | ((__uint16_t)(x)) >> 8) : __bswap16_var(x))...
>      ~~^
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %d
> 1 warning generated.
> 
> 
> 
> And I missed it the first mail:
> 
> FreeBSD moonlight 9.0-RC1 FreeBSD 9.0-RC1 #0: Fri Oct 28 22:53:45 CDT 2011
> toor@moonlight:/usr/obj/usr/src/sys/LXCORE9  i386
> 
> 
> Thanks!
> 
> A
> 
> On Tuesday 01 November 2011 07:56:51 Roman Divacky wrote:
> > It doesnt warn here. Can you check with "clang -E" what the ntohs()
> > is being expanded to and what the real prototype is?
-- 
Fri Nov  4 15:11:00 2011 GMT

        **
       ******
      *********
      **********
      **********
      *********
       ******
        **      9.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3103300.opx6oxscCi>