Skip to content

Commit 7584ba6

Browse files
authored
Merge branch 'main' into remove-old-res-middle
2 parents 2c57c89 + 73e12de commit 7584ba6

File tree

674 files changed

+14374
-14041
lines changed

Some content is hidden

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

674 files changed

+14374
-14041
lines changed

bolt/lib/Passes/AsmDump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void dumpFunction(const BinaryFunction &BF) {
143143
std::move(MCEInstance.MCE), std::move(MAB)));
144144
AsmStreamer->initSections(true, *BC.STI);
145145
std::unique_ptr<TargetMachine> TM(BC.TheTarget->createTargetMachine(
146-
BC.TripleName, "", "", TargetOptions(), std::nullopt));
146+
*BC.TheTriple, "", "", TargetOptions(), std::nullopt));
147147
std::unique_ptr<AsmPrinter> MAP(
148148
BC.TheTarget->createAsmPrinter(*TM, std::move(AsmStreamer)));
149149

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Bug Fixes to Attribute Support
292292
Bug Fixes to C++ Support
293293
^^^^^^^^^^^^^^^^^^^^^^^^
294294

295+
- Clang now diagnoses copy constructors taking the class by value in template instantiations. (#GH130866)
295296
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
296297
- Clang now prints the correct instantiation context for diagnostics suppressed
297298
by template argument deduction.

clang/docs/analyzer/checkers.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,6 +3476,24 @@ Limitations:
34763476
alpha.WebKit
34773477
^^^^^^^^^^^^
34783478
3479+
alpha.webkit.ForwardDeclChecker
3480+
"""""""""""""""""""""""""""""""
3481+
Check for local variables, member variables, and function arguments that are forward declared.
3482+
3483+
.. code-block:: cpp
3484+
3485+
struct Obj;
3486+
Obj* provide();
3487+
3488+
struct Foo {
3489+
Obj* ptr; // warn
3490+
};
3491+
3492+
void foo() {
3493+
Obj* obj = provide(); // warn
3494+
consume(obj); // warn
3495+
}
3496+
34793497
.. _alpha-webkit-NoUncheckedPtrMemberChecker:
34803498
34813499
alpha.webkit.MemoryUnsafeCastChecker
@@ -3642,6 +3660,12 @@ The goal of this rule is to make sure that lifetime of any dynamically allocated
36423660
36433661
The rules of when to use and not to use CheckedPtr / CheckedRef are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
36443662
3663+
alpha.webkit.UnretainedCallArgsChecker
3664+
""""""""""""""""""""""""""""""""""""""
3665+
The goal of this rule is to make sure that lifetime of any dynamically allocated NS or CF objects passed as a call argument keeps its memory region past the end of the call. This applies to call to any function, method, lambda, function pointer or functor. NS or CF objects aren't supposed to be allocated on stack so we check arguments for parameters of raw pointers and references to unretained types.
3666+
3667+
The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3668+
36453669
alpha.webkit.UncountedLocalVarsChecker
36463670
""""""""""""""""""""""""""""""""""""""
36473671
The goal of this rule is to make sure that any uncounted local variable is backed by a ref-counted object with lifetime that is strictly larger than the scope of the uncounted local variable. To be on the safe side we require the scope of an uncounted variable to be embedded in the scope of ref-counted object that backs it.
@@ -3773,6 +3797,26 @@ Here are some examples of situations that we warn about as they *might* be poten
37733797
NSObject* unretained = retained.get(); // warn
37743798
}
37753799
3800+
webkit.RetainPtrCtorAdoptChecker
3801+
""""""""""""""""""""""""""""""""
3802+
The goal of this rule is to make sure the constructor of RetainPtr as well as adoptNS and adoptCF are used correctly.
3803+
When creating a RetainPtr with +1 semantics, adoptNS or adoptCF should be used, and in +0 semantics, RetainPtr constructor should be used.
3804+
Warn otherwise.
3805+
3806+
These are examples of cases that we consider correct:
3807+
3808+
.. code-block:: cpp
3809+
3810+
RetainPtr ptr = adoptNS([[NSObject alloc] init]); // ok
3811+
RetainPtr ptr = CGImageGetColorSpace(image); // ok
3812+
3813+
Here are some examples of cases that we consider incorrect use of RetainPtr constructor and adoptCF
3814+
3815+
.. code-block:: cpp
3816+
3817+
RetainPtr ptr = [[NSObject alloc] init]; // warn
3818+
auto ptr = adoptCF(CGImageGetColorSpace(image)); // warn
3819+
37763820
Debug Checkers
37773821
---------------
37783822

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct MissingFeatures {
8383
static bool emitNullabilityCheck() { return false; }
8484
static bool astVarDeclInterface() { return false; }
8585
static bool stackSaveOp() { return false; }
86+
static bool aggValueSlot() { return false; }
8687
};
8788

8889
} // namespace cir

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,10 @@ def UncountedLambdaCapturesChecker : Checker<"UncountedLambdaCapturesChecker">,
17611761

17621762
let ParentPackage = WebKitAlpha in {
17631763

1764+
def ForwardDeclChecker : Checker<"ForwardDeclChecker">,
1765+
HelpText<"Check for forward declared local or member variables and function arguments">,
1766+
Documentation<HasDocumentation>;
1767+
17641768
def MemoryUnsafeCastChecker : Checker<"MemoryUnsafeCastChecker">,
17651769
HelpText<"Check for memory unsafe casts from base type to derived type.">,
17661770
Documentation<HasDocumentation>;
@@ -1785,6 +1789,10 @@ def UncheckedCallArgsChecker : Checker<"UncheckedCallArgsChecker">,
17851789
HelpText<"Check unchecked call arguments.">,
17861790
Documentation<HasDocumentation>;
17871791

1792+
def UnretainedCallArgsChecker : Checker<"UnretainedCallArgsChecker">,
1793+
HelpText<"Check unretained call arguments.">,
1794+
Documentation<HasDocumentation>;
1795+
17881796
def UncountedLocalVarsChecker : Checker<"UncountedLocalVarsChecker">,
17891797
HelpText<"Check uncounted local variables.">,
17901798
Documentation<HasDocumentation>;
@@ -1797,4 +1805,8 @@ def UnretainedLocalVarsChecker : Checker<"UnretainedLocalVarsChecker">,
17971805
HelpText<"Check unretained local variables.">,
17981806
Documentation<HasDocumentation>;
17991807

1808+
def RetainPtrCtorAdoptChecker : Checker<"RetainPtrCtorAdoptChecker">,
1809+
HelpText<"Check for correct use of RetainPtr constructor, adoptNS, and adoptCF">,
1810+
Documentation<HasDocumentation>;
1811+
18001812
} // end alpha.webkit

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,34 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
165165
return LValue();
166166
}
167167

168+
/// Emit code to compute the specified expression which
169+
/// can have any type. The result is returned as an RValue struct.
170+
RValue CIRGenFunction::emitAnyExpr(const Expr *e) {
171+
switch (CIRGenFunction::getEvaluationKind(e->getType())) {
172+
case cir::TEK_Scalar:
173+
return RValue::get(emitScalarExpr(e));
174+
case cir::TEK_Complex:
175+
cgm.errorNYI(e->getSourceRange(), "emitAnyExpr: complex type");
176+
return RValue::get(nullptr);
177+
case cir::TEK_Aggregate:
178+
cgm.errorNYI(e->getSourceRange(), "emitAnyExpr: aggregate type");
179+
return RValue::get(nullptr);
180+
}
181+
llvm_unreachable("bad evaluation kind");
182+
}
183+
184+
/// Emit code to compute the specified expression, ignoring the result.
185+
void CIRGenFunction::emitIgnoredExpr(const Expr *e) {
186+
if (e->isPRValue()) {
187+
assert(!cir::MissingFeatures::aggValueSlot());
188+
emitAnyExpr(e);
189+
return;
190+
}
191+
192+
// Just emit it as an l-value and drop the result.
193+
emitLValue(e);
194+
}
195+
168196
mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
169197
mlir::Location loc,
170198
CharUnits alignment) {

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ class CIRGenFunction : public CIRGenTypeCache {
154154

155155
const clang::LangOptions &getLangOpts() const { return cgm.getLangOpts(); }
156156

157+
/// Emit code to compute the specified expression which can have any type. The
158+
/// result is returned as an RValue struct. If this is an aggregate
159+
/// expression, the aggloc/agglocvolatile arguments indicate where the result
160+
/// should be returned.
161+
RValue emitAnyExpr(const clang::Expr *e);
162+
157163
void finishFunction(SourceLocation endLoc);
158164
mlir::LogicalResult emitFunctionBody(const clang::Stmt *body);
159165

@@ -170,6 +176,10 @@ class CIRGenFunction : public CIRGenTypeCache {
170176

171177
void emitCompoundStmtWithoutScope(const clang::CompoundStmt &s);
172178

179+
/// Emit code to compute the specified expression,
180+
/// ignoring the result.
181+
void emitIgnoredExpr(const clang::Expr *e);
182+
173183
mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
174184

175185
mlir::LogicalResult emitReturnStmt(const clang::ReturnStmt &s);

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 158 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,160 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
5555
if (mlir::succeeded(emitSimpleStmt(s, useCurrentScope)))
5656
return mlir::success();
5757

58-
// Only a subset of simple statements are supported at the moment. When more
59-
// kinds of statements are supported, a
60-
// switch (s->getStmtClass()) {
61-
// will be added here.
62-
return mlir::failure();
58+
switch (s->getStmtClass()) {
59+
60+
#define STMT(Type, Base)
61+
#define ABSTRACT_STMT(Op)
62+
#define EXPR(Type, Base) case Stmt::Type##Class:
63+
#include "clang/AST/StmtNodes.inc"
64+
{
65+
// Remember the block we came in on.
66+
mlir::Block *incoming = builder.getInsertionBlock();
67+
assert(incoming && "expression emission must have an insertion point");
68+
69+
emitIgnoredExpr(cast<Expr>(s));
70+
71+
mlir::Block *outgoing = builder.getInsertionBlock();
72+
assert(outgoing && "expression emission cleared block!");
73+
return mlir::success();
74+
}
75+
76+
case Stmt::OMPScopeDirectiveClass:
77+
case Stmt::OMPErrorDirectiveClass:
78+
case Stmt::NoStmtClass:
79+
case Stmt::CXXCatchStmtClass:
80+
case Stmt::SEHExceptStmtClass:
81+
case Stmt::SEHFinallyStmtClass:
82+
case Stmt::MSDependentExistsStmtClass:
83+
case Stmt::NullStmtClass:
84+
case Stmt::CompoundStmtClass:
85+
case Stmt::DeclStmtClass:
86+
case Stmt::LabelStmtClass:
87+
case Stmt::AttributedStmtClass:
88+
case Stmt::GotoStmtClass:
89+
case Stmt::BreakStmtClass:
90+
case Stmt::ContinueStmtClass:
91+
case Stmt::DefaultStmtClass:
92+
case Stmt::CaseStmtClass:
93+
case Stmt::SEHLeaveStmtClass:
94+
case Stmt::SYCLKernelCallStmtClass:
95+
case Stmt::IfStmtClass:
96+
case Stmt::SwitchStmtClass:
97+
case Stmt::ForStmtClass:
98+
case Stmt::WhileStmtClass:
99+
case Stmt::DoStmtClass:
100+
case Stmt::CoroutineBodyStmtClass:
101+
case Stmt::CoreturnStmtClass:
102+
case Stmt::CXXTryStmtClass:
103+
case Stmt::CXXForRangeStmtClass:
104+
case Stmt::IndirectGotoStmtClass:
105+
case Stmt::ReturnStmtClass:
106+
case Stmt::GCCAsmStmtClass:
107+
case Stmt::MSAsmStmtClass:
108+
case Stmt::OMPParallelDirectiveClass:
109+
case Stmt::OMPTaskwaitDirectiveClass:
110+
case Stmt::OMPTaskyieldDirectiveClass:
111+
case Stmt::OMPBarrierDirectiveClass:
112+
case Stmt::CapturedStmtClass:
113+
case Stmt::ObjCAtTryStmtClass:
114+
case Stmt::ObjCAtThrowStmtClass:
115+
case Stmt::ObjCAtSynchronizedStmtClass:
116+
case Stmt::ObjCForCollectionStmtClass:
117+
case Stmt::ObjCAutoreleasePoolStmtClass:
118+
case Stmt::SEHTryStmtClass:
119+
case Stmt::OMPMetaDirectiveClass:
120+
case Stmt::OMPCanonicalLoopClass:
121+
case Stmt::OMPSimdDirectiveClass:
122+
case Stmt::OMPTileDirectiveClass:
123+
case Stmt::OMPUnrollDirectiveClass:
124+
case Stmt::OMPForDirectiveClass:
125+
case Stmt::OMPForSimdDirectiveClass:
126+
case Stmt::OMPSectionsDirectiveClass:
127+
case Stmt::OMPSectionDirectiveClass:
128+
case Stmt::OMPSingleDirectiveClass:
129+
case Stmt::OMPMasterDirectiveClass:
130+
case Stmt::OMPCriticalDirectiveClass:
131+
case Stmt::OMPParallelForDirectiveClass:
132+
case Stmt::OMPParallelForSimdDirectiveClass:
133+
case Stmt::OMPParallelMasterDirectiveClass:
134+
case Stmt::OMPParallelSectionsDirectiveClass:
135+
case Stmt::OMPTaskDirectiveClass:
136+
case Stmt::OMPTaskgroupDirectiveClass:
137+
case Stmt::OMPFlushDirectiveClass:
138+
case Stmt::OMPDepobjDirectiveClass:
139+
case Stmt::OMPScanDirectiveClass:
140+
case Stmt::OMPOrderedDirectiveClass:
141+
case Stmt::OMPAtomicDirectiveClass:
142+
case Stmt::OMPTargetDirectiveClass:
143+
case Stmt::OMPTeamsDirectiveClass:
144+
case Stmt::OMPCancellationPointDirectiveClass:
145+
case Stmt::OMPCancelDirectiveClass:
146+
case Stmt::OMPTargetDataDirectiveClass:
147+
case Stmt::OMPTargetEnterDataDirectiveClass:
148+
case Stmt::OMPTargetExitDataDirectiveClass:
149+
case Stmt::OMPTargetParallelDirectiveClass:
150+
case Stmt::OMPTargetParallelForDirectiveClass:
151+
case Stmt::OMPTaskLoopDirectiveClass:
152+
case Stmt::OMPTaskLoopSimdDirectiveClass:
153+
case Stmt::OMPMaskedTaskLoopDirectiveClass:
154+
case Stmt::OMPMaskedTaskLoopSimdDirectiveClass:
155+
case Stmt::OMPMasterTaskLoopDirectiveClass:
156+
case Stmt::OMPMasterTaskLoopSimdDirectiveClass:
157+
case Stmt::OMPParallelGenericLoopDirectiveClass:
158+
case Stmt::OMPParallelMaskedDirectiveClass:
159+
case Stmt::OMPParallelMaskedTaskLoopDirectiveClass:
160+
case Stmt::OMPParallelMaskedTaskLoopSimdDirectiveClass:
161+
case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
162+
case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
163+
case Stmt::OMPDistributeDirectiveClass:
164+
case Stmt::OMPDistributeParallelForDirectiveClass:
165+
case Stmt::OMPDistributeParallelForSimdDirectiveClass:
166+
case Stmt::OMPDistributeSimdDirectiveClass:
167+
case Stmt::OMPTargetParallelGenericLoopDirectiveClass:
168+
case Stmt::OMPTargetParallelForSimdDirectiveClass:
169+
case Stmt::OMPTargetSimdDirectiveClass:
170+
case Stmt::OMPTargetTeamsGenericLoopDirectiveClass:
171+
case Stmt::OMPTargetUpdateDirectiveClass:
172+
case Stmt::OMPTeamsDistributeDirectiveClass:
173+
case Stmt::OMPTeamsDistributeSimdDirectiveClass:
174+
case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
175+
case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
176+
case Stmt::OMPTeamsGenericLoopDirectiveClass:
177+
case Stmt::OMPTargetTeamsDirectiveClass:
178+
case Stmt::OMPTargetTeamsDistributeDirectiveClass:
179+
case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
180+
case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
181+
case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
182+
case Stmt::OMPInteropDirectiveClass:
183+
case Stmt::OMPDispatchDirectiveClass:
184+
case Stmt::OMPGenericLoopDirectiveClass:
185+
case Stmt::OMPReverseDirectiveClass:
186+
case Stmt::OMPInterchangeDirectiveClass:
187+
case Stmt::OMPAssumeDirectiveClass:
188+
case Stmt::OMPMaskedDirectiveClass:
189+
case Stmt::OMPStripeDirectiveClass:
190+
case Stmt::OpenACCComputeConstructClass:
191+
case Stmt::OpenACCLoopConstructClass:
192+
case Stmt::OpenACCCombinedConstructClass:
193+
case Stmt::OpenACCDataConstructClass:
194+
case Stmt::OpenACCEnterDataConstructClass:
195+
case Stmt::OpenACCExitDataConstructClass:
196+
case Stmt::OpenACCHostDataConstructClass:
197+
case Stmt::OpenACCWaitConstructClass:
198+
case Stmt::OpenACCInitConstructClass:
199+
case Stmt::OpenACCShutdownConstructClass:
200+
case Stmt::OpenACCSetConstructClass:
201+
case Stmt::OpenACCUpdateConstructClass:
202+
case Stmt::OpenACCCacheConstructClass:
203+
case Stmt::OpenACCAtomicConstructClass:
204+
case Stmt::ObjCAtCatchStmtClass:
205+
case Stmt::ObjCAtFinallyStmtClass:
206+
cgm.errorNYI(s->getSourceRange(),
207+
std::string("emitStmt: ") + s->getStmtClassName());
208+
return mlir::failure();
209+
}
210+
211+
llvm_unreachable("Unexpected statement class");
63212
}
64213

65214
mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
@@ -106,16 +255,11 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) {
106255
// this section will do nothing. But for now a ReturnOp is necessary.
107256
builder.create<ReturnOp>(loc);
108257
} else if (rv->getType()->isVoidType()) {
109-
// No return value. Emit the return expression for its side effects.
110-
// TODO(CIR): Once emitAnyExpr(e) has been upstreamed, get rid of the check
111-
// and just call emitAnyExpr(rv) here.
112-
if (CIRGenFunction::hasScalarEvaluationKind(rv->getType())) {
113-
emitScalarExpr(rv);
114-
} else {
115-
getCIRGenModule().errorNYI(s.getSourceRange(),
116-
"non-scalar function return type");
258+
// Make sure not to return anything, but evaluate the expression
259+
// for side effects.
260+
if (rv) {
261+
emitAnyExpr(rv);
117262
}
118-
builder.create<ReturnOp>(loc);
119263
} else if (fnRetTy->isReferenceType()) {
120264
getCIRGenModule().errorNYI(s.getSourceRange(),
121265
"function return type that is a reference");

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
595595
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
596596
// Create the TargetMachine for generating code.
597597
std::string Error;
598-
std::string Triple = TheModule->getTargetTriple().str();
598+
const llvm::Triple &Triple = TheModule->getTargetTriple();
599599
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
600600
if (!TheTarget) {
601601
if (MustCreateTM)

0 commit comments

Comments
 (0)