[libcxx-commits] [libcxx] mark std::make_format_args with clang::lifetimebound attribute (PR #78997)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 22 11:06:37 PST 2024
https://github.com/kelbon updated https://github.com/llvm/llvm-project/pull/78997
>From 1638b0d3d8c16473b1d51d69b4b01756f2e7d760 Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Mon, 22 Jan 2024 19:46:13 +0400
Subject: [PATCH 1/6] add lifetime bound on make_format_args
---
libcxx/include/__format/format_functions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 015bff70f51d977..0de1c5dc7c5e326 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -63,7 +63,7 @@ using wformat_args = basic_format_args<wformat_context>;
# endif
template <class _Context = format_context, class... _Args>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&... __args) {
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&... __args [[clang::lifetimebound]]) {
return _VSTD::__format_arg_store<_Context, _Args...>(__args...);
}
>From 91d484f7b1701e0003aa68c7bc019c5be10ece1f Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Mon, 22 Jan 2024 20:03:08 +0400
Subject: [PATCH 2/6] format
---
libcxx/include/__format/format_functions.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 0de1c5dc7c5e326..8e5396b053967ca 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -63,7 +63,8 @@ using wformat_args = basic_format_args<wformat_context>;
# endif
template <class _Context = format_context, class... _Args>
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&... __args [[clang::lifetimebound]]) {
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...>
+make_format_args(_Args&... __args [[clang::lifetimebound]]) {
return _VSTD::__format_arg_store<_Context, _Args...>(__args...);
}
>From 9012f00a62c59947a683aa93ea7358916ea3b443 Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Mon, 22 Jan 2024 20:05:34 +0400
Subject: [PATCH 3/6] use macroname intead raw attribute
---
libcxx/include/__format/format_functions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 8e5396b053967ca..d4f53ad66ef99e9 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -64,7 +64,7 @@ using wformat_args = basic_format_args<wformat_context>;
template <class _Context = format_context, class... _Args>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...>
-make_format_args(_Args&... __args [[clang::lifetimebound]]) {
+make_format_args(_Args&... __args _LIBCPP_LIFETIMEBOUND) {
return _VSTD::__format_arg_store<_Context, _Args...>(__args...);
}
>From 814b4e848fcd7e627d165877f1f4811407c5a60c Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Mon, 22 Jan 2024 23:00:57 +0400
Subject: [PATCH 4/6] wformat and test
---
libcxx/include/__format/format_functions.h | 2 +-
...format.lifetimebound_extensions.verify.cpp | 25 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index d4f53ad66ef99e9..595159e3ada20ab 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -71,7 +71,7 @@ make_format_args(_Args&... __args _LIBCPP_LIFETIMEBOUND) {
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <class... _Args>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...>
-make_wformat_args(_Args&... __args) {
+make_wformat_args(_Args&... __args _LIBCPP_LIFETIMEBOUND) {
return _VSTD::__format_arg_store<wformat_context, _Args...>(__args...);
}
# endif
diff --git a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
new file mode 100644
index 000000000000000..b3f81bc407f5d24
--- /dev/null
+++ b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Check that format functions are marked [[clang::lifetimebound]] as a conforming extension
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+#include <format>
+
+int j;
+
+auto test_format() {
+ int i = 0;
+ return std::make_format_args(j, i); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
+}
+
+auto test_wformat() {
+ int i = 0;
+ return std::make_format_args(i, j); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
+}
>From 42e1b00e85c37d143221cece3a8877ec3fe3305b Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Mon, 22 Jan 2024 23:01:45 +0400
Subject: [PATCH 5/6] test
---
.../diagnostics/format.lifetimebound_extensions.verify.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
index b3f81bc407f5d24..6b21e886f1e8564 100644
--- a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
@@ -21,5 +21,5 @@ auto test_format() {
auto test_wformat() {
int i = 0;
- return std::make_format_args(i, j); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
+ return std::make_wformat_args(i, j); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}
>From 0297fd2aae15227c55fbeb4bbfe62e49a35286f8 Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Mon, 22 Jan 2024 23:06:23 +0400
Subject: [PATCH 6/6] format
---
.../format.lifetimebound_extensions.verify.cpp | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
index 6b21e886f1e8564..3bab29844bdc97e 100644
--- a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
@@ -15,11 +15,13 @@
int j;
auto test_format() {
- int i = 0;
- return std::make_format_args(j, i); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
+ int i = 0;
+ return std::make_format_args(
+ j, i); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}
auto test_wformat() {
- int i = 0;
- return std::make_wformat_args(i, j); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
+ int i = 0;
+ return std::make_wformat_args(
+ i, j); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}
More information about the libcxx-commits
mailing list