Skip to content

Commit 0dc2e26

Browse files
author
git apple-llvm automerger
committed
Merge commit '21a2aaa4dd9c' from swift/release/6.2 into stable/20240723
2 parents d3d2462 + 21a2aaa commit 0dc2e26

File tree

3 files changed

+197
-0
lines changed

3 files changed

+197
-0
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,26 @@ void DarwinClang::addClangTargetOptions(
12951295
Action::OffloadKind DeviceOffloadKind) const {
12961296

12971297
Darwin::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
1298+
1299+
/* TO_UPSTREAM(BoundsSafety) ON*/
1300+
// When `-fbounds-safety` and new userspace Libc attributes are enabled
1301+
// set a macro that userspace Libc will look for to decide whether or not to
1302+
// enable -fbounds-safety annotations in its headers (rdar://84733153). This
1303+
// is only being set during the gradual enablement of new checks and will be
1304+
// removed once the transition is complete (rdar://137912561).
1305+
if (DriverArgs.hasFlagNoClaim(options::OPT_fbounds_safety,
1306+
options::OPT_fno_bounds_safety, false)) {
1307+
LangOptions::BoundsSafetyNewChecksMaskIntTy NewChecks =
1308+
ParseBoundsSafetyNewChecksMaskFromArgs(DriverArgs,
1309+
/*DiagnosticsEngine=*/nullptr);
1310+
if (NewChecks & LangOptions::BS_CHK_LibCAttributes) {
1311+
bool TargetWithoutUserspaceLibc = false;
1312+
if (getTriple().isOSDarwin() && !TargetWithoutUserspaceLibc) {
1313+
CC1Args.push_back("-D__LIBC_STAGED_BOUNDS_SAFETY_ATTRIBUTES");
1314+
}
1315+
}
1316+
}
1317+
/* TO_UPSTREAM(BoundsSafety) OFF*/
12981318
}
12991319

13001320
/// Take a path that speculatively points into Xcode and return the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// =============================================================================
2+
// Supported target triples
3+
// =============================================================================
4+
5+
// MACRO: -D__LIBC_STAGED_BOUNDS_SAFETY_ATTRIBUTES
6+
// NO_MACRO-NOT: -D__LIBC_STAGED_BOUNDS_SAFETY_ATTRIBUTES
7+
8+
// ios
9+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
10+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
11+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
12+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
13+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
14+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
15+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
16+
// RUN: | FileCheck --check-prefix=MACRO %s
17+
18+
// macos
19+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-macos \
20+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
21+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
22+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
23+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-macos \
24+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
25+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
26+
// RUN: | FileCheck --check-prefix=MACRO %s
27+
28+
// macos (legacy `darwin` os name in triple)
29+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-darwin \
30+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
31+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
32+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
33+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-darwin \
34+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
35+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
36+
// RUN: | FileCheck --check-prefix=MACRO %s
37+
38+
// watchos
39+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-watchos \
40+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
41+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
42+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
43+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-watchos \
44+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
45+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
46+
// RUN: | FileCheck --check-prefix=MACRO %s
47+
48+
// tvos
49+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-tvos \
50+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
51+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
52+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
53+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-tvos \
54+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
55+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
56+
// RUN: | FileCheck --check-prefix=MACRO %s
57+
58+
// =============================================================================
59+
// Check option is included in all and option variant without `=all` suffix
60+
// =============================================================================
61+
62+
// ios
63+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
64+
// RUN: -fno-bounds-safety-bringup-missing-checks=all \
65+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
66+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
67+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
68+
// RUN: -fno-bounds-safety-bringup-missing-checks \
69+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
70+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
71+
72+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
73+
// RUN: -fbounds-safety-bringup-missing-checks=all \
74+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
75+
// RUN: | FileCheck --check-prefix=MACRO %s
76+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
77+
// RUN: -fbounds-safety-bringup-missing-checks \
78+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
79+
// RUN: | FileCheck --check-prefix=MACRO %s
80+
81+
// =============================================================================
82+
// Unsupported target triples
83+
// =============================================================================
84+
85+
// linux
86+
// RUN: %clang -Wno-incompatible-sysroot -target x86_64-unknown-linux \
87+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
88+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
89+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
90+
// RUN: %clang -Wno-incompatible-sysroot -target x86_64-unknown-linux \
91+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
92+
// RUN: -x c -### -fbounds-safety %s 2>&1 \
93+
// RUN: | FileCheck --check-prefix=NO_MACRO %s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// This is similar to the driver test of the same name but we verify that
2+
// the macro is actually set/unset as expected.
3+
4+
// =============================================================================
5+
// Supported target triples
6+
// =============================================================================
7+
8+
// ios
9+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
10+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
11+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
12+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
13+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
14+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
15+
16+
// macos
17+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-macos \
18+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
19+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
20+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-macos \
21+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
22+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
23+
24+
// macos (legacy `darwin` os name in triple)
25+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-darwin \
26+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
27+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
28+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-darwin \
29+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
30+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
31+
32+
// watchos
33+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-watchos \
34+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
35+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
36+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-watchos \
37+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
38+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
39+
40+
// tvos
41+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-tvos \
42+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
43+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
44+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-tvos \
45+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
46+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
47+
48+
// =============================================================================
49+
// Unsupported target triples
50+
// =============================================================================
51+
52+
// linux
53+
// RUN: %clang -Wno-incompatible-sysroot -target x86_64-unknown-linux \
54+
// RUN: -fno-bounds-safety-bringup-missing-checks=libc_attributes \
55+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
56+
// RUN: %clang -Wno-incompatible-sysroot -target x86_64-unknown-linux \
57+
// RUN: -fbounds-safety-bringup-missing-checks=libc_attributes \
58+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
59+
60+
// =============================================================================
61+
// Check option is included in all and option variant without `=all` suffix
62+
// =============================================================================
63+
64+
// ios
65+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
66+
// RUN: -fno-bounds-safety-bringup-missing-checks=all \
67+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
68+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
69+
// RUN: -fno-bounds-safety-bringup-missing-checks \
70+
// RUN: -x c -Xclang -verify=no_macro -fbounds-safety -fsyntax-only %s
71+
72+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
73+
// RUN: -fbounds-safety-bringup-missing-checks=all \
74+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
75+
// RUN: %clang -Wno-incompatible-sysroot -target arm64-apple-ios \
76+
// RUN: -fbounds-safety-bringup-missing-checks \
77+
// RUN: -x c -Xclang -verify=macro -fbounds-safety -fsyntax-only %s
78+
79+
#ifndef __LIBC_STAGED_BOUNDS_SAFETY_ATTRIBUTES
80+
// no_macro-error@+1{{expected __LIBC_STAGED_BOUNDS_SAFETY_ATTRIBUTES macro}}
81+
#error expected __LIBC_STAGED_BOUNDS_SAFETY_ATTRIBUTES macro
82+
#endif
83+
84+
// macro-no-diagnostics

0 commit comments

Comments
 (0)