[cfe-commits] r109867 - /cfe/trunk/lib/Frontend/PCHWriter.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Jul 30 10:03:48 PDT 2010
Author: cornedbee
Date: Fri Jul 30 12:03:48 2010
New Revision: 109867
URL: http://llvm.org/viewvc/llvm-project?rev=109867&view=rev
Log:
Safely get a data pointer for vectors that might be empty.
Modified:
cfe/trunk/lib/Frontend/PCHWriter.cpp
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=109867&r1=109866&r2=109867&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Jul 30 12:03:48 2010
@@ -40,6 +40,15 @@
#include <cstdio>
using namespace clang;
+template <typename T, typename Allocator>
+T *data(std::vector<T, Allocator> &v) {
+ return v.empty() ? 0 : &v.front();
+}
+template <typename T, typename Allocator>
+const T *data(const std::vector<T, Allocator> &v) {
+ return v.empty() ? 0 : &v.front();
+}
+
//===----------------------------------------------------------------------===//
// Type serialization
//===----------------------------------------------------------------------===//
@@ -1218,7 +1227,7 @@
Record.push_back(SLocEntryOffsets.size());
Record.push_back(SourceMgr.getNextOffset());
Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
- (const char *)&SLocEntryOffsets.front(),
+ (const char *)data(SLocEntryOffsets),
SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0]));
// Write the source location entry preloads array, telling the PCH
@@ -1376,7 +1385,7 @@
Record.push_back(NumPreprocessingRecords);
Record.push_back(MacroDefinitionOffsets.size());
Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record,
- (const char *)&MacroDefinitionOffsets.front(),
+ (const char *)data(MacroDefinitionOffsets),
MacroDefinitionOffsets.size() * sizeof(uint32_t));
}
}
@@ -1523,7 +1532,7 @@
Record.push_back(pch::TYPE_OFFSET);
Record.push_back(TypeOffsets.size());
Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record,
- (const char *)&TypeOffsets.front(),
+ (const char *)data(TypeOffsets),
TypeOffsets.size() * sizeof(TypeOffsets[0]));
// Write the declaration offsets array
@@ -1536,7 +1545,7 @@
Record.push_back(pch::DECL_OFFSET);
Record.push_back(DeclOffsets.size());
Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record,
- (const char *)&DeclOffsets.front(),
+ (const char *)data(DeclOffsets),
DeclOffsets.size() * sizeof(DeclOffsets[0]));
}
@@ -1738,7 +1747,7 @@
Record.push_back(pch::SELECTOR_OFFSETS);
Record.push_back(SelectorOffsets.size());
Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record,
- (const char *)&SelectorOffsets.front(),
+ (const char *)data(SelectorOffsets),
SelectorOffsets.size() * 4);
}
}
@@ -1939,7 +1948,7 @@
Record.push_back(pch::IDENTIFIER_OFFSET);
Record.push_back(IdentifierOffsets.size());
Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record,
- (const char *)&IdentifierOffsets.front(),
+ (const char *)data(IdentifierOffsets),
IdentifierOffsets.size() * sizeof(uint32_t));
}
More information about the cfe-commits
mailing list