llvm-project/clang/test/CodeCompletion/source-loc-zero.cpp
Naveen Seth Hanig 636628d8fd
[clang] Enforce 1-based indexing for command line source locations (#139457)
Fixes #139375

Clang expects command line source locations to be provided using 1-based
indexing.
Currently, Clang does not reject zero as invalid argument for column or
line number, which can cause Clang to crash.

This commit extends validation in `ParsedSourceLocation::FromString` to
only accept (unsinged) non-zero integers.
2025-05-15 09:36:28 -04:00

12 lines
657 B
C++

// Regression test for #139375
// Clang uses 1-based indexing for source locations given from the command-line.
// Verify that Clang rejects 0 as an invalid value for line or column number.
// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:0:1 %s -o - 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-DIAG %s
// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:1:0 %s -o - 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-DIAG %s
// CHECK-DIAG: error: invalid value '{{.*}}' in '-code-completion-at={{.*}}'
// CHECK-NEXT: hint: -code-completion-at=<file>:<line>:<column> requires <line> and <column> to be integers greater than zero