Skip to content

Commit 52d67a5

Browse files
committed
Merge branch 'main' into dealloc-vgprs
2 parents ae13d8a + b060661 commit 52d67a5

File tree

60 files changed

+1598
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1598
-414
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12499,7 +12499,7 @@ def warn_unsafe_buffer_variable : Warning<
1249912499
InGroup<UnsafeBufferUsage>, DefaultIgnore;
1250012500
def warn_unsafe_buffer_operation : Warning<
1250112501
"%select{unsafe pointer operation|unsafe pointer arithmetic|"
12502-
"unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of span::data|"
12502+
"unsafe buffer access|function introduces unsafe buffer manipulation|unsafe invocation of %1|"
1250312503
"field %1 prone to unsafe buffer manipulation}0">,
1250412504
InGroup<UnsafeBufferUsage>, DefaultIgnore;
1250512505
def warn_unsafe_buffer_libc_call : Warning<

clang/include/clang/Driver/Distro.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Distro {
8080
UbuntuMantic,
8181
UbuntuNoble,
8282
UbuntuOracular,
83+
UbuntuPlucky,
8384
UnknownDistro
8485
};
8586

@@ -131,7 +132,7 @@ class Distro {
131132
}
132133

133134
bool IsUbuntu() const {
134-
return DistroVal >= UbuntuHardy && DistroVal <= UbuntuOracular;
135+
return DistroVal >= UbuntuHardy && DistroVal <= UbuntuPlucky;
135136
}
136137

137138
bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,11 @@ class DataInvocationGadget : public WarningGadget {
14991499
}
15001500

15011501
static Matcher matcher() {
1502-
Matcher callExpr = cxxMemberCallExpr(
1503-
callee(cxxMethodDecl(hasName("data"), ofClass(hasName("std::span")))));
1502+
1503+
Matcher callExpr = cxxMemberCallExpr(callee(
1504+
cxxMethodDecl(hasName("data"),
1505+
ofClass(anyOf(hasName("std::span"), hasName("std::array"),
1506+
hasName("std::vector"))))));
15041507
return stmt(
15051508
explicitCastExpr(anyOf(has(callExpr), has(parenExpr(has(callExpr)))))
15061509
.bind(OpTag));

clang/lib/Driver/Distro.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static Distro::DistroType DetectLsbRelease(llvm::vfs::FileSystem &VFS) {
9696
.Case("mantic", Distro::UbuntuMantic)
9797
.Case("noble", Distro::UbuntuNoble)
9898
.Case("oracular", Distro::UbuntuOracular)
99+
.Case("plucky", Distro::UbuntuPlucky)
99100
.Default(Distro::UnknownDistro);
100101
return Version;
101102
}

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,9 +2279,18 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler {
22792279
QualType srcType = ECE->getSubExpr()->getType();
22802280
const uint64_t sSize =
22812281
Ctx.getTypeSize(srcType.getTypePtr()->getPointeeType());
2282+
22822283
if (sSize >= dSize)
22832284
return;
22842285

2286+
if (const auto *CE = dyn_cast<CXXMemberCallExpr>(
2287+
ECE->getSubExpr()->IgnoreParens())) {
2288+
D = CE->getMethodDecl();
2289+
}
2290+
2291+
if (!D)
2292+
return;
2293+
22852294
MsgParam = 4;
22862295
}
22872296
Loc = Operation->getBeginLoc();

clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,68 @@ void foo(int *p){}
3232
namespace std{
3333
template <typename T> class span {
3434

35-
T *elements;
35+
T *elements;
3636

37-
span(T *, unsigned){}
37+
span(T *, unsigned){}
3838

39-
public:
39+
public:
4040

41-
constexpr span<T> subspan(size_t offset, size_t count) const {
42-
return span<T> (elements+offset, count); // expected-warning{{unsafe pointer arithmetic}}
43-
}
41+
constexpr span<T> subspan(size_t offset, size_t count) const {
42+
return span<T> (elements+offset, count); // expected-warning{{unsafe pointer arithmetic}}
43+
}
4444

45-
constexpr T* data() const noexcept {
46-
return elements;
47-
}
45+
constexpr T* data() const noexcept {
46+
return elements;
47+
}
48+
49+
constexpr T* hello() const noexcept {
50+
return elements;
51+
}
52+
};
53+
54+
template <typename T> class vector {
55+
56+
T *elements;
57+
58+
public:
59+
60+
vector(size_t n) {
61+
elements = new T[n];
62+
}
63+
64+
constexpr T* data() const noexcept {
65+
return elements;
66+
}
67+
68+
~vector() {
69+
delete[] elements;
70+
}
71+
};
72+
73+
template <class T, size_t N>
74+
class array {
75+
T elements[N];
76+
77+
public:
78+
79+
constexpr const T* data() const noexcept {
80+
return elements;
81+
}
82+
83+
};
4884

49-
50-
constexpr T* hello() const noexcept {
51-
return elements;
52-
}
53-
};
54-
5585
template <typename T> class span_duplicate {
56-
span_duplicate(T *, unsigned){}
86+
span_duplicate(T *, unsigned){}
5787

58-
T array[10];
88+
T array[10];
5989

60-
public:
90+
public:
6191

62-
T* data() {
63-
return array;
64-
}
92+
T* data() {
93+
return array;
94+
}
6595

66-
};
96+
};
6797
}
6898

6999
using namespace std;
@@ -89,21 +119,28 @@ void cast_without_data(int *ptr) {
89119
float *p = (float*) ptr;
90120
}
91121

92-
void warned_patterns(std::span<int> span_ptr, std::span<Base> base_span, span<int> span_without_qual) {
93-
A *a1 = (A*)span_ptr.data(); // expected-warning{{unsafe invocation of span::data}}
94-
a1 = (A*)span_ptr.data(); // expected-warning{{unsafe invocation of span::data}}
122+
void warned_patterns_span(std::span<int> span_ptr, std::span<Base> base_span, span<int> span_without_qual) {
123+
A *a1 = (A*)span_ptr.data(); // expected-warning{{unsafe invocation of 'data'}}
124+
a1 = (A*)span_ptr.data(); // expected-warning{{unsafe invocation of 'data'}}
95125

96-
a1 = (A*)(span_ptr.data()); // expected-warning{{unsafe invocation of span::data}}
97-
A *a2 = (A*) (span_without_qual.data()); // expected-warning{{unsafe invocation of span::data}}
126+
a1 = (A*)(span_ptr.data()); // expected-warning{{unsafe invocation of 'data'}}
127+
A *a2 = (A*) (span_without_qual.data()); // expected-warning{{unsafe invocation of 'data'}}
98128

99-
a2 = (A*) span_without_qual.data(); // expected-warning{{unsafe invocation of span::data}}
129+
a2 = (A*) span_without_qual.data(); // expected-warning{{unsafe invocation of 'data'}}
100130

101131
// TODO:: Should we warn when we cast from base to derived type?
102-
Derived *b = dynamic_cast<Derived*> (base_span.data());// expected-warning{{unsafe invocation of span::data}}
132+
Derived *b = dynamic_cast<Derived*> (base_span.data());// expected-warning{{unsafe invocation of 'data'}}
103133

104134
// TODO:: This pattern is safe. We can add special handling for it, if we decide this
105135
// is the recommended fixit for the unsafe invocations.
106-
A *a3 = (A*)span_ptr.subspan(0, sizeof(A)).data(); // expected-warning{{unsafe invocation of span::data}}
136+
A *a3 = (A*)span_ptr.subspan(0, sizeof(A)).data(); // expected-warning{{unsafe invocation of 'data'}}
137+
}
138+
139+
void warned_patterns_array(std::array<int, 5> array_ptr, std::array<Base, 10> base_span, span<int> span_without_qual) {
140+
const A *a1 = (A*)array_ptr.data(); // expected-warning{{unsafe invocation of 'data'}}
141+
a1 = (A*)array_ptr.data(); // expected-warning{{unsafe invocation of 'data'}}
142+
143+
a1 = (A*)(array_ptr.data()); // expected-warning{{unsafe invocation of 'data'}}
107144
}
108145

109146
void not_warned_patterns(std::span<A> span_ptr, std::span<Base> base_span) {

compiler-rt/lib/rtsan/rtsan_stats.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@
1919
using namespace __sanitizer;
2020
using namespace __rtsan;
2121

22-
static atomic_uint32_t rtsan_total_error_count{0};
23-
static atomic_uint32_t rtsan_unique_error_count{0};
24-
static atomic_uint32_t rtsan_suppressed_count{0};
22+
static atomic_uint32_t total_error_count{0};
23+
static atomic_uint32_t unique_error_count{0};
24+
static atomic_uint32_t suppressed_count{0};
2525

2626
void __rtsan::IncrementTotalErrorCount() {
27-
atomic_fetch_add(&rtsan_total_error_count, 1, memory_order_relaxed);
27+
atomic_fetch_add(&total_error_count, 1, memory_order_relaxed);
2828
}
2929

3030
void __rtsan::IncrementUniqueErrorCount() {
31-
atomic_fetch_add(&rtsan_unique_error_count, 1, memory_order_relaxed);
31+
atomic_fetch_add(&unique_error_count, 1, memory_order_relaxed);
3232
}
3333

3434
static u32 GetTotalErrorCount() {
35-
return atomic_load(&rtsan_total_error_count, memory_order_relaxed);
35+
return atomic_load(&total_error_count, memory_order_relaxed);
3636
}
3737

3838
static u32 GetUniqueErrorCount() {
39-
return atomic_load(&rtsan_unique_error_count, memory_order_relaxed);
39+
return atomic_load(&unique_error_count, memory_order_relaxed);
4040
}
4141

4242
void __rtsan::IncrementSuppressedCount() {
43-
atomic_fetch_add(&rtsan_suppressed_count, 1, memory_order_relaxed);
43+
atomic_fetch_add(&suppressed_count, 1, memory_order_relaxed);
4444
}
4545

4646
static u32 GetSuppressedCount() {
47-
return atomic_load(&rtsan_suppressed_count, memory_order_relaxed);
47+
return atomic_load(&suppressed_count, memory_order_relaxed);
4848
}
4949

5050
void __rtsan::PrintStatisticsSummary() {

compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,42 @@ bool SignalContext::IsStackOverflow() const {
288288

289289
#endif // SANITIZER_GO
290290

291+
static void SetNonBlock(int fd) {
292+
int res = fcntl(fd, F_GETFL, 0);
293+
CHECK(!internal_iserror(res, nullptr));
294+
295+
res |= O_NONBLOCK;
296+
res = fcntl(fd, F_SETFL, res);
297+
CHECK(!internal_iserror(res, nullptr));
298+
}
299+
291300
bool IsAccessibleMemoryRange(uptr beg, uptr size) {
292-
uptr page_size = GetPageSizeCached();
293-
// Checking too large memory ranges is slow.
294-
CHECK_LT(size, page_size * 10);
295-
int sock_pair[2];
296-
if (pipe(sock_pair))
297-
return false;
298-
uptr bytes_written =
299-
internal_write(sock_pair[1], reinterpret_cast<void *>(beg), size);
300-
int write_errno;
301-
bool result;
302-
if (internal_iserror(bytes_written, &write_errno)) {
303-
CHECK_EQ(EFAULT, write_errno);
304-
result = false;
305-
} else {
306-
result = (bytes_written == size);
301+
while (size) {
302+
// `read` from `fds[0]` into a dummy buffer to free up the pipe buffer for
303+
// more `write` is slower than just recreating a pipe.
304+
int fds[2];
305+
CHECK_EQ(0, pipe(fds));
306+
307+
auto cleanup = at_scope_exit([&]() {
308+
internal_close(fds[0]);
309+
internal_close(fds[1]);
310+
});
311+
312+
SetNonBlock(fds[1]);
313+
314+
int write_errno;
315+
uptr w = internal_write(fds[1], reinterpret_cast<char *>(beg), size);
316+
if (internal_iserror(w, &write_errno)) {
317+
if (write_errno == EINTR)
318+
continue;
319+
CHECK_EQ(EFAULT, write_errno);
320+
return false;
321+
}
322+
size -= w;
323+
beg += w;
307324
}
308-
internal_close(sock_pair[0]);
309-
internal_close(sock_pair[1]);
310-
return result;
325+
326+
return true;
311327
}
312328

313329
void PlatformPrepareForSandboxing(void *args) {

compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ TEST(SanitizerCommon, PthreadDestructorIterations) {
6565

6666
TEST(SanitizerCommon, IsAccessibleMemoryRange) {
6767
const int page_size = GetPageSize();
68-
uptr mem = (uptr)mmap(0, 3 * page_size, PROT_READ | PROT_WRITE,
69-
MAP_PRIVATE | MAP_ANON, -1, 0);
68+
InternalMmapVector<char> buffer(3 * page_size);
69+
uptr mem = reinterpret_cast<uptr>(buffer.data());
7070
// Protect the middle page.
7171
mprotect((void *)(mem + page_size), page_size, PROT_NONE);
7272
EXPECT_TRUE(IsAccessibleMemoryRange(mem, page_size - 1));
@@ -78,8 +78,12 @@ TEST(SanitizerCommon, IsAccessibleMemoryRange) {
7878
EXPECT_TRUE(IsAccessibleMemoryRange(mem + 2 * page_size, page_size));
7979
EXPECT_FALSE(IsAccessibleMemoryRange(mem, 3 * page_size));
8080
EXPECT_FALSE(IsAccessibleMemoryRange(0x0, 2));
81+
}
8182

82-
munmap((void *)mem, 3 * page_size);
83+
TEST(SanitizerCommon, IsAccessibleMemoryRangeLarge) {
84+
InternalMmapVector<char> buffer(10000 * GetPageSize());
85+
EXPECT_TRUE(IsAccessibleMemoryRange(reinterpret_cast<uptr>(buffer.data()),
86+
buffer.size()));
8387
}
8488

8589
} // namespace __sanitizer

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,10 @@ class ParseTreeDumper {
884884
} else if constexpr (HasSource<T>::value) {
885885
return x.source.ToString();
886886
#endif
887-
} else if constexpr (std::is_same_v<T, std::string>) {
888-
return x;
887+
} else if constexpr (std::is_same_v<T, int>) {
888+
return std::to_string(x);
889+
} else if constexpr (std::is_same_v<T, bool>) {
890+
return x ? "true" : "false";
889891
} else {
890892
return "";
891893
}

0 commit comments

Comments
 (0)