[all-commits] [llvm/llvm-project] 7a086e: [clang][CodeGen] Zero init unspecified fields in i...
yabinc via All-commits
all-commits at lists.llvm.org
Tue Sep 24 19:06:42 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7a086e1b2dc05f54afae3591614feede727601fa
https://github.com/llvm/llvm-project/commit/7a086e1b2dc05f54afae3591614feede727601fa
Author: yabinc <yabinc at google.com>
Date: 2024-09-24 (Tue, 24 Sep 2024)
Changed paths:
M clang/docs/LanguageExtensions.rst
M clang/lib/CodeGen/CGExprAgg.cpp
M clang/lib/CodeGen/CGExprConstant.cpp
M clang/lib/CodeGen/CodeGenModule.h
M clang/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c
M clang/test/CodeGen/2008-08-07-AlignPadding1.c
M clang/test/CodeGen/2009-06-14-anonymous-union-init.c
M clang/test/CodeGen/64bit-swiftcall.c
M clang/test/CodeGen/arm-swiftcall.c
M clang/test/CodeGen/const-init.c
M clang/test/CodeGen/decl.c
M clang/test/CodeGen/designated-initializers.c
M clang/test/CodeGen/ext-int.c
M clang/test/CodeGen/flexible-array-init.c
M clang/test/CodeGen/global-init.c
M clang/test/CodeGen/init.c
A clang/test/CodeGen/linux-kernel-struct-union-initializer.c
A clang/test/CodeGen/linux-kernel-struct-union-initializer2.c
M clang/test/CodeGen/mingw-long-double.c
M clang/test/CodeGen/mms-bitfields.c
M clang/test/CodeGen/union-init2.c
M clang/test/CodeGen/windows-swiftcall.c
M clang/test/CodeGenObjC/designated-initializers.m
Log Message:
-----------
[clang][CodeGen] Zero init unspecified fields in initializers in C (#97121)
When an initializer is provided to a variable, the Linux kernel relied
on the compiler to zero-initialize unspecified fields, as clarified in
https://www.spinics.net/lists/netdev/msg1007244.html.
But clang doesn't guarantee this:
1. For a union type, if an empty initializer is given, clang only
initializes bytes for the first field, left bytes for other (larger)
fields are marked as undef. Accessing those undef bytes can lead
to undefined behaviors.
2. For a union type, if an initializer explicitly sets a field, left
bytes for other (larger) fields are marked as undef.
3. When an initializer is given, clang doesn't zero initialize padding.
So this patch makes the following change:
1. In C, when an initializer is provided for a variable, zero-initialize
undef and padding fields in the initializer.
2. Document the change in LanguageExtensions.rst.
As suggested in
https://github.com/llvm/llvm-project/issues/78034#issuecomment-2183437928,
the change isn't required by C23, but it's standards conforming to do
so.
Fixes: https://github.com/llvm/llvm-project/issues/97459
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list