[llvm] [MC][RISCV][LoongArch] Add AlignFragment size if layout is available and not need insert nops (PR #76552)

Jinyang He via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 17:13:56 PST 2024


MQ-mengqing wrote:


> ```assembly
> .section ""
> ```

I find it is because the AF->STI is uninitialized in this section. (Not call MCAlignFragment::setEmitNops). I think it can fix by the following diff,
```diff
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 9dae026535cc..80def6dfc24b 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -708,7 +708,7 @@ static void AttemptToFoldSymbolOffsetDifference(
       if (DF) {
         Displacement += DF->getContents().size();
       } else if (auto *AF = dyn_cast<MCAlignFragment>(FI);
-                 AF && Layout &&
+                 AF && Layout && AF->hasEmitNops() &&
                  !Asm->getBackend().shouldInsertExtraNopBytesForCodeAlign(
                      *AF, Count)) {
         Displacement += Asm->computeFragmentSize(*Layout, *AF);
```

https://github.com/llvm/llvm-project/pull/76552


More information about the llvm-commits mailing list