[llvm] [NFC][ADT/Support] Add {} for else when if body has {} (PR #140758)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 09:22:15 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Rahul Joshi (jurahul)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/140758.diff


19 Files Affected:

- (modified) llvm/include/llvm/ADT/IntervalMap.h (+2-1) 
- (modified) llvm/include/llvm/ADT/STLExtras.h (+4-2) 
- (modified) llvm/include/llvm/ADT/SmallBitVector.h (+4-2) 
- (modified) llvm/include/llvm/ADT/Twine.h (+2-1) 
- (modified) llvm/include/llvm/Support/Error.h (+4-2) 
- (modified) llvm/include/llvm/Support/GenericLoopInfoImpl.h (+3-2) 
- (modified) llvm/include/llvm/Support/GraphWriter.h (+2-1) 
- (modified) llvm/include/llvm/Support/YAMLParser.h (+2-1) 
- (modified) llvm/lib/Support/APFixedPoint.cpp (+10-5) 
- (modified) llvm/lib/Support/APFloat.cpp (+8-5) 
- (modified) llvm/lib/Support/APInt.cpp (+4-2) 
- (modified) llvm/lib/Support/CommandLine.cpp (+2-1) 
- (modified) llvm/lib/Support/Mustache.cpp (+2-1) 
- (modified) llvm/lib/Support/PrettyStackTrace.cpp (+2-1) 
- (modified) llvm/lib/Support/ScaledNumber.cpp (+4-2) 
- (modified) llvm/lib/Support/Unix/Path.inc (+4-2) 
- (modified) llvm/lib/Support/Windows/Path.inc (+4-2) 
- (modified) llvm/lib/Support/YAMLParser.cpp (+13-11) 
- (modified) llvm/lib/Support/regcomp.c (+8-4) 


``````````diff
diff --git a/llvm/include/llvm/ADT/IntervalMap.h b/llvm/include/llvm/ADT/IntervalMap.h
index 3463194fb301a..cb5943dc60e0e 100644
--- a/llvm/include/llvm/ADT/IntervalMap.h
+++ b/llvm/include/llvm/ADT/IntervalMap.h
@@ -2132,9 +2132,10 @@ class IntervalMapOverlaps {
       posB.advanceTo(posA.start());
       if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
         return;
-    } else
+    } else {
       // Already overlapping.
       return;
+    }
 
     while (true) {
       // Make a.end > b.start.
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 8926489faf391..897dc76a420b2 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1804,8 +1804,9 @@ T *find_singleton(R &&Range, Predicate P, bool AllowRepeats = false) {
       if (RC) {
         if (!AllowRepeats || PRC != RC)
           return nullptr;
-      } else
+      } else {
         RC = PRC;
+      }
     }
   }
   return RC;
@@ -1835,8 +1836,9 @@ std::pair<T *, bool> find_singleton_nested(R &&Range, Predicate P,
       if (RC) {
         if (!AllowRepeats || PRC.first != RC)
           return {nullptr, true};
-      } else
+      } else {
         RC = PRC.first;
+      }
     }
   }
   return {RC, false};
diff --git a/llvm/include/llvm/ADT/SmallBitVector.h b/llvm/include/llvm/ADT/SmallBitVector.h
index c538a4d4023b2..5b2a5221b791f 100644
--- a/llvm/include/llvm/ADT/SmallBitVector.h
+++ b/llvm/include/llvm/ADT/SmallBitVector.h
@@ -393,8 +393,9 @@ class SmallBitVector {
       uintptr_t IMask = ((uintptr_t)1) << I;
       uintptr_t Mask = EMask - IMask;
       setSmallBits(getSmallBits() | Mask);
-    } else
+    } else {
       getPointer()->set(I, E);
+    }
     return *this;
   }
 
@@ -424,8 +425,9 @@ class SmallBitVector {
       uintptr_t IMask = ((uintptr_t)1) << I;
       uintptr_t Mask = EMask - IMask;
       setSmallBits(getSmallBits() & ~Mask);
-    } else
+    } else {
       getPointer()->reset(I, E);
+    }
     return *this;
   }
 
diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index 7718150780e3a..4501f928834e2 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -275,8 +275,9 @@ namespace llvm {
       if (Str[0] != '\0') {
         LHS.cString = Str;
         LHSKind = CStringKind;
-      } else
+      } else {
         LHSKind = EmptyKind;
+      }
 
       assert(isValid() && "Invalid twine!");
     }
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index b0bcdd55e4831..9bb952ceb0dc2 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -418,8 +418,9 @@ class LLVM_ABI ErrorList final : public ErrorInfo<ErrorList> {
         auto &E2List = static_cast<ErrorList &>(*E2Payload);
         for (auto &Payload : E2List.Payloads)
           E1List.Payloads.push_back(std::move(Payload));
-      } else
+      } else {
         E1List.Payloads.push_back(E2.takePayload());
+      }
 
       return E1;
     }
@@ -714,10 +715,11 @@ template <class T> class [[nodiscard]] Expected {
     if (HasError) {
       dbgs() << "Unchecked Expected<T> contained error:\n";
       (*getErrorStorage())->log(dbgs());
-    } else
+    } else {
       dbgs() << "Expected<T> value was in success state. (Note: Expected<T> "
                 "values in success mode must still be checked prior to being "
                 "destroyed).\n";
+    }
     abort();
   }
 #endif
diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index dd5d805544eaa..6fc508b0e0cca 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -425,8 +425,9 @@ void LoopBase<BlockT, LoopT>::print(raw_ostream &OS, bool Verbose,
       if (i)
         OS << ",";
       BB->printAsOperand(OS, false);
-    } else
-      OS << "\n";
+    } else {
+      OS << '\n';
+    }
 
     if (BB == H)
       OS << "<header>";
diff --git a/llvm/include/llvm/Support/GraphWriter.h b/llvm/include/llvm/Support/GraphWriter.h
index 8b619a3a9c3ce..39a4c0befbb89 100644
--- a/llvm/include/llvm/Support/GraphWriter.h
+++ b/llvm/include/llvm/Support/GraphWriter.h
@@ -200,8 +200,9 @@ class GraphWriter {
       O << "<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\""
         << " cellpadding=\"0\"><tr><td align=\"text\" colspan=\"" << ColSpan
         << "\">";
-    } else
+    } else {
       O << "\"{";
+    }
 
     if (!DTraits.renderGraphFromBottomUp()) {
       if (RenderUsingHTML)
diff --git a/llvm/include/llvm/Support/YAMLParser.h b/llvm/include/llvm/Support/YAMLParser.h
index da645f2848e90..c64ef53c3afaa 100644
--- a/llvm/include/llvm/Support/YAMLParser.h
+++ b/llvm/include/llvm/Support/YAMLParser.h
@@ -27,8 +27,9 @@
 //    yaml::Node *n = di->getRoot();
 //    if (n) {
 //      // Do something with n...
-//    } else
+//    } else {
 //      break;
+//    }
 //  }
 //
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Support/APFixedPoint.cpp b/llvm/lib/Support/APFixedPoint.cpp
index 9a7caa4112625..e8f0e786fcfda 100644
--- a/llvm/lib/Support/APFixedPoint.cpp
+++ b/llvm/lib/Support/APFixedPoint.cpp
@@ -289,8 +289,9 @@ APFixedPoint APFixedPoint::mul(const APFixedPoint &Other,
       Result = Min;
     else if (Result > Max)
       Result = Max;
-  } else
+  } else {
     Overflowed = Result < Min || Result > Max;
+  }
 
   if (Overflow)
     *Overflow = Overflowed;
@@ -335,8 +336,9 @@ APFixedPoint APFixedPoint::div(const APFixedPoint &Other,
     // towards negative infinity by subtracting epsilon from the result.
     if (ThisVal.isNegative() != OtherVal.isNegative() && !Rem.isZero())
       Result = Result - 1;
-  } else
+  } else {
     Result = ThisVal.udiv(OtherVal);
+  }
   Result.setIsSigned(CommonFXSema.isSigned());
 
   // If our result lies outside of the representative range of the common
@@ -350,8 +352,9 @@ APFixedPoint APFixedPoint::div(const APFixedPoint &Other,
       Result = Min;
     else if (Result > Max)
       Result = Max;
-  } else
+  } else {
     Overflowed = Result < Min || Result > Max;
+  }
 
   if (Overflow)
     *Overflow = Overflowed;
@@ -385,8 +388,9 @@ APFixedPoint APFixedPoint::shl(unsigned Amt, bool *Overflow) const {
       Result = Min;
     else if (Result > Max)
       Result = Max;
-  } else
+  } else {
     Overflowed = Result < Min || Result > Max;
+  }
 
   if (Overflow)
     *Overflow = Overflowed;
@@ -612,8 +616,9 @@ APFixedPoint::getFromFloatValue(const APFloat &Value,
       Res = getMax(DstFXSema).getValue();
     else if (Val < FloatMin)
       Res = getMin(DstFXSema).getValue();
-  } else
+  } else {
     Overflowed = Val > FloatMax || Val < FloatMin;
+  }
 
   if (Overflow)
     *Overflow = Overflowed;
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index e99649d26ce88..5e0b29ffb2590 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -893,8 +893,9 @@ writeSignedDecimal (char *dst, int value)
   if (value < 0) {
     *dst++ = '-';
     dst = writeUnsignedDecimal(dst, -(unsigned) value);
-  } else
+  } else {
     dst = writeUnsignedDecimal(dst, value);
+  }
 
   return dst;
 }
@@ -2814,8 +2815,8 @@ APFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
   if (lost_fraction == lfExactlyZero) {
     *isExact = true;
     return opOK;
-  } else
-    return opInexact;
+  }
+  return opInexact;
 }
 
 /* Same as convertToSignExtendedInteger, except we provide
@@ -3302,8 +3303,9 @@ bool IEEEFloat::convertFromStringSpecials(StringRef str) {
       if (str.size() > 1 && tolower(str[1]) == 'x') {
         str = str.drop_front(2);
         Radix = 16;
-      } else
+      } else {
         Radix = 8;
+      }
     }
 
     // Parse the payload and make the NaN.
@@ -4529,8 +4531,9 @@ void IEEEFloat::toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
           Str.append(FormatPrecision - 1, '0');
         append(Str, "e+00");
       }
-    } else
+    } else {
       Str.push_back('0');
+    }
     return;
 
   case fcNormal:
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 0119cb2f6e1f7..a9f6f11ab5673 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -885,8 +885,9 @@ double APInt::roundToDouble(bool isSigned) const {
     if (isSigned) {
       int64_t sext = SignExtend64(getWord(0), BitWidth);
       return double(sext);
-    } else
+    } else {
       return double(getWord(0));
+    }
   }
 
   // Determine if the value is negative.
@@ -2578,8 +2579,9 @@ int APInt::tcMultiplyPart(WordType *dst, const WordType *src,
       if (low + dst[i] < low)
         high++;
       dst[i] += low;
-    } else
+    } else {
       dst[i] = low;
+    }
 
     carry = high;
   }
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index ced7e7bc8a028..d5c3cba13e030 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2692,8 +2692,9 @@ void HelpPrinterWrapper::operator=(bool Value) {
     CommonOptions->HLOp.setHiddenFlag(NotHidden);
 
     CategorizedPrinter = true; // Invoke categorized printer
-  } else
+  } else {
     UncategorizedPrinter = true; // Invoke uncategorized printer
+  }
 }
 
 // Print the value of each option.
diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 222587e19b31f..89900ed4d03a5 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -660,8 +660,9 @@ const json::Value *ASTNode::findContext() {
       CurrentContext = CurrentValue->getAsObject();
       if (!CurrentContext)
         return nullptr;
-    } else
+    } else {
       Context = CurrentValue;
+    }
   }
   return Context;
 }
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index 9b09384e95bfe..3f03368c5d22e 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -185,8 +185,9 @@ static void CrashHandler(void *) {
   if (!crashHandlerString.empty()) {
     setCrashLogMessage(crashHandlerString.c_str());
     errs() << crashHandlerString.str();
-  } else
+  } else {
     setCrashLogMessage("No crash information.");
+  }
 #endif
 }
 
diff --git a/llvm/lib/Support/ScaledNumber.cpp b/llvm/lib/Support/ScaledNumber.cpp
index 85d7afbea5c69..4d5923e3634b1 100644
--- a/llvm/lib/Support/ScaledNumber.cpp
+++ b/llvm/lib/Support/ScaledNumber.cpp
@@ -240,8 +240,9 @@ std::string ScaledNumberBase::toString(uint64_t D, int16_t E, int Width,
   if (Above0) {
     appendNumber(Str, Above0);
     DigitsOut = Str.size();
-  } else
+  } else {
     appendDigit(Str, 0);
+  }
   std::reverse(Str.begin(), Str.end());
 
   // Return early if there's nothing after the decimal.
@@ -262,8 +263,9 @@ std::string ScaledNumberBase::toString(uint64_t D, int16_t E, int Width,
     if (ExtraShift) {
       --ExtraShift;
       Error *= 5;
-    } else
+    } else {
       Error *= 10;
+    }
 
     Below0 *= 10;
     Extra *= 10;
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index fae12f7efffe8..0728413f4db6e 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -389,8 +389,9 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
       }
       // Otherwise there just wasn't enough space.
       result.resize_for_overwrite(result.capacity() * 2);
-    } else
+    } else {
       break;
+    }
   }
 
   result.truncate(strlen(result.data()));
@@ -938,8 +939,9 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
         (Name.size() == 2 && Name[0] == '.' && Name[1] == '.'))
       return directory_iterator_increment(It);
     It.CurrentEntry.replace_filename(Name, direntType(CurDir));
-  } else
+  } else {
     return directory_iterator_destruct(It);
+  }
 
   return std::error_code();
 }
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 5b311e7c475c5..0afd0141b525a 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -118,8 +118,9 @@ std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16,
   if (RootName[1] != ':') { // Check if UNC.
     FullPath.append("UNC\\");
     FullPath.append(Path8Str.begin() + 2, Path8Str.end());
-  } else
+  } else {
     FullPath.append(Path8Str);
+  }
 
   return UTF8ToUTF16(FullPath, Path16);
 }
@@ -1057,8 +1058,9 @@ std::error_code detail::directory_iterator_construct(detail::DirIterState &IT,
       if (LastError == ERROR_NO_MORE_FILES)
         return detail::directory_iterator_destruct(IT);
       return mapWindowsError(LastError);
-    } else
+    } else {
       FilenameLen = ::wcslen(FirstFind.cFileName);
+    }
 
   // Construct the current directory entry.
   SmallString<128> DirectoryEntryNameUTF8;
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index d2bedbaf0119f..fa5db46598905 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -761,8 +761,9 @@ std::string yaml::escape(StringRef Input, bool EscapePrintable) {
           EscapedInput += "\\U" + std::string(8 - HexStr.size(), '0') + HexStr;
       }
       i += UnicodeScalarValue.second - 1;
-    } else
+    } else {
       EscapedInput.push_back(*i);
+    }
   }
   return EscapedInput;
 }
@@ -1011,17 +1012,16 @@ void Scanner::scan_ns_uri_char() {
   while (true) {
     if (Current == End)
       break;
-    if ((   *Current == '%'
-          && Current + 2 < End
-          && is_ns_hex_digit(*(Current + 1))
-          && is_ns_hex_digit(*(Current + 2)))
-        || is_ns_word_char(*Current)
-        || StringRef(Current, 1).find_first_of("#;/?:@&=+$,_.!~*'()[]")
-          != StringRef::npos) {
+    if ((*Current == '%' && Current + 2 < End &&
+         is_ns_hex_digit(*(Current + 1)) && is_ns_hex_digit(*(Current + 2))) ||
+        is_ns_word_char(*Current) ||
+        StringRef(Current, 1).find_first_of("#;/?:@&=+$,_.!~*'()[]") !=
+            StringRef::npos) {
       ++Current;
       ++Column;
-    } else
+    } else {
       break;
+    }
   }
 }
 
@@ -1105,8 +1105,9 @@ void Scanner::removeStaleSimpleKeyCandidates() {
         setError( "Could not find expected : for simple key"
                 , i->Tok->Range.begin());
       i = SimpleKeys.erase(i);
-    } else
+    } else {
       ++i;
+    }
   }
 }
 
@@ -2631,8 +2632,9 @@ bool Document::parseDirectives() {
     } else if (T.Kind == Token::TK_VersionDirective) {
       parseYAMLDirective();
       isDirective = true;
-    } else
+    } else {
       break;
+    }
   }
   return isDirective;
 }
diff --git a/llvm/lib/Support/regcomp.c b/llvm/lib/Support/regcomp.c
index 1ffb92f52dfd8..4ed59823f6f44 100644
--- a/llvm/lib/Support/regcomp.c
+++ b/llvm/lib/Support/regcomp.c
@@ -304,8 +304,9 @@ llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags) {
     if (preg->re_endp < pattern)
       return (REG_INVARG);
     len = preg->re_endp - pattern;
-  } else
+  } else {
     len = strlen((const char *)pattern);
+  }
 
   /* do the mallocs early so failure handling is easy */
   g = (struct re_guts *)malloc(sizeof(struct re_guts) +
@@ -715,8 +716,9 @@ p_simp_re(struct parse *p,
       assert(OP(p->strip[p->pend[i]]) == ORPAREN);
       (void)dupl(p, p->pbegin[i] + 1, p->pend[i]);
       EMIT(O_BACK, i);
-    } else
+    } else {
       SETERROR(REG_ESUBREG);
+    }
     p->g->backrefs = 1;
     break;
   case '*':
@@ -851,8 +853,9 @@ static void p_bracket(struct parse *p) {
   if (nch(p, cs) == 1) { /* optimize singleton sets */
     ordinary(p, firstch(p, cs));
     freeset(p, cs);
-  } else
+  } else {
     EMIT(OANYOF, freezeset(p, cs));
+  }
 }
 
 /*
@@ -906,8 +909,9 @@ static void p_b_term(struct parse *p, cset *cs) {
         finish = '-';
       else
         finish = p_b_symbol(p);
-    } else
+    } else {
       finish = start;
+    }
     /* xxx what about signed chars here... */
     REQUIRE(start <= finish, REG_ERANGE);
     for (i = start; i <= finish; i++)

``````````

</details>


https://github.com/llvm/llvm-project/pull/140758


More information about the llvm-commits mailing list