Skip to content

Commit 7621cd2

Browse files
committed
patch: add patch for uninit dummy vars in typecheck macro
1 parent 3432113 commit 7621cd2

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
From: Nathan Chancellor <[email protected]>
2+
Date: Thu, 01 May 2025 16:00:22 -0700
3+
Subject: [PATCH 2/2] include/linux/typecheck.h: Zero initialize dummy
4+
variables
5+
Precedence: bulk
6+
X-Mailing-List: [email protected]
7+
List-Id: <linux-kernel.vger.kernel.org>
8+
List-Subscribe: <mailto:[email protected]>
9+
List-Unsubscribe: <mailto:[email protected]>
10+
MIME-Version: 1.0
11+
Content-Type: text/plain; charset="utf-8"
12+
Content-Transfer-Encoding: quoted-printable
13+
Message-Id: <[email protected]>
14+
References: <[email protected]>
15+
In-Reply-To: <[email protected]>
16+
To: Andrew Morton <[email protected]>,
17+
Masahiro Yamada <[email protected]>
18+
Cc: Nicolas Schier <[email protected]>,
19+
Andrew Morton <[email protected]>,
20+
Nick Desaulniers <[email protected]>,
21+
Bill Wendling <[email protected]>, Justin Stitt <[email protected]>,
22+
Linus Torvalds <[email protected]>,
23+
24+
25+
Linux Kernel Functional Testing <[email protected]>,
26+
Marcus Seyfarth <[email protected]>,
27+
Nathan Chancellor <[email protected]>
28+
X-Mailer: b4 0.14.2
29+
X-Developer-Signature: v=1; a=openpgp-sha256; l=2895; [email protected];
30+
h=from:subject:message-id; bh=682lfWiGOY5H1gQ7Q6kvG5sTLVNVS+CC8Ch3D7YMRiM=;
31+
b=owGbwMvMwCUmm602sfCA1DTG02pJDBnCf0W6u1VOX9z+XGNdXAi/xfz8SZpGb2LeKrnE2txmt
32+
WfbXdfZUcrCIMbFICumyFL9WPW4oeGcs4w3Tk2CmcPKBDKEgYtTACaSLcfIMK3kgUj7oftcM7Ms
33+
M2xmyDydMfnmwcougXN/nVfN3jLR6isjwzVx6blxv8Rn2Aow+S+r4pm2KOx4wt9n8z6fK7JZErn
34+
ClB0A
35+
X-Developer-Key: [email protected]; a=openpgp;
36+
fpr=2437CB76E544CB6AB3D9DFD399739260CB6CB716
37+
38+
A new on by default warning in clang [1] aims to flags instances where
39+
const variables without static or thread local storage are not
40+
initialized because it can lead to an indeterminate value. The __dummy
41+
variables in the typecheck() macro are the only places within the kernel
42+
where this warning currently occurs.
43+
44+
drivers/gpu/drm/i915/gt/intel_ring.h:62:2: error: default initialization =
45+
of an object of type 'typeof (ring->size)' (aka 'const unsigned int') leave=
46+
s the object uninitialized and is incompatible with C++ [-Werror,-Wdefault-=
47+
const-init-var-unsafe]
48+
62 | typecheck(typeof(ring->size), next);
49+
| ^
50+
include/linux/typecheck.h:10:9: note: expanded from macro 'typecheck'
51+
10 | ({ type __dummy; \
52+
| ^
53+
54+
include/net/ip.h:478:14: error: default initialization of an object of ty=
55+
pe 'typeof (rt->dst.expires)' (aka 'const unsigned long') leaves the object=
56+
uninitialized and is incompatible with C++ [-Werror,-Wdefault-const-init-v=
57+
ar-unsafe]
58+
478 | if (mtu && time_before(jiffies, rt->dst.expires))
59+
| ^
60+
include/linux/jiffies.h:138:26: note: expanded from macro 'time_before'
61+
138 | #define time_before(a,b) time_after(b,a)
62+
| ^
63+
include/linux/jiffies.h:128:3: note: expanded from macro 'time_after'
64+
128 | (typecheck(unsigned long, a) && \
65+
| ^
66+
include/linux/typecheck.h:11:12: note: expanded from macro 'typecheck'
67+
11 | typeof(x) __dummy2; \
68+
| ^
69+
70+
Zero initialize the variables to silence the warning while not impacting
71+
the final code generation because the comparison only matters at compile
72+
time, as suggested on the PR of [1] by the clang maintainer.
73+
74+
75+
Link: https://github.com/llvm/llvm-project/commit/576161cb6069e2c7656a8ef53=
76+
0727a0f4aefff30 [1]
77+
Reported-by: Linux Kernel Functional Testing <[email protected]>
78+
Closes: https://lore.kernel.org/CA+G9fYuNjKcxFKS_MKPRuga32XbndkLGcY-PVuoSwz=
79+
80+
Reported-by: Marcus Seyfarth <[email protected]>
81+
Closes: https://github.com/ClangBuiltLinux/linux/issues/2088
82+
Signed-off-by: Nathan Chancellor <[email protected]>
83+
---
84+
include/linux/typecheck.h | 4 ++--
85+
1 file changed, 2 insertions(+), 2 deletions(-)
86+
87+
diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
88+
index 46b15e2aaefb4e7a4d21c8797ec4d1578998981c..5b473c9905ae7fce58b7226b57b=
89+
668f9ddaccaca 100644
90+
--- a/include/linux/typecheck.h
91+
+++ b/include/linux/typecheck.h
92+
@@ -7,8 +7,8 @@
93+
* Always evaluates to 1 so you may use it easily in comparisons.
94+
*/
95+
#define typecheck(type,x) \
96+
-({ type __dummy; \
97+
- typeof(x) __dummy2; \
98+
+({ type __dummy =3D {}; \
99+
+ typeof(x) __dummy2 =3D {}; \
100+
(void)(&__dummy =3D=3D &__dummy2); \
101+
1; \
102+
})
103+
104+
--
105+
2.49.0

0 commit comments

Comments
 (0)