Skip to content

Commit ac356e7

Browse files
committed
[Clang] Add macros for noescape and lifetime annotations
rdar://149691819
1 parent 1e52793 commit ac356e7

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
@@ -329,6 +329,9 @@ set(files
329329
# TO_UPSTREAM(BoundsSafety)
330330
list(APPEND files ptrcheck.h)
331331

332+
# TO_UPSTREAM(Lifetimebound)
333+
list(APPEND files lifetimebound.h)
334+
332335
set(cuda_wrapper_files
333336
cuda_wrappers/algorithm
334337
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
@@ -332,4 +332,11 @@ module ptrcheck {
332332
header "ptrcheck.h"
333333
export *
334334
}
335-
/* TO_UPSTREAM(BoundsSafety) OFF */
335+
/* TO_UPSTREAM(BoundsSafety) OFF */
336+
337+
/* TO_UPSTREAM(Lifetimebound) ON */
338+
module lifetimebound {
339+
header "lifetimebound.h"
340+
export *
341+
}
342+
/* 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)