Skip to content

Commit 0ba2414

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:44d0e9522a80e1301e96c4751b7572ae0c9cb4dd into amd-gfx:a2e75de8b74c
Local branch amd-gfx a2e75de Merged main:8e14c6c172b122203f46a9ad114d51c74535cbb7 into amd-gfx:6a6bbec15c31 Remote branch main 44d0e95 [CodeGen][NewPM] Port TailDuplicate pass to NPM (llvm#113293)
2 parents a2e75de + 44d0e95 commit 0ba2414

File tree

248 files changed

+2909
-1142
lines changed

Some content is hidden

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

248 files changed

+2909
-1142
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@ struct CFISnapshot {
25772577
case MCCFIInstruction::OpAdjustCfaOffset:
25782578
case MCCFIInstruction::OpWindowSave:
25792579
case MCCFIInstruction::OpNegateRAState:
2580+
case MCCFIInstruction::OpNegateRAStateWithPC:
25802581
case MCCFIInstruction::OpLLVMDefAspaceCfa:
25812582
case MCCFIInstruction::OpLabel:
25822583
llvm_unreachable("unsupported CFI opcode");
@@ -2715,6 +2716,7 @@ struct CFISnapshotDiff : public CFISnapshot {
27152716
case MCCFIInstruction::OpAdjustCfaOffset:
27162717
case MCCFIInstruction::OpWindowSave:
27172718
case MCCFIInstruction::OpNegateRAState:
2719+
case MCCFIInstruction::OpNegateRAStateWithPC:
27182720
case MCCFIInstruction::OpLLVMDefAspaceCfa:
27192721
case MCCFIInstruction::OpLabel:
27202722
llvm_unreachable("unsupported CFI opcode");
@@ -2864,6 +2866,7 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
28642866
case MCCFIInstruction::OpAdjustCfaOffset:
28652867
case MCCFIInstruction::OpWindowSave:
28662868
case MCCFIInstruction::OpNegateRAState:
2869+
case MCCFIInstruction::OpNegateRAStateWithPC:
28672870
case MCCFIInstruction::OpLLVMDefAspaceCfa:
28682871
case MCCFIInstruction::OpLabel:
28692872
llvm_unreachable("unsupported CFI opcode");

clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) {
8080
});
8181
}
8282

83-
AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
83+
AST_MATCHER(CXXRecordDecl, isAggregate) {
84+
return Node.hasDefinition() && Node.isAggregate();
85+
}
8486

85-
AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
87+
AST_MATCHER(CXXRecordDecl, isPOD) {
88+
return Node.hasDefinition() && Node.isPOD();
89+
}
8690

8791
AST_MATCHER(InitListExpr, isFullyDesignated) {
8892
if (const InitListExpr *SyntacticForm =

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ Changes in existing checks
216216
a false positive when only an implicit conversion happened inside an
217217
initializer list.
218218

219+
- Improved :doc:`modernize-use-designated-initializers
220+
<clang-tidy/checks/modernize/use-designated-initializers>` check to fix a
221+
crash when a class is declared but not defined.
222+
219223
- Improved :doc:`modernize-use-nullptr
220224
<clang-tidy/checks/modernize/use-nullptr>` check to also recognize
221225
``NULL``/``__null`` (but not ``0``) when used with a templated type.

clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,11 @@ DECLARE_S93;
201201
// CHECK-MESSAGES-MACROS: :[[@LINE-1]]:1: warning: use designated initializer list to initialize 'S9' [modernize-use-designated-initializers]
202202
// CHECK-MESSAGES-MACROS: :[[@LINE-4]]:28: note: expanded from macro 'DECLARE_S93'
203203
// CHECK-MESSAGES-MACROS: :[[@LINE-71]]:1: note: aggregate type is defined here
204+
205+
// Issue #113652.
206+
struct S14;
207+
208+
struct S15{
209+
S15(S14& d):d{d}{}
210+
S14& d;
211+
};

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,65 @@ bool isRefcountedStringsHack(const VarDecl *V) {
4848
return false;
4949
}
5050

51+
struct GuardianVisitor : public RecursiveASTVisitor<GuardianVisitor> {
52+
using Base = RecursiveASTVisitor<GuardianVisitor>;
53+
54+
const VarDecl *Guardian{nullptr};
55+
56+
public:
57+
explicit GuardianVisitor(const VarDecl *Guardian) : Guardian(Guardian) {
58+
assert(Guardian);
59+
}
60+
61+
bool VisitBinaryOperator(const BinaryOperator *BO) {
62+
if (BO->isAssignmentOp()) {
63+
if (auto *VarRef = dyn_cast<DeclRefExpr>(BO->getLHS())) {
64+
if (VarRef->getDecl() == Guardian)
65+
return false;
66+
}
67+
}
68+
return true;
69+
}
70+
71+
bool VisitCXXConstructExpr(const CXXConstructExpr *CE) {
72+
if (auto *Ctor = CE->getConstructor()) {
73+
if (Ctor->isMoveConstructor() && CE->getNumArgs() == 1) {
74+
auto *Arg = CE->getArg(0)->IgnoreParenCasts();
75+
if (auto *VarRef = dyn_cast<DeclRefExpr>(Arg)) {
76+
if (VarRef->getDecl() == Guardian)
77+
return false;
78+
}
79+
}
80+
}
81+
return true;
82+
}
83+
84+
bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
85+
auto MethodName = safeGetName(MCE->getMethodDecl());
86+
if (MethodName == "swap" || MethodName == "leakRef" ||
87+
MethodName == "releaseNonNull") {
88+
auto *ThisArg = MCE->getImplicitObjectArgument()->IgnoreParenCasts();
89+
if (auto *VarRef = dyn_cast<DeclRefExpr>(ThisArg)) {
90+
if (VarRef->getDecl() == Guardian)
91+
return false;
92+
}
93+
}
94+
return true;
95+
}
96+
97+
bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) {
98+
if (OCE->isAssignmentOp()) {
99+
assert(OCE->getNumArgs() == 2);
100+
auto *ThisArg = OCE->getArg(0)->IgnoreParenCasts();
101+
if (auto *VarRef = dyn_cast<DeclRefExpr>(ThisArg)) {
102+
if (VarRef->getDecl() == Guardian)
103+
return false;
104+
}
105+
}
106+
return true;
107+
}
108+
};
109+
51110
bool isGuardedScopeEmbeddedInGuardianScope(const VarDecl *Guarded,
52111
const VarDecl *MaybeGuardian) {
53112
assert(Guarded);
@@ -81,7 +140,7 @@ bool isGuardedScopeEmbeddedInGuardianScope(const VarDecl *Guarded,
81140

82141
// We need to skip the first CompoundStmt to avoid situation when guardian is
83142
// defined in the same scope as guarded variable.
84-
bool HaveSkippedFirstCompoundStmt = false;
143+
const CompoundStmt *FirstCompondStmt = nullptr;
85144
for (DynTypedNodeList guardedVarAncestors = ctx.getParents(*Guarded);
86145
!guardedVarAncestors.empty();
87146
guardedVarAncestors = ctx.getParents(
@@ -90,12 +149,15 @@ bool isGuardedScopeEmbeddedInGuardianScope(const VarDecl *Guarded,
90149
) {
91150
for (auto &guardedVarAncestor : guardedVarAncestors) {
92151
if (auto *CStmtAncestor = guardedVarAncestor.get<CompoundStmt>()) {
93-
if (!HaveSkippedFirstCompoundStmt) {
94-
HaveSkippedFirstCompoundStmt = true;
152+
if (!FirstCompondStmt) {
153+
FirstCompondStmt = CStmtAncestor;
95154
continue;
96155
}
97-
if (CStmtAncestor == guardiansClosestCompStmtAncestor)
98-
return true;
156+
if (CStmtAncestor == guardiansClosestCompStmtAncestor) {
157+
GuardianVisitor guardianVisitor(MaybeGuardian);
158+
auto *GuardedScope = const_cast<CompoundStmt *>(FirstCompondStmt);
159+
return guardianVisitor.TraverseCompoundStmt(GuardedScope);
160+
}
99161
}
100162
}
101163
}

clang/test/Analysis/Checkers/WebKit/mock-types.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,23 @@ template <typename T, typename PtrTraits = RawPtrTraits<T>, typename RefDerefTra
4949
Ref() : t{} {};
5050
Ref(T &t) : t(&RefDerefTraits::ref(t)) { }
5151
Ref(const Ref& o) : t(RefDerefTraits::refIfNotNull(PtrTraits::unwrap(o.t))) { }
52+
Ref(Ref&& o) : t(o.leakRef()) { }
5253
~Ref() { RefDerefTraits::derefIfNotNull(PtrTraits::exchange(t, nullptr)); }
54+
Ref& operator=(T &t) {
55+
Ref o(t);
56+
swap(o);
57+
return *this;
58+
}
59+
Ref& operator=(Ref &&o) {
60+
Ref m(o);
61+
swap(m);
62+
return *this;
63+
}
64+
void swap(Ref& o) {
65+
typename PtrTraits::StorageType tmp = t;
66+
t = o.t;
67+
o.t = tmp;
68+
}
5369
T &get() { return *PtrTraits::unwrap(t); }
5470
T *ptr() { return PtrTraits::unwrap(t); }
5571
T *operator->() { return PtrTraits::unwrap(t); }
@@ -74,11 +90,27 @@ template <typename T> struct RefPtr {
7490
if (t)
7591
t->deref();
7692
}
93+
Ref<T> releaseNonNull() {
94+
Ref<T> tmp(*t);
95+
if (t)
96+
t->deref();
97+
t = nullptr;
98+
return tmp;
99+
}
100+
void swap(RefPtr& o) {
101+
T* tmp = t;
102+
t = o.t;
103+
o.t = tmp;
104+
}
77105
T *get() { return t; }
78106
T *operator->() { return t; }
79107
const T *operator->() const { return t; }
80108
T &operator*() { return *t; }
81-
RefPtr &operator=(T *) { return *this; }
109+
RefPtr &operator=(T *t) {
110+
RefPtr o(t);
111+
swap(o);
112+
return *this;
113+
}
82114
operator bool() const { return t; }
83115
};
84116

clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,83 @@ void foo7(RefCountable* obj) {
8383
bar.obj->method();
8484
}
8585

86+
void foo8(RefCountable* obj) {
87+
RefPtr<RefCountable> foo;
88+
{
89+
RefCountable *bar = foo.get();
90+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
91+
foo = nullptr;
92+
bar->method();
93+
}
94+
RefPtr<RefCountable> baz;
95+
{
96+
RefCountable *bar = baz.get();
97+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
98+
baz = obj;
99+
bar->method();
100+
}
101+
foo = nullptr;
102+
{
103+
RefCountable *bar = foo.get();
104+
// No warning. It's okay to mutate RefPtr in an outer scope.
105+
bar->method();
106+
}
107+
foo = obj;
108+
{
109+
RefCountable *bar = foo.get();
110+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
111+
foo.releaseNonNull();
112+
bar->method();
113+
}
114+
{
115+
RefCountable *bar = foo.get();
116+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
117+
foo = obj ? obj : nullptr;
118+
bar->method();
119+
}
120+
{
121+
RefCountable *bar = foo->trivial() ? foo.get() : nullptr;
122+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
123+
foo = nullptr;
124+
bar->method();
125+
}
126+
}
127+
128+
void foo9(RefCountable& o) {
129+
Ref<RefCountable> guardian(o);
130+
{
131+
RefCountable &bar = guardian.get();
132+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
133+
guardian = o; // We don't detect that we're setting it to the same value.
134+
bar.method();
135+
}
136+
{
137+
RefCountable *bar = guardian.ptr();
138+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
139+
Ref<RefCountable> other(*bar); // We don't detect other has the same value as guardian.
140+
guardian.swap(other);
141+
bar->method();
142+
}
143+
{
144+
RefCountable *bar = guardian.ptr();
145+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
146+
Ref<RefCountable> other(static_cast<Ref<RefCountable>&&>(guardian));
147+
bar->method();
148+
}
149+
{
150+
RefCountable *bar = guardian.ptr();
151+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
152+
guardian.leakRef();
153+
bar->method();
154+
}
155+
{
156+
RefCountable *bar = guardian.ptr();
157+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
158+
guardian = o.trivial() ? o : *bar;
159+
bar->method();
160+
}
161+
}
162+
86163
} // namespace guardian_scopes
87164

88165
namespace auto_keyword {

clang/test/CodeGen/pgo-cold-function-coverage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test -fprofile-generate-cold-function-coverage
22

33
// RUN: rm -rf %t && split-file %s %t
4-
// RUN: %clang -O2 -fprofile-generate-cold-function-coverage=/xxx/yyy/ -fprofile-sample-accurate -fprofile-sample-use=%t/pgo-cold-func.prof -S -emit-llvm -o - %t/pgo-cold-func.c | FileCheck %s
4+
// RUN: %clang --target=x86_64 -O2 -fprofile-generate-cold-function-coverage=/xxx/yyy/ -fprofile-sample-accurate -fprofile-sample-use=%t/pgo-cold-func.prof -S -emit-llvm -o - %t/pgo-cold-func.c | FileCheck %s
55

66
// CHECK: @__llvm_profile_filename = {{.*}} c"/xxx/yyy/default_%m.profraw\00"
77

clang/test/Driver/nvlink-wrapper.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ int bar() {
2121
}
2222
#else
2323
extern int y;
24-
int __attribute__((visibility("hidden"))) x = 999;
24+
extern int x;
2525
int baz() { return y + x; }
2626
#endif
2727

2828
// Create various inputs to test basic linking and LTO capabilities. Creating a
2929
// CUDA binary requires access to the `ptxas` executable, so we just use x64.
30+
// RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -o %t.o
3031
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DX -o %t-x.o
3132
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DY -o %t-y.o
3233
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DZ -o %t-z.o
@@ -36,6 +37,7 @@ int baz() { return y + x; }
3637
// RUN: llvm-ar rcs %t-y.a %t-y.o
3738
// RUN: llvm-ar rcs %t-z.a %t-z.o
3839
// RUN: llvm-ar rcs %t-w.a %t-w.o
40+
// RUN: llvm-ar rcs %t-u.a %t-u.o
3941

4042
//
4143
// Check that we forward any unrecognized argument to 'nvlink'.
@@ -49,11 +51,16 @@ int baz() { return y + x; }
4951
// `libx.a` and `liby.a` because extern weak symbols do not extract and `libz.a`
5052
// is not used at all.
5153
//
52-
// RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.o %t-y.a %t-z.a %t-w.a \
54+
// RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
5355
// RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK
5456
// LINK: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin
5557

56-
// RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -o %t.o
58+
//
59+
// Same as above but we use '--undefined' to forcibly extract 'libz.a'
60+
//
61+
// RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
62+
// RUN: -u z -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK
63+
// UNDEFINED: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin{{.*}}-z-{{.*}}.cubin
5764

5865
//
5966
// Check that the LTO interface works and properly preserves symbols used in a

clang/test/Driver/riscv-profiles.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
// RVA23U64: "-target-feature" "+zvbb"
148148
// RVA23U64: "-target-feature" "+zvfhmin"
149149
// RVA23U64: "-target-feature" "+zvkt"
150+
// RVA23U64: "-target-feature" "+supm"
150151

151152
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rva23s64 \
152153
// RUN: | FileCheck -check-prefix=RVA23S64 %s
@@ -186,6 +187,7 @@
186187
// RVA23S64: "-target-feature" "+zvbb"
187188
// RVA23S64: "-target-feature" "+zvfhmin"
188189
// RVA23S64: "-target-feature" "+zvkt"
190+
// RVA23S64: "-target-feature" "+sha"
189191
// RVA23S64: "-target-feature" "+shcounterenw"
190192
// RVA23S64: "-target-feature" "+shgatpa"
191193
// RVA23S64: "-target-feature" "+shtvala"
@@ -201,6 +203,7 @@
201203
// RVA23S64: "-target-feature" "+sstvala"
202204
// RVA23S64: "-target-feature" "+sstvecd"
203205
// RVA23S64: "-target-feature" "+ssu64xl"
206+
// RVA23S64: "-target-feature" "+supm"
204207
// RVA23S64: "-target-feature" "+svade"
205208
// RVA23S64: "-target-feature" "+svbare"
206209
// RVA23S64: "-target-feature" "+svinval"

0 commit comments

Comments
 (0)