[PATCH] D129541: [llvm][IPO] Add IR function attribute fine_grained_bitfields
John McIver via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 12 10:18:10 PDT 2022
jmciver created this revision.
Herald added subscribers: jdoerfert, hiraditya.
Herald added a project: All.
jmciver edited the summary of this revision.
jmciver edited the summary of this revision.
jmciver published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The IR function attribute fine_grained_bitfields is used to prevent the IPO
inlining of functions with different bit-field addressing schemes. Use of fine
grained and non fine grained bit-fields can result in data corruption. See the
following example:
// File A: compiled with -ffine-grained-bitfield-accesses
struct X {
int a : 8;
int b : 24;
};
void callee(struct X*);
int caller() {
struct X x;
x.a = 10; // Variable a is directly stored to.
callee(&x);
return x.a;
}
// File B: compiled with -fno-fine-grained-bitfield-accesses
struct X {
int a : 8;
int b : 24;
};
void callee(struct X* x) {
x->b = 10; // Load occurs on struct object, followed by freeze,
// clear, set, and store sequence to assign b.
}
Because the caller uses `fine-grained-bitfield-accesses`, only the byte
associated with `a` is assigned and the value of `b` remains `poison`. The
callee does not have individual member variable addressing and thus loads the
full 32-bits (8-bits of value and 24-bits `poison`) resulting in a load of
`poison`. The proceeding `freeze` in the freeze, clear, set, and store sequence
will corrupt the already assigned value of `a`.
The IPO inlining issue was identified in D128501 <https://reviews.llvm.org/D128501>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129541
Files:
llvm/docs/BitCodeFormat.rst
llvm/docs/LangRef.rst
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Bitcode/compatibility.ll
llvm/test/Transforms/Inline/fine_grained_bitfields.ll
llvm/test/Transforms/Inline/module-fine_grained_bitfield-both.ll
llvm/test/Transforms/Inline/module-fine_grained_bitfield-callee.ll
llvm/test/Transforms/Inline/module-fine_grained_bitfield-caller.ll
llvm/utils/emacs/llvm-mode.el
llvm/utils/vim/syntax/llvm.vim
llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129541.443842.patch
Type: text/x-patch
Size: 26263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220712/c7b1464d/attachment-0001.bin>
More information about the llvm-commits
mailing list