From owner-svn-src-all@freebsd.org Wed Feb 7 15:06:55 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 169E7F0CC65; Wed, 7 Feb 2018 15:06:55 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B19ED6D5ED; Wed, 7 Feb 2018 15:06:54 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A3F4A6B8; Wed, 7 Feb 2018 15:06:54 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w17F6soJ043165; Wed, 7 Feb 2018 15:06:54 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w17F6s5l043163; Wed, 7 Feb 2018 15:06:54 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201802071506.w17F6s5l043163@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 7 Feb 2018 15:06:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328973 - in stable/11: include sys/sys X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/11: include sys/sys X-SVN-Commit-Revision: 328973 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Feb 2018 15:06:55 -0000 Author: hselasky Date: Wed Feb 7 15:06:54 2018 New Revision: 328973 URL: https://svnweb.freebsd.org/changeset/base/328973 Log: MFC r328237: Use the __alloc_size2 attribute where relevant. This follows the documented use in GCC. It is basically only relevant for calloc(3), reallocarray(3) and mallocarray(9). NOTE: Without this change clang 5.0.1 can produce incorrect optimisation code for static processing of data using the allocated object. For example this has been seen compiling the mlx4 core module, which allocates a fixed size array which is then sorted by a fixed order loop. The optimised result, -O2, is incorrect unless this patch is in place. Suggested by: Mark Millard Reference: https://docs.freebsd.org/cgi/mid.cgi?9DE674C6-EAA3-4E8A-906F-446E74D82FC4 Modified: stable/11/include/stdlib.h stable/11/sys/sys/malloc.h Directory Properties: stable/11/ (props changed) Modified: stable/11/include/stdlib.h ============================================================================== --- stable/11/include/stdlib.h Wed Feb 7 14:50:06 2018 (r328972) +++ stable/11/include/stdlib.h Wed Feb 7 15:06:54 2018 (r328973) @@ -90,7 +90,7 @@ long atol(const char *); void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void * _Nonnull, const void *)); void *calloc(size_t, size_t) __malloc_like __result_use_check - __alloc_size(1) __alloc_size(2); + __alloc_size2(1, 2); div_t div(int, int) __pure2; _Noreturn void exit(int); void free(void *); @@ -307,8 +307,8 @@ void qsort_r(void *, size_t, size_t, void *, int (*)(void *, const void *, const void *)); int radixsort(const unsigned char **, int, const unsigned char *, unsigned); -void *reallocarray(void *, size_t, size_t) __result_use_check __alloc_size(2) - __alloc_size(3); +void *reallocarray(void *, size_t, size_t) __result_use_check + __alloc_size2(2, 3); void *reallocf(void *, size_t) __result_use_check __alloc_size(2); int rpmatch(const char *); void setprogname(const char *); Modified: stable/11/sys/sys/malloc.h ============================================================================== --- stable/11/sys/sys/malloc.h Wed Feb 7 14:50:06 2018 (r328972) +++ stable/11/sys/sys/malloc.h Wed Feb 7 15:06:54 2018 (r328973) @@ -178,7 +178,7 @@ void *malloc(unsigned long size, struct malloc_type *t __malloc_like __result_use_check __alloc_size(1); void *mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags) __malloc_like __result_use_check - __alloc_size(1) __alloc_size(2); + __alloc_size2(1, 2); void malloc_init(void *); int malloc_last_fail(void); void malloc_type_allocated(struct malloc_type *type, unsigned long size);