[llvm] r295243 - [Support] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Eugene Zelenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 14:17:03 PST 2017
Author: eugenezelenko
Date: Wed Feb 15 16:17:02 2017
New Revision: 295243
URL: http://llvm.org/viewvc/llvm-project?rev=295243&view=rev
Log:
[Support] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Modified:
llvm/trunk/include/llvm/Support/MD5.h
llvm/trunk/include/llvm/Support/RWMutex.h
llvm/trunk/include/llvm/Support/SMLoc.h
llvm/trunk/include/llvm/Support/SourceMgr.h
llvm/trunk/include/llvm/Support/UniqueLock.h
llvm/trunk/lib/Support/MD5.cpp
llvm/trunk/lib/Support/RWMutex.cpp
llvm/trunk/lib/Support/SourceMgr.cpp
Modified: llvm/trunk/include/llvm/Support/MD5.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MD5.h?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MD5.h (original)
+++ llvm/trunk/include/llvm/Support/MD5.h Wed Feb 15 16:17:02 2017
@@ -1,4 +1,4 @@
-/*
+/* -*- C++ -*-
* This code is derived from (original license follows):
*
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
@@ -29,19 +29,25 @@
#define LLVM_SUPPORT_MD5_H
#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Endian.h"
#include <array>
+#include <cstdint>
namespace llvm {
+
template <typename T> class ArrayRef;
class MD5 {
// Any 32-bit or wider unsigned integer data type will do.
typedef uint32_t MD5_u32plus;
- MD5_u32plus a, b, c, d;
- MD5_u32plus hi, lo;
+ MD5_u32plus a = 0x67452301;
+ MD5_u32plus b = 0xefcdab89;
+ MD5_u32plus c = 0x98badcfe;
+ MD5_u32plus d = 0x10325476;
+ MD5_u32plus hi = 0;
+ MD5_u32plus lo = 0;
uint8_t buffer[64];
MD5_u32plus block[16];
@@ -72,16 +78,17 @@ private:
/// Helper to compute and return lower 64 bits of the given string's MD5 hash.
inline uint64_t MD5Hash(StringRef Str) {
+ using namespace support;
+
MD5 Hash;
Hash.update(Str);
- llvm::MD5::MD5Result Result;
+ MD5::MD5Result Result;
Hash.final(Result);
// Return the least significant 8 bytes. Our MD5 implementation returns the
// result in little endian, so we may need to swap bytes.
- using namespace llvm::support;
return endian::read<uint64_t, little, unaligned>(Result);
}
-}
+} // end namespace llvm
-#endif
+#endif // LLVM_SUPPORT_MD5_H
Modified: llvm/trunk/include/llvm/Support/RWMutex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/RWMutex.h?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/RWMutex.h (original)
+++ llvm/trunk/include/llvm/Support/RWMutex.h Wed Feb 15 16:17:02 2017
@@ -14,7 +14,7 @@
#ifndef LLVM_SUPPORT_RWMUTEX_H
#define LLVM_SUPPORT_RWMUTEX_H
-#include "llvm/Support/Compiler.h"
+#include "llvm/Config/config.h"
#include "llvm/Support/Threading.h"
#include <cassert>
@@ -32,6 +32,13 @@ namespace sys {
/// @brief Default Constructor.
explicit RWMutexImpl();
+ /// @}
+ /// @name Do Not Implement
+ /// @{
+ RWMutexImpl(const RWMutexImpl & original) = delete;
+ RWMutexImpl &operator=(const RWMutexImpl &) = delete;
+ /// @}
+
/// Releases and removes the lock
/// @brief Destructor
~RWMutexImpl();
@@ -70,16 +77,8 @@ namespace sys {
/// @{
private:
#if defined(LLVM_ENABLE_THREADS) && LLVM_ENABLE_THREADS != 0
- void* data_; ///< We don't know what the data will be
+ void* data_ = nullptr; ///< We don't know what the data will be
#endif
-
- /// @}
- /// @name Do Not Implement
- /// @{
- private:
- RWMutexImpl(const RWMutexImpl & original) = delete;
- void operator=(const RWMutexImpl &) = delete;
- /// @}
};
/// SmartMutex - An R/W mutex with a compile time constant parameter that
@@ -93,6 +92,8 @@ namespace sys {
public:
explicit SmartRWMutex() = default;
+ SmartRWMutex(const SmartRWMutex<mt_only> & original) = delete;
+ SmartRWMutex<mt_only> &operator=(const SmartRWMutex<mt_only> &) = delete;
bool lock_shared() {
if (!mt_only || llvm_is_multithreaded())
@@ -136,10 +137,6 @@ namespace sys {
--writers;
return true;
}
-
- private:
- SmartRWMutex(const SmartRWMutex<mt_only> & original);
- void operator=(const SmartRWMutex<mt_only> &);
};
typedef SmartRWMutex<false> RWMutex;
Modified: llvm/trunk/include/llvm/Support/SMLoc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SMLoc.h?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/SMLoc.h (original)
+++ llvm/trunk/include/llvm/Support/SMLoc.h Wed Feb 15 16:17:02 2017
@@ -22,10 +22,10 @@ namespace llvm {
/// Represents a location in source code.
class SMLoc {
- const char *Ptr;
+ const char *Ptr = nullptr;
public:
- SMLoc() : Ptr(nullptr) {}
+ SMLoc() = default;
bool isValid() const { return Ptr != nullptr; }
Modified: llvm/trunk/include/llvm/Support/SourceMgr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SourceMgr.h?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/SourceMgr.h (original)
+++ llvm/trunk/include/llvm/Support/SourceMgr.h Wed Feb 15 16:17:02 2017
@@ -17,18 +17,24 @@
#define LLVM_SUPPORT_SOURCEMGR_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SMLoc.h"
+#include <algorithm>
+#include <cassert>
+#include <memory>
#include <string>
+#include <utility>
+#include <vector>
namespace llvm {
- class SourceMgr;
- class SMDiagnostic;
- class SMFixIt;
- class Twine;
- class raw_ostream;
+
+class raw_ostream;
+class SMDiagnostic;
+class SMFixIt;
/// This owns the files read by a parser, handles include stacks,
/// and handles diagnostic wrangling.
@@ -44,6 +50,7 @@ public:
/// register a function pointer+context as a diagnostic handler.
/// It gets called each time PrintMessage is invoked.
typedef void (*DiagHandlerTy)(const SMDiagnostic &, void *Context);
+
private:
struct SrcBuffer {
/// The memory buffer for the file.
@@ -61,18 +68,17 @@ private:
/// This is a cache for line number queries, its implementation is really
/// private to SourceMgr.cpp.
- mutable void *LineNoCache;
+ mutable void *LineNoCache = nullptr;
- DiagHandlerTy DiagHandler;
- void *DiagContext;
+ DiagHandlerTy DiagHandler = nullptr;
+ void *DiagContext = nullptr;
bool isValidBufferID(unsigned i) const { return i && i <= Buffers.size(); }
- SourceMgr(const SourceMgr&) = delete;
- void operator=(const SourceMgr&) = delete;
public:
- SourceMgr()
- : LineNoCache(nullptr), DiagHandler(nullptr), DiagContext(nullptr) {}
+ SourceMgr() = default;
+ SourceMgr(const SourceMgr &) = delete;
+ SourceMgr &operator=(const SourceMgr &) = delete;
~SourceMgr();
void setIncludeDirs(const std::vector<std::string> &Dirs) {
@@ -190,7 +196,6 @@ public:
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const;
};
-
/// Represents a single fixit, a replacement of one range of text with another.
class SMFixIt {
SMRange Range;
@@ -222,33 +227,31 @@ public:
}
};
-
/// Instances of this class encapsulate one diagnostic report, allowing
/// printing to a raw_ostream as a caret diagnostic.
class SMDiagnostic {
- const SourceMgr *SM;
+ const SourceMgr *SM = nullptr;
SMLoc Loc;
std::string Filename;
- int LineNo, ColumnNo;
- SourceMgr::DiagKind Kind;
+ int LineNo = 0;
+ int ColumnNo = 0;
+ SourceMgr::DiagKind Kind = SourceMgr::DK_Error;
std::string Message, LineContents;
- std::vector<std::pair<unsigned, unsigned> > Ranges;
+ std::vector<std::pair<unsigned, unsigned>> Ranges;
SmallVector<SMFixIt, 4> FixIts;
public:
// Null diagnostic.
- SMDiagnostic()
- : SM(nullptr), LineNo(0), ColumnNo(0), Kind(SourceMgr::DK_Error) {}
+ SMDiagnostic() = default;
// Diagnostic with no location (e.g. file not found, command line arg error).
SMDiagnostic(StringRef filename, SourceMgr::DiagKind Knd, StringRef Msg)
- : SM(nullptr), Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Knd),
- Message(Msg) {}
+ : Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Knd), Message(Msg) {}
// Diagnostic with a location.
SMDiagnostic(const SourceMgr &sm, SMLoc L, StringRef FN,
int Line, int Col, SourceMgr::DiagKind Kind,
StringRef Msg, StringRef LineStr,
- ArrayRef<std::pair<unsigned,unsigned> > Ranges,
+ ArrayRef<std::pair<unsigned,unsigned>> Ranges,
ArrayRef<SMFixIt> FixIts = None);
const SourceMgr *getSourceMgr() const { return SM; }
@@ -259,9 +262,7 @@ public:
SourceMgr::DiagKind getKind() const { return Kind; }
StringRef getMessage() const { return Message; }
StringRef getLineContents() const { return LineContents; }
- ArrayRef<std::pair<unsigned, unsigned> > getRanges() const {
- return Ranges;
- }
+ ArrayRef<std::pair<unsigned, unsigned>> getRanges() const { return Ranges; }
void addFixIt(const SMFixIt &Hint) {
FixIts.push_back(Hint);
@@ -275,6 +276,6 @@ public:
bool ShowKindLabel = true) const;
};
-} // end llvm namespace
+} // end namespace llvm
-#endif
+#endif // LLVM_SUPPORT_SOURCEMGR_H
Modified: llvm/trunk/include/llvm/Support/UniqueLock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/UniqueLock.h?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/UniqueLock.h (original)
+++ llvm/trunk/include/llvm/Support/UniqueLock.h Wed Feb 15 16:17:02 2017
@@ -1,4 +1,4 @@
-//===-- Support/UniqueLock.h - Acquire/Release Mutex In Scope ---*- C++ -*-===//
+//===- Support/UniqueLock.h - Acquire/Release Mutex In Scope ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -15,9 +15,10 @@
#ifndef LLVM_SUPPORT_UNIQUE_LOCK_H
#define LLVM_SUPPORT_UNIQUE_LOCK_H
-#include "llvm/Support/Mutex.h"
+#include <cassert>
namespace llvm {
+
/// A pared-down imitation of std::unique_lock from C++11. Contrary to the
/// name, it's really more of a wrapper for a lock. It may or may not have
/// an associated mutex, which is guaranteed to be locked upon creation
@@ -26,14 +27,14 @@ namespace llvm {
/// @brief Guard a section of code with a mutex.
template<typename MutexT>
class unique_lock {
- MutexT *M;
- bool locked;
+ MutexT *M = nullptr;
+ bool locked = false;
- unique_lock(const unique_lock &) = delete;
- void operator=(const unique_lock &) = delete;
public:
- unique_lock() : M(nullptr), locked(false) {}
+ unique_lock() = default;
explicit unique_lock(MutexT &m) : M(&m), locked(true) { M->lock(); }
+ unique_lock(const unique_lock &) = delete;
+ unique_lock &operator=(const unique_lock &) = delete;
void operator=(unique_lock &&o) {
if (owns_lock())
@@ -62,6 +63,7 @@ namespace llvm {
bool owns_lock() { return locked; }
};
-}
+
+} // end namespace llvm
#endif // LLVM_SUPPORT_UNIQUE_LOCK_H
Modified: llvm/trunk/lib/Support/MD5.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MD5.cpp?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MD5.cpp (original)
+++ llvm/trunk/lib/Support/MD5.cpp Wed Feb 15 16:17:02 2017
@@ -38,9 +38,13 @@
*/
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Endian.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/raw_ostream.h"
+#include <array>
+#include <cstdint>
#include <cstring>
// The basic MD5 functions.
@@ -68,7 +72,7 @@
((MD5_u32plus) ptr[(n) * 4 + 3] << 24))
#define GET(n) (block[(n)])
-namespace llvm {
+using namespace llvm;
/// \brief This processes one or more 64-byte data blocks, but does NOT update
///the bit counters. There are no alignment requirements.
@@ -179,9 +183,7 @@ const uint8_t *MD5::body(ArrayRef<uint8_
return ptr;
}
-MD5::MD5()
- : a(0x67452301), b(0xefcdab89), c(0x98badcfe), d(0x10325476), hi(0), lo(0) {
-}
+MD5::MD5() = default;
/// Incrementally add the bytes in \p Data to the hash.
void MD5::update(ArrayRef<uint8_t> Data) {
@@ -275,4 +277,3 @@ std::array<uint8_t, 16> MD5::hash(ArrayR
memcpy(Arr.data(), Res, sizeof(Res));
return Arr;
}
-}
Modified: llvm/trunk/lib/Support/RWMutex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/RWMutex.cpp?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/lib/Support/RWMutex.cpp (original)
+++ llvm/trunk/lib/Support/RWMutex.cpp Wed Feb 15 16:17:02 2017
@@ -13,7 +13,6 @@
#include "llvm/Config/config.h"
#include "llvm/Support/RWMutex.h"
-#include <cstring>
//===----------------------------------------------------------------------===//
//=== WARNING: Implementation here must contain only TRULY operating system
@@ -22,29 +21,31 @@
#if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
// Define all methods as no-ops if threading is explicitly disabled
-namespace llvm {
+
+using namespace llvm;
using namespace sys;
-RWMutexImpl::RWMutexImpl() { }
-RWMutexImpl::~RWMutexImpl() { }
+
+RWMutexImpl::RWMutexImpl() = default;
+RWMutexImpl::~RWMutexImpl() = default;
+
bool RWMutexImpl::reader_acquire() { return true; }
bool RWMutexImpl::reader_release() { return true; }
bool RWMutexImpl::writer_acquire() { return true; }
bool RWMutexImpl::writer_release() { return true; }
-}
+
#else
#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_RWLOCK_INIT)
#include <cassert>
+#include <cstdlib>
#include <pthread.h>
-#include <stdlib.h>
-namespace llvm {
+using namespace llvm;
using namespace sys;
// Construct a RWMutex using pthread calls
RWMutexImpl::RWMutexImpl()
- : data_(nullptr)
{
// Declare the pthread_rwlock data structures
pthread_rwlock_t* rwlock =
@@ -113,8 +114,6 @@ RWMutexImpl::writer_release()
return errorcode == 0;
}
-}
-
#elif defined(LLVM_ON_UNIX)
#include "Unix/RWMutex.inc"
#elif defined( LLVM_ON_WIN32)
Modified: llvm/trunk/lib/Support/SourceMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SourceMgr.cpp?rev=295243&r1=295242&r2=295243&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SourceMgr.cpp (original)
+++ llvm/trunk/lib/Support/SourceMgr.cpp Wed Feb 15 16:17:02 2017
@@ -13,30 +13,43 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Support/SourceMgr.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/Locale.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/SMLoc.h"
+#include "llvm/Support/SourceMgr.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <memory>
+#include <string>
+#include <utility>
+
using namespace llvm;
static const size_t TabStop = 8;
namespace {
+
struct LineNoCacheTy {
const char *LastQuery;
unsigned LastQueryBufferID;
unsigned LineNoOfQuery;
};
-}
+
+} // end anonymous namespace
static LineNoCacheTy *getCache(void *Ptr) {
return (LineNoCacheTy*)Ptr;
}
-
SourceMgr::~SourceMgr() {
// Delete the line # cache if allocated.
if (LineNoCacheTy *Cache = getCache(LineNoCache))
@@ -132,12 +145,10 @@ void SourceMgr::PrintIncludeStack(SMLoc
<< ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
}
-
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
const Twine &Msg,
ArrayRef<SMRange> Ranges,
ArrayRef<SMFixIt> FixIts) const {
-
// First thing to do: find the current buffer containing the specified
// location to pull out the source line.
SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
@@ -223,7 +234,7 @@ void SourceMgr::PrintMessage(raw_ostream
void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
const Twine &Msg, ArrayRef<SMRange> Ranges,
ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
- PrintMessage(llvm::errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors);
+ PrintMessage(errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors);
}
//===----------------------------------------------------------------------===//
@@ -233,7 +244,7 @@ void SourceMgr::PrintMessage(SMLoc Loc,
SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, StringRef FN,
int Line, int Col, SourceMgr::DiagKind Kind,
StringRef Msg, StringRef LineStr,
- ArrayRef<std::pair<unsigned,unsigned> > Ranges,
+ ArrayRef<std::pair<unsigned,unsigned>> Ranges,
ArrayRef<SMFixIt> Hints)
: SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
@@ -286,7 +297,7 @@ static void buildFixItLine(std::string &
// FIXME: This assertion is intended to catch unintended use of multibyte
// characters in fixits. If we decide to do this, we'll have to track
// separate byte widths for the source and fixit lines.
- assert((size_t)llvm::sys::locale::columnWidth(I->getText()) ==
+ assert((size_t)sys::locale::columnWidth(I->getText()) ==
I->getText().size());
// This relies on one byte per column in our fixit hints.
More information about the llvm-commits
mailing list