[llvm] 2cc4bc1 - MCFragment: Initialize Offset to 0
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 14:13:25 PDT 2024
Author: Fangrui Song
Date: 2024-06-12T14:13:20-07:00
New Revision: 2cc4bc132cbcc76c5552cbc128830943ea596b3e
URL: https://github.com/llvm/llvm-project/commit/2cc4bc132cbcc76c5552cbc128830943ea596b3e
DIFF: https://github.com/llvm/llvm-project/commit/2cc4bc132cbcc76c5552cbc128830943ea596b3e.diff
LOG: MCFragment: Initialize Offset to 0
After 9d0754ada5dbbc0c009bcc2f7824488419cc5530 ("[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.
Added:
Modified:
llvm/include/llvm/MC/MCFragment.h
llvm/lib/MC/MCFragment.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/test/MC/ELF/layout-interdependency.s
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h
index 45599c940659e..ccfe6203514b0 100644
--- a/llvm/include/llvm/MC/MCFragment.h
+++ b/llvm/include/llvm/MC/MCFragment.h
@@ -61,14 +61,13 @@ class MCFragment {
MCSection *Parent;
/// The atom this fragment is in, as represented by its defining symbol.
- const MCSymbol *Atom;
+ const MCSymbol *Atom = nullptr;
- /// The offset of this fragment in its section. This is ~0 until
- /// initialized.
- uint64_t Offset;
+ /// The offset of this fragment in its section.
+ uint64_t Offset = 0;
/// The layout order of this fragment.
- unsigned LayoutOrder;
+ unsigned LayoutOrder = 0;
FragmentType Kind;
diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index 6d97e8ce552ba..e911fa21650f4 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -199,8 +199,7 @@ uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
MCFragment::MCFragment(FragmentType Kind, bool HasInstructions,
MCSection *Parent)
- : Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)), LayoutOrder(0),
- Kind(Kind), HasInstructions(HasInstructions) {
+ : Parent(Parent), Kind(Kind), HasInstructions(HasInstructions) {
if (Parent && !isa<MCDummyFragment>(*this))
Parent->addFragment(*this);
}
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index bf1ce76cdc14b..ff0558b186936 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -300,7 +300,7 @@ void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
// Assign all pending labels to offset 0 within the dummy "pending"
// fragment. (They will all be reassigned to a real fragment in
// flushPendingLabels())
- Symbol->setOffset(0);
+ assert(Symbol->getOffset() == 0);
addPendingLabel(Symbol);
}
diff --git a/llvm/test/MC/ELF/layout-interdependency.s b/llvm/test/MC/ELF/layout-interdependency.s
index 5ebcdfacdbad7..fc33b552a1d82 100644
--- a/llvm/test/MC/ELF/layout-interdependency.s
+++ b/llvm/test/MC/ELF/layout-interdependency.s
@@ -1,10 +1,13 @@
-# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null
+# RUN: not llvm-mc -filetype=obj -triple=x86_64 --defsym GAP=1 %s -o /dev/null 2>&1 | FileCheck %s
fct_end:
-# CHECK: layout-interdependency.s:[[#@LINE+1]]:7: error: invalid number of bytes
.fill (data_start - fct_end), 1, 42
-# CHECK: layout-interdependency.s:[[#@LINE+1]]:7: error: invalid number of bytes
+.ifdef GAP
+.byte 0
+.endif
+# CHECK: [[#@LINE+1]]:7: error: invalid number of bytes
.fill (fct_end - data_start), 1, 42
data_start:
More information about the llvm-commits
mailing list