[lld] [LLD] Fix crash on parsing ':ALIGN' in linker script (PR #146723)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 09:37:41 PDT 2025


================
@@ -1229,6 +1229,9 @@ SymbolAssignment *ScriptParser::readSymbolAssignment(StringRef name) {
 // This is an operator-precedence parser to parse a linker
 // script expression.
 Expr ScriptParser::readExpr() {
+  // Do not try to read expression if an error has already been encountered.
+  if (atEOF())
----------------
smithp35 wrote:

I think this will work, although I think it may be more idiomatic to use
```
if (errCount(ctx))
  return 0;
```
That way you don't need the comment to explain that atEOF will return true if there's an error. The return 0 comes from other places where an ErrAlways has occurred, such as
```
      ErrAlways(ctx) << loc << ": division by zero";
      return 0;
```

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


More information about the llvm-commits mailing list