summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PCHWriter.cpp
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2010-07-30 17:03:48 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2010-07-30 17:03:48 +0000
commit3df5a08b9997f9240ac87474835f43e4007dc8fe (patch)
tree76febdee2f7d4ee8860063b8df9b2740053908c2 /clang/lib/Frontend/PCHWriter.cpp
parent7b70eb4bb190541e999c434df737277bc5b55777 (diff)
downloadbcm5719-llvm-3df5a08b9997f9240ac87474835f43e4007dc8fe.tar.gz
bcm5719-llvm-3df5a08b9997f9240ac87474835f43e4007dc8fe.zip
Safely get a data pointer for vectors that might be empty.
llvm-svn: 109867
Diffstat (limited to 'clang/lib/Frontend/PCHWriter.cpp')
-rw-r--r--clang/lib/Frontend/PCHWriter.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp
index b574656bb6d..a72f7cfea89 100644
--- a/clang/lib/Frontend/PCHWriter.cpp
+++ b/clang/lib/Frontend/PCHWriter.cpp
@@ -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 @@ void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
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 @@ void PCHWriter::WritePreprocessor(const Preprocessor &PP) {
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 @@ void PCHWriter::WriteTypeDeclOffsets() {
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 @@ void PCHWriter::WriteTypeDeclOffsets() {
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 @@ void PCHWriter::WriteMethodPool(Sema &SemaRef) {
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 @@ void PCHWriter::WriteIdentifierTable(Preprocessor &PP) {
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));
}
OpenPOWER on IntegriCloud