https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/233305
>From f23aa2ac902fe60344ef697becfc8b024b461c28 Mon Sep 17 00:00:00 2001 From: Alex Richardson <[email protected]> Date: Wed, 28 Oct 2026 11:12:57 -0700 Subject: [PATCH] [nspr] initial commit --- .../Support/SourceMgrDiagnosticVerifier.cpp | 31 ++++++++++++++++--- llvm/test/tools/llvm-mc/verify/line-offsets.s | 24 +++++++------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp index 89926a00867857..d911f63610cf42 100644 --- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp +++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp @@ -174,13 +174,36 @@ SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os, if (!offsetMatch.empty()) { // Get the integer value without the @ and +/- prefix. if (offsetMatch[0] == '+' || offsetMatch[0] == '-') { - int offset; - offsetMatch.drop_front().getAsInteger(0, offset); + // Parse as decimal so that e.g. '@+08' is not treated as octal. + unsigned offset; + if (offsetMatch.drop_front().getAsInteger(10, offset)) { + record.emitError(os, mgr, + "invalid line offset '" + offsetMatch + "'"); + ok = false; + continue; + } - if (offsetMatch.front() == '+') + if (offsetMatch.front() == '+') { + if (offset > e - record.lineNo) { + record.emitError(os, mgr, + "line offset '" + offsetMatch + + "' is past the end of the file"); + ok = false; + continue; + } record.lineNo += offset; - else + } else { + // Line 0 is allowed since MLIR uses it for the implicit top-level + // module. + if (offset > record.lineNo) { + record.emitError(os, mgr, + "line offset '" + offsetMatch + + "' is before the start of the file"); + ok = false; + continue; + } record.lineNo -= offset; + } } else if (offsetMatch.consume_front("unknown")) { // This is matching unknown locations. record.fileLoc = SMLoc(); diff --git a/llvm/test/tools/llvm-mc/verify/line-offsets.s b/llvm/test/tools/llvm-mc/verify/line-offsets.s index a794f86979064d..941760234e83d8 100644 --- a/llvm/test/tools/llvm-mc/verify/line-offsets.s +++ b/llvm/test/tools/llvm-mc/verify/line-offsets.s @@ -4,11 +4,10 @@ # RUN: rm -rf %t && split-file %s %t && cd %t #--- octal.s -## FIXME: '010' is parsed as octal (8), so the directive points at line 6. -# RUN: not llvm-mc --triple=x86_64 --verify octal.s 2>&1 \ -# RUN: | FileCheck octal.s --implicit-check-not=error: +## '010' is decimal, not octal. +# RUN: llvm-mc --triple=x86_64 --verify octal.s .foo_directive -# CHECK: octal.s:[[#@LINE-1]]:1: error: unexpected error: unknown directive + @@ -18,11 +17,10 @@ # expected-error@-010 {{unknown directive}} -# CHECK: octal.s:[[#@LINE-1]]:3: error: expected error "unknown directive" was not produced #--- leading-zero.s -## FIXME: '08' is not valid octal, so the offset is read uninitialized. -# DISABLED: llvm-mc --triple=x86_64 --verify leading-zero.s +## '08' is decimal, not an invalid octal number. +# RUN: llvm-mc --triple=x86_64 --verify leading-zero.s .foo_directive @@ -34,20 +32,20 @@ # expected-error@-08 {{unknown directive}} #--- overflow.s -## FIXME: The offset does not fit in an int, so it is read uninitialized. -# DISABLED: not llvm-mc --triple=x86_64 --verify overflow.s 2>&1 \ -# DISABLED: | FileCheck overflow.s --implicit-check-not=error: +## Offsets that do not fit in an int are rejected. +# RUN: not llvm-mc --triple=x86_64 --verify overflow.s 2>&1 \ +# RUN: | FileCheck overflow.s --implicit-check-not=error: # expected-error@+99999999999 {{overflow}} # CHECK: overflow.s:[[#@LINE-1]]:3: error: invalid line offset '+99999999999' #--- out-of-range.s -## FIXME: Offsets before the start or past the end of the file are accepted. +## Offsets before the start or past the end of the file are rejected. # RUN: not llvm-mc --triple=x86_64 --verify out-of-range.s 2>&1 \ # RUN: | FileCheck out-of-range.s --implicit-check-not=error: ## Line 0 is allowed since MLIR uses it for the implicit top-level module. # expected-error@-5 {{line zero}} # expected-error@-99 {{before start}} # expected-error@+99 {{past end}} +# CHECK: out-of-range.s:6:3: error: line offset '-99' is before the start of the file +# CHECK: out-of-range.s:7:3: error: line offset '+99' is past the end of the file # CHECK: out-of-range.s:5:3: error: expected error "line zero" was not produced -# CHECK: out-of-range.s:6:3: error: expected error "before start" was not produced -# CHECK: out-of-range.s:7:3: error: expected error "past end" was not produced _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
