[llvm] r342949 - Add macro LLVM_ATTRIBUTE_REINITIALIZES

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 25 01:06:32 PDT 2018


Author: maskray
Date: Tue Sep 25 01:06:32 2018
New Revision: 342949

URL: http://llvm.org/viewvc/llvm-project?rev=342949&view=rev
Log:
Add macro LLVM_ATTRIBUTE_REINITIALIZES

Summary:
This marks legitimate use-after-move (e.g. `Found.clear()` in rC342925)
which would otherwise be caught by bugprone-use-after-move.

bugprone-use-after-move recognizes this attribute after rCTE339571.

Reviewers: aaron.ballman, rsmith, mboehme, hokein

Reviewed By: mboehme

Subscribers: kristina, llvm-commits

Differential Revision: https://reviews.llvm.org/D52451

Modified:
    llvm/trunk/include/llvm/Support/Compiler.h

Modified: llvm/trunk/include/llvm/Support/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=342949&r1=342948&r2=342949&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h (original)
+++ llvm/trunk/include/llvm/Support/Compiler.h Tue Sep 25 01:06:32 2018
@@ -133,6 +133,19 @@
 #define LLVM_NODISCARD
 #endif
 
+// Indicate that a non-static, non-const C++ member function reinitializes
+// the entire object to a known state, independent of the previous state of
+// the object.
+//
+// The clang-tidy check bugprone-use-after-move recognizes this attribute as a
+// marker that a moved-from object has left the indeterminate state and can be
+// reused.
+#if __has_cpp_attribute(clang::reinitializes)
+#define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
+#else
+#define LLVM_ATTRIBUTE_REINITIALIZES
+#endif
+
 // Some compilers warn about unused functions. When a function is sometimes
 // used or not depending on build settings (e.g. a function only called from
 // within "assert"), this attribute can be used to suppress such warnings.




More information about the llvm-commits mailing list