<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 27/01/2014 17:40, David Blaikie
wrote:<br>
</div>
<blockquote
cite="mid:CAENS6EuK_wZ+AOVesvVsSmJkCCKQamfqm7oU2ja7oJSJYJnhcw@mail.gmail.com"
type="cite">
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Sun, Jan 26, 2014 at 9:46 PM, Alp
Toker <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:alp@nuanti.com" target="_blank">alp@nuanti.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">They say
you should practice what you preach, and this commit had
some changes that'll affect all users of StringRef so I've
rolled it back in r200187 until we get some discussion
going.<br>
<br>
The need derives from dozens of cases in clang where user
input was being passed in as a format string to the
diagnostic system. With all those fixed following ongoing
work the last few months we now want a stricter check for
compile-time fixed strings and this general solution has
come together.<br>
<br>
I'll kick off with a self-review, posted inline below..
:-)
<div>
<div class="h5"><br>
<br>
<br>
On 27/01/2014 04:07, Alp Toker wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: alp<br>
Date: Sun Jan 26 22:07:17 2014<br>
New Revision: 200187<br>
<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project?rev=200187&view=rev"
target="_blank">http://llvm.org/viewvc/llvm-project?rev=200187&view=rev</a><br>
Log:<br>
StringRef: Extend constexpr capabilities and
introduce ConstStringRef<br>
<br>
(1) Add llvm_expect(), an asserting macro that can
be evaluated as a constexpr<br>
expression as well as a runtime assert or
compiler hint in release builds. This<br>
technique can be used to construct functions
that are both unevaluated and<br>
compiled depending on usage.<br>
<br>
(2) Update StringRef using llvm_expect() to preserve
runtime assertions while<br>
extending the same checks to static asserts in
C++11 builds that support the<br>
feature.<br>
<br>
(3) Introduce ConstStringRef, a strong subclass of
StringRef that references<br>
compile-time constant strings. It's convertible
to, but not from, ordinary<br>
StringRef and thus can be used to add
compile-time safety to various interfaces<br>
in LLVM and clang that only accept fixed inputs
such as diagnostic format<br>
strings that tend to get misused.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/ADT/StringRef.h<br>
llvm/trunk/include/llvm/Support/ErrorHandling.h<br>
llvm/trunk/lib/Support/ErrorHandling.cpp<br>
llvm/trunk/unittests/ADT/StringRefTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/StringRef.h<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=200187&r1=200186&r2=200187&view=diff"
target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=200187&r1=200186&r2=200187&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/StringRef.h
(original)<br>
+++ llvm/trunk/include/llvm/ADT/StringRef.h Sun Jan
26 22:07:17 2014<br>
@@ -10,6 +10,8 @@<br>
#ifndef LLVM_ADT_STRINGREF_H<br>
#define LLVM_ADT_STRINGREF_H<br>
+#include "llvm/Support/Compiler.h"<br>
+#include "llvm/Support/ErrorHandling.h"<br>
#include "llvm/Support/type_traits.h"<br>
#include <algorithm><br>
#include <cassert><br>
@@ -70,7 +72,7 @@ namespace llvm {<br>
/// @{<br>
/// Construct an empty string ref.<br>
- /*implicit*/ StringRef() : Data(0), Length(0)
{}<br>
+ /*implicit*/ LLVM_CONSTEXPR StringRef() :
Data(0), Length(0) {}<br>
/// Construct a string ref from a cstring.<br>
/*implicit*/ StringRef(const char *Str)<br>
@@ -80,11 +82,8 @@ namespace llvm {<br>
}<br>
/// Construct a string ref from a pointer
and length.<br>
- /*implicit*/ StringRef(const char *data, size_t
length)<br>
- : Data(data), Length(length) {<br>
- assert((data || length == 0) &&<br>
- "StringRef cannot be built from a NULL
argument with non-null length");<br>
- }<br>
+ /*implicit*/ LLVM_CONSTEXPR StringRef(const
char *data, size_t length)<br>
+ : Data(data), Length((llvm_expect(data ||
length == 0), length)) {}<br>
</blockquote>
<br>
</div>
</div>
We lose friendly messages here, but we get back
subjectively equal benefit by using the built-in LLVM
fatal error handler instead of the one in the system.
<div>
<div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
/// Construct a string ref from an
std::string.<br>
/*implicit*/ StringRef(const std::string
&Str)<br>
@@ -104,24 +103,20 @@ namespace llvm {<br>
/// data - Get a pointer to the start of the
string (which may not be null<br>
/// terminated).<br>
- const char *data() const { return Data; }<br>
+ LLVM_CONSTEXPR const char *data() const {
return Data; }<br>
/// empty - Check if the string is empty.<br>
- bool empty() const { return Length == 0; }<br>
+ LLVM_CONSTEXPR bool empty() const { return
Length == 0; }<br>
/// size - Get the string size.<br>
- size_t size() const { return Length; }<br>
+ LLVM_CONSTEXPR size_t size() const { return
Length; }<br>
/// front - Get the first character in the
string.<br>
- char front() const {<br>
- assert(!empty());<br>
- return Data[0];<br>
- }<br>
+ LLVM_CONSTEXPR char front() const { return
llvm_expect(!empty()), Data[0]; }<br>
/// back - Get the last character in the
string.<br>
- char back() const {<br>
- assert(!empty());<br>
- return Data[Length-1];<br>
+ LLVM_CONSTEXPR char back() const {<br>
+ return llvm_expect(!empty()), Data[Length -
1];<br>
}<br>
/// equals - Check for string equality, this
is more efficient than<br>
@@ -187,9 +182,8 @@ namespace llvm {<br>
/// @name Operator Overloads<br>
/// @{<br>
- char operator[](size_t Index) const {<br>
- assert(Index < Length && "Invalid
index!");<br>
- return Data[Index];<br>
+ LLVM_CONSTEXPR char operator[](size_t Index)
const {<br>
+ return llvm_expect(Index < Length),
Data[Index];<br>
}<br>
</blockquote>
<br>
</div>
</div>
Ditto.
<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
/// @}<br>
@@ -547,6 +541,20 @@ namespace llvm {<br>
/// @}<br>
+ /// ConstStringRef - A \c StringRef carrying the
additional stipulation that<br>
+ /// the referenced string is a compile-time
constant.<br>
+ ///<br>
+ /// Use this to specify function parameters that
require fixed inputs such<br>
+ /// as debug and diagnostic messages or format
strings.<br>
+ class ConstStringRef : public StringRef {<br>
+ public:<br>
+ /*implicit*/ LLVM_CONSTEXPR ConstStringRef() :
StringRef() {}<br>
+<br>
+ template <size_t N><br>
+ /*implicit*/ LLVM_CONSTEXPR ConstStringRef(const
char (&data)[N])<br>
+ : StringRef(data, (llvm_expect(N > 0
&& data[N - 1] == '\0'), N - 1)) {}<br>
</blockquote>
<br>
</div>
This constructor doesn't technically require a constant
string literal and you can trick it into accepting a
fixed-length char array, but in all uses it detected
errors that have been fixed. </blockquote>
<div><br>
</div>
<div>Could you point to revisions that demonstrate the fixes
that have been prompted by this?</div>
</div>
</div>
</div>
</blockquote>
<br>
Hi David,<br>
<br>
I'm including a few of them below. These include fixes for around
200 diagnostics that went through 30 incorrect entry points that
have been fixed from December. Not including fixes by others, or
that were caught during pre-commit review.<br>
<br>
Each of these would have previously leaked, been potentially
misformatted or insecure except for two cases which actually tried
to escaping the user input before still incorrectly using it as a
format string.<br>
<br>
There's a tendency for developers to land features when they appear
to work without paying attention to conditions where they can fail,
much like printf() but perhaps more serious because we don't do any
validation at all for format strings. Safe facilities like
ConstStringRef provide the kind of compile-time safety we need.<br>
<br>
(For background, I'm holding back on the patches because Chandler
spotted a possible missed optimization in llvm_expect. We need to
make sure the test condition is never evaluated in release builds so
StringRef won't regress.)<br>
<br>
<br>
<br>
<p><code>commit d6de61539c778f1d8449208c381234d13f7643cb</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sun Jan 26 05:08:49 2014 +0000</code></p>
<p><code><br>
</code><code> Identify two more unsafe uses of
getCustomDiagID()</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@200126">https://llvm.org/svn/llvm-project/cfe/trunk@200126</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit 0e20dca20ed1f55af630b4f117ff9add50b1cf7b</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sun Jan 26 05:08:07 2014 +0000</code></p>
<p><code><br>
</code><code> Remove buggy example code from the documentation</code></p>
<p><code> </code></p>
<p><code> Instead point readers to the latest, correct example
code in SVN until we find</code></p>
<p><code> a way to automatically include example sources into the
documentation (or until</code></p>
<p><code> someone steps up to maintain these actively).</code></p>
<p><code> </code></p>
<p><code> This ensures that the examples are up-to-date,
buildable, and most of all that</code></p>
<p><code> readers don't pick up incorrect usage.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@200125">https://llvm.org/svn/llvm-project/cfe/trunk@200125</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit 35fe9a0c1e52c387dfadabafa4b2d26761595786</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sun Jan 26 05:07:32 2014 +0000</code></p>
<p><code><br>
</code><code> ARCMigrate: Introduce proper diagnostics for
TransformActions</code></p>
<p><code> </code></p>
<p><code> This starts to switch ARCMT to use proper diagnostic
messages. The old use was</code></p>
<p><code> based on incorrect example code from the documentation.</code></p>
<p><code> </code></p>
<p><code> The logic of the previous report() functions has been
retained to support any</code></p>
<p><code> external consumers that might be intercepting
diagnostic messages through the</code></p>
<p><code> old interface.</code></p>
<p><code> </code></p>
<p><code> Note that the change in test/Misc/warning-flags.c isn't
a new warning without a</code></p>
<p><code> flag, rather one that was previously invisible to the
test. Adding a flag might</code></p>
<p><code> be a good idea though.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@200124">https://llvm.org/svn/llvm-project/cfe/trunk@200124</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit 2a030a3aec48ed18846518aab60e5e5e72f381cc</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Thu Jan 2 15:08:04 2014 +0000</code></p>
<p><code><br>
</code><code> Verify that clang TargetInfo descriptions match
DataLayout strings from LLVM</code></p>
<p><code> </code></p>
<p><code> The backend string is only verified when available as
it's possible to run</code></p>
<p><code> clang IRGen for targets that haven't been built or
don't exist in LLVM.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@198309">https://llvm.org/svn/llvm-project/cfe/trunk@198309</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit d5e04a5d9e356fbf3634ab113885039da57eaadc</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Mon Dec 23 17:59:59 2013 +0000</code></p>
<p><code><br>
</code><code> Fix another misuse of getCustomDiagID()</code></p>
<p><code> </code></p>
<p><code> There's no need to escape strings and generate new
DiagIDs for each message.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@197915">https://llvm.org/svn/llvm-project/cfe/trunk@197915</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit a2cd7434fdd6e55d780b290aaef4365fd011252c</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sat Dec 21 05:20:03 2013 +0000</code></p>
<p><code><br>
</code><code> Fix getCustomDiagID() usage in CodeGen and
TextDiagnosticBuffer</code></p>
<p><code> </code></p>
<p><code> DiagIDs are a cached resource generally only
constructed from compile-time</code></p>
<p><code> constant or stable format strings.</code></p>
<p><code> </code></p>
<p><code> Escaping arbitrary messages and constructing DiagIDs
from them didn't make</code></p>
<p><code> sense.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@197856">https://llvm.org/svn/llvm-project/cfe/trunk@197856</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit f83451512ecb54410e1ca80a1b3a762051bcc2d1</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sat Dec 21 05:19:58 2013 +0000</code></p>
<p><code><br>
</code><code> Fix getCustomDiagID() usage in example code</code></p>
<p><code> </code></p>
<p><code> This was setting a bad example. DiagIDs are a limited
resource and the message</code></p>
<p><code> argument is evaluated as a format string.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@197855">https://llvm.org/svn/llvm-project/cfe/trunk@197855</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit a2474459beca778d352a16e6463cf4dd9e29dc06</code></p>
<p><code>
Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>
Date: Sun Jan 26 06:17:37 2014 +0000</code></p>
<p>
</p>
<p><code>
Enforce safe usage of DiagnosticsEngine::getCustomDiagID()</code></p>
<p><code>
</code></p>
<p><code>
Replace the last incorrect uses and templatize the function
to require a</code></p>
<p><code>
compile-time constant string preventing further misuse.</code></p>
<p><code>
</code></p>
<p><code>
The diagnostic formatter expects well-formed input and has
undefined behaviour</code></p>
<p><code>
with arbitrary input or crafted user strings in source
files. Accepting user</code></p>
<p><code>
input would also have caused unbounded generation of new
diagnostic IDs which</code></p>
<p><code>
can be problematic in long-running sessions or language
bindings.</code></p>
<p><code>
</code></p>
<p><code>
This completes the work to fix several incorrect callers
that passed user</code></p>
<p><code>
input or raw messages to the diagnostics engine where a
constant format string</code></p>
<p><code>
was expected.</code></p>
<p><code>
</code></p>
<p><code>
git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/cfe/trunk@200132">https://llvm.org/svn/llvm-project/cfe/trunk@200132</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit 33fc63be61210df4b2a89386b95fde1c26c4fe99</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sun Jan 26 08:36:03 2014 +0000</code></p>
<p><code><br>
</code><code> Fix another invalid getCustomDiagID() use to
unbreak the build</code></p>
<p><code> </code></p>
<p><code> It was calling the utility wrapper that now requires a
constant string</code></p>
<p><code> following clang r200132. The StringRef version on
DiagnosticIDs appears to have</code></p>
<p><code> been what was intended so change to that.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@200142">https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@200142</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<p><code><br>
</code><code>commit a81090fcf5ed403a580e74cfeb704eade3c2c41d</code></p>
<p><code>Author: Alp Toker <a class="moz-txt-link-rfc2396E" href="mailto:alp@nuanti.com"><alp@nuanti.com></a></code></p>
<p><code>Date: Sun Jan 26 06:58:01 2014 +0000</code></p>
<p><code><br>
</code><code> Prospective build fix for unsafe usage of
getCustomDiagID()</code></p>
<p><code> </code></p>
<p><code> This now requires a compile-time constant string so
let's build proper</code></p>
<p><code> diagnostic IDs and pass through the inputs as
arguments.</code></p>
<p><code> </code></p>
<p><code> Tracks clang changes in r200132.</code></p>
<p><code> </code></p>
<p><code> git-svn-id:
<a class="moz-txt-link-freetext" href="https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@200139">https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@200139</a>
91177308-0d34-0410-b5e6-96231b3b80d8</code></p>
<br>
Alp.<br>
<br>
<br>
<blockquote
cite="mid:CAENS6EuK_wZ+AOVesvVsSmJkCCKQamfqm7oU2ja7oJSJYJnhcw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">There's
some interest in introducing a clang attribute to check
for literals and that would get added here as the feature
evolves.
<div>
<div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
+ };<br>
+<br>
/// \brief Compute a hash_code for a StringRef.<br>
hash_code hash_value(StringRef S);<br>
<br>
Modified: llvm/trunk/include/llvm/Support/ErrorHandling.h<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorHandling.h?rev=200187&r1=200186&r2=200187&view=diff"
target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorHandling.h?rev=200187&r1=200186&r2=200187&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/ErrorHandling.h
(original)<br>
+++ llvm/trunk/include/llvm/Support/ErrorHandling.h
Sun Jan 26 22:07:17 2014<br>
@@ -15,11 +15,11 @@<br>
#ifndef LLVM_SUPPORT_ERRORHANDLING_H<br>
#define LLVM_SUPPORT_ERRORHANDLING_H<br>
-#include "llvm/ADT/StringRef.h"<br>
#include "llvm/Support/Compiler.h"<br>
#include <string><br>
namespace llvm {<br>
+ class StringRef;<br>
class Twine;<br>
/// An error handler callback.<br>
@@ -78,7 +78,7 @@ namespace llvm {<br>
bool gen_crash_diag = true);<br>
LLVM_ATTRIBUTE_NORETURN void
report_fatal_error(const std::string &reason,<br>
bool gen_crash_diag = true);<br>
- LLVM_ATTRIBUTE_NORETURN void
report_fatal_error(StringRef reason,<br>
+ LLVM_ATTRIBUTE_NORETURN void
report_fatal_error(const StringRef &reason,<br>
bool gen_crash_diag = true);<br>
</blockquote>
<br>
</div>
</div>
This tweak drops the early dependency on StringRef.h so we
can use ErrorHandling in StringRef itself.
<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
LLVM_ATTRIBUTE_NORETURN void
report_fatal_error(const Twine &reason,<br>
bool gen_crash_diag = true);<br>
@@ -108,4 +108,14 @@ namespace llvm {<br>
#define llvm_unreachable(msg)
::llvm::llvm_unreachable_internal()<br>
#endif<br>
+/// An assert macro that's usable in constexprs and
that becomes an optimizer<br>
+/// hint in NDEBUG builds.<br>
+///<br>
+/// Unlike \c assert() the \param test expression may
be evaluated in optimized<br>
+/// builds and so should be simple, accurate and
never have side effects.<br>
+#define llvm_expect(test) (void)(!!(test) ? 0 :
(llvm_unreachable(#test), 0))<br>
</blockquote>
<br>
</div>
This macro expansion could do with checking over. If it
works out llvm_expect() will have better characteristics
in debug builds.<br>
<br>
The optimizer hint approach is something to consider. We
have to evaluate 'test' to support constexpr evaluation
but we don't strictly need to use it as a hint if
llvm_unreachable() feels too strong here.<br>
<br>
Alp.
<div class="HOEnZb">
<div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+// TODO: Update other headers to explicitly include
StringRef.h and drop this.<br>
+#include "llvm/ADT/StringRef.h"<br>
+<br>
#endif<br>
<br>
Modified: llvm/trunk/lib/Support/ErrorHandling.cpp<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ErrorHandling.cpp?rev=200187&r1=200186&r2=200187&view=diff"
target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ErrorHandling.cpp?rev=200187&r1=200186&r2=200187&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/ErrorHandling.cpp
(original)<br>
+++ llvm/trunk/lib/Support/ErrorHandling.cpp Sun Jan
26 22:07:17 2014<br>
@@ -58,7 +58,7 @@ void
llvm::report_fatal_error(const std:<br>
report_fatal_error(Twine(Reason), GenCrashDiag);<br>
}<br>
-void llvm::report_fatal_error(StringRef Reason,
bool GenCrashDiag) {<br>
+void llvm::report_fatal_error(const StringRef
&Reason, bool GenCrashDiag) {<br>
report_fatal_error(Twine(Reason), GenCrashDiag);<br>
}<br>
<br>
Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=200187&r1=200186&r2=200187&view=diff"
target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=200187&r1=200186&r2=200187&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/ADT/StringRefTest.cpp
(original)<br>
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Sun
Jan 26 22:07:17 2014<br>
@@ -531,4 +531,22 @@ TEST(StringRefTest,
joinStrings) {<br>
EXPECT_TRUE(v2_join3);<br>
}<br>
+static void fn_stringref(StringRef str) {<br>
+ EXPECT_TRUE(str == "hello");<br>
+}<br>
+static void fn_conststringref(ConstStringRef str) {<br>
+ fn_stringref(str);<br>
+}<br>
+<br>
+TEST(StringRefTest, constStringRef) {<br>
+ LLVM_CONSTEXPR ConstStringRef csr("hello");<br>
+#if __has_feature(cxx_constexpr) ||
defined(__GXX_EXPERIMENTAL_CXX0X__)<br>
+ LLVM_STATIC_ASSERT(csr[0] != csr[1], "");<br>
+ LLVM_STATIC_ASSERT(csr[2] == csr[3], "");<br>
+ LLVM_STATIC_ASSERT(csr.size() == 5, "");<br>
+#endif<br>
+ llvm_expect(csr[2] == csr[3]);<br>
+ fn_conststringref(csr);<br>
+}<br>
+<br>
} // end anonymous namespace<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a moz-do-not-send="true"
href="mailto:llvm-commits@cs.uiuc.edu"
target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote>
<br>
</div>
</div>
<span class="HOEnZb"><font color="#888888">
-- <br>
<a moz-do-not-send="true" href="http://www.nuanti.com"
target="_blank">http://www.nuanti.com</a><br>
the browser experts</font></span>
<div class="HOEnZb">
<div class="h5"><br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a moz-do-not-send="true"
href="mailto:llvm-commits@cs.uiuc.edu"
target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits"
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.nuanti.com">http://www.nuanti.com</a>
the browser experts
</pre>
</body>
</html>