summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DataLayout.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-08-07 17:20:55 +0000
committerFlorian Hahn <flo@fhahn.com>2019-08-07 17:20:55 +0000
commitd8c3c173945e7653b76e0326868464bad2130482 (patch)
tree4cec7ffe14e7e3d89577973a50e3b5e69e942456 /llvm/lib/IR/DataLayout.cpp
parentfa2f4395e901df27b77daa0b708c788d4b8d4316 (diff)
downloadbcm5719-llvm-d8c3c173945e7653b76e0326868464bad2130482.tar.gz
bcm5719-llvm-d8c3c173945e7653b76e0326868464bad2130482.zip
[DataLayout] Check StackNatural and FunctionPtr alignments.
MaybeAlignment asserts that the passed in value is == 0 or a power of 2. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16272 Reviewers: michaelplatings, gchatelet, jakehehrlich, jfb Reviewed By: gchatelet Tags: #llvm Differential Revision: https://reviews.llvm.org/D65858 llvm-svn: 368191
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r--llvm/lib/IR/DataLayout.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index ab90388fae3..1b9ff3922d1 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -378,7 +378,10 @@ void DataLayout::parseSpecifier(StringRef Desc) {
}
break;
case 'S': { // Stack natural alignment.
- StackNaturalAlign = MaybeAlign(inBytes(getInt(Tok)));
+ uint64_t Alignment = inBytes(getInt(Tok));
+ if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
+ report_fatal_error("Alignment is neither 0 nor a power of 2");
+ StackNaturalAlign = MaybeAlign(Alignment);
break;
}
case 'F': {
@@ -394,7 +397,10 @@ void DataLayout::parseSpecifier(StringRef Desc) {
"datalayout string");
}
Tok = Tok.substr(1);
- FunctionPtrAlign = MaybeAlign(inBytes(getInt(Tok)));
+ uint64_t Alignment = inBytes(getInt(Tok));
+ if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
+ report_fatal_error("Alignment is neither 0 nor a power of 2");
+ FunctionPtrAlign = MaybeAlign(Alignment);
break;
}
case 'P': { // Function address space.
OpenPOWER on IntegriCloud