Skip to content

Commit 06a9bfa

Browse files
committed
merge main into amd-staging
Change-Id: I82e57261113c1af5d2a2e2613942fee77770e88c
2 parents 163b666 + 6521945 commit 06a9bfa

File tree

106 files changed

+3384
-4177
lines changed

Some content is hidden

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

106 files changed

+3384
-4177
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ AST_MATCHER_P(Stmt, ignoreUnsafeBufferInContainer,
250250

251251
AST_MATCHER_P(Stmt, ignoreUnsafeLibcCall, const UnsafeBufferUsageHandler *,
252252
Handler) {
253-
return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc());
253+
if (Finder->getASTContext().getLangOpts().CPlusPlus)
254+
return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc());
255+
return true; /* Only warn about libc calls for C++ */
254256
}
255257

256258
AST_MATCHER_P(CastExpr, castSubExpr, internal::Matcher<Expr>, innerMatcher) {
@@ -784,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg,
784786
return false; // possibly some user-defined printf function
785787

786788
ASTContext &Ctx = Finder->getASTContext();
787-
QualType FristParmTy = FD->getParamDecl(0)->getType();
789+
QualType FirstParmTy = FD->getParamDecl(0)->getType();
788790

789-
if (!FristParmTy->isPointerType())
791+
if (!FirstParmTy->isPointerType())
790792
return false; // possibly some user-defined printf function
791793

792-
QualType FirstPteTy = (cast<PointerType>(FristParmTy))->getPointeeType();
794+
QualType FirstPteTy = FirstParmTy->castAs<PointerType>()->getPointeeType();
793795

794796
if (!Ctx.getFILEType()
795797
.isNull() && //`FILE *` must be in the context if it is fprintf
@@ -865,7 +867,7 @@ AST_MATCHER(CallExpr, hasUnsafeSnprintfBuffer) {
865867
if (!FirstParmTy->isPointerType())
866868
return false; // Not an snprint
867869

868-
QualType FirstPteTy = cast<PointerType>(FirstParmTy)->getPointeeType();
870+
QualType FirstPteTy = FirstParmTy->castAs<PointerType>()->getPointeeType();
869871
const Expr *Buf = Node.getArg(0), *Size = Node.getArg(1);
870872

871873
if (FirstPteTy.isConstQualified() || !Buf->getType()->isPointerType() ||

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
348348
}
349349
}
350350

351+
// Don't allow breaking before a closing brace of a block-indented braced list
352+
// initializer if there isn't already a break.
353+
if (Current.is(tok::r_brace) && Current.MatchingParen &&
354+
Current.isBlockIndentedInitRBrace(Style)) {
355+
return CurrentState.BreakBeforeClosingBrace;
356+
}
357+
351358
// If binary operators are moved to the next line (including commas for some
352359
// styles of constructor initializers), that's always ok.
353360
if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
25812581
!Diags.isIgnored(diag::warn_unsafe_buffer_variable, SourceLocation()) ||
25822582
!Diags.isIgnored(diag::warn_unsafe_buffer_usage_in_container,
25832583
SourceLocation()) ||
2584-
!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation())) {
2584+
(!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation()) &&
2585+
S.getLangOpts().CPlusPlus /* only warn about libc calls in C++ */)) {
25852586
CallableVisitor(CallAnalyzers).TraverseTranslationUnitDecl(TU);
25862587
}
25872588
}

clang/test/Driver/riscv32-toolchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// C-RV32-BAREMETAL-ILP32: "{{.*}}Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/../../../../bin/riscv32-unknown-elf-ld"
2525
// C-RV32-BAREMETAL-ILP32: "--sysroot={{.*}}/Inputs/basic_riscv32_tree/riscv32-unknown-elf"
26-
// C-RV64-BAREMETAL-LP64-SAME: "-X"
26+
// C-RV32-BAREMETAL-ILP32: "-X"
2727
// C-RV32-BAREMETAL-ILP32: "{{.*}}/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib/crt0.o"
2828
// C-RV32-BAREMETAL-ILP32: "{{.*}}/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/crtbegin.o"
2929
// C-RV32-BAREMETAL-ILP32: "-L{{.*}}/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1"

clang/test/Driver/riscv64-toolchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// C-RV64-BAREMETAL-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin/riscv64-unknown-elf-ld"
2525
// C-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf"
26-
// C-RV64-BAREMETAL-LP64-SAME: "-X"
26+
// C-RV64-BAREMETAL-LP64: "-X"
2727
// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib/crt0.o"
2828
// C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/crtbegin.o"
2929
// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1"

clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \
22
// RUN: -verify %s
3+
// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \
4+
// RUN: -verify %s -x objective-c++
35
// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage-in-libc-call \
46
// RUN: -verify %s
57

@@ -56,6 +58,11 @@ namespace std {
5658
}
5759

5860
void f(char * p, char * q, std::span<char> s, std::span<char> s2) {
61+
typedef FILE * _Nullable aligned_file_ptr_t __attribute__((align_value(64)));
62+
typedef char * _Nullable aligned_char_ptr_t __attribute__((align_value(64)));
63+
aligned_file_ptr_t fp;
64+
aligned_char_ptr_t cp;
65+
5966
memcpy(); // expected-warning{{function 'memcpy' is unsafe}}
6067
std::memcpy(); // expected-warning{{function 'memcpy' is unsafe}}
6168
__builtin_memcpy(p, q, 64); // expected-warning{{function '__builtin_memcpy' is unsafe}}
@@ -71,9 +78,11 @@ void f(char * p, char * q, std::span<char> s, std::span<char> s2) {
7178
printf("%s%d", // expected-warning{{function 'printf' is unsafe}}
7279
p, // expected-note{{string argument is not guaranteed to be null-terminated}} note attached to the unsafe argument
7380
*p);
81+
printf(cp, p, *p); // expected-warning{{function 'printf' is unsafe}} // expected-note{{string argument is not guaranteed to be null-terminated}}
7482
sprintf(q, "%s%d", "hello", *p); // expected-warning{{function 'sprintf' is unsafe}} expected-note{{change to 'snprintf' for explicit bounds checking}}
7583
swprintf(q, "%s%d", "hello", *p); // expected-warning{{function 'swprintf' is unsafe}} expected-note{{change to 'snprintf' for explicit bounds checking}}
7684
snprintf(q, 10, "%s%d", "hello", *p); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
85+
snprintf(cp, 10, "%s%d", "hello", *p); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
7786
snprintf(s.data(), s2.size(), "%s%d", "hello", *p); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
7887
snwprintf(s.data(), s2.size(), "%s%d", "hello", *p); // expected-warning{{function 'snwprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
7988
snwprintf_s( // expected-warning{{function 'snwprintf_s' is unsafe}}
@@ -84,15 +93,18 @@ void f(char * p, char * q, std::span<char> s, std::span<char> s2) {
8493
sscanf(p, "%s%d", "hello", *p); // expected-warning{{function 'sscanf' is unsafe}}
8594
sscanf_s(p, "%s%d", "hello", *p); // expected-warning{{function 'sscanf_s' is unsafe}}
8695
fprintf((FILE*)p, "%P%d%p%i hello world %32s", *p, *p, p, *p, p); // expected-warning{{function 'fprintf' is unsafe}} expected-note{{string argument is not guaranteed to be null-terminated}}
96+
fprintf(fp, "%P%d%p%i hello world %32s", *p, *p, p, *p, p); // expected-warning{{function 'fprintf' is unsafe}} expected-note{{string argument is not guaranteed to be null-terminated}}
8797
wprintf(L"hello %s", p); // expected-warning{{function 'wprintf' is unsafe}} expected-note{{string argument is not guaranteed to be null-terminated}}
8898

99+
89100
char a[10], b[11];
90101
int c[10];
91102
std::wstring WS;
92103

93104
snprintf(a, sizeof(b), "%s", __PRETTY_FUNCTION__); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
94105
snprintf((char*)c, sizeof(c), "%s", __PRETTY_FUNCTION__); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
95106
fprintf((FILE*)p, "%P%d%p%i hello world %32s", *p, *p, p, *p, "hello"); // no warn
107+
fprintf(fp, "%P%d%p%i hello world %32s", *p, *p, p, *p, "hello"); // no warn
96108
printf("%s%d", "hello", *p); // no warn
97109
snprintf(s.data(), s.size_bytes(), "%s%d", "hello", *p); // no warn
98110
snprintf(s.data(), s.size_bytes(), "%s%d", __PRETTY_FUNCTION__, *p); // no warn
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -Wunsafe-buffer-usage %s -verify %s -x c
2+
// RUN: %clang_cc1 -Wunsafe-buffer-usage %s -verify %s -x objective-c
3+
4+
void* __asan_memcpy(void *dst,const void *src, unsigned long size);
5+
6+
void f(int *p, int *q) {
7+
8+
__asan_memcpy(p, q, 10); // no libc warn in C
9+
++p[5]; // expected-warning{{unsafe buffer access}}
10+
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9441,6 +9441,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
94419441
" aaaaaaaaaaaaaaaa\n"
94429442
");",
94439443
Style);
9444+
verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
9445+
" aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)\n"
9446+
"};",
9447+
Style);
9448+
94449449
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
94459450
" const bool &aaaaaaaaa, const void *aaaaaaaaaa\n"
94469451
") const {\n"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %clangxx -O1 %s -o %t
2+
// RUN: rm -rf %t.tmp
3+
// RUN: %run %t 1
4+
// RUN: %run %t 2
5+
6+
#include <assert.h>
7+
#include <errno.h>
8+
#include <fcntl.h>
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
#include <sys/stat.h>
13+
#include <unistd.h>
14+
15+
void test(const char *path, int flags) {
16+
int fd = open(path, flags, 0600);
17+
if (fd == -1) {
18+
perror(path);
19+
if (errno == EOPNOTSUPP)
20+
return;
21+
}
22+
assert(fd != -1);
23+
struct stat info;
24+
int result = fstat(fd, &info);
25+
assert((info.st_mode & ~S_IFMT) == 0600);
26+
assert(result == 0);
27+
close(fd);
28+
}
29+
30+
int main(int argc, char *argv[]) {
31+
assert(argc == 2);
32+
char buff[10000];
33+
sprintf(buff, "%s.tmp", argv[0]);
34+
if (atoi(argv[1]) == 1) {
35+
unlink(buff);
36+
test(buff, O_RDWR | O_CREAT);
37+
}
38+
39+
#ifdef O_TMPFILE
40+
if (atoi(argv[1]) == 2) {
41+
char *last = strrchr(buff, '/');
42+
assert(last);
43+
*last = 0;
44+
test(buff, O_RDWR | O_TMPFILE);
45+
}
46+
#endif
47+
}

compiler-rt/test/tsan/Darwin/variadic-open.cpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ bool elf::isMipsN32Abi(const InputFile *f) {
377377
case ELF64BEKind:
378378
return isN32Abi<ELF64BE>(f);
379379
default:
380-
llvm_unreachable("unknown Config->EKind");
380+
llvm_unreachable("unknown ctx.arg.ekind");
381381
}
382382
}
383383

lld/ELF/CallGraphSort.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ constexpr uint64_t MAX_CLUSTER_SIZE = 1024 * 1024;
108108
using SectionPair =
109109
std::pair<const InputSectionBase *, const InputSectionBase *>;
110110

111-
// Take the edge list in Config->CallGraphProfile, resolve symbol names to
111+
// Take the edge list in ctx.arg.callGraphProfile, resolve symbol names to
112112
// Symbols, and generate a graph between InputSections with the provided
113113
// weights.
114114
CallGraphSort::CallGraphSort() {

0 commit comments

Comments
 (0)