Skip to content

Commit f8ce4a0

Browse files
tsepezAngle LUCI CQ
authored andcommitted
Add src/common/unsafe_buffers.h
Allow for line-by-line control of unsafe buffers warnings. Bug: b/436880895 Change-Id: I609d60c83611037f39d541d5b8c9aba98a6656a7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6886308 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Tom Sepez <tsepez@chromium.org>
1 parent 778969f commit f8ce4a0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/common/unsafe_buffers.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Copyright 2025 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
7+
// unsafe_buffers.h: exempts code from unsafe buffers warnings. Based upon
8+
// https://source.chromium.org/chromium/chromium/src/+/main:base/compiler_specific.h
9+
10+
#ifndef COMMON_UNSAFE_BUFFERS_H_
11+
#define COMMON_UNSAFE_BUFFERS_H_
12+
13+
#if defined(__clang__) && defined(__has_attribute)
14+
# if __has_attribute(unsafe_buffer_usage)
15+
# define ANGLE_UNSAFE_BUFFER_USAGE [[clang::unsafe_buffer_usage]]
16+
# endif
17+
#endif
18+
#if !defined(ANGLE_UNSAFE_BUFFER_USAGE)
19+
# define ANGLE_UNSAFE_BUFFER_USAGE
20+
#endif
21+
22+
// Formatting is off so that we can put each _Pragma on its own line.
23+
// clang-format off
24+
#if defined(UNSAFE_BUFFERS_BUILD)
25+
# define ANGLE_UNSAFE_BUFFERS(...) \
26+
_Pragma("clang unsafe_buffer_usage begin") \
27+
__VA_ARGS__ \
28+
_Pragma("clang unsafe_buffer_usage end")
29+
#else
30+
# define ANGLE_UNSAFE_BUFFERS(...) __VA_ARGS__
31+
#endif
32+
// clang-format on
33+
34+
// Like ANGLE_UNSAFE_BUFFERS(), but indicates there is a TODO() task.
35+
#define ANGLE_UNSAFE_TODO(...) ANGLE_UNSAFE_BUFFERS(__VA_ARGS__)
36+
37+
#endif // COMMON_UNSAFE_BUFFERS_H_

src/libGLESv2.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ libangle_common_headers = [
6363
"src/common/system_utils.h",
6464
"src/common/tls.h",
6565
"src/common/uniform_type_info_autogen.h",
66+
"src/common/unsafe_buffers.h",
6667
"src/common/utilities.h",
6768
"src/common/vector_utils.h",
6869
"src/libANGLE/CLBitField.h",

0 commit comments

Comments
 (0)