aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2021-05-19 13:02:29 -0700
committerArthur Eubanks <aeubanks@google.com>2021-05-21 13:41:17 -0700
commit7a29a1230148385e93493891cc7eb7f7f3b4a6cb (patch)
tree1a2a2d9e1bffcdf4b75f2698ae90cfc0f1570016 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent8110a7316401b30632d7efb0211f6059243260ac (diff)
downloadllvm-7a29a1230148385e93493891cc7eb7f7f3b4a6cb.zip
llvm-7a29a1230148385e93493891cc7eb7f7f3b4a6cb.tar.gz
llvm-7a29a1230148385e93493891cc7eb7f7f3b4a6cb.tar.bz2
[Verifier] Move some atomicrmw/cmpxchg checks to instruction creation
These checks already exist as asserts when creating the corresponding instruction. Anybody creating these instructions already need to take care to not break these checks. Move the checks for success/failure ordering in cmpxchg from the verifier to the LLParser and BitcodeReader plus an assert. Add some tests for cmpxchg ordering. The .bc files are created from the .ll files with an llvm-as with these checks disabled. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102803
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index ea655f9..7d23f3b 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5143,6 +5143,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
? AtomicCmpXchgInst::getStrongestFailureOrdering(SuccessOrdering)
: getDecodedOrdering(Record[OpNum + 3]);
+ if (FailureOrdering == AtomicOrdering::NotAtomic ||
+ FailureOrdering == AtomicOrdering::Unordered)
+ return error("Invalid record");
+
const Align Alignment(
TheModule->getDataLayout().getTypeStoreSize(Cmp->getType()));
@@ -5192,9 +5196,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
const AtomicOrdering SuccessOrdering =
getDecodedOrdering(Record[OpNum + 1]);
- if (SuccessOrdering == AtomicOrdering::NotAtomic ||
- SuccessOrdering == AtomicOrdering::Unordered)
- return error("Invalid record");
+ if (!AtomicCmpXchgInst::isValidSuccessOrdering(SuccessOrdering))
+ return error("Invalid cmpxchg success ordering");
const SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 2]);
@@ -5203,6 +5206,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
const AtomicOrdering FailureOrdering =
getDecodedOrdering(Record[OpNum + 3]);
+ if (!AtomicCmpXchgInst::isValidFailureOrdering(FailureOrdering))
+ return error("Invalid cmpxchg failure ordering");
const bool IsWeak = Record[OpNum + 4];