Skip to content

Commit b1b69d1

Browse files
authored
[Clang] Add macros for noescape and lifetime annotations (#10644)
rdar://149691819 (cherry picked from commit ac356e7)
1 parent 606a7f3 commit b1b69d1

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

clang/lib/Headers/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ set(files
290290
# TO_UPSTREAM(BoundsSafety)
291291
list(APPEND files ptrcheck.h)
292292

293+
# TO_UPSTREAM(Lifetimebound)
294+
list(APPEND files lifetimebound.h)
295+
293296
set(cuda_wrapper_files
294297
cuda_wrappers/algorithm
295298
cuda_wrappers/cmath

clang/lib/Headers/lifetimebound.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*===---- lifetimebound.h - Lifetime attributes -----------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===------------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __LIFETIMEBOUND_H
11+
#define __LIFETIMEBOUND_H
12+
13+
#define __lifetimebound __attribute__((lifetimebound))
14+
15+
#define __lifetime_capture_by(X) __attribute__((lifetime_capture_by(X)))
16+
17+
#define __noescape __attribute__((noescape))
18+
19+
#endif /* __LIFETIMEBOUND_H */

clang/lib/Headers/module.modulemap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,11 @@ module ptrcheck {
334334
header "ptrcheck.h"
335335
export *
336336
}
337-
/* TO_UPSTREAM(BoundsSafety) OFF */
337+
/* TO_UPSTREAM(BoundsSafety) OFF */
338+
339+
/* TO_UPSTREAM(Lifetimebound) ON */
340+
module lifetimebound {
341+
header "lifetimebound.h"
342+
export *
343+
}
344+
/* TO_UPSTREAM(Lifetimebound) OFF */

clang/test/Headers/lifetimebound.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
// Verify that we can include <lifetimebound.h>
5+
#include <lifetimebound.h>
6+
7+
struct has_lifetimebound_method {
8+
const char* get_ptr(char* ptr __lifetimebound) const;
9+
};
10+
11+
struct has_lifetime_capture_by_method {
12+
void take_ptr(char* ptr __lifetime_capture_by(this));
13+
void take_ptr(has_lifetimebound_method a, char* ptr __lifetime_capture_by(a));
14+
};
15+
16+
struct has_noescape_method {
17+
void takes_noescape(char* ptr __noescape);
18+
};

0 commit comments

Comments
 (0)