From nobody Sat Jul 06 16:16:45 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WGb9n72pYz5Nx9x; Sat, 06 Jul 2024 16:16:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WGb9n6TF7z4nd9; Sat, 6 Jul 2024 16:16:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720282605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7hHOaOca4eIE2lOzGWOa7x3Y0Y0Xi4uZUxybnYpgRCU=; b=hquWYCxu6JGOx1cRixe4zmQ7cOA4vzY7M+sIxzB6x4jCR3nk9G83qrylz00iytOyDTm/Yw bgTyTqYKctYwGu9SEPRMSsVZPkm09UR0jJZk5vhuGpJMUBMqzZQQ+MOMvTAh7VQnk037dz q0INVdEFoRopUxMcM7OAEgQLyXki3St/x6q2YIs+E1/E2kuy6XJWhwl12GVfkc4OUWxkp3 MvTluN3CnbpvGLILqybjsUE3WGvuPx75kur3iarn/RxSZKOi4600SaH3/7dUXPUCTgvMkB JaOiGSIc5wcwV32N4cTy9D296R9BkO9FCmJO01tVKJHVm2rLuyfNui8FybnGOw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720282605; a=rsa-sha256; cv=none; b=wK9qG9LngUPXgcFyhx9pyY0RoVvaa3DuxscqPuA6YGZ2oUOjE97u4Ac1yDsQZ8G3JFxDQr V2GeR/4Qm4rqraUkWLSzX+NpAp/ZBWIhtkqpyRDSgKMUyYq8U7IqTNTdgahDKpuD4ZgrvH +8RNl/KQigg+IElMCa9gaB1KTivzkKoNi1QnXy0x3WUEpeO3Zi/V7WltaNPcKI8wIv0OOS mER5LljsTK9uoKWttqYY1O6BzoKrBZTdcCMH0lk9REV+iPVWxsf7EQA9zhHymxTzMs3CPL TwMSFZKuEvH4UwhAlIMYW+I+0gJ3PumfpWtpYPyzNgNfBHqe+IY6erH4OdYunQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720282605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7hHOaOca4eIE2lOzGWOa7x3Y0Y0Xi4uZUxybnYpgRCU=; b=Rihn5IJYbweHaldLmSNZF28A1UfsA10sTi8UGjnPwSVCdaWOALqBZlambrfR3inSPEXLOH tP6XcjsHMt637LZOHI95/HMYeUHSPfhM4Fcu1QY7ddfJcDdr9xGvQ+m/nkcjlKMVo3fHVF o/Np7IJDitaMVjNtRvRWYVZFw3hrsGX/NyH4wGaTxa1bCsgepue/ubAm+5dHQTg3eVi6l5 UoQLSIPYMuzmAsEvxdFeKNQ+6rZLBhZM9uRlk/2TNpigmmf9bEF278G/cakSeKm3lQL+Ne 6OY13eoqKIMoNduCwqtZCaKP5Yd1kGKuKPaCllG/xnpm5P8p32EfKiHoWMY+MA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WGb9n5jJjzmR0; Sat, 6 Jul 2024 16:16:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 466GGjXi038338; Sat, 6 Jul 2024 16:16:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 466GGjTK038334; Sat, 6 Jul 2024 16:16:45 GMT (envelope-from git) Date: Sat, 6 Jul 2024 16:16:45 GMT Message-Id: <202407061616.466GGjTK038334@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 0b82dac337e7 - main - cdefs.h: Add back fallback define for __printf0like List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0b82dac337e7db79fa1a78bb29f2de6825a877ab Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=0b82dac337e7db79fa1a78bb29f2de6825a877ab commit 0b82dac337e7db79fa1a78bb29f2de6825a877ab Author: Warner Losh AuthorDate: 2024-07-06 16:07:52 +0000 Commit: Warner Losh CommitDate: 2024-07-06 16:15:12 +0000 cdefs.h: Add back fallback define for __printf0like The format function printf0 is originally a FreeBSD extension. clang has adopted it as an alias for printf. Starting with gcc 11, gcc doesn't do a NULL pointer check for fmtarg. Instead, it has to be tagged with a nonnull attribute, so this gives us the behavior we want. For earlier gcc and other cmopilers, define it away so do not get false positives for NULL pointers for the err*/warn* family of functions. This also fixes -Wsystem-headers by avoiding print0 entirely. My testing for 67d1a1cd9e77 didn't test that case, so I introduced a regression. All these compilers need to be considered because __printf0like is used in err.h and stdlib.h. Since it's used in system headers, it has to work on all the compilers we support on FreeBSD, not just the ones that can build FreeBSD itself. __printf0like will likely be deleted in the future, since the proper way to do this is with _Nullable or _Nonnull, but the compiler support for those hasn't been completely evaluated. Noticed by: jhb Fixes: 67d1a1cd9e77 Sponsored by: Netflix Suggestions by: jhb Differential Revision: https://reviews.freebsd.org/D45836 --- sys/sys/cdefs.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index b8908138bd65..6b861b1903f6 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -338,9 +338,7 @@ /* * Compiler-dependent macros to declare that functions take printf-like - * or scanf-like arguments. They are null except for versions of gcc - * that are known to support the features properly (old versions of gcc-2 - * didn't permit keeping the keywords out of the application namespace). + * or scanf-like arguments. */ #define __printflike(fmtarg, firstvararg) \ __attribute__((__format__ (__printf__, fmtarg, firstvararg))) @@ -352,8 +350,18 @@ #define __strftimelike(fmtarg, firstvararg) \ __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) -#define __printf0like(fmtarg, firstvararg) \ - __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) +/* + * Like __printflike, but allows fmtarg to be NULL. FreeBSD invented 'printf0' + * for this because older versions of gcc issued warnings for NULL first args. + * Clang has always had printf and printf0 as aliases. gcc 11.0 now follows + * clang. So now this is an alias for __printflike, or nothing. In the future + * _Nullable or _Nonnull will replace this. + */ +#if defined(__clang__) || __GNUC_PREREQ__(11, 0) +#define __printf0like(fmtarg, firstvararg) __printflike(fmtarg, firstvararg) +#else +#define __printf0like(fmtarg, firstvararg) +#endif #define __strong_reference(sym,aliassym) \ extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))