Skip to content

Commit 85fdb03

Browse files
committed
Manually merged main:416884544e02 into amd-gfx:39064028b3b3
Local branch amd-gfx 3906402 Merged main:80b2aac2c671 into amd-gfx:634c100884f8 Remote branch main 4168845 [TableGen] Update editor modes for new keywords and bang operators. (llvm#68897) Change-Id: If2911764744d61a3f92fb61c405a28a6f1b7978a
2 parents 3906402 + 4168845 commit 85fdb03

Some content is hidden

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

54 files changed

+773
-157
lines changed

.github/workflows/docs.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ on:
1414
- 'main'
1515
paths:
1616
- 'llvm/docs/**'
17+
- 'clang/docs/**'
1718
pull_request:
1819
paths:
1920
- 'llvm/docs/**'
21+
- 'clang/docs/**'
2022

2123
jobs:
2224
check-docs-build:
@@ -39,10 +41,23 @@ jobs:
3941
run: |
4042
sudo apt-get update
4143
sudo apt-get install -y cmake ninja-build
42-
- name: Build docs
44+
- name: Get subprojects that have doc changes
45+
id: docs-changed-subprojects
46+
uses: tj-actions/changed-files@v39
47+
with:
48+
files_yaml: |
49+
llvm:
50+
- 'llvm/docs/**'
51+
clang:
52+
- 'clang/docs/**'
53+
- name: Build LLVM docs
54+
if: steps.docs-changed-subprojects.outputs.llvm_any_changed == 'true'
55+
run: |
56+
cmake -B llvm-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_SPHINX=ON -DSPHINX_OUTPUT_HTML=ON -DSPHINX_OUTPUT_MAN=ON ./llvm
57+
TZ=UTC ninja -C llvm-build docs-llvm-html docs-llvm-man
58+
- name: Build Clang docs
59+
if: steps.docs-changed-subprojects.outputs.clang_any_changed == 'true'
4360
run: |
44-
mkdir build
45-
cd build
46-
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_SPHINX=ON -DSPHINX_OUTPUT_HTML=ON -DSPHINX_OUTPUT_MAN=ON ../llvm
47-
TZ=UTC ninja docs-llvm-html docs-llvm-man
61+
cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON -DSPHINX_OUTPUT_HTML=ON -DSPHINX_OUTPUT_MAN=ON ./llvm
62+
TZ=UTC ninja -C clang-build docs-clang-html docs-clang-man
4863

.github/workflows/pr-code-format.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
name: "Check code formatting"
2-
3-
on:
4-
pull_request_target:
5-
paths:
6-
- '**/*.cpp'
7-
- '**/*.c'
8-
- '**/*.h'
9-
- '**/*.inc'
10-
2+
on: pull_request_target
113
permissions:
124
pull-requests: write
135

146
jobs:
15-
cpp_code_formatter:
16-
name: "Check C++ Formatting"
7+
code_formatter:
178
runs-on: ubuntu-latest
189
steps:
1910
- name: Fetch LLVM sources

clang-tools-extra/clangd/TidyProvider.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks) {
219219
"-bugprone-use-after-move",
220220
// Alias for bugprone-use-after-move.
221221
"-hicpp-invalid-access-moved",
222+
// Check uses dataflow analysis, which might hang/crash unexpectedly on
223+
// incomplete code.
224+
"-bugprone-unchecked-optional-access",
222225

223226
// ----- Performance problems -----
224227

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ X86 Support
571571
* Support intrinsic of ``_urdmsr``.
572572
* Support intrinsic of ``_uwrmsr``.
573573
- Support ISA of ``AVX10.1``.
574+
- ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
574575

575576
Arm and AArch64 Support
576577
^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Analysis/Analyses/ThreadSafety.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ enum ProtectedOperationKind {
4747
POK_PassByRef,
4848

4949
/// Passing a pt-guarded variable by reference.
50-
POK_PtPassByRef
50+
POK_PtPassByRef,
51+
52+
/// Returning a guarded variable by reference.
53+
POK_ReturnByRef,
54+
55+
/// Returning a pt-guarded variable by reference.
56+
POK_PtReturnByRef,
5157
};
5258

5359
/// This enum distinguishes between different kinds of lock actions. For

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,9 @@ def Most : DiagGroup<"most", [
10661066
def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
10671067
def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
10681068
def ThreadSafetyPrecise : DiagGroup<"thread-safety-precise">;
1069-
def ThreadSafetyReference : DiagGroup<"thread-safety-reference">;
1069+
def ThreadSafetyReferenceReturn : DiagGroup<"thread-safety-reference-return">;
1070+
def ThreadSafetyReference : DiagGroup<"thread-safety-reference",
1071+
[ThreadSafetyReferenceReturn]>;
10701072
def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
10711073
def ThreadSafety : DiagGroup<"thread-safety",
10721074
[ThreadSafetyAttributes,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning<
38643864
"calling function %0 requires negative capability '%1'">,
38653865
InGroup<ThreadSafetyAnalysis>, DefaultIgnore;
38663866

3867-
// Thread safety warnings on pass by reference
3867+
// Thread safety warnings on pass/return by reference
38683868
def warn_guarded_pass_by_reference : Warning<
38693869
"passing variable %1 by reference requires holding %0 "
38703870
"%select{'%2'|'%2' exclusively}3">,
@@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning<
38733873
"passing the value that %1 points to by reference requires holding %0 "
38743874
"%select{'%2'|'%2' exclusively}3">,
38753875
InGroup<ThreadSafetyReference>, DefaultIgnore;
3876+
def warn_guarded_return_by_reference : Warning<
3877+
"returning variable %1 by reference requires holding %0 "
3878+
"%select{'%2'|'%2' exclusively}3">,
3879+
InGroup<ThreadSafetyReferenceReturn>, DefaultIgnore;
3880+
def warn_pt_guarded_return_by_reference : Warning<
3881+
"returning the value that %1 points to by reference requires holding %0 "
3882+
"%select{'%2'|'%2' exclusively}3">,
3883+
InGroup<ThreadSafetyReferenceReturn>, DefaultIgnore;
38763884

38773885
// Imprecise thread safety warnings
38783886
def warn_variable_requires_lock : Warning<

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,9 +1665,9 @@ bool ByteCodeExprGen<Emitter>::visitZeroInitializer(PrimType T, QualType QT,
16651665
case PT_Uint64:
16661666
return this->emitZeroUint64(E);
16671667
case PT_IntAP:
1668+
return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
16681669
case PT_IntAPS:
1669-
assert(false);
1670-
return false;
1670+
return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
16711671
case PT_Ptr:
16721672
return this->emitNullPtr(E);
16731673
case PT_FnPtr:

clang/lib/AST/Interp/IntegralAP.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ template <bool Signed> class IntegralAP final {
7878

7979
template <typename T> static IntegralAP from(T Value, unsigned NumBits = 0) {
8080
assert(NumBits > 0);
81-
APSInt Copy = APSInt(APInt(NumBits, static_cast<int64_t>(Value), Signed), !Signed);
81+
APSInt Copy =
82+
APSInt(APInt(NumBits, static_cast<uint64_t>(Value), Signed), !Signed);
8283

8384
return IntegralAP<Signed>(Copy);
8485
}
@@ -97,16 +98,16 @@ template <bool Signed> class IntegralAP final {
9798
template <unsigned Bits, bool InputSigned>
9899
static IntegralAP from(Integral<Bits, InputSigned> I, unsigned BitWidth) {
99100
APSInt Copy =
100-
APSInt(APInt(BitWidth, static_cast<int64_t>(I), InputSigned), !Signed);
101+
APSInt(APInt(BitWidth, static_cast<uint64_t>(I), InputSigned), !Signed);
101102
Copy.setIsSigned(Signed);
102103

103104
assert(Copy.isSigned() == Signed);
104105
return IntegralAP<Signed>(Copy);
105106
}
106107

107-
static IntegralAP zero() {
108-
assert(false);
109-
return IntegralAP(0);
108+
static IntegralAP zero(int32_t BitWidth) {
109+
APSInt V = APSInt(APInt(BitWidth, 0LL, Signed), !Signed);
110+
return IntegralAP(V);
110111
}
111112

112113
constexpr unsigned bitWidth() const { return V.getBitWidth(); }

clang/lib/AST/Interp/Interp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,16 @@ bool Zero(InterpState &S, CodePtr OpPC) {
16881688
return true;
16891689
}
16901690

1691+
static inline bool ZeroIntAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
1692+
S.Stk.push<IntegralAP<false>>(IntegralAP<false>::zero(BitWidth));
1693+
return true;
1694+
}
1695+
1696+
static inline bool ZeroIntAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
1697+
S.Stk.push<IntegralAP<true>>(IntegralAP<true>::zero(BitWidth));
1698+
return true;
1699+
}
1700+
16911701
template <PrimType Name, class T = typename PrimConv<Name>::T>
16921702
inline bool Null(InterpState &S, CodePtr OpPC) {
16931703
S.Stk.push<T>();

clang/lib/AST/Interp/Opcodes.td

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ def IntegerTypeClass : TypeClass {
7272
Uint32, Sint64, Uint64, IntAP, IntAPS];
7373
}
7474

75+
def FixedSizeIntegralTypeClass : TypeClass {
76+
let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
77+
Uint32, Sint64, Uint64, Bool];
78+
}
79+
7580
def NumberTypeClass : TypeClass {
7681
let Types = !listconcat(IntegerTypeClass.Types, [Float]);
7782
}
@@ -243,10 +248,18 @@ def ConstBool : ConstOpcode<Bool, ArgBool>;
243248

244249
// [] -> [Integer]
245250
def Zero : Opcode {
246-
let Types = [AluTypeClass];
251+
let Types = [FixedSizeIntegralTypeClass];
247252
let HasGroup = 1;
248253
}
249254

255+
def ZeroIntAP : Opcode {
256+
let Args = [ArgUint32];
257+
}
258+
259+
def ZeroIntAPS : Opcode {
260+
let Args = [ArgUint32];
261+
}
262+
250263
// [] -> [Pointer]
251264
def Null : Opcode {
252265
let Types = [PtrTypeClass];

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer {
10081008
threadSafety::SExprBuilder SxBuilder;
10091009

10101010
ThreadSafetyHandler &Handler;
1011-
const CXXMethodDecl *CurrentMethod = nullptr;
1011+
const FunctionDecl *CurrentFunction;
10121012
LocalVariableMap LocalVarMap;
10131013
FactManager FactMan;
10141014
std::vector<CFGBlockInfo> BlockInfo;
@@ -1243,10 +1243,10 @@ bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr &CapE) {
12431243

12441244
// Members are in scope from methods of the same class.
12451245
if (const auto *P = dyn_cast<til::Project>(SExp)) {
1246-
if (!CurrentMethod)
1246+
if (!isa_and_nonnull<CXXMethodDecl>(CurrentFunction))
12471247
return false;
12481248
const ValueDecl *VD = P->clangDecl();
1249-
return VD->getDeclContext() == CurrentMethod->getDeclContext();
1249+
return VD->getDeclContext() == CurrentFunction->getDeclContext();
12501250
}
12511251

12521252
return false;
@@ -1541,6 +1541,8 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15411541

15421542
ThreadSafetyAnalyzer *Analyzer;
15431543
FactSet FSet;
1544+
// The fact set for the function on exit.
1545+
const FactSet &FunctionExitFSet;
15441546
/// Maps constructed objects to `this` placeholder prior to initialization.
15451547
llvm::SmallDenseMap<const Expr *, til::LiteralPtr *> ConstructedObjects;
15461548
LocalVariableMap::Context LVarCtx;
@@ -1566,9 +1568,11 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15661568
bool SkipFirstParam = false);
15671569

15681570
public:
1569-
BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info)
1571+
BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info,
1572+
const FactSet &FunctionExitFSet)
15701573
: ConstStmtVisitor<BuildLockset>(), Analyzer(Anlzr), FSet(Info.EntrySet),
1571-
LVarCtx(Info.EntryContext), CtxIndex(Info.EntryIndex) {}
1574+
FunctionExitFSet(FunctionExitFSet), LVarCtx(Info.EntryContext),
1575+
CtxIndex(Info.EntryIndex) {}
15721576

15731577
void VisitUnaryOperator(const UnaryOperator *UO);
15741578
void VisitBinaryOperator(const BinaryOperator *BO);
@@ -1577,6 +1581,7 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15771581
void VisitCXXConstructExpr(const CXXConstructExpr *Exp);
15781582
void VisitDeclStmt(const DeclStmt *S);
15791583
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Exp);
1584+
void VisitReturnStmt(const ReturnStmt *S);
15801585
};
15811586

15821587
} // namespace
@@ -1758,6 +1763,8 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp,
17581763
// Pass by reference warnings are under a different flag.
17591764
ProtectedOperationKind PtPOK = POK_VarDereference;
17601765
if (POK == POK_PassByRef) PtPOK = POK_PtPassByRef;
1766+
if (POK == POK_ReturnByRef)
1767+
PtPOK = POK_PtReturnByRef;
17611768

17621769
const ValueDecl *D = getValueDecl(Exp);
17631770
if (!D || !D->hasAttrs())
@@ -2142,6 +2149,25 @@ void BuildLockset::VisitMaterializeTemporaryExpr(
21422149
}
21432150
}
21442151

2152+
void BuildLockset::VisitReturnStmt(const ReturnStmt *S) {
2153+
if (Analyzer->CurrentFunction == nullptr)
2154+
return;
2155+
const Expr *RetVal = S->getRetValue();
2156+
if (!RetVal)
2157+
return;
2158+
2159+
// If returning by reference, check that the function requires the appropriate
2160+
// capabilities.
2161+
const QualType ReturnType =
2162+
Analyzer->CurrentFunction->getReturnType().getCanonicalType();
2163+
if (ReturnType->isLValueReferenceType()) {
2164+
Analyzer->checkAccess(
2165+
FunctionExitFSet, RetVal,
2166+
ReturnType->getPointeeType().isConstQualified() ? AK_Read : AK_Written,
2167+
POK_ReturnByRef);
2168+
}
2169+
}
2170+
21452171
/// Given two facts merging on a join point, possibly warn and decide whether to
21462172
/// keep or replace.
21472173
///
@@ -2251,8 +2277,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
22512277

22522278
CFG *CFGraph = walker.getGraph();
22532279
const NamedDecl *D = walker.getDecl();
2254-
const auto *CurrentFunction = dyn_cast<FunctionDecl>(D);
2255-
CurrentMethod = dyn_cast<CXXMethodDecl>(D);
2280+
CurrentFunction = dyn_cast<FunctionDecl>(D);
22562281

22572282
if (D->hasAttr<NoThreadSafetyAnalysisAttr>())
22582283
return;
@@ -2348,6 +2373,25 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
23482373
}
23492374
}
23502375

2376+
// Compute the expected exit set.
2377+
// By default, we expect all locks held on entry to be held on exit.
2378+
FactSet ExpectedFunctionExitSet = Initial.EntrySet;
2379+
2380+
// Adjust the expected exit set by adding or removing locks, as declared
2381+
// by *-LOCK_FUNCTION and UNLOCK_FUNCTION. The intersect below will then
2382+
// issue the appropriate warning.
2383+
// FIXME: the location here is not quite right.
2384+
for (const auto &Lock : ExclusiveLocksAcquired)
2385+
ExpectedFunctionExitSet.addLock(
2386+
FactMan, std::make_unique<LockableFactEntry>(Lock, LK_Exclusive,
2387+
D->getLocation()));
2388+
for (const auto &Lock : SharedLocksAcquired)
2389+
ExpectedFunctionExitSet.addLock(
2390+
FactMan,
2391+
std::make_unique<LockableFactEntry>(Lock, LK_Shared, D->getLocation()));
2392+
for (const auto &Lock : LocksReleased)
2393+
ExpectedFunctionExitSet.removeLock(FactMan, Lock);
2394+
23512395
for (const auto *CurrBlock : *SortedGraph) {
23522396
unsigned CurrBlockID = CurrBlock->getBlockID();
23532397
CFGBlockInfo *CurrBlockInfo = &BlockInfo[CurrBlockID];
@@ -2407,7 +2451,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
24072451
if (!CurrBlockInfo->Reachable)
24082452
continue;
24092453

2410-
BuildLockset LocksetBuilder(this, *CurrBlockInfo);
2454+
BuildLockset LocksetBuilder(this, *CurrBlockInfo, ExpectedFunctionExitSet);
24112455

24122456
// Visit all the statements in the basic block.
24132457
for (const auto &BI : *CurrBlock) {
@@ -2483,24 +2527,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
24832527
if (!Final.Reachable)
24842528
return;
24852529

2486-
// By default, we expect all locks held on entry to be held on exit.
2487-
FactSet ExpectedExitSet = Initial.EntrySet;
2488-
2489-
// Adjust the expected exit set by adding or removing locks, as declared
2490-
// by *-LOCK_FUNCTION and UNLOCK_FUNCTION. The intersect below will then
2491-
// issue the appropriate warning.
2492-
// FIXME: the location here is not quite right.
2493-
for (const auto &Lock : ExclusiveLocksAcquired)
2494-
ExpectedExitSet.addLock(FactMan, std::make_unique<LockableFactEntry>(
2495-
Lock, LK_Exclusive, D->getLocation()));
2496-
for (const auto &Lock : SharedLocksAcquired)
2497-
ExpectedExitSet.addLock(FactMan, std::make_unique<LockableFactEntry>(
2498-
Lock, LK_Shared, D->getLocation()));
2499-
for (const auto &Lock : LocksReleased)
2500-
ExpectedExitSet.removeLock(FactMan, Lock);
2501-
25022530
// FIXME: Should we call this function for all blocks which exit the function?
2503-
intersectAndWarn(ExpectedExitSet, Final.ExitSet, Final.ExitLoc,
2531+
intersectAndWarn(ExpectedFunctionExitSet, Final.ExitSet, Final.ExitLoc,
25042532
LEK_LockedAtEndOfFunction, LEK_NotLockedAtEndOfFunction);
25052533

25062534
Handler.leaveFunction(CurrentFunction);

0 commit comments

Comments
 (0)