From 636628d8fde45fc2bb99a1016f7503d0e744ab89 Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig Date: Thu, 15 May 2025 15:36:28 +0200 Subject: [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. --- clang/lib/Frontend/CompilerInvocation.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 3945129..fd48e42 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3112,9 +3112,11 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) { Opts.CodeCompletionAt = ParsedSourceLocation::FromString(A->getValue()); - if (Opts.CodeCompletionAt.FileName.empty()) + if (Opts.CodeCompletionAt.FileName.empty()) { Diags.Report(diag::err_drv_invalid_value) - << A->getAsString(Args) << A->getValue(); + << A->getAsString(Args) << A->getValue(); + Diags.Report(diag::note_command_line_code_loc_requirement); + } } Opts.Plugins = Args.getAllArgValues(OPT_load); -- cgit v1.1