diff options
author | Vedant Kumar <vsk@apple.com> | 2017-03-09 16:06:27 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-03-09 16:06:27 +0000 |
commit | 129edab125931162665df2ceecb87bf917f2425d (patch) | |
tree | 619625ca620e42ca553699edbc2a7b8dd7368f91 /clang/lib/CodeGen/CGAtomic.cpp | |
parent | 4d297df95c4e6299087ed12e9aa67a1b686d01fd (diff) | |
download | bcm5719-llvm-129edab125931162665df2ceecb87bf917f2425d.tar.gz bcm5719-llvm-129edab125931162665df2ceecb87bf917f2425d.zip |
Retry: [ubsan] Detect UB loads from bitfields
It's possible to load out-of-range values from bitfields backed by a
boolean or an enum. Check for UB loads from bitfields.
This is the motivating example:
struct S {
BOOL b : 1; // Signed ObjC BOOL.
};
S s;
s.b = 1; // This is actually stored as -1.
if (s.b == 1) // Evaluates to false, -1 != 1.
...
Changes since the original commit:
- Single-bit bools are a special case (see CGF::EmitFromMemory), and we
can't avoid dealing with them when loading from a bitfield. Don't try to
insert a check in this case.
Differential Revision: https://reviews.llvm.org/D30423
llvm-svn: 297389
Diffstat (limited to 'clang/lib/CodeGen/CGAtomic.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGAtomic.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp index 9287e46127b..28e20b53d65 100644 --- a/clang/lib/CodeGen/CGAtomic.cpp +++ b/clang/lib/CodeGen/CGAtomic.cpp @@ -1181,7 +1181,7 @@ RValue AtomicInfo::convertAtomicTempToRValue(Address addr, if (LVal.isBitField()) return CGF.EmitLoadOfBitfieldLValue( LValue::MakeBitfield(addr, LVal.getBitFieldInfo(), LVal.getType(), - LVal.getAlignmentSource())); + LVal.getAlignmentSource()), loc); if (LVal.isVectorElt()) return CGF.EmitLoadOfLValue( LValue::MakeVectorElt(addr, LVal.getVectorIdx(), LVal.getType(), |