From owner-freebsd-toolchain@freebsd.org Sat Jan 20 23:59:51 2018 Return-Path: Delivered-To: freebsd-toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 565FFECEC1D for ; Sat, 20 Jan 2018 23:59:51 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) Received: from sonic309-21.consmr.mail.ne1.yahoo.com (sonic309-21.consmr.mail.ne1.yahoo.com [66.163.184.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2A0A670FB8 for ; Sat, 20 Jan 2018 23:59:50 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) X-YMail-OSG: G3DJ7PQVM1n5ncjEYlrmnpHQKiEMKCzkt6ts4rQAGKGjXe4zYGsjW7193BcjCCJ xYTZoVjliu1tL8MGFG_BChOw5ReWrRFQBCYe_67jF.wnX09LTlpsxqm5.mDTvV5p26bQ4vtlLWgH BG0lMreIYly5qs2gCH11ksnT3jvpBgeyJTBoX92X2yAe62WLP7GhK3j6rrTN4dmdFGT_eumMSd8_ _vnBo.ohP59CZL4oyfrx1hDcmpmdYLSLpkmawKvVwG2rsB9Ct_M8IRD7CrnfB.R7KsjsUqRdq7aL XqvyB3_cYiqdTsiWv.ouMxqbKXMmWTkGpmow.zxQT7JO2ilNWnrcxl.aq2q.32Bty44otGAWPaZU vW9ew4j3YbaPXaM.QRNFdb4mOVhd5ZM3oF.Q3LtK9XNJJHW1b_9II1xzXsJAkCtE2EMM68d41pgr 3.a48UyXfe3WS0pIA3TzQPuuJqpQ1v0puOqp6ZXfz0tzN9_aWLMO4RLiCmcwFPQEOSMge Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Sat, 20 Jan 2018 23:59:44 +0000 Received: from smtpgate103.mail.ne1.yahoo.com (EHLO [192.168.1.25]) ([216.155.193.162]) by smtp416.mail.ne1.yahoo.com (JAMES SMTP Server ) with ESMTPA ID 3966b0e8031e630d539b8a5755cf2897; Sat, 20 Jan 2018 23:59:40 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Attribute alloc__size use and clang 5.0.1 vs. gcc7 (e.g.): __builtin_object_size(p,1) and __builtin_object_size(p,3) disagreements result Date: Sat, 20 Jan 2018 15:59:38 -0800 References: <1AA0993D-81E4-4DC0-BBD9-CC42B26ADB1C@yahoo.com> To: Pedro Giffuni , FreeBSD Toolchain , FreeBSD Hackers In-Reply-To: <1AA0993D-81E4-4DC0-BBD9-CC42B26ADB1C@yahoo.com> Message-Id: X-Mailer: Apple Mail (2.3273) X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jan 2018 23:59:51 -0000 [Noting a typo in the program source, and so in the output text: the 2nd occurance of: "my_calloc_alt0 should have been: "my_calloc_alt1 . Hand edited corrections below for clarity.] On 2018-Jan-20, at 3:27 PM, Mark Millard = wrote: > [Bugzilla 225197 indirectly lead to this. > Avoiding continuing there.] >=20 > I decided to compare some alternate uses of > __attribute__((alloc_size(. . .))) compiled > and run under clang 5.0.1 and gcc7. I did not > get what I expected based on prior discussion > material. >=20 > This is an FYI since I do not know how important > the distinctions that I found are. >=20 > Here is the quick program: >=20 > # more alloc_size_attr_test.c=20 > #include > #include >=20 > __attribute__((alloc_size(1,2))) > void* my_calloc_alt0(size_t n, size_t s) > { > void* p =3D calloc(n,s); > printf("calloc __builtin_object_size 0,1,2,3: %ld, %ld, %ld, %ld\n" > ,(long) __builtin_object_size(p, 0) > ,(long) __builtin_object_size(p, 1) > ,(long) __builtin_object_size(p, 2) > ,(long) __builtin_object_size(p, 3) > ); > return p; > } >=20 > __attribute__((alloc_size(1))) __attribute__((alloc_size(2))) > void* my_calloc_alt1(size_t n, size_t s) > { > void* p =3D calloc(n,s); > printf("calloc __builtin_object_size 0,1,2,3: %ld, %ld, %ld, %ld\n" > ,(long) __builtin_object_size(p, 0) > ,(long) __builtin_object_size(p, 1) > ,(long) __builtin_object_size(p, 2) > ,(long) __builtin_object_size(p, 3) > ); > return p; > } >=20 > int main() > { > void* p =3D my_calloc_alt0(2,7); > printf("my_calloc_alt0 __builtin_object_size 0,1,2,3: %ld, %ld, %ld, = %ld\n" > ,(long) __builtin_object_size(p, 0) > ,(long) __builtin_object_size(p, 1) > ,(long) __builtin_object_size(p, 2) > ,(long) __builtin_object_size(p, 3) > ); > void* q =3D my_calloc_alt1(2,7); > printf("my_calloc_alt0 __builtin_object_size 0,1,2,3: %ld, %ld, %ld, = %ld\n" The above line should have been: printf("my_calloc_alt1 __builtin_object_size 0,1,2,3: %ld, %ld, %ld, = %ld\n" > ,(long) __builtin_object_size(q, 0) > ,(long) __builtin_object_size(q, 1) > ,(long) __builtin_object_size(q, 2) > ,(long) __builtin_object_size(q, 3) > ); > } >=20 > # uname -apKU > FreeBSD FBSDFSSD 12.0-CURRENT FreeBSD 12.0-CURRENT r327485M amd64 = amd64 1200054 1200054 >=20 > The system-clang 5.0.1 result was: >=20 > # clang -O2 alloc_size_attr_test.c The later outputs are edited for clarity: > # ./a.out > calloc __builtin_object_size 0,1,2,3: 14, 14, 14, 0 > my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 > calloc __builtin_object_size 0,1,2,3: 14, 14, 14, 0 my_calloc_alt1 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 >=20 > The lang/gcc7 result was: >=20 > # gcc7 -O2 alloc_size_attr_test.c >=20 > # ./a.out > calloc __builtin_object_size 0,1,2,3: -1, -1, 0, 0 > my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 14 > calloc __builtin_object_size 0,1,2,3: -1, -1, 0, 0 my_calloc_alt1 __builtin_object_size 0,1,2,3: 14, 7, 14, 14 >=20 > I'll ignore that gcc does not provide actual sizes > via __builtin_object_size for calloc use. >=20 > Pairing the other lines for easy comparison, with > some notes mixed in: >=20 > __attribute__((alloc_size(1,2))) style: > my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 (system = clang) > my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 14 (gcc7) >=20 > __attribute__((alloc_size(1))) __attribute__((alloc_size(2))) style: my_calloc_alt1 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 (system = clang) my_calloc_alt1 __builtin_object_size 0,1,2,3: 14, 7, 14, 14 (gcc7) >=20 > Thus. . . >=20 > For __attribute__((alloc_size(1))) __attribute__((alloc_size(2))): > __builtin_object_size(p,1) is not equivalent (clang vs. gcc7) >=20 > For both of the alloc_size usage styles: > __builtin_object_size(p,3) is not equivalent (clang vs. gcc7) >=20 > This means that the two style of alloc_size use are not > equivalent across some major compilers/toolchains. >=20 > But I do not know if either of the differences is a problem or > not. >=20 >=20 > Note: without a sufficient -O all the figures can be > the mix of -1's and 0's. =3D=3D=3D Mark Millard marklmi at yahoo.com ( markmi at dsl-only.net is going away in 2018-Feb, late)