From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DC45374F1 for ; Mon, 20 Jan 2025 12:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737374457; cv=none; b=KAkbRGR6oc2MeurRDqbMMSRCSqZjmP2zcSIu+BYZ6YqA6Ag/LJrWp3ikwoeQjAcbb6yCpZpxhOj9H94qLrY0IP3+XzXKvpxCYcHRRTDYonRGtij32tb+aqFalt9D4mJZY/N7IGmpdCBAHvtZCCo+AZVUWyZaLhUIh6ioSYUPzwQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737374457; c=relaxed/simple; bh=zj/6JGXK1TaRtxAl6LEOPn4xcwh5jkeZwGjR1yh39cc=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=lyu2Ge2rDJ/2zcD+RDVn2tu5qw/9njhG+Lom0Hprx3RpYhFR8f4Dvfuqo6Czn8yGt1gMQlax8nv8Mbq+l7kHaQPMZhnTfy4+ljsYhxdtM+gcaofyqmUjHcgqorJaup79T//vH+gT5rNPE0JvG/ad6eJ6ikhhVeaEaTffm0l91fY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ISk6HLQL; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ISk6HLQL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737374454; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=rDljs5rsngLlTSa/hG89cmXHlB4yuHWrdKvA0aflz4Y=; b=ISk6HLQLAeDJh4vEziq+VjZOeSYlcqXWR7yzyoA95LaPH0dA3EcVum2W2L6LhSOhA9Hjri mvXQ0nwjQT7BEsvj9xYjtQayoM8pPVJ3QxUkNVeObazu15OOUUtWWGt8cM1GC4J1QLSh8E PlfwRIANBDmy90gB2u8h+1qyzIqBzOA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-CxD2QlTGPTStsM38zKFV5A-1; Mon, 20 Jan 2025 07:00:52 -0500 X-MC-Unique: CxD2QlTGPTStsM38zKFV5A-1 X-Mimecast-MFC-AGG-ID: CxD2QlTGPTStsM38zKFV5A Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 893BB19560A1; Mon, 20 Jan 2025 12:00:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0FB461956056; Mon, 20 Jan 2025 12:00:50 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 50KC0l9E1833140 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Jan 2025 13:00:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 50KC0kvk1833139; Mon, 20 Jan 2025 13:00:46 +0100 Date: Mon, 20 Jan 2025 13:00:46 +0100 From: Jakub Jelinek To: linux-kernel@vger.kernel.org Cc: linux-toolchains@vger.kernel.org Subject: [PATCH] include/linux: Adjust headers for C23 Message-ID: Reply-To: Jakub Jelinek Precedence: bulk X-Mailing-List: linux-toolchains@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 GCC 15 changed default from -std=gnu17 to -std=gnu23. In C23 among many other changes bool, false and true are keywords (like in C++), so defining those using typedef or enum is invalid. The following patch adjusts the include/linux/ headers to be C23 compatible. _Bool and the C23 bool are ABI compatible, false/true have the same values but different types (previously in the kernel case it was an anonymous enum, in C23 it is bool), so if something uses say sizeof(false) or typeof(true), those do change, but I doubt that is used anywhere in the kernel. The last change is about va_start. In C23 ellipsis can be specified without any arguments before it, like int foo(...) { va_list ap; va_start(ap); int ret = va_arg(ap, int); va_end(ap); return ret; } and unlike in C17 and earlier, va_start is macro with variable argument count. Normally one should use it with just one argument or for backwards compatibility with C17 and earlier with two arguments, second being the last named argument. Of course, if there is no last named argument, only the single argument va_start is an option. The stdarg.h change attempts to be compatible with older versions of GCC and with clang as well. Both GCC 13-14 and recent versions of clang define va_start for C23 as #define va_start(v, ...) __builtin_va_start(v, 0) The problem with that definition is that it doesn't emit warnings when one uses complete nonsense in there (e.g. va_start(ap, 8) or va_start(ap, +-*, /, 3, 4.0)), so for GCC 15 it uses a different builtin which takes care about warnings for unexpected va_start uses (as suggested by the C23 standard). Hopefully clang will one day implement that too. Anyway, without these changes, kernel could detect compiler defaulting to C23 and use say -std=gnu17 option instead, but even in that case IMHO this patch doesn't hurt. Signed-off-by: Jakub Jelinek --- include/linux/types.h | 2 ++ include/linux/stddef.h | 2 ++ include/linux/stdarg.h | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/include/linux/types.h b/include/linux/types.h index 2d7b9ae8714c..f62dca96c7f1 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -32,7 +32,9 @@ typedef __kernel_timer_t timer_t; typedef __kernel_clockid_t clockid_t; typedef __kernel_mqd_t mqd_t; +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L typedef _Bool bool; +#endif typedef __kernel_uid32_t uid_t; typedef __kernel_gid32_t gid_t; diff --git a/include/linux/stddef.h b/include/linux/stddef.h index 929d67710cc5..16508c74fca9 100644 --- a/include/linux/stddef.h +++ b/include/linux/stddef.h @@ -7,10 +7,12 @@ #undef NULL #define NULL ((void *)0) +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L enum { false = 0, true = 1 }; +#endif #undef offsetof #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) diff --git a/include/linux/stdarg.h b/include/linux/stdarg.h index c8dc7f4f390c..038214722c6e 100644 --- a/include/linux/stdarg.h +++ b/include/linux/stdarg.h @@ -3,7 +3,17 @@ #define _LINUX_STDARG_H typedef __builtin_va_list va_list; +#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L +#define va_start(v, ...) __builtin_va_start(v, 0) +#ifdef __has_builtin +#if __has_builtin(__builtin_c23_va_start) +#undef va_start +#define va_start(...) __builtin_c23_va_start(__VA_ARGS__) +#endif +#endif +#else #define va_start(v, l) __builtin_va_start(v, l) +#endif #define va_end(v) __builtin_va_end(v) #define va_arg(v, T) __builtin_va_arg(v, T) #define va_copy(d, s) __builtin_va_copy(d, s)