summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-10-11 01:40:38 +0000
committerReid Kleckner <rnk@google.com>2017-10-11 01:40:38 +0000
commit51b2cd8fb9a5928d8fb69bcb107448d330088e4e (patch)
tree70dd03207eb63efe012ae496a41023bbfba32ba6
parenta323e2a722e0ca154dc3c9bd7ab9046ce7639162 (diff)
downloadbcm5719-llvm-51b2cd8fb9a5928d8fb69bcb107448d330088e4e.tar.gz
bcm5719-llvm-51b2cd8fb9a5928d8fb69bcb107448d330088e4e.zip
Silence MSVC warnings about unsigned wrapping without UB
Of course, casting an unsigned value too large for 'int' is UB. So, write out the ternary. LLVM folds it to ADD anyway. Fixes the warning from r303693 a different way. Thanks to Erich Keane for pointing this out! llvm-svn: 315406
-rw-r--r--llvm/lib/IR/Attributes.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 54b9761bd03..c8f1aaaccee 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -790,14 +790,12 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
// AttributeListImpl Definition
//===----------------------------------------------------------------------===//
-/// Map from AttributeList index to the internal array index. Adding one works:
-/// FunctionIndex: ~0U -> 0
-/// ReturnIndex: 0 -> 1
-/// FirstArgIndex: 1.. -> 2..
+/// Map from AttributeList index to the internal array index. Adding one happens
+/// to work, but it relies on unsigned integer wrapping. MSVC warns about
+/// unsigned wrapping in constexpr functions, so write out the conditional. LLVM
+/// folds it to add anyway.
static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
- // MSVC warns about '~0U + 1' wrapping around when this is called on
- // FunctionIndex, so cast to int first.
- return static_cast<int>(Index) + 1;
+ return Index == AttributeList::FunctionIndex ? 0 : Index + 1;
}
AttributeListImpl::AttributeListImpl(LLVMContext &C,
OpenPOWER on IntegriCloud