llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-temporal-safety

Author: NeKon69

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/198092.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaLifetimeSafety.h (+6) 
- (modified) clang/test/Sema/warn-lifetime-safety-fixits.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaLifetimeSafety.h 
b/clang/lib/Sema/SemaLifetimeSafety.h
index 1b5907a09e291..7c3be40c22b0e 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 argument.
+      InsertionPoint =
+          Lexer::getLocForEndOfToken(ParmToAnnotate->getLocation(), 0,
+                                     S.getSourceManager(), S.getLangOpts());
     }
     S.Diag(ParmToAnnotate->getBeginLoc(), DiagID)
         << ParmToAnnotate->getSourceRange()
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;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/198092
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to