]> granicus.if.org Git - llvm/commitdiff
[CodeView] Fix off-by-one error in def range gap emission
authorReid Kleckner <rnk@google.com>
Tue, 24 Jan 2017 16:57:55 +0000 (16:57 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 24 Jan 2017 16:57:55 +0000 (16:57 +0000)
Also fixes a much worse bug where we emitted the wrong gap size for the
def range uncovered by the test for this issue.

Fixes PR31726.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292949 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCCodeView.cpp
test/MC/COFF/cv-def-range-gap.s

index 3773542cf8a240428d92a1165795f13e36671417..99a5c11a498e9863342b5cac07dfbc6b8ebf7b2b 100644 (file)
@@ -509,17 +509,17 @@ void CodeViewContext::encodeDefRange(MCAsmLayout &Layout,
       // are artificially constructing.
       size_t RecordSize = FixedSizePortion.size() +
                           sizeof(LocalVariableAddrRange) + 4 * NumGaps;
-      // Write out the recrod size.
-      support::endian::Writer<support::little>(OS).write<uint16_t>(RecordSize);
+      // Write out the record size.
+      LEWriter.write<uint16_t>(RecordSize);
       // Write out the fixed size prefix.
       OS << FixedSizePortion;
       // Make space for a fixup that will eventually have a section relative
       // relocation pointing at the offset where the variable becomes live.
       Fixups.push_back(MCFixup::create(Contents.size(), BE, FK_SecRel_4));
-      Contents.resize(Contents.size() + 4); // Fixup for code start.
+      LEWriter.write<uint32_t>(0); // Fixup for code start.
       // Make space for a fixup that will record the section index for the code.
       Fixups.push_back(MCFixup::create(Contents.size(), BE, FK_SecRel_2));
-      Contents.resize(Contents.size() + 2); // Fixup for section index.
+      LEWriter.write<uint16_t>(0); // Fixup for section index.
       // Write down the range's extent.
       LEWriter.write<uint16_t>(Chunk);
 
@@ -529,7 +529,7 @@ void CodeViewContext::encodeDefRange(MCAsmLayout &Layout,
     } while (RangeSize > 0);
 
     // Emit the gaps afterwards.
-    assert((NumGaps == 0 || Bias < MaxDefRange) &&
+    assert((NumGaps == 0 || Bias <= MaxDefRange) &&
            "large ranges should not have gaps");
     unsigned GapStartOffset = GapAndRangeSizes[I].second;
     for (++I; I != J; ++I) {
@@ -537,7 +537,7 @@ void CodeViewContext::encodeDefRange(MCAsmLayout &Layout,
       assert(I < GapAndRangeSizes.size());
       std::tie(GapSize, RangeSize) = GapAndRangeSizes[I];
       LEWriter.write<uint16_t>(GapStartOffset);
-      LEWriter.write<uint16_t>(RangeSize);
+      LEWriter.write<uint16_t>(GapSize);
       GapStartOffset += GapSize + RangeSize;
     }
   }
index 243e777d92ea5d9125b54f16adfcb720e7d1fca2..9c1531819963fbba3bb40066e359d8927eae2e77 100644 (file)
 # CHECK-NEXT:        ISectStart: 0x0
 # CHECK-NEXT:        Range: 0x1
 # CHECK-NEXT:      }
+# CHECK-NEXT:    }
+# CHECK-NEXT:    DefRangeRegister {
+# CHECK-NEXT:      Register: 23
+# CHECK-NEXT:      MayHaveNoName: 0
+# CHECK-NEXT:      LocalVariableAddrRange {
+# CHECK-NEXT:        OffsetStart: .text+0x2001C
+# CHECK-NEXT:        ISectStart: 0x0
+# CHECK-NEXT:        Range: 0xF000
+# CHECK-NEXT:      }
+# CHECK-NEXT:      LocalVariableAddrGap [
+# CHECK-NEXT:        GapStartOffset: 0x1
+# CHECK-NEXT:        Range: 0xEFFE
+# CHECK-NEXT:      ]
 # CHECK-NEXT:    }
 
        .text
@@ -62,6 +75,16 @@ f:                                      # @f
 .Lbegin3:
        nop
 .Lend3:
+
+       # Create a range that is exactly 0xF000 bytes long with a gap in the
+       # middle.
+.Lbegin4:
+       nop
+.Lend4:
+       .fill 0xeffe, 1, 0x90
+.Lbegin5:
+       nop
+.Lend5:
        ret
 .Lfunc_end0:
 
@@ -94,6 +117,7 @@ f:                                      # @f
        .asciz  "p"
 .Ltmp19:
        .cv_def_range    .Lbegin0 .Lend0 .Lbegin1 .Lend1 .Lbegin2 .Lend2 .Lbegin3 .Lend3, "A\021\027\000\000\000"
+       .cv_def_range    .Lbegin4 .Lend4 .Lbegin5 .Lend5, "A\021\027\000\000\000"
        .short  2                       # Record length
        .short  4431                    # Record kind: S_PROC_ID_END
 .Ltmp15: