From 061e7017039f963caff79bff51c0fb43a88bebdd Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 11 Oct 2017 01:40:38 +0000 Subject: [PATCH] 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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315406 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Attributes.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 54b9761bd03..c8f1aaaccee 100644 --- a/lib/IR/Attributes.cpp +++ b/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(Index) + 1; + return Index == AttributeList::FunctionIndex ? 0 : Index + 1; } AttributeListImpl::AttributeListImpl(LLVMContext &C, -- 2.11.0