r200190 - Use ConstStringRef facility for getCustomDiagID() safety

Alp Toker alp at nuanti.com
Sun Jan 26 20:22:23 PST 2014


Author: alp
Date: Sun Jan 26 22:22:22 2014
New Revision: 200190

URL: http://llvm.org/viewvc/llvm-project?rev=200190&view=rev
Log:
Use ConstStringRef facility for getCustomDiagID() safety

This is one of various functions in clang that don't handle arbitrary strings
well and can benefit from compile-time safety checks.

Also fixes an off-by-one error that caused one additional null byte to get
added to the end of custom diagnostic descriptions. ConstStringRef handles
tricky details like that for us now.

Requires supporting changes in LLVM r200187.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Basic/LLVM.h

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=200190&r1=200189&r2=200190&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Sun Jan 26 22:22:22 2014
@@ -595,10 +595,8 @@ public:
   ///
   /// \param FormatString A fixed diagnostic format string that will be hashed
   /// and mapped to a unique DiagID.
-  template <unsigned N>
-  unsigned getCustomDiagID(Level L, const char (&FormatString)[N]) {
-    return Diags->getCustomDiagID((DiagnosticIDs::Level)L,
-                                  StringRef(FormatString, N));
+  unsigned getCustomDiagID(Level L, ConstStringRef FormatString) {
+    return Diags->getCustomDiagID((DiagnosticIDs::Level)L, FormatString);
   }
 
   /// \brief Converts a diagnostic argument (as an intptr_t) into the string

Modified: cfe/trunk/include/clang/Basic/LLVM.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LLVM.h?rev=200190&r1=200189&r2=200190&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LLVM.h (original)
+++ cfe/trunk/include/clang/Basic/LLVM.h Sun Jan 26 22:22:22 2014
@@ -27,6 +27,7 @@
 namespace llvm {
   // ADT's.
   class StringRef;
+  class ConstStringRef;
   class Twine;
   template<typename T> class ArrayRef;
   template<typename T> class OwningPtr;
@@ -61,6 +62,7 @@ namespace clang {
   using llvm::None;
   using llvm::Optional;
   using llvm::StringRef;
+  using llvm::ConstStringRef;
   using llvm::Twine;
   using llvm::ArrayRef;
   using llvm::OwningPtr;





More information about the cfe-commits mailing list