[llvm] fa66789 - [llvm] LLVM_NODISCARD => [[nodiscard]]. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 6 17:26:40 PDT 2022


Author: Fangrui Song
Date: 2022-08-07T00:26:33Z
New Revision: fa66789d06be2937b15e02a286b67c5f5274df31

URL: https://github.com/llvm/llvm-project/commit/fa66789d06be2937b15e02a286b67c5f5274df31
DIFF: https://github.com/llvm/llvm-project/commit/fa66789d06be2937b15e02a286b67c5f5274df31.diff

LOG: [llvm] LLVM_NODISCARD => [[nodiscard]]. NFC

With C++17 there is no Clang pedantic warning.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/APInt.h
    llvm/include/llvm/ADT/APSInt.h
    llvm/include/llvm/ADT/ArrayRef.h
    llvm/include/llvm/ADT/DenseMap.h
    llvm/include/llvm/ADT/ImmutableList.h
    llvm/include/llvm/ADT/ImmutableMap.h
    llvm/include/llvm/ADT/ImmutableSet.h
    llvm/include/llvm/ADT/PriorityWorklist.h
    llvm/include/llvm/ADT/ScopeExit.h
    llvm/include/llvm/ADT/SetVector.h
    llvm/include/llvm/ADT/SmallPtrSet.h
    llvm/include/llvm/ADT/SmallSet.h
    llvm/include/llvm/ADT/SmallVector.h
    llvm/include/llvm/ADT/StringRef.h
    llvm/include/llvm/ADT/StringSwitch.h
    llvm/include/llvm/ADT/TypeSwitch.h
    llvm/include/llvm/ADT/simple_ilist.h
    llvm/include/llvm/Analysis/AliasAnalysis.h
    llvm/include/llvm/Analysis/ScalarEvolution.h
    llvm/include/llvm/CodeGen/MachineFunction.h
    llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h
    llvm/include/llvm/IR/Attributes.h
    llvm/include/llvm/IR/ConstantRange.h
    llvm/include/llvm/Support/Casting.h
    llvm/include/llvm/Support/Error.h
    llvm/include/llvm/Support/raw_ostream.h
    llvm/lib/CodeGen/MachineFunction.cpp
    llvm/lib/CodeGen/RegisterCoalescer.cpp
    llvm/lib/Transforms/Coroutines/CoroFrame.cpp
    llvm/lib/Transforms/InstCombine/InstCombineInternal.h
    llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
    llvm/unittests/ProfileData/CoverageMappingTest.cpp
    llvm/unittests/ProfileData/InstrProfTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 5bdc1541f6302..9d371928e636d 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -72,7 +72,7 @@ inline APInt operator-(APInt);
 ///     shifts are defined, but sign extension and ashr is not.  Zero bit values
 ///     compare and hash equal to themselves, and countLeadingZeros returns 0.
 ///
-class LLVM_NODISCARD APInt {
+class [[nodiscard]] APInt {
 public:
   typedef uint64_t WordType;
 

diff  --git a/llvm/include/llvm/ADT/APSInt.h b/llvm/include/llvm/ADT/APSInt.h
index 727d95ed8c1ca..bf7454c41843c 100644
--- a/llvm/include/llvm/ADT/APSInt.h
+++ b/llvm/include/llvm/ADT/APSInt.h
@@ -20,7 +20,7 @@
 namespace llvm {
 
 /// An arbitrary precision integer that knows its signedness.
-class LLVM_NODISCARD APSInt : public APInt {
+class [[nodiscard]] APSInt : public APInt {
   bool IsUnsigned = false;
 
 public:

diff  --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index ee35a5686fc48..acfa324e6b100 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -25,7 +25,7 @@
 #include <vector>
 
 namespace llvm {
-  template<typename T> class LLVM_NODISCARD MutableArrayRef;
+  template<typename T> class [[nodiscard]] MutableArrayRef;
 
   /// ArrayRef - Represent a constant reference to an array (0 or more elements
   /// consecutively in memory), i.e. a start pointer and a length.  It allows
@@ -39,7 +39,7 @@ namespace llvm {
   /// This is intended to be trivially copyable, so it should be passed by
   /// value.
   template<typename T>
-  class LLVM_GSL_POINTER LLVM_NODISCARD ArrayRef {
+  class LLVM_GSL_POINTER [[nodiscard]] ArrayRef {
   public:
     using value_type = T;
     using pointer = value_type *;
@@ -303,7 +303,7 @@ namespace llvm {
   /// This is intended to be trivially copyable, so it should be passed by
   /// value.
   template<typename T>
-  class LLVM_NODISCARD MutableArrayRef : public ArrayRef<T> {
+  class [[nodiscard]] MutableArrayRef : public ArrayRef<T> {
   public:
     using value_type = T;
     using pointer = value_type *;

diff  --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index a6d19d342822f..c22a1f8a76e0e 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -95,9 +95,7 @@ class DenseMapBase : public DebugEpochBase {
     return makeConstIterator(getBucketsEnd(), getBucketsEnd(), *this, true);
   }
 
-  LLVM_NODISCARD bool empty() const {
-    return getNumEntries() == 0;
-  }
+  [[nodiscard]] bool empty() const { return getNumEntries() == 0; }
   unsigned size() const { return getNumEntries(); }
 
   /// Grow the densemap so that it can contain at least \p NumEntries items

diff  --git a/llvm/include/llvm/ADT/ImmutableList.h b/llvm/include/llvm/ADT/ImmutableList.h
index 23f82691825cf..185634cc8885b 100644
--- a/llvm/include/llvm/ADT/ImmutableList.h
+++ b/llvm/include/llvm/ADT/ImmutableList.h
@@ -174,7 +174,7 @@ class ImmutableListFactory {
   }
 
   template <typename ElemT>
-  LLVM_NODISCARD ImmutableList<T> concat(ElemT &&Head, ImmutableList<T> Tail) {
+  [[nodiscard]] ImmutableList<T> concat(ElemT &&Head, ImmutableList<T> Tail) {
     // Profile the new list to see if it already exists in our cache.
     FoldingSetNodeID ID;
     void* InsertPos;
@@ -197,13 +197,13 @@ class ImmutableListFactory {
   }
 
   template <typename ElemT>
-  LLVM_NODISCARD ImmutableList<T> add(ElemT &&Data, ImmutableList<T> L) {
+  [[nodiscard]] ImmutableList<T> add(ElemT &&Data, ImmutableList<T> L) {
     return concat(std::forward<ElemT>(Data), L);
   }
 
-  template <typename ...CtorArgs>
-  LLVM_NODISCARD ImmutableList<T> emplace(ImmutableList<T> Tail,
-                                          CtorArgs &&...Args) {
+  template <typename... CtorArgs>
+  [[nodiscard]] ImmutableList<T> emplace(ImmutableList<T> Tail,
+                                         CtorArgs &&...Args) {
     return concat(T(std::forward<CtorArgs>(Args)...), Tail);
   }
 

diff  --git a/llvm/include/llvm/ADT/ImmutableMap.h b/llvm/include/llvm/ADT/ImmutableMap.h
index c9351b3213dc7..3d19ca41a5be0 100644
--- a/llvm/include/llvm/ADT/ImmutableMap.h
+++ b/llvm/include/llvm/ADT/ImmutableMap.h
@@ -95,13 +95,13 @@ class ImmutableMap {
 
     ImmutableMap getEmptyMap() { return ImmutableMap(F.getEmptyTree()); }
 
-    LLVM_NODISCARD ImmutableMap add(ImmutableMap Old, key_type_ref K,
-                                    data_type_ref D) {
+    [[nodiscard]] ImmutableMap add(ImmutableMap Old, key_type_ref K,
+                                   data_type_ref D) {
       TreeTy *T = F.add(Old.Root.get(), std::pair<key_type, data_type>(K, D));
       return ImmutableMap(Canonicalize ? F.getCanonicalTree(T): T);
     }
 
-    LLVM_NODISCARD ImmutableMap remove(ImmutableMap Old, key_type_ref K) {
+    [[nodiscard]] ImmutableMap remove(ImmutableMap Old, key_type_ref K) {
       TreeTy *T = F.remove(Old.Root.get(), K);
       return ImmutableMap(Canonicalize ? F.getCanonicalTree(T): T);
     }

diff  --git a/llvm/include/llvm/ADT/ImmutableSet.h b/llvm/include/llvm/ADT/ImmutableSet.h
index b513fe9ec0118..5bee746688ce4 100644
--- a/llvm/include/llvm/ADT/ImmutableSet.h
+++ b/llvm/include/llvm/ADT/ImmutableSet.h
@@ -996,7 +996,7 @@ class ImmutableSet {
     ///  of this operation is logarithmic in the size of the original set.
     ///  The memory allocated to represent the set is released when the
     ///  factory object that created the set is destroyed.
-    LLVM_NODISCARD ImmutableSet add(ImmutableSet Old, value_type_ref V) {
+    [[nodiscard]] ImmutableSet add(ImmutableSet Old, value_type_ref V) {
       TreeTy *NewT = F.add(Old.Root.get(), V);
       return ImmutableSet(Canonicalize ? F.getCanonicalTree(NewT) : NewT);
     }
@@ -1008,7 +1008,7 @@ class ImmutableSet {
     ///  of this operation is logarithmic in the size of the original set.
     ///  The memory allocated to represent the set is released when the
     ///  factory object that created the set is destroyed.
-    LLVM_NODISCARD ImmutableSet remove(ImmutableSet Old, value_type_ref V) {
+    [[nodiscard]] ImmutableSet remove(ImmutableSet Old, value_type_ref V) {
       TreeTy *NewT = F.remove(Old.Root.get(), V);
       return ImmutableSet(Canonicalize ? F.getCanonicalTree(NewT) : NewT);
     }

diff  --git a/llvm/include/llvm/ADT/PriorityWorklist.h b/llvm/include/llvm/ADT/PriorityWorklist.h
index e9fbf296973d2..2b6510f42d569 100644
--- a/llvm/include/llvm/ADT/PriorityWorklist.h
+++ b/llvm/include/llvm/ADT/PriorityWorklist.h
@@ -150,7 +150,7 @@ class PriorityWorklist {
     } while (!V.empty() && V.back() == T());
   }
 
-  LLVM_NODISCARD T pop_back_val() {
+  [[nodiscard]] T pop_back_val() {
     T Ret = back();
     pop_back();
     return Ret;

diff  --git a/llvm/include/llvm/ADT/ScopeExit.h b/llvm/include/llvm/ADT/ScopeExit.h
index 7f013f3f79796..e2a19db1686d1 100644
--- a/llvm/include/llvm/ADT/ScopeExit.h
+++ b/llvm/include/llvm/ADT/ScopeExit.h
@@ -55,7 +55,7 @@ template <typename Callable> class scope_exit {
 //
 // Interface is specified by p0052r2.
 template <typename Callable>
-LLVM_NODISCARD detail::scope_exit<typename std::decay<Callable>::type>
+[[nodiscard]] detail::scope_exit<typename std::decay<Callable>::type>
 make_scope_exit(Callable &&F) {
   return detail::scope_exit<typename std::decay<Callable>::type>(
       std::forward<Callable>(F));

diff  --git a/llvm/include/llvm/ADT/SetVector.h b/llvm/include/llvm/ADT/SetVector.h
index 08cf42f0b2106..556aacd2033e4 100644
--- a/llvm/include/llvm/ADT/SetVector.h
+++ b/llvm/include/llvm/ADT/SetVector.h
@@ -229,7 +229,7 @@ class SetVector {
     vector_.pop_back();
   }
 
-  LLVM_NODISCARD T pop_back_val() {
+  [[nodiscard]] T pop_back_val() {
     T Ret = back();
     pop_back();
     return Ret;

diff  --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h
index ef6dae68b4a65..3d8191b3d1621 100644
--- a/llvm/include/llvm/ADT/SmallPtrSet.h
+++ b/llvm/include/llvm/ADT/SmallPtrSet.h
@@ -89,7 +89,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
 
   SmallPtrSetImplBase &operator=(const SmallPtrSetImplBase &) = delete;
 
-  LLVM_NODISCARD bool empty() const { return size() == 0; }
+  [[nodiscard]] bool empty() const { return size() == 0; }
   size_type size() const { return NumNonEmpty - NumTombstones; }
 
   void clear() {

diff  --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index 0eed85449c9d6..99f7c55ab8fdd 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -154,9 +154,7 @@ class SmallSet {
 
   SmallSet() = default;
 
-  LLVM_NODISCARD bool empty() const {
-    return Vector.empty() && Set.empty();
-  }
+  [[nodiscard]] bool empty() const { return Vector.empty() && Set.empty(); }
 
   size_type size() const {
     return isSmall() ? Vector.size() : Set.size();

diff  --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 9a127552c5499..e2c07fefc637f 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -77,7 +77,7 @@ template <class Size_T> class SmallVectorBase {
   size_t size() const { return Size; }
   size_t capacity() const { return Capacity; }
 
-  LLVM_NODISCARD bool empty() const { return !Size; }
+  [[nodiscard]] bool empty() const { return !Size; }
 
 protected:
   /// Set the array size to \p N, which the current array must have enough
@@ -658,7 +658,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
     truncate(this->size() - NumItems);
   }
 
-  LLVM_NODISCARD T pop_back_val() {
+  [[nodiscard]] T pop_back_val() {
     T Result = ::std::move(this->back());
     this->pop_back();
     return Result;

diff  --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 80ba47dd619cb..1ba92038dd759 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -145,34 +145,29 @@ namespace llvm {
 
     /// data - Get a pointer to the start of the string (which may not be null
     /// terminated).
-    LLVM_NODISCARD
-    const char *data() const { return Data; }
+    [[nodiscard]] const char *data() const { return Data; }
 
     /// empty - Check if the string is empty.
-    LLVM_NODISCARD
-    constexpr bool empty() const { return Length == 0; }
+    [[nodiscard]] constexpr bool empty() const { return Length == 0; }
 
     /// size - Get the string size.
-    LLVM_NODISCARD
-    constexpr size_t size() const { return Length; }
+    [[nodiscard]] constexpr size_t size() const { return Length; }
 
     /// front - Get the first character in the string.
-    LLVM_NODISCARD
-    char front() const {
+    [[nodiscard]] char front() const {
       assert(!empty());
       return Data[0];
     }
 
     /// back - Get the last character in the string.
-    LLVM_NODISCARD
-    char back() const {
+    [[nodiscard]] char back() const {
       assert(!empty());
       return Data[Length-1];
     }
 
     // copy - Allocate copy in Allocator and return StringRef to it.
     template <typename Allocator>
-    LLVM_NODISCARD StringRef copy(Allocator &A) const {
+    [[nodiscard]] StringRef copy(Allocator &A) const {
       // Don't request a length 0 copy from the allocator.
       if (empty())
         return StringRef();
@@ -183,22 +178,19 @@ namespace llvm {
 
     /// equals - Check for string equality, this is more efficient than
     /// compare() when the relative ordering of inequal strings isn't needed.
-    LLVM_NODISCARD
-    bool equals(StringRef RHS) const {
+    [[nodiscard]] bool equals(StringRef RHS) const {
       return (Length == RHS.Length &&
               compareMemory(Data, RHS.Data, RHS.Length) == 0);
     }
 
     /// Check for string equality, ignoring case.
-    LLVM_NODISCARD
-    bool equals_insensitive(StringRef RHS) const {
+    [[nodiscard]] bool equals_insensitive(StringRef RHS) const {
       return Length == RHS.Length && compare_insensitive(RHS) == 0;
     }
 
     /// compare - Compare two strings; the result is -1, 0, or 1 if this string
     /// is lexicographically less than, equal to, or greater than the \p RHS.
-    LLVM_NODISCARD
-    int compare(StringRef RHS) const {
+    [[nodiscard]] int compare(StringRef RHS) const {
       // Check the prefix for a mismatch.
       if (int Res = compareMemory(Data, RHS.Data, std::min(Length, RHS.Length)))
         return Res < 0 ? -1 : 1;
@@ -210,13 +202,11 @@ namespace llvm {
     }
 
     /// Compare two strings, ignoring case.
-    LLVM_NODISCARD
-    int compare_insensitive(StringRef RHS) const;
+    [[nodiscard]] int compare_insensitive(StringRef RHS) const;
 
     /// compare_numeric - Compare two strings, treating sequences of digits as
     /// numbers.
-    LLVM_NODISCARD
-    int compare_numeric(StringRef RHS) const;
+    [[nodiscard]] int compare_numeric(StringRef RHS) const;
 
     /// Determine the edit distance between this string and another
     /// string.
@@ -236,17 +226,16 @@ namespace llvm {
     /// or (if \p AllowReplacements is \c true) replacements needed to
     /// transform one of the given strings into the other. If zero,
     /// the strings are identical.
-    LLVM_NODISCARD
-    unsigned edit_distance(StringRef Other, bool AllowReplacements = true,
-                           unsigned MaxEditDistance = 0) const;
+    [[nodiscard]] unsigned edit_distance(StringRef Other,
+                                         bool AllowReplacements = true,
+                                         unsigned MaxEditDistance = 0) const;
 
-    LLVM_NODISCARD unsigned
+    [[nodiscard]] unsigned
     edit_distance_insensitive(StringRef Other, bool AllowReplacements = true,
                               unsigned MaxEditDistance = 0) const;
 
     /// str - Get the contents as an std::string.
-    LLVM_NODISCARD
-    std::string str() const {
+    [[nodiscard]] std::string str() const {
       if (!Data) return std::string();
       return std::string(Data, Length);
     }
@@ -255,8 +244,7 @@ namespace llvm {
     /// @name Operator Overloads
     /// @{
 
-    LLVM_NODISCARD
-    char operator[](size_t Index) const {
+    [[nodiscard]] char operator[](size_t Index) const {
       assert(Index < Length && "Invalid index!");
       return Data[Index];
     }
@@ -286,26 +274,22 @@ namespace llvm {
     /// @{
 
     /// Check if this string starts with the given \p Prefix.
-    LLVM_NODISCARD
-    bool startswith(StringRef Prefix) const {
+    [[nodiscard]] bool startswith(StringRef Prefix) const {
       return Length >= Prefix.Length &&
              compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
     }
 
     /// Check if this string starts with the given \p Prefix, ignoring case.
-    LLVM_NODISCARD
-    bool startswith_insensitive(StringRef Prefix) const;
+    [[nodiscard]] bool startswith_insensitive(StringRef Prefix) const;
 
     /// Check if this string ends with the given \p Suffix.
-    LLVM_NODISCARD
-    bool endswith(StringRef Suffix) const {
+    [[nodiscard]] bool endswith(StringRef Suffix) const {
       return Length >= Suffix.Length &&
         compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
     }
 
     /// Check if this string ends with the given \p Suffix, ignoring case.
-    LLVM_NODISCARD
-    bool endswith_insensitive(StringRef Suffix) const;
+    [[nodiscard]] bool endswith_insensitive(StringRef Suffix) const;
 
     /// @}
     /// @name String Searching
@@ -315,8 +299,7 @@ namespace llvm {
     ///
     /// \returns The index of the first occurrence of \p C, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find(char C, size_t From = 0) const {
+    [[nodiscard]] size_t find(char C, size_t From = 0) const {
       size_t FindBegin = std::min(From, Length);
       if (FindBegin < Length) { // Avoid calling memchr with nullptr.
         // Just forward to memchr, which is faster than a hand-rolled loop.
@@ -330,15 +313,14 @@ namespace llvm {
     ///
     /// \returns The index of the first occurrence of \p C, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find_insensitive(char C, size_t From = 0) const;
+    [[nodiscard]] size_t find_insensitive(char C, size_t From = 0) const;
 
     /// Search for the first character satisfying the predicate \p F
     ///
     /// \returns The index of the first character satisfying \p F starting from
     /// \p From, or npos if not found.
-    LLVM_NODISCARD
-    size_t find_if(function_ref<bool(char)> F, size_t From = 0) const {
+    [[nodiscard]] size_t find_if(function_ref<bool(char)> F,
+                                 size_t From = 0) const {
       StringRef S = drop_front(From);
       while (!S.empty()) {
         if (F(S.front()))
@@ -352,8 +334,8 @@ namespace llvm {
     ///
     /// \returns The index of the first character not satisfying \p F starting
     /// from \p From, or npos if not found.
-    LLVM_NODISCARD
-    size_t find_if_not(function_ref<bool(char)> F, size_t From = 0) const {
+    [[nodiscard]] size_t find_if_not(function_ref<bool(char)> F,
+                                     size_t From = 0) const {
       return find_if([F](char c) { return !F(c); }, From);
     }
 
@@ -361,22 +343,19 @@ namespace llvm {
     ///
     /// \returns The index of the first occurrence of \p Str, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find(StringRef Str, size_t From = 0) const;
+    [[nodiscard]] size_t find(StringRef Str, size_t From = 0) const;
 
     /// Search for the first string \p Str in the string, ignoring case.
     ///
     /// \returns The index of the first occurrence of \p Str, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find_insensitive(StringRef Str, size_t From = 0) const;
+    [[nodiscard]] size_t find_insensitive(StringRef Str, size_t From = 0) const;
 
     /// Search for the last character \p C in the string.
     ///
     /// \returns The index of the last occurrence of \p C, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t rfind(char C, size_t From = npos) const {
+    [[nodiscard]] size_t rfind(char C, size_t From = npos) const {
       From = std::min(From, Length);
       size_t i = From;
       while (i != 0) {
@@ -391,27 +370,23 @@ namespace llvm {
     ///
     /// \returns The index of the last occurrence of \p C, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t rfind_insensitive(char C, size_t From = npos) const;
+    [[nodiscard]] size_t rfind_insensitive(char C, size_t From = npos) const;
 
     /// Search for the last string \p Str in the string.
     ///
     /// \returns The index of the last occurrence of \p Str, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t rfind(StringRef Str) const;
+    [[nodiscard]] size_t rfind(StringRef Str) const;
 
     /// Search for the last string \p Str in the string, ignoring case.
     ///
     /// \returns The index of the last occurrence of \p Str, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t rfind_insensitive(StringRef Str) const;
+    [[nodiscard]] size_t rfind_insensitive(StringRef Str) const;
 
     /// Find the first character in the string that is \p C, or npos if not
     /// found. Same as find.
-    LLVM_NODISCARD
-    size_t find_first_of(char C, size_t From = 0) const {
+    [[nodiscard]] size_t find_first_of(char C, size_t From = 0) const {
       return find(C, From);
     }
 
@@ -419,25 +394,22 @@ namespace llvm {
     /// not found.
     ///
     /// Complexity: O(size() + Chars.size())
-    LLVM_NODISCARD
-    size_t find_first_of(StringRef Chars, size_t From = 0) const;
+    [[nodiscard]] size_t find_first_of(StringRef Chars, size_t From = 0) const;
 
     /// Find the first character in the string that is not \p C or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find_first_not_of(char C, size_t From = 0) const;
+    [[nodiscard]] size_t find_first_not_of(char C, size_t From = 0) const;
 
     /// Find the first character in the string that is not in the string
     /// \p Chars, or npos if not found.
     ///
     /// Complexity: O(size() + Chars.size())
-    LLVM_NODISCARD
-    size_t find_first_not_of(StringRef Chars, size_t From = 0) const;
+    [[nodiscard]] size_t find_first_not_of(StringRef Chars,
+                                           size_t From = 0) const;
 
     /// Find the last character in the string that is \p C, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find_last_of(char C, size_t From = npos) const {
+    [[nodiscard]] size_t find_last_of(char C, size_t From = npos) const {
       return rfind(C, From);
     }
 
@@ -445,42 +417,41 @@ namespace llvm {
     /// found.
     ///
     /// Complexity: O(size() + Chars.size())
-    LLVM_NODISCARD
-    size_t find_last_of(StringRef Chars, size_t From = npos) const;
+    [[nodiscard]] size_t find_last_of(StringRef Chars,
+                                      size_t From = npos) const;
 
     /// Find the last character in the string that is not \p C, or npos if not
     /// found.
-    LLVM_NODISCARD
-    size_t find_last_not_of(char C, size_t From = npos) const;
+    [[nodiscard]] size_t find_last_not_of(char C, size_t From = npos) const;
 
     /// Find the last character in the string that is not in \p Chars, or
     /// npos if not found.
     ///
     /// Complexity: O(size() + Chars.size())
-    LLVM_NODISCARD
-    size_t find_last_not_of(StringRef Chars, size_t From = npos) const;
+    [[nodiscard]] size_t find_last_not_of(StringRef Chars,
+                                          size_t From = npos) const;
 
     /// Return true if the given string is a substring of *this, and false
     /// otherwise.
-    LLVM_NODISCARD
-    bool contains(StringRef Other) const { return find(Other) != npos; }
+    [[nodiscard]] bool contains(StringRef Other) const {
+      return find(Other) != npos;
+    }
 
     /// Return true if the given character is contained in *this, and false
     /// otherwise.
-    LLVM_NODISCARD
-    bool contains(char C) const { return find_first_of(C) != npos; }
+    [[nodiscard]] bool contains(char C) const {
+      return find_first_of(C) != npos;
+    }
 
     /// Return true if the given string is a substring of *this, and false
     /// otherwise.
-    LLVM_NODISCARD
-    bool contains_insensitive(StringRef Other) const {
+    [[nodiscard]] bool contains_insensitive(StringRef Other) const {
       return find_insensitive(Other) != npos;
     }
 
     /// Return true if the given character is contained in *this, and false
     /// otherwise.
-    LLVM_NODISCARD
-    bool contains_insensitive(char C) const {
+    [[nodiscard]] bool contains_insensitive(char C) const {
       return find_insensitive(C) != npos;
     }
 
@@ -489,8 +460,7 @@ namespace llvm {
     /// @{
 
     /// Return the number of occurrences of \p C in the string.
-    LLVM_NODISCARD
-    size_t count(char C) const {
+    [[nodiscard]] size_t count(char C) const {
       size_t Count = 0;
       for (size_t i = 0, e = Length; i != e; ++i)
         if (Data[i] == C)
@@ -591,12 +561,10 @@ namespace llvm {
     /// @{
 
     // Convert the given ASCII string to lowercase.
-    LLVM_NODISCARD
-    std::string lower() const;
+    [[nodiscard]] std::string lower() const;
 
     /// Convert the given ASCII string to uppercase.
-    LLVM_NODISCARD
-    std::string upper() const;
+    [[nodiscard]] std::string upper() const;
 
     /// @}
     /// @name Substring Operations
@@ -611,8 +579,7 @@ namespace llvm {
     /// \param N The number of characters to included in the substring. If N
     /// exceeds the number of characters remaining in the string, the string
     /// suffix (starting with \p Start) will be returned.
-    LLVM_NODISCARD
-    StringRef substr(size_t Start, size_t N = npos) const {
+    [[nodiscard]] StringRef substr(size_t Start, size_t N = npos) const {
       Start = std::min(Start, Length);
       return StringRef(Data + Start, std::min(N, Length - Start));
     }
@@ -620,8 +587,7 @@ namespace llvm {
     /// Return a StringRef equal to 'this' but with only the first \p N
     /// elements remaining.  If \p N is greater than the length of the
     /// string, the entire string is returned.
-    LLVM_NODISCARD
-    StringRef take_front(size_t N = 1) const {
+    [[nodiscard]] StringRef take_front(size_t N = 1) const {
       if (N >= size())
         return *this;
       return drop_back(size() - N);
@@ -630,8 +596,7 @@ namespace llvm {
     /// Return a StringRef equal to 'this' but with only the last \p N
     /// elements remaining.  If \p N is greater than the length of the
     /// string, the entire string is returned.
-    LLVM_NODISCARD
-    StringRef take_back(size_t N = 1) const {
+    [[nodiscard]] StringRef take_back(size_t N = 1) const {
       if (N >= size())
         return *this;
       return drop_front(size() - N);
@@ -639,45 +604,39 @@ namespace llvm {
 
     /// Return the longest prefix of 'this' such that every character
     /// in the prefix satisfies the given predicate.
-    LLVM_NODISCARD
-    StringRef take_while(function_ref<bool(char)> F) const {
+    [[nodiscard]] StringRef take_while(function_ref<bool(char)> F) const {
       return substr(0, find_if_not(F));
     }
 
     /// Return the longest prefix of 'this' such that no character in
     /// the prefix satisfies the given predicate.
-    LLVM_NODISCARD
-    StringRef take_until(function_ref<bool(char)> F) const {
+    [[nodiscard]] StringRef take_until(function_ref<bool(char)> F) const {
       return substr(0, find_if(F));
     }
 
     /// Return a StringRef equal to 'this' but with the first \p N elements
     /// dropped.
-    LLVM_NODISCARD
-    StringRef drop_front(size_t N = 1) const {
+    [[nodiscard]] StringRef drop_front(size_t N = 1) const {
       assert(size() >= N && "Dropping more elements than exist");
       return substr(N);
     }
 
     /// Return a StringRef equal to 'this' but with the last \p N elements
     /// dropped.
-    LLVM_NODISCARD
-    StringRef drop_back(size_t N = 1) const {
+    [[nodiscard]] StringRef drop_back(size_t N = 1) const {
       assert(size() >= N && "Dropping more elements than exist");
       return substr(0, size()-N);
     }
 
     /// Return a StringRef equal to 'this', but with all characters satisfying
     /// the given predicate dropped from the beginning of the string.
-    LLVM_NODISCARD
-    StringRef drop_while(function_ref<bool(char)> F) const {
+    [[nodiscard]] StringRef drop_while(function_ref<bool(char)> F) const {
       return substr(find_if_not(F));
     }
 
     /// Return a StringRef equal to 'this', but with all characters not
     /// satisfying the given predicate dropped from the beginning of the string.
-    LLVM_NODISCARD
-    StringRef drop_until(function_ref<bool(char)> F) const {
+    [[nodiscard]] StringRef drop_until(function_ref<bool(char)> F) const {
       return substr(find_if(F));
     }
 
@@ -732,8 +691,7 @@ namespace llvm {
     /// remaining in the string, the string suffix (starting with \p Start)
     /// will be returned. If this is less than \p Start, an empty string will
     /// be returned.
-    LLVM_NODISCARD
-    StringRef slice(size_t Start, size_t End) const {
+    [[nodiscard]] StringRef slice(size_t Start, size_t End) const {
       Start = std::min(Start, Length);
       End = std::min(std::max(Start, End), Length);
       return StringRef(Data + Start, End - Start);
@@ -749,8 +707,7 @@ namespace llvm {
     ///
     /// \param Separator The character to split on.
     /// \returns The split substrings.
-    LLVM_NODISCARD
-    std::pair<StringRef, StringRef> split(char Separator) const {
+    [[nodiscard]] std::pair<StringRef, StringRef> split(char Separator) const {
       return split(StringRef(&Separator, 1));
     }
 
@@ -764,8 +721,8 @@ namespace llvm {
     ///
     /// \param Separator - The string to split on.
     /// \return - The split substrings.
-    LLVM_NODISCARD
-    std::pair<StringRef, StringRef> split(StringRef Separator) const {
+    [[nodiscard]] std::pair<StringRef, StringRef>
+    split(StringRef Separator) const {
       size_t Idx = find(Separator);
       if (Idx == npos)
         return std::make_pair(*this, StringRef());
@@ -782,8 +739,8 @@ namespace llvm {
     ///
     /// \param Separator - The string to split on.
     /// \return - The split substrings.
-    LLVM_NODISCARD
-    std::pair<StringRef, StringRef> rsplit(StringRef Separator) const {
+    [[nodiscard]] std::pair<StringRef, StringRef>
+    rsplit(StringRef Separator) const {
       size_t Idx = rfind(Separator);
       if (Idx == npos)
         return std::make_pair(*this, StringRef());
@@ -835,50 +792,43 @@ namespace llvm {
     ///
     /// \param Separator - The character to split on.
     /// \return - The split substrings.
-    LLVM_NODISCARD
-    std::pair<StringRef, StringRef> rsplit(char Separator) const {
+    [[nodiscard]] std::pair<StringRef, StringRef> rsplit(char Separator) const {
       return rsplit(StringRef(&Separator, 1));
     }
 
     /// Return string with consecutive \p Char characters starting from the
     /// the left removed.
-    LLVM_NODISCARD
-    StringRef ltrim(char Char) const {
+    [[nodiscard]] StringRef ltrim(char Char) const {
       return drop_front(std::min(Length, find_first_not_of(Char)));
     }
 
     /// Return string with consecutive characters in \p Chars starting from
     /// the left removed.
-    LLVM_NODISCARD
-    StringRef ltrim(StringRef Chars = " \t\n\v\f\r") const {
+    [[nodiscard]] StringRef ltrim(StringRef Chars = " \t\n\v\f\r") const {
       return drop_front(std::min(Length, find_first_not_of(Chars)));
     }
 
     /// Return string with consecutive \p Char characters starting from the
     /// right removed.
-    LLVM_NODISCARD
-    StringRef rtrim(char Char) const {
+    [[nodiscard]] StringRef rtrim(char Char) const {
       return drop_back(Length - std::min(Length, find_last_not_of(Char) + 1));
     }
 
     /// Return string with consecutive characters in \p Chars starting from
     /// the right removed.
-    LLVM_NODISCARD
-    StringRef rtrim(StringRef Chars = " \t\n\v\f\r") const {
+    [[nodiscard]] StringRef rtrim(StringRef Chars = " \t\n\v\f\r") const {
       return drop_back(Length - std::min(Length, find_last_not_of(Chars) + 1));
     }
 
     /// Return string with consecutive \p Char characters starting from the
     /// left and right removed.
-    LLVM_NODISCARD
-    StringRef trim(char Char) const {
+    [[nodiscard]] StringRef trim(char Char) const {
       return ltrim(Char).rtrim(Char);
     }
 
     /// Return string with consecutive characters in \p Chars starting from
     /// the left and right removed.
-    LLVM_NODISCARD
-    StringRef trim(StringRef Chars = " \t\n\v\f\r") const {
+    [[nodiscard]] StringRef trim(StringRef Chars = " \t\n\v\f\r") const {
       return ltrim(Chars).rtrim(Chars);
     }
 
@@ -888,8 +838,7 @@ namespace llvm {
     /// sequence that is detected. Otherwise return '\n' for unix line endings.
     ///
     /// \return - The line ending character sequence.
-    LLVM_NODISCARD
-    StringRef detectEOL() const {
+    [[nodiscard]] StringRef detectEOL() const {
       size_t Pos = find('\r');
       if (Pos == npos) {
         // If there is no carriage return, assume unix
@@ -968,8 +917,7 @@ namespace llvm {
   /// @}
 
   /// Compute a hash_code for a StringRef.
-  LLVM_NODISCARD
-  hash_code hash_value(StringRef S);
+  [[nodiscard]] hash_code hash_value(StringRef S);
 
   // Provide DenseMapInfo for StringRefs.
   template <> struct DenseMapInfo<StringRef, void> {

diff  --git a/llvm/include/llvm/ADT/StringSwitch.h b/llvm/include/llvm/ADT/StringSwitch.h
index 95ab1df8d2974..6ba75eba9b2e0 100644
--- a/llvm/include/llvm/ADT/StringSwitch.h
+++ b/llvm/include/llvm/ADT/StringSwitch.h
@@ -179,15 +179,13 @@ class StringSwitch {
     return CaseLower(S0, Value).CasesLower(S1, S2, S3, S4, Value);
   }
 
-  LLVM_NODISCARD
-  R Default(T Value) {
+  [[nodiscard]] R Default(T Value) {
     if (Result)
       return std::move(*Result);
     return Value;
   }
 
-  LLVM_NODISCARD
-  operator R() {
+  [[nodiscard]] operator R() {
     assert(Result && "Fell off the end of a string-switch");
     return std::move(*Result);
   }

diff  --git a/llvm/include/llvm/ADT/TypeSwitch.h b/llvm/include/llvm/ADT/TypeSwitch.h
index 892a7d43b3174..cc69f76594a20 100644
--- a/llvm/include/llvm/ADT/TypeSwitch.h
+++ b/llvm/include/llvm/ADT/TypeSwitch.h
@@ -125,20 +125,19 @@ class TypeSwitch : public detail::TypeSwitchBase<TypeSwitch<T, ResultT>, T> {
 
   /// As a default, invoke the given callable within the root value.
   template <typename CallableT>
-  LLVM_NODISCARD ResultT Default(CallableT &&defaultFn) {
+  [[nodiscard]] ResultT Default(CallableT &&defaultFn) {
     if (result)
       return std::move(*result);
     return defaultFn(this->value);
   }
   /// As a default, return the given value.
-  LLVM_NODISCARD ResultT Default(ResultT defaultResult) {
+  [[nodiscard]] ResultT Default(ResultT defaultResult) {
     if (result)
       return std::move(*result);
     return defaultResult;
   }
 
-  LLVM_NODISCARD
-  operator ResultT() {
+  [[nodiscard]] operator ResultT() {
     assert(result && "Fell off the end of a type-switch");
     return std::move(*result);
   }

diff  --git a/llvm/include/llvm/ADT/simple_ilist.h b/llvm/include/llvm/ADT/simple_ilist.h
index d4b6be3472191..3a96e1ba56575 100644
--- a/llvm/include/llvm/ADT/simple_ilist.h
+++ b/llvm/include/llvm/ADT/simple_ilist.h
@@ -128,12 +128,10 @@ class simple_ilist
   }
 
   /// Check if the list is empty in constant time.
-  LLVM_NODISCARD bool empty() const { return Sentinel.empty(); }
+  [[nodiscard]] bool empty() const { return Sentinel.empty(); }
 
   /// Calculate the size of the list in linear time.
-  LLVM_NODISCARD size_type size() const {
-    return std::distance(begin(), end());
-  }
+  [[nodiscard]] size_type size() const { return std::distance(begin(), end()); }
 
   reference front() { return *begin(); }
   const_reference front() const { return *begin(); }

diff  --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h
index 65d7d5bd3f223..47c5d6b9834c9 100644
--- a/llvm/include/llvm/Analysis/AliasAnalysis.h
+++ b/llvm/include/llvm/Analysis/AliasAnalysis.h
@@ -155,46 +155,44 @@ enum class ModRefInfo : uint8_t {
   LLVM_MARK_AS_BITMASK_ENUM(ModRef),
 };
 
-LLVM_NODISCARD inline bool isNoModRef(const ModRefInfo MRI) {
+[[nodiscard]] inline bool isNoModRef(const ModRefInfo MRI) {
   return MRI == ModRefInfo::NoModRef;
 }
-LLVM_NODISCARD inline bool isModOrRefSet(const ModRefInfo MRI) {
+[[nodiscard]] inline bool isModOrRefSet(const ModRefInfo MRI) {
   return MRI != ModRefInfo::NoModRef;
 }
-LLVM_NODISCARD inline bool isModAndRefSet(const ModRefInfo MRI) {
+[[nodiscard]] inline bool isModAndRefSet(const ModRefInfo MRI) {
   return MRI == ModRefInfo::ModRef;
 }
-LLVM_NODISCARD inline bool isModSet(const ModRefInfo MRI) {
+[[nodiscard]] inline bool isModSet(const ModRefInfo MRI) {
   return static_cast<int>(MRI) & static_cast<int>(ModRefInfo::Mod);
 }
-LLVM_NODISCARD inline bool isRefSet(const ModRefInfo MRI) {
+[[nodiscard]] inline bool isRefSet(const ModRefInfo MRI) {
   return static_cast<int>(MRI) & static_cast<int>(ModRefInfo::Ref);
 }
 
-[[deprecated("Use operator | instead")]]
-LLVM_NODISCARD inline ModRefInfo setMod(const ModRefInfo MRI) {
+[[deprecated("Use operator | instead")]] [[nodiscard]] inline ModRefInfo
+setMod(const ModRefInfo MRI) {
   return MRI | ModRefInfo::Mod;
 }
-[[deprecated("Use operator | instead")]]
-LLVM_NODISCARD inline ModRefInfo setRef(const ModRefInfo MRI) {
+[[deprecated("Use operator | instead")]] [[nodiscard]] inline ModRefInfo
+setRef(const ModRefInfo MRI) {
   return MRI | ModRefInfo::Ref;
 }
-[[deprecated("Use operator & instead")]]
-LLVM_NODISCARD inline ModRefInfo clearMod(const ModRefInfo MRI) {
+[[deprecated("Use operator & instead")]] [[nodiscard]] inline ModRefInfo
+clearMod(const ModRefInfo MRI) {
   return MRI & ModRefInfo::Ref;
 }
-[[deprecated("Use operator & instead")]]
-LLVM_NODISCARD inline ModRefInfo clearRef(const ModRefInfo MRI) {
+[[deprecated("Use operator & instead")]] [[nodiscard]] inline ModRefInfo
+clearRef(const ModRefInfo MRI) {
   return MRI & ModRefInfo::Mod;
 }
-[[deprecated("Use operator | instead")]]
-LLVM_NODISCARD inline ModRefInfo unionModRef(const ModRefInfo MRI1,
-                                             const ModRefInfo MRI2) {
+[[deprecated("Use operator | instead")]] [[nodiscard]] inline ModRefInfo
+unionModRef(const ModRefInfo MRI1, const ModRefInfo MRI2) {
   return MRI1 | MRI2;
 }
-[[deprecated("Use operator & instead")]]
-LLVM_NODISCARD inline ModRefInfo intersectModRef(const ModRefInfo MRI1,
-                                                 const ModRefInfo MRI2) {
+[[deprecated("Use operator & instead")]] [[nodiscard]] inline ModRefInfo
+intersectModRef(const ModRefInfo MRI1, const ModRefInfo MRI2) {
   return MRI1 & MRI2;
 }
 
@@ -333,7 +331,7 @@ enum FunctionModRefBehavior {
 // to obtain a valid ModRefInfo. The benefit of using the wrapper is that if
 // ModRefInfo enum changes, the wrapper can be updated to & with the new enum
 // entry with all bits set to 1.
-LLVM_NODISCARD inline ModRefInfo
+[[nodiscard]] inline ModRefInfo
 createModRefInfo(const FunctionModRefBehavior FMRB) {
   return ModRefInfo(FMRB & static_cast<int>(ModRefInfo::ModRef));
 }

diff  --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 987b146cda62f..0de9ba7a4b8f3 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -348,7 +348,7 @@ class SCEVWrapPredicate final : public SCEVPredicate {
   };
 
   /// Convenient IncrementWrapFlags manipulation methods.
-  LLVM_NODISCARD static SCEVWrapPredicate::IncrementWrapFlags
+  [[nodiscard]] static SCEVWrapPredicate::IncrementWrapFlags
   clearFlags(SCEVWrapPredicate::IncrementWrapFlags Flags,
              SCEVWrapPredicate::IncrementWrapFlags OffFlags) {
     assert((Flags & IncrementNoWrapMask) == Flags && "Invalid flags value!");
@@ -357,7 +357,7 @@ class SCEVWrapPredicate final : public SCEVPredicate {
     return (SCEVWrapPredicate::IncrementWrapFlags)(Flags & ~OffFlags);
   }
 
-  LLVM_NODISCARD static SCEVWrapPredicate::IncrementWrapFlags
+  [[nodiscard]] static SCEVWrapPredicate::IncrementWrapFlags
   maskFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, int Mask) {
     assert((Flags & IncrementNoWrapMask) == Flags && "Invalid flags value!");
     assert((Mask & IncrementNoWrapMask) == Mask && "Invalid mask value!");
@@ -365,7 +365,7 @@ class SCEVWrapPredicate final : public SCEVPredicate {
     return (SCEVWrapPredicate::IncrementWrapFlags)(Flags & Mask);
   }
 
-  LLVM_NODISCARD static SCEVWrapPredicate::IncrementWrapFlags
+  [[nodiscard]] static SCEVWrapPredicate::IncrementWrapFlags
   setFlags(SCEVWrapPredicate::IncrementWrapFlags Flags,
            SCEVWrapPredicate::IncrementWrapFlags OnFlags) {
     assert((Flags & IncrementNoWrapMask) == Flags && "Invalid flags value!");
@@ -377,7 +377,7 @@ class SCEVWrapPredicate final : public SCEVPredicate {
 
   /// Returns the set of SCEVWrapPredicate no wrap flags implied by a
   /// SCEVAddRecExpr.
-  LLVM_NODISCARD static SCEVWrapPredicate::IncrementWrapFlags
+  [[nodiscard]] static SCEVWrapPredicate::IncrementWrapFlags
   getImpliedFlags(const SCEVAddRecExpr *AR, ScalarEvolution &SE);
 
 private:
@@ -466,20 +466,20 @@ class ScalarEvolution {
 
   /// Convenient NoWrapFlags manipulation that hides enum casts and is
   /// visible in the ScalarEvolution name space.
-  LLVM_NODISCARD static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags,
-                                                    int Mask) {
+  [[nodiscard]] static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags,
+                                                   int Mask) {
     return (SCEV::NoWrapFlags)(Flags & Mask);
   }
-  LLVM_NODISCARD static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags,
-                                                   SCEV::NoWrapFlags OnFlags) {
+  [[nodiscard]] static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags,
+                                                  SCEV::NoWrapFlags OnFlags) {
     return (SCEV::NoWrapFlags)(Flags | OnFlags);
   }
-  LLVM_NODISCARD static SCEV::NoWrapFlags
+  [[nodiscard]] static SCEV::NoWrapFlags
   clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags) {
     return (SCEV::NoWrapFlags)(Flags & ~OffFlags);
   }
-  LLVM_NODISCARD static bool hasFlags(SCEV::NoWrapFlags Flags,
-                                      SCEV::NoWrapFlags TestFlags) {
+  [[nodiscard]] static bool hasFlags(SCEV::NoWrapFlags Flags,
+                                     SCEV::NoWrapFlags TestFlags) {
     return TestFlags == maskFlags(Flags, TestFlags);
   };
 

diff  --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index fc1188186ac4e..d0ca7733633bc 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -1055,7 +1055,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
     return FrameInstructions;
   }
 
-  LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst);
+  [[nodiscard]] unsigned addFrameInst(const MCCFIInstruction &Inst);
 
   /// Returns a reference to a list of symbols immediately following calls to
   /// _setjmp in the function. Used to construct the longjmp target table used

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h b/llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h
index d4960ab8b0bbf..c0df69ffcd882 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h
@@ -37,7 +37,7 @@ class ThreadSafeContext {
 
 public:
   // RAII based lock for ThreadSafeContext.
-  class LLVM_NODISCARD Lock {
+  class [[nodiscard]] Lock {
   public:
     Lock(std::shared_ptr<State> S) : S(std::move(S)), L(this->S->Mutex) {}
 

diff  --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 6a4e6d63a973a..0657cfdb2e884 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -315,32 +315,32 @@ class AttributeSet {
 
   /// Add an argument attribute. Returns a new set because attribute sets are
   /// immutable.
-  LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C,
-                                           Attribute::AttrKind Kind) const;
+  [[nodiscard]] AttributeSet addAttribute(LLVMContext &C,
+                                          Attribute::AttrKind Kind) const;
 
   /// Add a target-dependent attribute. Returns a new set because attribute sets
   /// are immutable.
-  LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C, StringRef Kind,
-                                           StringRef Value = StringRef()) const;
+  [[nodiscard]] AttributeSet addAttribute(LLVMContext &C, StringRef Kind,
+                                          StringRef Value = StringRef()) const;
 
   /// Add attributes to the attribute set. Returns a new set because attribute
   /// sets are immutable.
-  LLVM_NODISCARD AttributeSet addAttributes(LLVMContext &C,
-                                            AttributeSet AS) const;
+  [[nodiscard]] AttributeSet addAttributes(LLVMContext &C,
+                                           AttributeSet AS) const;
 
   /// Remove the specified attribute from this set. Returns a new set because
   /// attribute sets are immutable.
-  LLVM_NODISCARD AttributeSet removeAttribute(LLVMContext &C,
-                                              Attribute::AttrKind Kind) const;
+  [[nodiscard]] AttributeSet removeAttribute(LLVMContext &C,
+                                             Attribute::AttrKind Kind) const;
 
   /// Remove the specified attribute from this set. Returns a new set because
   /// attribute sets are immutable.
-  LLVM_NODISCARD AttributeSet removeAttribute(LLVMContext &C,
-                                              StringRef Kind) const;
+  [[nodiscard]] AttributeSet removeAttribute(LLVMContext &C,
+                                             StringRef Kind) const;
 
   /// Remove the specified attributes from this set. Returns a new set because
   /// attribute sets are immutable.
-  LLVM_NODISCARD AttributeSet
+  [[nodiscard]] AttributeSet
   removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const;
 
   /// Return the number of attributes in this set.
@@ -486,86 +486,88 @@ class AttributeList {
   // TODO: remove non-AtIndex versions of these methods.
   /// Add an attribute to the attribute set at the given index.
   /// Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addAttributeAtIndex(
-      LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const;
+  [[nodiscard]] AttributeList
+  addAttributeAtIndex(LLVMContext &C, unsigned Index,
+                      Attribute::AttrKind Kind) const;
 
   /// Add an attribute to the attribute set at the given index.
   /// Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   addAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind,
                       StringRef Value = StringRef()) const;
 
   /// Add an attribute to the attribute set at the given index.
   /// Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addAttributeAtIndex(LLVMContext &C,
-                                                   unsigned Index,
-                                                   Attribute A) const;
+  [[nodiscard]] AttributeList
+  addAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute A) const;
 
   /// Add attributes to the attribute set at the given index.
   /// Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addAttributesAtIndex(LLVMContext &C,
-                                                    unsigned Index,
-                                                    const AttrBuilder &B) const;
+  [[nodiscard]] AttributeList addAttributesAtIndex(LLVMContext &C,
+                                                   unsigned Index,
+                                                   const AttrBuilder &B) const;
 
   /// Add a function attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addFnAttribute(LLVMContext &C,
-                                              Attribute::AttrKind Kind) const {
+  [[nodiscard]] AttributeList addFnAttribute(LLVMContext &C,
+                                             Attribute::AttrKind Kind) const {
     return addAttributeAtIndex(C, FunctionIndex, Kind);
   }
 
   /// Add a function attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addFnAttribute(LLVMContext &C,
-                                              Attribute Attr) const {
+  [[nodiscard]] AttributeList addFnAttribute(LLVMContext &C,
+                                             Attribute Attr) const {
     return addAttributeAtIndex(C, FunctionIndex, Attr);
   }
 
   /// Add a function attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addFnAttribute(
-      LLVMContext &C, StringRef Kind, StringRef Value = StringRef()) const {
+  [[nodiscard]] AttributeList
+  addFnAttribute(LLVMContext &C, StringRef Kind,
+                 StringRef Value = StringRef()) const {
     return addAttributeAtIndex(C, FunctionIndex, Kind, Value);
   }
 
   /// Add function attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addFnAttributes(LLVMContext &C,
-                                               const AttrBuilder &B) const {
+  [[nodiscard]] AttributeList addFnAttributes(LLVMContext &C,
+                                              const AttrBuilder &B) const {
     return addAttributesAtIndex(C, FunctionIndex, B);
   }
 
   /// Add a return value attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addRetAttribute(LLVMContext &C,
-                                               Attribute::AttrKind Kind) const {
+  [[nodiscard]] AttributeList addRetAttribute(LLVMContext &C,
+                                              Attribute::AttrKind Kind) const {
     return addAttributeAtIndex(C, ReturnIndex, Kind);
   }
 
   /// Add a return value attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addRetAttribute(LLVMContext &C,
-                                               Attribute Attr) const {
+  [[nodiscard]] AttributeList addRetAttribute(LLVMContext &C,
+                                              Attribute Attr) const {
     return addAttributeAtIndex(C, ReturnIndex, Attr);
   }
 
   /// Add a return value attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addRetAttributes(LLVMContext &C,
-                                                const AttrBuilder &B) const {
+  [[nodiscard]] AttributeList addRetAttributes(LLVMContext &C,
+                                               const AttrBuilder &B) const {
     return addAttributesAtIndex(C, ReturnIndex, B);
   }
 
   /// Add an argument attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addParamAttribute(
-      LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const {
+  [[nodiscard]] AttributeList
+  addParamAttribute(LLVMContext &C, unsigned ArgNo,
+                    Attribute::AttrKind Kind) const {
     return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
   }
 
   /// Add an argument attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind,
                     StringRef Value = StringRef()) const {
     return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind, Value);
@@ -573,109 +575,110 @@ class AttributeList {
 
   /// Add an attribute to the attribute list at the given arg indices. Returns a
   /// new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C,
-                                                 ArrayRef<unsigned> ArgNos,
-                                                 Attribute A) const;
+  [[nodiscard]] AttributeList addParamAttribute(LLVMContext &C,
+                                                ArrayRef<unsigned> ArgNos,
+                                                Attribute A) const;
 
   /// Add an argument attribute to the list. Returns a new list because
   /// attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addParamAttributes(LLVMContext &C,
-                                                  unsigned ArgNo,
-                                                  const AttrBuilder &B) const {
+  [[nodiscard]] AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo,
+                                                 const AttrBuilder &B) const {
     return addAttributesAtIndex(C, ArgNo + FirstArgIndex, B);
   }
 
   /// Remove the specified attribute at the specified index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeAttributeAtIndex(
-      LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const;
+  [[nodiscard]] AttributeList
+  removeAttributeAtIndex(LLVMContext &C, unsigned Index,
+                         Attribute::AttrKind Kind) const;
 
   /// Remove the specified attribute at the specified index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeAttributeAtIndex(LLVMContext &C,
-                                                      unsigned Index,
-                                                      StringRef Kind) const;
-  LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index,
-                                               StringRef Kind) const {
+  [[nodiscard]] AttributeList
+  removeAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind) const;
+  [[nodiscard]] AttributeList removeAttribute(LLVMContext &C, unsigned Index,
+                                              StringRef Kind) const {
     return removeAttributeAtIndex(C, Index, Kind);
   }
 
   /// Remove the specified attributes at the specified index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeAttributesAtIndex(
-      LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const;
+  [[nodiscard]] AttributeList
+  removeAttributesAtIndex(LLVMContext &C, unsigned Index,
+                          const AttributeMask &AttrsToRemove) const;
 
   /// Remove all attributes at the specified index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeAttributesAtIndex(LLVMContext &C,
-                                                       unsigned Index) const;
+  [[nodiscard]] AttributeList removeAttributesAtIndex(LLVMContext &C,
+                                                      unsigned Index) const;
 
   /// Remove the specified attribute at the function index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
     return removeAttributeAtIndex(C, FunctionIndex, Kind);
   }
 
   /// Remove the specified attribute at the function index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeFnAttribute(LLVMContext &C,
-                                                 StringRef Kind) const {
+  [[nodiscard]] AttributeList removeFnAttribute(LLVMContext &C,
+                                                StringRef Kind) const {
     return removeAttributeAtIndex(C, FunctionIndex, Kind);
   }
 
   /// Remove the specified attribute at the function index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   removeFnAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const {
     return removeAttributesAtIndex(C, FunctionIndex, AttrsToRemove);
   }
 
   /// Remove the attributes at the function index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeFnAttributes(LLVMContext &C) const {
+  [[nodiscard]] AttributeList removeFnAttributes(LLVMContext &C) const {
     return removeAttributesAtIndex(C, FunctionIndex);
   }
 
   /// Remove the specified attribute at the return value index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
     return removeAttributeAtIndex(C, ReturnIndex, Kind);
   }
 
   /// Remove the specified attribute at the return value index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeRetAttribute(LLVMContext &C,
-                                                  StringRef Kind) const {
+  [[nodiscard]] AttributeList removeRetAttribute(LLVMContext &C,
+                                                 StringRef Kind) const {
     return removeAttributeAtIndex(C, ReturnIndex, Kind);
   }
 
   /// Remove the specified attribute at the return value index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeRetAttributes(
-      LLVMContext &C, const AttributeMask &AttrsToRemove) const {
+  [[nodiscard]] AttributeList
+  removeRetAttributes(LLVMContext &C,
+                      const AttributeMask &AttrsToRemove) const {
     return removeAttributesAtIndex(C, ReturnIndex, AttrsToRemove);
   }
 
   /// Remove the specified attribute at the specified arg index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeParamAttribute(
-      LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const {
+  [[nodiscard]] AttributeList
+  removeParamAttribute(LLVMContext &C, unsigned ArgNo,
+                       Attribute::AttrKind Kind) const {
     return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
   }
 
   /// Remove the specified attribute at the specified arg index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C,
-                                                    unsigned ArgNo,
-                                                    StringRef Kind) const {
+  [[nodiscard]] AttributeList
+  removeParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind) const {
     return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
   }
 
   /// Remove the specified attribute at the specified arg index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   removeParamAttributes(LLVMContext &C, unsigned ArgNo,
                         const AttributeMask &AttrsToRemove) const {
     return removeAttributesAtIndex(C, ArgNo + FirstArgIndex, AttrsToRemove);
@@ -683,16 +686,17 @@ class AttributeList {
 
   /// Remove all attributes at the specified arg index from this
   /// attribute list. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList removeParamAttributes(LLVMContext &C,
-                                                     unsigned ArgNo) const {
+  [[nodiscard]] AttributeList removeParamAttributes(LLVMContext &C,
+                                                    unsigned ArgNo) const {
     return removeAttributesAtIndex(C, ArgNo + FirstArgIndex);
   }
 
   /// Replace the type contained by attribute \p AttrKind at index \p ArgNo wih
   /// \p ReplacementTy, preserving all other attributes.
-  LLVM_NODISCARD AttributeList replaceAttributeTypeAtIndex(
-      LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind,
-      Type *ReplacementTy) const {
+  [[nodiscard]] AttributeList
+  replaceAttributeTypeAtIndex(LLVMContext &C, unsigned ArgNo,
+                              Attribute::AttrKind Kind,
+                              Type *ReplacementTy) const {
     Attribute Attr = getAttributeAtIndex(ArgNo, Kind);
     auto Attrs = removeAttributeAtIndex(C, ArgNo, Kind);
     return Attrs.addAttributeAtIndex(C, ArgNo,
@@ -701,23 +705,25 @@ class AttributeList {
 
   /// \brief Add the dereferenceable attribute to the attribute set at the given
   /// index. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addDereferenceableRetAttr(LLVMContext &C,
-                                                         uint64_t Bytes) const;
+  [[nodiscard]] AttributeList addDereferenceableRetAttr(LLVMContext &C,
+                                                        uint64_t Bytes) const;
 
   /// \brief Add the dereferenceable attribute to the attribute set at the given
   /// arg index. Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList addDereferenceableParamAttr(
-      LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const;
+  [[nodiscard]] AttributeList addDereferenceableParamAttr(LLVMContext &C,
+                                                          unsigned ArgNo,
+                                                          uint64_t Bytes) const;
 
   /// Add the dereferenceable_or_null attribute to the attribute set at
   /// the given arg index. Returns a new list because attribute lists are
   /// immutable.
-  LLVM_NODISCARD AttributeList addDereferenceableOrNullParamAttr(
-      LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const;
+  [[nodiscard]] AttributeList
+  addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo,
+                                    uint64_t Bytes) const;
 
   /// Add the allocsize attribute to the attribute set at the given arg index.
   /// Returns a new list because attribute lists are immutable.
-  LLVM_NODISCARD AttributeList
+  [[nodiscard]] AttributeList
   addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg,
                         const Optional<unsigned> &NumElemsArg);
 

diff  --git a/llvm/include/llvm/IR/ConstantRange.h b/llvm/include/llvm/IR/ConstantRange.h
index 68abf4ef555da..d2ff971485b38 100644
--- a/llvm/include/llvm/IR/ConstantRange.h
+++ b/llvm/include/llvm/IR/ConstantRange.h
@@ -44,7 +44,7 @@ class raw_ostream;
 struct KnownBits;
 
 /// This class represents a range of values.
-class LLVM_NODISCARD ConstantRange {
+class [[nodiscard]] ConstantRange {
   APInt Lower, Upper;
 
   /// Create empty constant range with same bitwidth.

diff  --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index b6bbff8ada10b..cf9c7c0efbf14 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -545,12 +545,12 @@ struct CastInfo<To, Optional<From>> : public OptionalValueCast<To, From> {};
 ///  if (isa<Type>(myVal)) { ... }
 ///  if (isa<Type0, Type1, Type2>(myVal)) { ... }
 template <typename To, typename From>
-LLVM_NODISCARD inline bool isa(const From &Val) {
+[[nodiscard]] inline bool isa(const From &Val) {
   return CastInfo<To, const From>::isPossible(Val);
 }
 
 template <typename First, typename Second, typename... Rest, typename From>
-LLVM_NODISCARD inline bool isa(const From &Val) {
+[[nodiscard]] inline bool isa(const From &Val) {
   return isa<First>(Val) || isa<Second, Rest...>(Val);
 }
 
@@ -562,25 +562,25 @@ LLVM_NODISCARD inline bool isa(const From &Val) {
 ///  cast<Instruction>(myVal)->getParent()
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) cast(const From &Val) {
+[[nodiscard]] inline decltype(auto) cast(const From &Val) {
   assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, const From>::doCast(Val);
 }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) cast(From &Val) {
+[[nodiscard]] inline decltype(auto) cast(From &Val) {
   assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, From>::doCast(Val);
 }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) cast(From *Val) {
+[[nodiscard]] inline decltype(auto) cast(From *Val) {
   assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, From *>::doCast(Val);
 }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) cast(std::unique_ptr<From> &&Val) {
+[[nodiscard]] inline decltype(auto) cast(std::unique_ptr<From> &&Val) {
   assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, std::unique_ptr<From>>::doCast(std::move(Val));
 }
@@ -594,22 +594,22 @@ LLVM_NODISCARD inline decltype(auto) cast(std::unique_ptr<From> &&Val) {
 ///  if (const Instruction *I = dyn_cast<Instruction>(myVal)) { ... }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) dyn_cast(const From &Val) {
+[[nodiscard]] inline decltype(auto) dyn_cast(const From &Val) {
   return CastInfo<To, const From>::doCastIfPossible(Val);
 }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) dyn_cast(From &Val) {
+[[nodiscard]] inline decltype(auto) dyn_cast(From &Val) {
   return CastInfo<To, From>::doCastIfPossible(Val);
 }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) dyn_cast(From *Val) {
+[[nodiscard]] inline decltype(auto) dyn_cast(From *Val) {
   return CastInfo<To, From *>::doCastIfPossible(Val);
 }
 
 template <typename To, typename From>
-LLVM_NODISCARD inline decltype(auto) dyn_cast(std::unique_ptr<From> &&Val) {
+[[nodiscard]] inline decltype(auto) dyn_cast(std::unique_ptr<From> &&Val) {
   return CastInfo<To, std::unique_ptr<From>>::doCastIfPossible(std::move(Val));
 }
 
@@ -667,35 +667,35 @@ template <typename T> inline decltype(auto) unwrapValue(T &t) {
 /// isa_and_present<X> - Functionally identical to isa, except that a null value
 /// is accepted.
 template <typename... X, class Y>
-LLVM_NODISCARD inline bool isa_and_present(const Y &Val) {
+[[nodiscard]] inline bool isa_and_present(const Y &Val) {
   if (!detail::isPresent(Val))
     return false;
   return isa<X...>(Val);
 }
 
 template <typename... X, class Y>
-LLVM_NODISCARD inline bool isa_and_nonnull(const Y &Val) {
+[[nodiscard]] inline bool isa_and_nonnull(const Y &Val) {
   return isa_and_present<X...>(Val);
 }
 
 /// cast_if_present<X> - Functionally identical to cast, except that a null
 /// value is accepted.
 template <class X, class Y>
-LLVM_NODISCARD inline auto cast_if_present(const Y &Val) {
+[[nodiscard]] inline auto cast_if_present(const Y &Val) {
   if (!detail::isPresent(Val))
     return CastInfo<X, const Y>::castFailed();
   assert(isa<X>(Val) && "cast_if_present<Ty>() argument of incompatible type!");
   return cast<X>(detail::unwrapValue(Val));
 }
 
-template <class X, class Y> LLVM_NODISCARD inline auto cast_if_present(Y &Val) {
+template <class X, class Y> [[nodiscard]] inline auto cast_if_present(Y &Val) {
   if (!detail::isPresent(Val))
     return CastInfo<X, Y>::castFailed();
   assert(isa<X>(Val) && "cast_if_present<Ty>() argument of incompatible type!");
   return cast<X>(detail::unwrapValue(Val));
 }
 
-template <class X, class Y> LLVM_NODISCARD inline auto cast_if_present(Y *Val) {
+template <class X, class Y> [[nodiscard]] inline auto cast_if_present(Y *Val) {
   if (!detail::isPresent(Val))
     return CastInfo<X, Y *>::castFailed();
   assert(isa<X>(Val) && "cast_if_present<Ty>() argument of incompatible type!");
@@ -703,7 +703,7 @@ template <class X, class Y> LLVM_NODISCARD inline auto cast_if_present(Y *Val) {
 }
 
 template <class X, class Y>
-LLVM_NODISCARD inline auto cast_if_present(std::unique_ptr<Y> &&Val) {
+[[nodiscard]] inline auto cast_if_present(std::unique_ptr<Y> &&Val) {
   if (!detail::isPresent(Val))
     return UniquePtrCast<X, Y>::castFailed();
   return UniquePtrCast<X, Y>::doCast(std::move(Val));
@@ -769,7 +769,7 @@ template <class X, class Y> auto dyn_cast_or_null(Y *Val) {
 /// is returned.  If the cast is unsuccessful, the function returns nullptr
 /// and From is unchanged.
 template <class X, class Y>
-LLVM_NODISCARD inline typename CastInfo<X, std::unique_ptr<Y>>::CastResultType
+[[nodiscard]] inline typename CastInfo<X, std::unique_ptr<Y>>::CastResultType
 unique_dyn_cast(std::unique_ptr<Y> &Val) {
   if (!isa<X>(Val))
     return nullptr;
@@ -777,14 +777,14 @@ unique_dyn_cast(std::unique_ptr<Y> &Val) {
 }
 
 template <class X, class Y>
-LLVM_NODISCARD inline auto unique_dyn_cast(std::unique_ptr<Y> &&Val) {
+[[nodiscard]] inline auto unique_dyn_cast(std::unique_ptr<Y> &&Val) {
   return unique_dyn_cast<X, Y>(Val);
 }
 
 // unique_dyn_cast_or_null<X> - Functionally identical to unique_dyn_cast,
 // except that a null value is accepted.
 template <class X, class Y>
-LLVM_NODISCARD inline typename CastInfo<X, std::unique_ptr<Y>>::CastResultType
+[[nodiscard]] inline typename CastInfo<X, std::unique_ptr<Y>>::CastResultType
 unique_dyn_cast_or_null(std::unique_ptr<Y> &Val) {
   if (!Val)
     return nullptr;
@@ -792,7 +792,7 @@ unique_dyn_cast_or_null(std::unique_ptr<Y> &Val) {
 }
 
 template <class X, class Y>
-LLVM_NODISCARD inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &&Val) {
+[[nodiscard]] inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &&Val) {
   return unique_dyn_cast_or_null<X, Y>(Val);
 }
 

diff  --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index f2d3388a328f4..fe56341b3083e 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -152,7 +152,7 @@ class ErrorInfoBase {
 /// *All* Error instances must be checked before destruction, even if
 /// they're moved-assigned or constructed from Success values that have already
 /// been checked. This enforces checking through all levels of the call stack.
-class LLVM_NODISCARD Error {
+class [[nodiscard]] Error {
   // ErrorList needs to be able to yank ErrorInfoBase pointers out of Errors
   // to add to the error list. It can't rely on handleErrors for this, since
   // handleErrors does not support ErrorList handlers.
@@ -466,7 +466,7 @@ inline Error joinErrors(Error E1, Error E2) {
 ///  For unit-testing a function returning an 'Expceted<T>', see the
 ///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
 
-template <class T> class LLVM_NODISCARD Expected {
+template <class T> class [[nodiscard]] Expected {
   template <class T1> friend class ExpectedAsOutParameter;
   template <class OtherT> friend class Expected;
 

diff  --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index f025cde4a16bc..b0f06ba4e223b 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -36,7 +36,7 @@ class format_object_base;
 class FormattedString;
 class FormattedNumber;
 class FormattedBytes;
-template <class T> class LLVM_NODISCARD Expected;
+template <class T> class [[nodiscard]] Expected;
 
 namespace sys {
 namespace fs {
@@ -565,7 +565,7 @@ class raw_fd_ostream : public raw_pwrite_stream {
   ///     });
   ///   }
   ///   @endcode
-  LLVM_NODISCARD Expected<sys::fs::FileLocker> lock();
+  [[nodiscard]] Expected<sys::fs::FileLocker> lock();
 
   /// Tries to lock the underlying file within the specified period.
   ///
@@ -574,8 +574,8 @@ class raw_fd_ostream : public raw_pwrite_stream {
   ///          error code.
   ///
   /// It is used as @ref lock.
-  LLVM_NODISCARD
-  Expected<sys::fs::FileLocker> tryLockFor(Duration const& Timeout);
+  [[nodiscard]] Expected<sys::fs::FileLocker>
+  tryLockFor(Duration const &Timeout);
 };
 
 /// This returns a reference to a raw_fd_ostream for standard output. Use it

diff  --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 6b481a3743821..d2c224898fe23 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -306,7 +306,7 @@ bool MachineFunction::shouldSplitStack() const {
   return getFunction().hasFnAttribute("split-stack");
 }
 
-LLVM_NODISCARD unsigned
+[[nodiscard]] unsigned
 MachineFunction::addFrameInst(const MCCFIInstruction &Inst) {
   FrameInstructions.push_back(Inst);
   return FrameInstructions.size() - 1;

diff  --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp
index 4f8b6b241a762..aac98cf924e10 100644
--- a/llvm/lib/CodeGen/RegisterCoalescer.cpp
+++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp
@@ -418,24 +418,24 @@ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
 INITIALIZE_PASS_END(RegisterCoalescer, "simple-register-coalescing",
                     "Simple Register Coalescing", false, false)
 
-LLVM_NODISCARD static bool isMoveInstr(const TargetRegisterInfo &tri,
-                                       const MachineInstr *MI, Register &Src,
-                                       Register &Dst, unsigned &SrcSub,
-                                       unsigned &DstSub) {
-  if (MI->isCopy()) {
-    Dst = MI->getOperand(0).getReg();
-    DstSub = MI->getOperand(0).getSubReg();
-    Src = MI->getOperand(1).getReg();
-    SrcSub = MI->getOperand(1).getSubReg();
-  } else if (MI->isSubregToReg()) {
-    Dst = MI->getOperand(0).getReg();
-    DstSub = tri.composeSubRegIndices(MI->getOperand(0).getSubReg(),
-                                      MI->getOperand(3).getImm());
-    Src = MI->getOperand(2).getReg();
-    SrcSub = MI->getOperand(2).getSubReg();
-  } else
-    return false;
-  return true;
+[[nodiscard]] static bool isMoveInstr(const TargetRegisterInfo &tri,
+                                      const MachineInstr *MI, Register &Src,
+                                      Register &Dst, unsigned &SrcSub,
+                                      unsigned &DstSub) {
+    if (MI->isCopy()) {
+      Dst = MI->getOperand(0).getReg();
+      DstSub = MI->getOperand(0).getSubReg();
+      Src = MI->getOperand(1).getReg();
+      SrcSub = MI->getOperand(1).getSubReg();
+    } else if (MI->isSubregToReg()) {
+      Dst = MI->getOperand(0).getReg();
+      DstSub = tri.composeSubRegIndices(MI->getOperand(0).getSubReg(),
+                                        MI->getOperand(3).getImm());
+      Src = MI->getOperand(2).getReg();
+      SrcSub = MI->getOperand(2).getSubReg();
+    } else
+      return false;
+    return true;
 }
 
 /// Return true if this block should be vacated by the coalescer to eliminate

diff  --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 627886316730b..5b0e0cba13a71 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -449,8 +449,8 @@ class FrameTypeBuilder {
 
   /// Add a field to this structure for the storage of an `alloca`
   /// instruction.
-  LLVM_NODISCARD FieldIDType addFieldForAlloca(AllocaInst *AI,
-                                               bool IsHeader = false) {
+  [[nodiscard]] FieldIDType addFieldForAlloca(AllocaInst *AI,
+                                              bool IsHeader = false) {
     Type *Ty = AI->getAllocatedType();
 
     // Make an array type if this is a static array allocation.
@@ -495,9 +495,9 @@ class FrameTypeBuilder {
                           coro::Shape &Shape);
 
   /// Add a field to this structure.
-  LLVM_NODISCARD FieldIDType addField(Type *Ty, MaybeAlign MaybeFieldAlignment,
-                                      bool IsHeader = false,
-                                      bool IsSpillOfValue = false) {
+  [[nodiscard]] FieldIDType addField(Type *Ty, MaybeAlign MaybeFieldAlignment,
+                                     bool IsHeader = false,
+                                     bool IsSpillOfValue = false) {
     assert(!IsFinished && "adding fields to a finished builder");
     assert(Ty && "must provide a type for a field");
 

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index cb533908e3fe9..544838de2622b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -792,13 +792,13 @@ class Negator final {
 
   std::array<Value *, 2> getSortedOperandsOfBinOp(Instruction *I);
 
-  LLVM_NODISCARD Value *visitImpl(Value *V, unsigned Depth);
+  [[nodiscard]] Value *visitImpl(Value *V, unsigned Depth);
 
-  LLVM_NODISCARD Value *negate(Value *V, unsigned Depth);
+  [[nodiscard]] Value *negate(Value *V, unsigned Depth);
 
   /// Recurse depth-first and attempt to sink the negation.
   /// FIXME: use worklist?
-  LLVM_NODISCARD Optional<Result> run(Value *Root);
+  [[nodiscard]] Optional<Result> run(Value *Root);
 
   Negator(const Negator &) = delete;
   Negator(Negator &&) = delete;
@@ -808,8 +808,8 @@ class Negator final {
 public:
   /// Attempt to negate \p Root. Retuns nullptr if negation can't be performed,
   /// otherwise returns negated value.
-  LLVM_NODISCARD static Value *Negate(bool LHSIsZero, Value *Root,
-                                      InstCombinerImpl &IC);
+  [[nodiscard]] static Value *Negate(bool LHSIsZero, Value *Root,
+                                     InstCombinerImpl &IC);
 };
 
 } // end namespace llvm

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
index c573b03f31a62..a3e0c45269ed6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
@@ -130,7 +130,7 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
 
 // FIXME: can this be reworked into a worklist-based algorithm while preserving
 // the depth-first, early bailout traversal?
-LLVM_NODISCARD Value *Negator::visitImpl(Value *V, unsigned Depth) {
+[[nodiscard]] Value *Negator::visitImpl(Value *V, unsigned Depth) {
   // -(undef) -> undef.
   if (match(V, m_Undef()))
     return V;
@@ -465,7 +465,7 @@ LLVM_NODISCARD Value *Negator::visitImpl(Value *V, unsigned Depth) {
   llvm_unreachable("Can't get here. We always return from switch.");
 }
 
-LLVM_NODISCARD Value *Negator::negate(Value *V, unsigned Depth) {
+[[nodiscard]] Value *Negator::negate(Value *V, unsigned Depth) {
   NegatorMaxDepthVisited.updateMax(Depth);
   ++NegatorNumValuesVisited;
 
@@ -502,7 +502,7 @@ LLVM_NODISCARD Value *Negator::negate(Value *V, unsigned Depth) {
   return NegatedV;
 }
 
-LLVM_NODISCARD Optional<Negator::Result> Negator::run(Value *Root) {
+[[nodiscard]] Optional<Negator::Result> Negator::run(Value *Root) {
   Value *Negated = negate(Root, /*Depth=*/0);
   if (!Negated) {
     // We must cleanup newly-inserted instructions, to avoid any potential
@@ -514,8 +514,8 @@ LLVM_NODISCARD Optional<Negator::Result> Negator::run(Value *Root) {
   return std::make_pair(ArrayRef<Instruction *>(NewInstructions), Negated);
 }
 
-LLVM_NODISCARD Value *Negator::Negate(bool LHSIsZero, Value *Root,
-                                      InstCombinerImpl &IC) {
+[[nodiscard]] Value *Negator::Negate(bool LHSIsZero, Value *Root,
+                                     InstCombinerImpl &IC) {
   ++NegatorTotalNegationsAttempted;
   LLVM_DEBUG(dbgs() << "Negator: attempting to sink negation into " << *Root
                     << "\n");

diff  --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index 758398daeeebc..e04265eb0813a 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -22,7 +22,7 @@
 using namespace llvm;
 using namespace coverage;
 
-LLVM_NODISCARD static ::testing::AssertionResult
+[[nodiscard]] static ::testing::AssertionResult
 ErrorEquals(coveragemap_error Expected, Error E) {
   coveragemap_error Found;
   std::string FoundMsg;

diff  --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 6f11a2e626220..86a049223eeb0 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -23,7 +23,7 @@
 
 using namespace llvm;
 
-LLVM_NODISCARD static ::testing::AssertionResult
+[[nodiscard]] static ::testing::AssertionResult
 ErrorEquals(instrprof_error Expected, Error E) {
   instrprof_error Found;
   std::string FoundMsg;


        


More information about the llvm-commits mailing list