Skip to content

Commit 2cc4bc1

Browse files
committed
MCFragment: Initialize Offset to 0
After 9d0754a ("[MC] Relax fragments eagerly") removes the assert of Offset, it is no longer useful to initialize the member to -1. Now the symbol value estimate is more precise, which leads to slight behavior change to layout-interdependency.s.
1 parent 2c6f486 commit 2cc4bc1

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

llvm/include/llvm/MC/MCFragment.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ class MCFragment {
6161
MCSection *Parent;
6262

6363
/// The atom this fragment is in, as represented by its defining symbol.
64-
const MCSymbol *Atom;
64+
const MCSymbol *Atom = nullptr;
6565

66-
/// The offset of this fragment in its section. This is ~0 until
67-
/// initialized.
68-
uint64_t Offset;
66+
/// The offset of this fragment in its section.
67+
uint64_t Offset = 0;
6968

7069
/// The layout order of this fragment.
71-
unsigned LayoutOrder;
70+
unsigned LayoutOrder = 0;
7271

7372
FragmentType Kind;
7473

llvm/lib/MC/MCFragment.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
199199

200200
MCFragment::MCFragment(FragmentType Kind, bool HasInstructions,
201201
MCSection *Parent)
202-
: Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)), LayoutOrder(0),
203-
Kind(Kind), HasInstructions(HasInstructions) {
202+
: Parent(Parent), Kind(Kind), HasInstructions(HasInstructions) {
204203
if (Parent && !isa<MCDummyFragment>(*this))
205204
Parent->addFragment(*this);
206205
}

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
300300
// Assign all pending labels to offset 0 within the dummy "pending"
301301
// fragment. (They will all be reassigned to a real fragment in
302302
// flushPendingLabels())
303-
Symbol->setOffset(0);
303+
assert(Symbol->getOffset() == 0);
304304
addPendingLabel(Symbol);
305305
}
306306

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s
1+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null
2+
# RUN: not llvm-mc -filetype=obj -triple=x86_64 --defsym GAP=1 %s -o /dev/null 2>&1 | FileCheck %s
23

34
fct_end:
45

5-
# CHECK: layout-interdependency.s:[[#@LINE+1]]:7: error: invalid number of bytes
66
.fill (data_start - fct_end), 1, 42
7-
# CHECK: layout-interdependency.s:[[#@LINE+1]]:7: error: invalid number of bytes
7+
.ifdef GAP
8+
.byte 0
9+
.endif
10+
# CHECK: [[#@LINE+1]]:7: error: invalid number of bytes
811
.fill (fct_end - data_start), 1, 42
912

1013
data_start:

0 commit comments

Comments
 (0)