Skip to content

Commit 31ed504

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:c718336c4cb1 into amd-gfx:1d8917372237
Local branch amd-gfx 1d89173 Merged main:6dd96d6e80e9 into amd-gfx:6fb83d89c902 Remote branch main c718336 Add option to dump IR to files instead of stderr (llvm#66412)
2 parents 1d89173 + c718336 commit 31ed504

File tree

148 files changed

+4947
-2524
lines changed

Some content is hidden

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

148 files changed

+4947
-2524
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ set -o pipefail
2222

2323
# Environment variables script works with:
2424
# List of files affected by this commit
25-
: ${MODIFIED_FILES:=$(git diff --name-only HEAD~1)}
25+
: ${MODIFIED_FILES:=$(git diff --name-only main...HEAD)}
2626
# Filter rules for generic windows tests
2727
: ${WINDOWS_AGENTS:='{"queue": "windows"}'}
2828
# Filter rules for generic linux tests

.github/new-issues-labeler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
'libc++':
1111
- '/libc[+x]{2}(?!\-)/i'
1212

13-
'libc++-abi':
14-
- '/libc[+x]{2}-abi/i'
13+
'libc++abi':
14+
- '/libc[+x]{2}-?abi/i'
1515

1616
'libc':
1717
- '/\blibc(?![-+])\b/i'

.github/new-prs-labeler.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ tools:llvm-mca:
309309
- llvm/include/llvm/MCA/**
310310
- llvm/lib/MCA/**
311311

312-
vectorizers:
313-
- llvm/lib/Transforms/Vectorize/**
314-
- llvm/include/llvm/Transforms/Vectorize/**
315-
316312
clang:
317313
- any:
318314
- clang/**

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ namespace clang::tooling {
2121
class ExpandModularHeadersPPCallbacks::FileRecorder {
2222
public:
2323
/// Records that a given file entry is needed for replaying callbacks.
24-
void addNecessaryFile(const FileEntry *File) {
24+
void addNecessaryFile(FileEntryRef File) {
2525
// Don't record modulemap files because it breaks same file detection.
26-
if (!(File->getName().endswith("module.modulemap") ||
27-
File->getName().endswith("module.private.modulemap") ||
28-
File->getName().endswith("module.map") ||
29-
File->getName().endswith("module_private.map")))
26+
if (!(File.getName().endswith("module.modulemap") ||
27+
File.getName().endswith("module.private.modulemap") ||
28+
File.getName().endswith("module.map") ||
29+
File.getName().endswith("module_private.map")))
3030
FilesToRecord.insert(File);
3131
}
3232

3333
/// Records content for a file and adds it to the FileSystem.
34-
void recordFileContent(const FileEntry *File,
34+
void recordFileContent(FileEntryRef File,
3535
const SrcMgr::ContentCache &ContentCache,
3636
llvm::vfs::InMemoryFileSystem &InMemoryFs) {
3737
// Return if we are not interested in the contents of this file.
@@ -43,7 +43,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
4343
if (!Data)
4444
return;
4545

46-
InMemoryFs.addFile(File->getName(), /*ModificationTime=*/0,
46+
InMemoryFs.addFile(File.getName(), /*ModificationTime=*/0,
4747
llvm::MemoryBuffer::getMemBufferCopy(*Data));
4848
// Remove the file from the set of necessary files.
4949
FilesToRecord.erase(File);
@@ -55,13 +55,13 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
5555
LLVM_DEBUG({
5656
for (auto FileEntry : FilesToRecord)
5757
llvm::dbgs() << "Did not record contents for input file: "
58-
<< FileEntry->getName() << "\n";
58+
<< FileEntry.getName() << "\n";
5959
});
6060
}
6161

6262
private:
6363
/// A set of files whose contents are to be recorded.
64-
llvm::DenseSet<const FileEntry *> FilesToRecord;
64+
llvm::DenseSet<FileEntryRef> FilesToRecord;
6565
};
6666

6767
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
@@ -125,7 +125,7 @@ void ExpandModularHeadersPPCallbacks::handleModuleFile(
125125
Compiler.getASTReader()->visitInputFiles(
126126
*MF, true, false,
127127
[this](const serialization::InputFile &IF, bool /*IsSystem*/) {
128-
Recorder->addNecessaryFile(IF.getFile());
128+
Recorder->addNecessaryFile(*IF.getFile());
129129
});
130130
// Recursively handle all transitively imported modules.
131131
for (auto *Import : MF->Imports)

clang/include/clang/AST/Expr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ class Expr : public ValueStmt {
541541
/// Note: This does not perform the implicit conversions required by C++11
542542
/// [expr.const]p5.
543543
std::optional<llvm::APSInt>
544-
getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc = nullptr,
545-
bool isEvaluated = true) const;
544+
getIntegerConstantExpr(const ASTContext &Ctx,
545+
SourceLocation *Loc = nullptr) const;
546546
bool isIntegerConstantExpr(const ASTContext &Ctx,
547547
SourceLocation *Loc = nullptr) const;
548548

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

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

4949
/// Passing a pt-guarded variable by reference.
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,
50+
POK_PtPassByRef
5751
};
5852

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

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,7 +3858,7 @@ def warn_fun_requires_negative_cap : Warning<
38583858
"calling function %0 requires negative capability '%1'">,
38593859
InGroup<ThreadSafetyAnalysis>, DefaultIgnore;
38603860

3861-
// Thread safety warnings on pass/return by reference
3861+
// Thread safety warnings on pass by reference
38623862
def warn_guarded_pass_by_reference : Warning<
38633863
"passing variable %1 by reference requires holding %0 "
38643864
"%select{'%2'|'%2' exclusively}3">,
@@ -3867,14 +3867,6 @@ def warn_pt_guarded_pass_by_reference : Warning<
38673867
"passing the value that %1 points to by reference requires holding %0 "
38683868
"%select{'%2'|'%2' exclusively}3">,
38693869
InGroup<ThreadSafetyReference>, DefaultIgnore;
3870-
def warn_guarded_return_by_reference : Warning<
3871-
"returning variable %1 by reference requires holding %0 "
3872-
"%select{'%2'|'%2' exclusively}3">,
3873-
InGroup<ThreadSafetyReference>, DefaultIgnore;
3874-
def warn_pt_guarded_return_by_reference : Warning<
3875-
"returning the value that %1 points to by reference requires holding %0 "
3876-
"%select{'%2'|'%2' exclusively}3">,
3877-
InGroup<ThreadSafetyReference>, DefaultIgnore;
38783870

38793871
// Imprecise thread safety warnings
38803872
def warn_variable_requires_lock : Warning<

clang/include/clang/Basic/FileEntry.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,18 @@ template <> struct DenseMapInfo<clang::FileEntryRef> {
292292
// It's safe to use operator==.
293293
return LHS == RHS;
294294
}
295+
296+
/// Support for finding `const FileEntry *` in a `DenseMap<FileEntryRef, T>`.
297+
/// @{
298+
static unsigned getHashValue(const clang::FileEntry *Val) {
299+
return llvm::hash_value(Val);
300+
}
301+
static bool isEqual(const clang::FileEntry *LHS, clang::FileEntryRef RHS) {
302+
if (RHS.isSpecialDenseMapKey())
303+
return false;
304+
return LHS == RHS;
305+
}
306+
/// @}
295307
};
296308

297309
} // end namespace llvm

clang/include/clang/Basic/Module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class alignas(8) Module {
360360

361361
/// Whether this C++20 named modules doesn't need an initializer.
362362
/// This is only meaningful for C++20 modules.
363-
unsigned NamedModuleHasNoInit : 1;
363+
unsigned NamedModuleHasInit : 1;
364364

365365
/// Describes the visibility of the various names within a
366366
/// particular module.
@@ -600,7 +600,7 @@ class alignas(8) Module {
600600
return Kind == ModuleInterfaceUnit || Kind == ModulePartitionInterface;
601601
}
602602

603-
bool isNamedModuleInterfaceHasNoInit() const { return NamedModuleHasNoInit; }
603+
bool isNamedModuleInterfaceHasInit() const { return NamedModuleHasInit; }
604604

605605
/// Get the primary module interface name from a partition.
606606
StringRef getPrimaryModuleInterfaceName() const {

clang/include/clang/Basic/SourceManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
649649
/// This map allows us to merge ContentCache entries based
650650
/// on their FileEntry*. All ContentCache objects will thus have unique,
651651
/// non-null, FileEntry pointers.
652-
llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
652+
llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache*> FileInfos;
653653

654654
/// True if the ContentCache for files that are overridden by other
655655
/// files, should report the original file name. Defaults to true.
@@ -1680,12 +1680,12 @@ class SourceManager : public RefCountedBase<SourceManager> {
16801680

16811681
// Iterators over FileInfos.
16821682
using fileinfo_iterator =
1683-
llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator;
1683+
llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache *>::const_iterator;
16841684

16851685
fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); }
16861686
fileinfo_iterator fileinfo_end() const { return FileInfos.end(); }
16871687
bool hasFileInfo(const FileEntry *File) const {
1688-
return FileInfos.contains(File);
1688+
return FileInfos.find_as(File) != FileInfos.end();
16891689
}
16901690

16911691
/// Print statistics to stderr.

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16174,8 +16174,7 @@ bool Expr::isIntegerConstantExpr(const ASTContext &Ctx,
1617416174
}
1617516175

1617616176
std::optional<llvm::APSInt>
16177-
Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc,
16178-
bool isEvaluated) const {
16177+
Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc) const {
1617916178
if (isValueDependent()) {
1618016179
// Expression evaluator can't succeed on a dependent expression.
1618116180
return std::nullopt;

clang/lib/AST/Interp/Source.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
#define LLVM_CLANG_AST_INTERP_SOURCE_H
1515

1616
#include "PrimType.h"
17-
#include "clang/AST/Decl.h"
18-
#include "clang/AST/Stmt.h"
17+
#include "llvm/ADT/PointerUnion.h"
1918
#include "llvm/Support/Endian.h"
2019

2120
namespace clang {
21+
class Stmt;
22+
class Decl;
23+
class Expr;
24+
class SourceLocation;
25+
class SourceRange;
2226
namespace interp {
2327
class Function;
2428

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 26 additions & 54 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 FunctionDecl *CurrentFunction;
1011+
const CXXMethodDecl *CurrentMethod = nullptr;
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 (!isa_and_nonnull<CXXMethodDecl>(CurrentFunction))
1246+
if (!CurrentMethod)
12471247
return false;
12481248
const ValueDecl *VD = P->clangDecl();
1249-
return VD->getDeclContext() == CurrentFunction->getDeclContext();
1249+
return VD->getDeclContext() == CurrentMethod->getDeclContext();
12501250
}
12511251

12521252
return false;
@@ -1541,8 +1541,6 @@ 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;
15461544
/// Maps constructed objects to `this` placeholder prior to initialization.
15471545
llvm::SmallDenseMap<const Expr *, til::LiteralPtr *> ConstructedObjects;
15481546
LocalVariableMap::Context LVarCtx;
@@ -1568,11 +1566,9 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15681566
bool SkipFirstParam = false);
15691567

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

15771573
void VisitUnaryOperator(const UnaryOperator *UO);
15781574
void VisitBinaryOperator(const BinaryOperator *BO);
@@ -1581,7 +1577,6 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15811577
void VisitCXXConstructExpr(const CXXConstructExpr *Exp);
15821578
void VisitDeclStmt(const DeclStmt *S);
15831579
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Exp);
1584-
void VisitReturnStmt(const ReturnStmt *S);
15851580
};
15861581

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

17691762
const ValueDecl *D = getValueDecl(Exp);
17701763
if (!D || !D->hasAttrs())
@@ -2149,25 +2142,6 @@ void BuildLockset::VisitMaterializeTemporaryExpr(
21492142
}
21502143
}
21512144

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-
21712145
/// Given two facts merging on a join point, possibly warn and decide whether to
21722146
/// keep or replace.
21732147
///
@@ -2277,7 +2251,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
22772251

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

22822257
if (D->hasAttr<NoThreadSafetyAnalysisAttr>())
22832258
return;
@@ -2303,7 +2278,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
23032278
PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph);
23042279

23052280
CFGBlockInfo &Initial = BlockInfo[CFGraph->getEntry().getBlockID()];
2306-
CFGBlockInfo &Final = BlockInfo[CFGraph->getExit().getBlockID()];
2281+
CFGBlockInfo &Final = BlockInfo[CFGraph->getExit().getBlockID()];
23072282

23082283
// Mark entry block as reachable
23092284
Initial.Reachable = true;
@@ -2373,25 +2348,6 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
23732348
}
23742349
}
23752350

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-
23952351
for (const auto *CurrBlock : *SortedGraph) {
23962352
unsigned CurrBlockID = CurrBlock->getBlockID();
23972353
CFGBlockInfo *CurrBlockInfo = &BlockInfo[CurrBlockID];
@@ -2451,7 +2407,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
24512407
if (!CurrBlockInfo->Reachable)
24522408
continue;
24532409

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

24562412
// Visit all the statements in the basic block.
24572413
for (const auto &BI : *CurrBlock) {
@@ -2527,8 +2483,24 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
25272483
if (!Final.Reachable)
25282484
return;
25292485

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+
25302502
// FIXME: Should we call this function for all blocks which exit the function?
2531-
intersectAndWarn(ExpectedFunctionExitSet, Final.ExitSet, Final.ExitLoc,
2503+
intersectAndWarn(ExpectedExitSet, Final.ExitSet, Final.ExitLoc,
25322504
LEK_LockedAtEndOfFunction, LEK_NotLockedAtEndOfFunction);
25332505

25342506
Handler.leaveFunction(CurrentFunction);

0 commit comments

Comments
 (0)