summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-05-02 20:01:24 +0000
committerJustin Bogner <mail@justinbogner.com>2014-05-02 20:01:24 +0000
commitc475e1bc7784be136b28b8791a69492b31c8fabe (patch)
tree350af4892bedbc6ba3dd75e9e871ac994bc4428b /llvm/lib
parent6ef0a2f1be16382744e234b89ade1d34e6acbfe3 (diff)
downloadbcm5719-llvm-c475e1bc7784be136b28b8791a69492b31c8fabe.tar.gz
bcm5719-llvm-c475e1bc7784be136b28b8791a69492b31c8fabe.zip
llvm-cov: Fix handling of line zero appearing in a line table
Reading line tables in llvm-cov was pretty broken, but would happen to work as long as no line in the table was 0. It's not clear to me whether a line of zero *should* show up in these tables, but deciding to read a string in the middle of the line table is certainly the wrong thing to do if it does. I've also added some comments, as trying to figure out what this block of code was doing was fairly unpleasant. llvm-svn: 207866
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/GCOV.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/lib/IR/GCOV.cpp b/llvm/lib/IR/GCOV.cpp
index 8f060d2ac90..522716309a9 100644
--- a/llvm/lib/IR/GCOV.cpp
+++ b/llvm/lib/IR/GCOV.cpp
@@ -166,9 +166,11 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
// read line table.
while (Buff.readLineTag()) {
uint32_t LineTableLength;
+ // Read the length of this line table.
if (!Buff.readInt(LineTableLength)) return false;
uint32_t EndPos = Buff.getCursor() + LineTableLength*4;
uint32_t BlockNo;
+ // Read the block number this table is associated with.
if (!Buff.readInt(BlockNo)) return false;
if (BlockNo >= BlockCount) {
errs() << "Unexpected block number: " << BlockNo << " (in " << Name
@@ -176,24 +178,34 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
return false;
}
GCOVBlock &Block = *Blocks[BlockNo];
- if (!Buff.readInt(Dummy)) return false; // flag
- while (Buff.getCursor() != (EndPos - 4)) {
+ // Read the word that pads the beginning of the line table. This may be a
+ // flag of some sort, but seems to always be zero.
+ if (!Buff.readInt(Dummy)) return false;
+
+ // Line information starts here and continues up until the last word.
+ if (Buff.getCursor() != (EndPos - sizeof(uint32_t))) {
StringRef F;
+ // Read the source file name.
if (!Buff.readString(F)) return false;
if (Filename != F) {
errs() << "Multiple sources for a single basic block: " << Filename
<< " != " << F << " (in " << Name << ").\n";
return false;
}
- if (Buff.getCursor() == (EndPos - 4)) break;
- while (true) {
+ // Read lines up to, but not including, the null terminator.
+ while (Buff.getCursor() < (EndPos - 2 * sizeof(uint32_t))) {
uint32_t Line;
if (!Buff.readInt(Line)) return false;
- if (!Line) break;
+ // Line 0 means this instruction was injected by the compiler. Skip it.
+ if (!Line) continue;
Block.addLine(Line);
}
+ // Read the null terminator.
+ if (!Buff.readInt(Dummy)) return false;
}
- if (!Buff.readInt(Dummy)) return false; // flag
+ // The last word is either a flag or padding, it isn't clear which. Skip
+ // over it.
+ if (!Buff.readInt(Dummy)) return false;
}
return true;
}
OpenPOWER on IntegriCloud