[clang] [LifetimeSafety] Fix lifetimebound fix-it location for defaulted parameters (PR #198092)
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 16 07:11:50 PDT 2026
https://github.com/NeKon69 created https://github.com/llvm/llvm-project/pull/198092
Earlier, we placed the attribute after the full parameter declaration. Now, in the default-argument case, we place it after the parameter name.
Fixes #192271
>From 5390628210a19e2139753a0d7de76bc89a27b60e Mon Sep 17 00:00:00 2001
From: NeKon69 <nobodqwe at gmail.com>
Date: Fri, 15 May 2026 23:58:09 +0300
Subject: [PATCH 1/2] apply fix
---
clang/lib/Sema/SemaLifetimeSafety.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/clang/lib/Sema/SemaLifetimeSafety.h b/clang/lib/Sema/SemaLifetimeSafety.h
index 1b5907a09e291..7acda33f7a8fa 100644
--- a/clang/lib/Sema/SemaLifetimeSafety.h
+++ b/clang/lib/Sema/SemaLifetimeSafety.h
@@ -240,6 +240,12 @@ class LifetimeSafetySemaHelperImpl : public LifetimeSafetySemaHelper {
// parsed as a type attribute, not a parameter attribute.
InsertionPoint = ParmToAnnotate->getBeginLoc();
FixItText = "[[clang::lifetimebound]] ";
+ } else if (ParmToAnnotate->hasDefaultArg()) {
+ // If the parameter has a default argument, place the attribute after the
+ // named parameter.
+ InsertionPoint =
+ Lexer::getLocForEndOfToken(ParmToAnnotate->getLocation(), 0,
+ S.getSourceManager(), S.getLangOpts());
}
S.Diag(ParmToAnnotate->getBeginLoc(), DiagID)
<< ParmToAnnotate->getSourceRange()
>From 57beb487c0ea13c7258445f3fca3cd06f20560fd Mon Sep 17 00:00:00 2001
From: NeKon69 <nobodqwe at gmail.com>
Date: Sat, 16 May 2026 17:08:16 +0300
Subject: [PATCH 2/2] change comment and fix a test
---
clang/lib/Sema/SemaLifetimeSafety.h | 2 +-
clang/test/Sema/warn-lifetime-safety-fixits.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaLifetimeSafety.h b/clang/lib/Sema/SemaLifetimeSafety.h
index 7acda33f7a8fa..7c3be40c22b0e 100644
--- a/clang/lib/Sema/SemaLifetimeSafety.h
+++ b/clang/lib/Sema/SemaLifetimeSafety.h
@@ -242,7 +242,7 @@ class LifetimeSafetySemaHelperImpl : public LifetimeSafetySemaHelper {
FixItText = "[[clang::lifetimebound]] ";
} else if (ParmToAnnotate->hasDefaultArg()) {
// If the parameter has a default argument, place the attribute after the
- // named parameter.
+ // named argument.
InsertionPoint =
Lexer::getLocForEndOfToken(ParmToAnnotate->getLocation(), 0,
S.getSourceManager(), S.getLangOpts());
diff --git a/clang/test/Sema/warn-lifetime-safety-fixits.cpp b/clang/test/Sema/warn-lifetime-safety-fixits.cpp
index 3ae252a9d00f2..3c440c9d554dc 100644
--- a/clang/test/Sema/warn-lifetime-safety-fixits.cpp
+++ b/clang/test/Sema/warn-lifetime-safety-fixits.cpp
@@ -52,7 +52,7 @@ View param_with_attr(View a [[maybe_unused]]) {
View param_default(View a = View()) {
// CHECK: :[[@LINE-1]]:20: warning: parameter in intra-TU function should be marked
- // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:35-[[@LINE-2]]:35}:" {{\[\[}}clang::lifetimebound]]"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:26-[[@LINE-2]]:26}:" {{\[\[}}clang::lifetimebound]]"
return a;
}
More information about the cfe-commits
mailing list