aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorEdwin Török <edwintorok@gmail.com>2009-11-19 15:39:50 +0000
committerEdwin Török <edwintorok@gmail.com>2009-11-19 15:39:50 +0000
commit449529d5cfab41b1899d04273a326065c4420223 (patch)
tree046a4741adde5c8b8a79a98bdda188d4dabb63b5 /include
parent02cec4c48f3c3daf922ee0d8aae5621c12ea3e81 (diff)
downloadexternal_llvm-449529d5cfab41b1899d04273a326065c4420223.zip
external_llvm-449529d5cfab41b1899d04273a326065c4420223.tar.gz
external_llvm-449529d5cfab41b1899d04273a326065c4420223.tar.bz2
Workaround PR5482, because all the gcc versions that I had were miscompiling StringRef:
4.2.4, 4.3.4, 4.4.2. The workaround is to use a local min/max implementation that takes an integer param, and not a reference to integer param (like std::min does). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/StringRef.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index ed651bf..3b3f3cd 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -39,6 +39,19 @@ namespace llvm {
/// The length of the string.
size_t Length;
+ // Workaround PR5482: nearly all gcc 4.x miscompile StringRef and std::min()
+ // Changing the arg of min to be an integer, instead of a reference to an
+ // integer works around this bug.
+ size_t min(size_t a, size_t b) const
+ {
+ return a < b ? a : b;
+ }
+
+ size_t max(size_t a, size_t b) const
+ {
+ return a > b ? a : b;
+ }
+
public:
/// @name Constructors
/// @{
@@ -108,7 +121,7 @@ namespace llvm {
/// is lexicographically less than, equal to, or greater than the \arg RHS.
int compare(StringRef RHS) const {
// Check the prefix for a mismatch.
- if (int Res = memcmp(Data, RHS.Data, std::min(Length, RHS.Length)))
+ if (int Res = memcmp(Data, RHS.Data, min(Length, RHS.Length)))
return Res < 0 ? -1 : 1;
// Otherwise the prefixes match, so we only need to check the lengths.
@@ -163,7 +176,7 @@ namespace llvm {
/// \return - The index of the first occurence of \arg C, or npos if not
/// found.
size_t find(char C, size_t From = 0) const {
- for (size_t i = std::min(From, Length), e = Length; i != e; ++i)
+ for (size_t i = min(From, Length), e = Length; i != e; ++i)
if (Data[i] == C)
return i;
return npos;
@@ -180,7 +193,7 @@ namespace llvm {
/// \return - The index of the last occurence of \arg C, or npos if not
/// found.
size_t rfind(char C, size_t From = npos) const {
- From = std::min(From, Length);
+ From = min(From, Length);
size_t i = From;
while (i != 0) {
--i;
@@ -262,8 +275,8 @@ namespace llvm {
/// exceeds the number of characters remaining in the string, the string
/// suffix (starting with \arg Start) will be returned.
StringRef substr(size_t Start, size_t N = npos) const {
- Start = std::min(Start, Length);
- return StringRef(Data + Start, std::min(N, Length - Start));
+ Start = min(Start, Length);
+ return StringRef(Data + Start, min(N, Length - Start));
}
/// slice - Return a reference to the substring from [Start, End).
@@ -277,8 +290,8 @@ namespace llvm {
/// number of characters remaining in the string, the string suffix
/// (starting with \arg Start) will be returned.
StringRef slice(size_t Start, size_t End) const {
- Start = std::min(Start, Length);
- End = std::min(std::max(Start, End), Length);
+ Start = min(Start, Length);
+ End = min(max(Start, End), Length);
return StringRef(Data + Start, End - Start);
}