[libcxx-commits] [libcxx] mark std::make_format_args with clang::lifetimebound attribute (PR #78997)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 24 08:19:35 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/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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}}
}
>From 64f5b0969ff6ca50a809a801bf443062644196c4 Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Wed, 24 Jan 2024 19:05:40 +0400
Subject: [PATCH 7/9] fix test wide characters support
---
.../diagnostics/format.lifetimebound_extensions.verify.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
index 3bab29844bdc97e..6f2b3f2487de40a 100644
--- a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
@@ -12,6 +12,8 @@
#include <format>
+#include "test_macros.h"
+
int j;
auto test_format() {
@@ -20,8 +22,10 @@ auto test_format() {
j, i); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
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}}
}
+#endif // TEST_HAS_NO_WIDE_CHARACTERS
>From 1a21f029fe64b0c2e7eb44d276aa13d5dba678fe Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Wed, 24 Jan 2024 19:22:55 +0400
Subject: [PATCH 8/9] ?fix test?
---
.../format.lifetimebound_extensions.verify.cpp | 8 --------
1 file changed, 8 deletions(-)
diff --git a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
index 6f2b3f2487de40a..289409d4c8e1e4d 100644
--- a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
@@ -1,11 +1,3 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
>From 2dbfba570f2d061bbf5ab90351ddde1aa5d325b2 Mon Sep 17 00:00:00 2001
From: Kelbon Nik <kelbonage at gmail.com>
Date: Wed, 24 Jan 2024 20:19:20 +0400
Subject: [PATCH 9/9] ?
---
.../diagnostics/format.lifetimebound_extensions.verify.cpp | 5 -----
1 file changed, 5 deletions(-)
diff --git a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
index 289409d4c8e1e4d..afc51b6bb337ff6 100644
--- a/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/format.lifetimebound_extensions.verify.cpp
@@ -1,19 +1,14 @@
// Check that format functions are marked [[clang::lifetimebound]] as a conforming extension
// UNSUPPORTED: c++03, c++11, c++14, c++17
-
#include <format>
-
#include "test_macros.h"
-
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}}
}
-
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
auto test_wformat() {
int i = 0;
More information about the libcxx-commits
mailing list