Skip to content

Commit 4e43160

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:d61ba038a9d4 into amd-gfx:41e3ec0eb900
Local branch amd-gfx 41e3ec0 Merged main:0b2778d5e591 into amd-gfx:737eb03a4009 Remote branch main d61ba03 [clang][Interp][NFC] Call delegate() for the RHS of a comma op
2 parents 41e3ec0 + d61ba03 commit 4e43160

File tree

43 files changed

+4310
-198
lines changed

Some content is hidden

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

43 files changed

+4310
-198
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,14 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
243243
std::optional<PrimType> RT = classify(RHS->getType());
244244
std::optional<PrimType> T = classify(BO->getType());
245245

246-
auto Discard = [this, T, BO](bool Result) {
247-
if (!Result)
248-
return false;
249-
return DiscardResult ? this->emitPop(*T, BO) : true;
250-
};
251-
252246
// Deal with operations which have composite or void types.
253247
if (BO->isCommaOp()) {
254248
if (!this->discard(LHS))
255249
return false;
256250
if (RHS->getType()->isVoidType())
257251
return this->discard(RHS);
258252

259-
// Otherwise, visit RHS and optionally discard its value.
260-
return Discard(Initializing ? this->visitInitializer(RHS)
261-
: this->visit(RHS));
253+
return this->delegate(RHS);
262254
}
263255

264256
if (!LT || !RT || !T)
@@ -285,6 +277,12 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
285277
return true;
286278
};
287279

280+
auto Discard = [this, T, BO](bool Result) {
281+
if (!Result)
282+
return false;
283+
return DiscardResult ? this->emitPop(*T, BO) : true;
284+
};
285+
288286
switch (BO->getOpcode()) {
289287
case BO_EQ:
290288
return MaybeCastToBool(this->emitEQ(*LT, BO));

clang/lib/Headers/arm_acle.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,21 @@ __smusdx(int16x2_t __a, int16x2_t __b) {
592592
}
593593
#endif
594594

595+
/* 8.6 Floating-point data-processing intrinsics */
596+
#if (defined(__ARM_FEATURE_DIRECTED_ROUNDING) && \
597+
(__ARM_FEATURE_DIRECTED_ROUNDING)) && \
598+
(defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE)
599+
static __inline__ double __attribute__((__always_inline__, __nodebug__))
600+
__rintn(double __a) {
601+
return __builtin_roundeven(__a);
602+
}
603+
604+
static __inline__ float __attribute__((__always_inline__, __nodebug__))
605+
__rintnf(float __a) {
606+
return __builtin_roundevenf(__a);
607+
}
608+
#endif
609+
595610
/* 9.7 CRC32 intrinsics */
596611
#if (defined(__ARM_FEATURE_CRC32) && __ARM_FEATURE_CRC32) || \
597612
(defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE)

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ bool isStdin(SVal Val, const ASTContext &ACtx) {
104104
// variable named stdin with the proper type.
105105
if (const auto *D = dyn_cast_or_null<VarDecl>(DeclReg->getDecl())) {
106106
D = D->getCanonicalDecl();
107-
// FIXME: This should look for an exact match.
108-
if (D->getName().contains("stdin") && D->isExternC()) {
107+
if (D->getName() == "stdin" && D->hasExternalStorage() && D->isExternC()) {
109108
const QualType FILETy = ACtx.getFILEType().getCanonicalType();
110109
const QualType Ty = D->getType().getCanonicalType();
111110

@@ -622,12 +621,14 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) const {
622621
{{{"getlogin_r"}}, TR::Source({{0}})},
623622

624623
// Props
624+
{{{"accept"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
625625
{{{"atoi"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
626626
{{{"atol"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
627627
{{{"atoll"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
628628
{{{"fgetc"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
629629
{{{"fgetln"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
630630
{{{"fgets"}}, TR::Prop({{2}}, {{0, ReturnValueIndex}})},
631+
{{{"fgetws"}}, TR::Prop({{2}}, {{0, ReturnValueIndex}})},
631632
{{{"fscanf"}}, TR::Prop({{0}}, {{}, 2})},
632633
{{{"fscanf_s"}}, TR::Prop({{0}}, {{}, {2}})},
633634
{{{"sscanf"}}, TR::Prop({{0}}, {{}, 2})},
@@ -695,6 +696,7 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) const {
695696
{{{"strndup"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
696697
{{{"strndupa"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
697698
{{{"strlen"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
699+
{{{"wcslen"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
698700
{{{"strnlen"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
699701
{{{"strtol"}}, TR::Prop({{0}}, {{1, ReturnValueIndex}})},
700702
{{{"strtoll"}}, TR::Prop({{0}}, {{1, ReturnValueIndex}})},
@@ -731,6 +733,8 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) const {
731733
TR::Prop({{1}}, {{0, ReturnValueIndex}})},
732734
{{CDF_MaybeBuiltin, {{"strcat"}}},
733735
TR::Prop({{1}}, {{0, ReturnValueIndex}})},
736+
{{CDF_MaybeBuiltin, {{"wcsncat"}}},
737+
TR::Prop({{1}}, {{0, ReturnValueIndex}})},
734738
{{CDF_MaybeBuiltin, {{"strdup"}}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
735739
{{CDF_MaybeBuiltin, {{"strdupa"}}},
736740
TR::Prop({{0}}, {{ReturnValueIndex}})},

clang/test/AST/Interp/literals.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ namespace DiscardExprs {
929929
(bool)1;
930930
__null;
931931
__builtin_offsetof(A, a);
932+
1,2;
932933

933934
return 0;
934935
}

clang/test/Analysis/taint-diagnostic-visitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ size_t strlen( const char* str );
1313
void *malloc(size_t size );
1414
void free( void *ptr );
1515
char *fgets(char *str, int n, FILE *stream);
16-
FILE *stdin;
16+
extern FILE *stdin;
1717

1818
void taintDiagnostic(void)
1919
{

clang/test/Analysis/taint-generic.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656
// CHECK-INVALID-ARG-SAME: rules greater or equal to -1
5757

5858
typedef long long rsize_t;
59+
typedef __typeof(sizeof(int)) size_t;
60+
typedef signed long long ssize_t;
61+
typedef __WCHAR_TYPE__ wchar_t;
5962
void clang_analyzer_isTainted_char(char);
63+
void clang_analyzer_isTainted_wchar(wchar_t);
6064
void clang_analyzer_isTainted_charp(char*);
6165
void clang_analyzer_isTainted_int(int);
6266

@@ -75,6 +79,17 @@ extern FILE *stdin;
7579
#define bool _Bool
7680
#define NULL (void*)0
7781

82+
wchar_t *fgetws(wchar_t *ws, int n, FILE *stream);
83+
wchar_t *wmemset(wchar_t *wcs, wchar_t wc, unsigned long n);
84+
wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t n);
85+
wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t n);
86+
size_t wcslen(const wchar_t *s);
87+
wchar_t *wcscpy(wchar_t * dest, const wchar_t * src);
88+
wchar_t *wcsncpy(wchar_t *dest, const wchar_t *src, size_t n);
89+
wchar_t *wcscat(wchar_t *dest, const wchar_t *src);
90+
wchar_t *wcsncat(wchar_t *dest,const wchar_t *src, size_t n);
91+
int swprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...);
92+
7893
char *getenv(const char *name);
7994

8095
FILE *fopen(const char *name, const char *mode);
@@ -83,8 +98,6 @@ int fscanf(FILE *restrict stream, const char *restrict format, ...);
8398
int sprintf(char *str, const char *format, ...);
8499
void setproctitle(const char *fmt, ...);
85100
void setproctitle_init(int argc, char *argv[], char *envp[]);
86-
typedef __typeof(sizeof(int)) size_t;
87-
typedef signed long long ssize_t;
88101

89102
// Define string functions. Use builtin for some of them. They all default to
90103
// the processing in the taint checker.
@@ -430,6 +443,24 @@ int testSprintf_propagates_taint(char *buf, char *msg) {
430443
return 1 / x; // expected-warning {{Division by a tainted value, possibly zero}}
431444
}
432445

446+
void test_wchar_apis_propagate(const char *path) {
447+
FILE *f = fopen(path, "r");
448+
clang_analyzer_isTainted_charp((char*)f); // expected-warning {{YES}}
449+
wchar_t wbuf[10];
450+
fgetws(wbuf, sizeof(wbuf)/sizeof(*wbuf), f);
451+
clang_analyzer_isTainted_wchar(*wbuf); // expected-warning {{YES}}
452+
int n = wcslen(wbuf);
453+
clang_analyzer_isTainted_int(n); // expected-warning {{YES}}
454+
455+
wchar_t dst[100] = L"ABC";
456+
clang_analyzer_isTainted_wchar(*dst); // expected-warning {{NO}}
457+
wcsncat(dst, wbuf, sizeof(wbuf)/sizeof(*wbuf));
458+
clang_analyzer_isTainted_wchar(*dst); // expected-warning {{YES}}
459+
460+
int m = wcslen(dst);
461+
clang_analyzer_isTainted_int(m); // expected-warning {{YES}}
462+
}
463+
433464
int scanf_s(const char *format, ...);
434465
int testScanf_s_(int *out) {
435466
scanf_s("%d", out);
@@ -544,6 +575,10 @@ void testFread(const char *fname, int *buffer, size_t size, size_t count) {
544575
}
545576

546577
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
578+
int accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
579+
int bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
580+
int listen(int fd, int backlog);
581+
547582
void testRecv(int *buf, size_t len, int flags) {
548583
int fd;
549584
scanf("%d", &fd); // fake a tainted a file descriptor
@@ -640,7 +675,6 @@ void testRawmemchr(int c) {
640675
clang_analyzer_isTainted_charp(result); // expected-warning {{YES}}
641676
}
642677

643-
typedef char wchar_t;
644678
int mbtowc(wchar_t *pwc, const char *s, size_t n);
645679
void testMbtowc(wchar_t *pwc, size_t n) {
646680
char buf[10];
@@ -653,8 +687,7 @@ void testMbtowc(wchar_t *pwc, size_t n) {
653687

654688
int wctomb(char *s, wchar_t wc);
655689
void testWctomb(char *buf) {
656-
wchar_t wc;
657-
scanf("%c", &wc);
690+
wchar_t wc = getchar();
658691

659692
int result = wctomb(buf, wc);
660693
clang_analyzer_isTainted_char(*buf); // expected-warning {{YES}}
@@ -663,8 +696,7 @@ void testWctomb(char *buf) {
663696

664697
int wcwidth(wchar_t c);
665698
void testWcwidth() {
666-
wchar_t wc;
667-
scanf("%c", &wc);
699+
wchar_t wc = getchar();
668700

669701
int width = wcwidth(wc);
670702
clang_analyzer_isTainted_int(width); // expected-warning {{YES}}
@@ -1107,3 +1139,10 @@ void testProctitle2(char *real_argv[]) {
11071139
setproctitle_init(1, argv, 0); // expected-warning {{Untrusted data is passed to a user-defined sink}}
11081140
setproctitle_init(1, real_argv, argv); // expected-warning {{Untrusted data is passed to a user-defined sink}}
11091141
}
1142+
1143+
void testAcceptPropagates() {
1144+
int listenSocket = socket(2, 1, 6);
1145+
clang_analyzer_isTainted_int(listenSocket); // expected-warning {{YES}}
1146+
int acceptSocket = accept(listenSocket, 0, 0);
1147+
clang_analyzer_isTainted_int(acceptSocket); // expected-warning {{YES}}
1148+
}

clang/test/Analysis/taint-generic.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ int scanf(const char*, ...);
77
int mySource1();
88
int mySource3();
99

10+
typedef struct _FILE FILE;
11+
extern "C" {
12+
extern FILE *stdin;
13+
}
14+
int fscanf(FILE *stream, const char *format, ...);
15+
1016
bool isOutOfRange2(const int*);
1117

1218
void mySink2(int);
@@ -124,3 +130,9 @@ void testConfigurationMemberFunc() {
124130
foo.myMemberScanf("%d", &x);
125131
Buffer[x] = 1; // expected-warning {{Out of bound memory access }}
126132
}
133+
134+
void testReadingFromStdin(char **p) {
135+
int n;
136+
fscanf(stdin, "%d", &n);
137+
Buffer[n] = 1; // expected-warning {{Out of bound memory access (index is tainted)}}
138+
}

clang/test/CodeGen/arm_acle.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,22 @@ int32_t test_jcvt(double v) {
16901690
}
16911691
#endif
16921692

1693+
#if defined(__ARM_FEATURE_DIRECTED_ROUNDING) && defined(__ARM_64BIT_STATE)
1694+
1695+
// AArch64-LABEL: @test_rintn(
1696+
// AArch64-NEXT: entry:
1697+
// AArch64-NEXT: call double @llvm.roundeven.f64(double [[TMP0:%.*]])
1698+
double test_rintn(double a) {
1699+
return __rintn(a);
1700+
}
1701+
1702+
// AArch64-LABEL: @test_rintnf(
1703+
// AArch64-NEXT: entry:
1704+
// AArch64-NEXT: call float @llvm.roundeven.f32(float [[TMP0:%.*]])
1705+
float test_rintnf(float b) {
1706+
return __rintnf(b);
1707+
}
1708+
#endif
16931709

16941710
#if defined(__ARM_64BIT_STATE) && defined(__ARM_FEATURE_RNG)
16951711

clang/unittests/Serialization/ForceCheckFileInputTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export int aa = 43;
7575
std::shared_ptr<CompilerInvocation> Invocation =
7676
createInvocation(Args, CIOpts);
7777
EXPECT_TRUE(Invocation);
78+
Invocation->getFrontendOpts().DisableFree = false;
7879

7980
auto Buf = CIOpts.VFS->getBufferForFile("a.cppm");
8081
EXPECT_TRUE(Buf);
@@ -113,6 +114,7 @@ export int aa = 43;
113114
std::shared_ptr<CompilerInvocation> Invocation =
114115
createInvocation(Args, CIOpts);
115116
EXPECT_TRUE(Invocation);
117+
Invocation->getFrontendOpts().DisableFree = false;
116118

117119
CompilerInstance Clang;
118120

lldb/docs/resources/debugging.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,8 @@ reproduction steps.
580580
Finally, that "thing" is the ptrace calls you got from the ``lldb-server`` logs.
581581
Add those to the debugger function and you now have a reproducer that doesn't
582582
need any part of LLDB.
583+
584+
Debugging Tests
585+
---------------
586+
587+
See :doc:`/resources/test`.

llvm/include/llvm/Config/llvm-config.h.cmake

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

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 474691
19+
#define LLVM_MAIN_REVISION 474705
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class MemMoveInst;
3434
class MemorySSA;
3535
class MemorySSAUpdater;
3636
class MemSetInst;
37+
class PostDominatorTree;
3738
class StoreInst;
3839
class TargetLibraryInfo;
3940
class Value;
@@ -43,6 +44,7 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
4344
AAResults *AA = nullptr;
4445
AssumptionCache *AC = nullptr;
4546
DominatorTree *DT = nullptr;
47+
PostDominatorTree *PDT = nullptr;
4648
MemorySSA *MSSA = nullptr;
4749
MemorySSAUpdater *MSSAU = nullptr;
4850

@@ -53,7 +55,8 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
5355

5456
// Glue for the old PM.
5557
bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA,
56-
AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA);
58+
AssumptionCache *AC, DominatorTree *DT, PostDominatorTree *PDT,
59+
MemorySSA *MSSA);
5760

5861
private:
5962
// Helper functions

0 commit comments

Comments
 (0)