Skip to content

Commit 9ee2e86

Browse files
committed
Merge remote-tracking branch 'origin/main' into addXeVMToLLVM
2 parents d7793e5 + aa99026 commit 9ee2e86

File tree

57 files changed

+18155
-490
lines changed

Some content is hidden

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

57 files changed

+18155
-490
lines changed

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ class ReusablePrerequisiteModules : public PrerequisiteModules {
160160
RequiredModule->getModuleFilePath().str());
161161
}
162162

163+
std::string getAsString() const {
164+
std::string Result;
165+
llvm::raw_string_ostream OS(Result);
166+
for (const auto &ModuleFile : RequiredModules) {
167+
OS << "-fmodule-file=" << ModuleFile->getModuleName() << "="
168+
<< ModuleFile->getModuleFilePath() << " ";
169+
}
170+
return Result;
171+
}
172+
163173
bool canReuse(const CompilerInvocation &CI,
164174
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) const override;
165175

@@ -296,8 +306,27 @@ buildModuleFile(llvm::StringRef ModuleName, PathRef ModuleUnitFileName,
296306
GenerateReducedModuleInterfaceAction Action;
297307
Clang->ExecuteAction(Action);
298308

299-
if (Clang->getDiagnostics().hasErrorOccurred())
300-
return llvm::createStringError("Compilation failed");
309+
if (Clang->getDiagnostics().hasErrorOccurred()) {
310+
std::string Cmds;
311+
for (const auto &Arg : Inputs.CompileCommand.CommandLine) {
312+
if (!Cmds.empty())
313+
Cmds += " ";
314+
Cmds += Arg;
315+
}
316+
317+
clangd::vlog("Failed to compile {0} with command: {1}.", ModuleUnitFileName,
318+
Cmds);
319+
320+
std::string BuiltModuleFilesStr = BuiltModuleFiles.getAsString();
321+
if (!BuiltModuleFilesStr.empty())
322+
clangd::vlog("The actual used module files built by clangd is {0}",
323+
BuiltModuleFilesStr);
324+
325+
return llvm::createStringError(
326+
llvm::formatv("Failed to compile {0}. Use '--log=verbose' to view "
327+
"detailed failure reasons.",
328+
ModuleUnitFileName));
329+
}
301330

302331
return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
303332
}

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,9 @@ the configuration (without a prefix: ``Auto``).
15541554

15551555
.. code-block:: c++
15561556

1557-
#define A \
1558-
int aaaa; \
1559-
int b; \
1557+
#define A \
1558+
int aaaa; \
1559+
int b; \
15601560
int dddddddddd;
15611561

15621562

clang/include/clang/Analysis/Analyses/UninitializedValues.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class UninitUse {
4747
/// Does this use always see an uninitialized value?
4848
bool AlwaysUninit;
4949

50+
/// Is this use a const reference to this variable?
51+
bool ConstRefUse = false;
52+
5053
/// This use is always uninitialized if it occurs after any of these branches
5154
/// is taken.
5255
SmallVector<Branch, 2> UninitBranches;
@@ -61,10 +64,13 @@ class UninitUse {
6164

6265
void setUninitAfterCall() { UninitAfterCall = true; }
6366
void setUninitAfterDecl() { UninitAfterDecl = true; }
67+
void setConstRefUse() { ConstRefUse = true; }
6468

6569
/// Get the expression containing the uninitialized use.
6670
const Expr *getUser() const { return User; }
6771

72+
bool isConstRefUse() const { return ConstRefUse; }
73+
6874
/// The kind of uninitialized use.
6975
enum Kind {
7076
/// The use might be uninitialized.
@@ -110,10 +116,6 @@ class UninitVariablesHandler {
110116
virtual void handleUseOfUninitVariable(const VarDecl *vd,
111117
const UninitUse &use) {}
112118

113-
/// Called when the uninitialized variable is used as const refernce argument.
114-
virtual void handleConstRefUseOfUninitVariable(const VarDecl *vd,
115-
const UninitUse &use) {}
116-
117119
/// Called when the uninitialized variable analysis detects the
118120
/// idiom 'int x = x'. All other uses of 'x' within the initializer
119121
/// are handled by handleUseOfUninitVariable.

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,9 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
17731773

17741774
A unit attribute `volatile` can be used to indicate a volatile load of the
17751775
bitfield.
1776+
```mlir
1777+
cir.get_bitfield(#bfi, %0 {is_volatile} : !cir.ptr<!u64i>) -> !s32i
1778+
```
17761779

17771780
Example:
17781781
Suppose we have a struct with multiple bitfields stored in

clang/include/clang/Format/Format.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ struct FormatStyle {
513513
ENAS_LeftWithLastLine,
514514
/// Align escaped newlines in the right-most column.
515515
/// \code
516-
/// #define A \
517-
/// int aaaa; \
518-
/// int b; \
516+
/// #define A \
517+
/// int aaaa; \
518+
/// int b; \
519519
/// int dddddddddd;
520520
/// \endcode
521521
ENAS_Right,

clang/lib/Analysis/UninitializedValues.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ class CFGBlockValues {
161161

162162
ValueVector::reference operator[](const VarDecl *vd);
163163

164-
Value getValue(const CFGBlock *block, const CFGBlock *dstBlock,
165-
const VarDecl *vd) {
164+
Value getValue(const CFGBlock *block, const VarDecl *vd) {
166165
std::optional<unsigned> idx = declToIndex.getValueIndex(vd);
167166
return getValueVector(block)[*idx];
168167
}
@@ -589,12 +588,12 @@ class TransferFunctions : public StmtVisitor<TransferFunctions> {
589588
if (!Pred)
590589
continue;
591590

592-
Value AtPredExit = vals.getValue(Pred, B, vd);
591+
Value AtPredExit = vals.getValue(Pred, vd);
593592
if (AtPredExit == Initialized)
594593
// This block initializes the variable.
595594
continue;
596595
if (AtPredExit == MayUninitialized &&
597-
vals.getValue(B, nullptr, vd) == Uninitialized) {
596+
vals.getValue(B, vd) == Uninitialized) {
598597
// This block declares the variable (uninitialized), and is reachable
599598
// from a block that initializes the variable. We can't guarantee to
600599
// give an earlier location for the diagnostic (and it appears that
@@ -625,6 +624,8 @@ class TransferFunctions : public StmtVisitor<TransferFunctions> {
625624
// Scan the frontier, looking for blocks where the variable was
626625
// uninitialized.
627626
for (const auto *Block : cfg) {
627+
if (vals.getValue(Block, vd) != Uninitialized)
628+
continue;
628629
unsigned BlockID = Block->getBlockID();
629630
const Stmt *Term = Block->getTerminatorStmt();
630631
if (SuccsVisited[BlockID] && SuccsVisited[BlockID] < Block->succ_size() &&
@@ -635,8 +636,7 @@ class TransferFunctions : public StmtVisitor<TransferFunctions> {
635636
for (CFGBlock::const_succ_iterator I = Block->succ_begin(),
636637
E = Block->succ_end(); I != E; ++I) {
637638
const CFGBlock *Succ = *I;
638-
if (Succ && SuccsVisited[Succ->getBlockID()] >= Succ->succ_size() &&
639-
vals.getValue(Block, Succ, vd) == Uninitialized) {
639+
if (Succ && SuccsVisited[Succ->getBlockID()] >= Succ->succ_size()) {
640640
// Switch cases are a special case: report the label to the caller
641641
// as the 'terminator', not the switch statement itself. Suppress
642642
// situations where no label matched: we can't be sure that's
@@ -675,8 +675,11 @@ void TransferFunctions::reportUse(const Expr *ex, const VarDecl *vd) {
675675

676676
void TransferFunctions::reportConstRefUse(const Expr *ex, const VarDecl *vd) {
677677
Value v = vals[vd];
678-
if (isAlwaysUninit(v))
679-
handler.handleConstRefUseOfUninitVariable(vd, getUninitUse(ex, vd, v));
678+
if (isAlwaysUninit(v)) {
679+
auto use = getUninitUse(ex, vd, v);
680+
use.setConstRefUse();
681+
handler.handleUseOfUninitVariable(vd, use);
682+
}
680683
}
681684

682685
void TransferFunctions::VisitObjCForCollectionStmt(ObjCForCollectionStmt *FS) {
@@ -891,12 +894,6 @@ struct PruneBlocksHandler : public UninitVariablesHandler {
891894
hadAnyUse = true;
892895
}
893896

894-
void handleConstRefUseOfUninitVariable(const VarDecl *vd,
895-
const UninitUse &use) override {
896-
hadUse[currentBlock] = true;
897-
hadAnyUse = true;
898-
}
899-
900897
/// Called when the uninitialized variable analysis detects the
901898
/// idiom 'int x = x'. All other uses of 'x' within the initializer
902899
/// are handled by handleUseOfUninitVariable.

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,8 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
12581258
case Decl::Enum:
12591259
case Decl::Using: // using X; [C++]
12601260
case Decl::UsingDirective: // using namespace X; [C++]
1261+
case Decl::UsingEnum: // using enum X; [C++]
1262+
case Decl::NamespaceAlias:
12611263
case Decl::Typedef:
12621264
case Decl::TypeAlias: // using foo = bar; [C++11]
12631265
case Decl::Record:

clang/lib/Format/BreakableToken.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@ namespace clang {
2626
namespace format {
2727

2828
static constexpr StringRef Blanks = " \t\v\f\r";
29-
static bool IsBlank(char C) {
30-
switch (C) {
31-
case ' ':
32-
case '\t':
33-
case '\v':
34-
case '\f':
35-
case '\r':
36-
return true;
37-
default:
38-
return false;
39-
}
40-
}
4129

4230
static StringRef getLineCommentIndentPrefix(StringRef Comment,
4331
const FormatStyle &Style) {
@@ -193,7 +181,7 @@ getStringSplit(StringRef Text, unsigned UsedColumns, unsigned ColumnLimit,
193181
if (Chars > MaxSplit || Text.size() <= Advance)
194182
break;
195183

196-
if (IsBlank(Text[0]))
184+
if (Blanks.contains(Text[0]))
197185
SpaceOffset = SplitPoint;
198186
if (Text[0] == '/')
199187
SlashOffset = SplitPoint;

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,23 +1329,26 @@ FormatToken *FormatTokenLexer::getNextToken() {
13291329
if (FormatTok->is(tok::unknown))
13301330
FormatTok->setType(TT_ImplicitStringLiteral);
13311331

1332+
const bool IsCpp = Style.isCpp();
1333+
13321334
// JavaScript and Java do not allow to escape the end of the line with a
13331335
// backslash. Backslashes are syntax errors in plain source, but can occur in
13341336
// comments. When a single line comment ends with a \, it'll cause the next
13351337
// line of code to be lexed as a comment, breaking formatting. The code below
13361338
// finds comments that contain a backslash followed by a line break, truncates
13371339
// the comment token at the backslash, and resets the lexer to restart behind
13381340
// the backslash.
1339-
if ((Style.isJavaScript() || Style.isJava()) && FormatTok->is(tok::comment) &&
1340-
FormatTok->TokenText.starts_with("//")) {
1341-
size_t BackslashPos = FormatTok->TokenText.find('\\');
1342-
while (BackslashPos != StringRef::npos) {
1343-
if (BackslashPos + 1 < FormatTok->TokenText.size() &&
1344-
FormatTok->TokenText[BackslashPos + 1] == '\n') {
1345-
truncateToken(BackslashPos + 1);
1341+
if (const auto Text = FormatTok->TokenText;
1342+
Text.starts_with("//") &&
1343+
(IsCpp || Style.isJavaScript() || Style.isJava())) {
1344+
assert(FormatTok->is(tok::comment));
1345+
for (auto Pos = Text.find('\\'); Pos++ != StringRef::npos;
1346+
Pos = Text.find('\\', Pos)) {
1347+
if (Pos < Text.size() && Text[Pos] == '\n' &&
1348+
(!IsCpp || Text.substr(Pos + 1).ltrim().starts_with("//"))) {
1349+
truncateToken(Pos);
13461350
break;
13471351
}
1348-
BackslashPos = FormatTok->TokenText.find('\\', BackslashPos + 1);
13491352
}
13501353
}
13511354

@@ -1450,7 +1453,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
14501453
Column = FormatTok->LastLineColumnWidth;
14511454
}
14521455

1453-
if (Style.isCpp()) {
1456+
if (IsCpp) {
14541457
auto *Identifier = FormatTok->Tok.getIdentifierInfo();
14551458
auto it = Macros.find(Identifier);
14561459
if ((Tokens.empty() || !Tokens.back()->Tok.getIdentifierInfo() ||

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,10 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,
987987
}
988988

989989
/// Diagnose uninitialized const reference usages.
990-
static bool DiagnoseUninitializedConstRefUse(Sema &S, const VarDecl *VD,
990+
static void DiagnoseUninitializedConstRefUse(Sema &S, const VarDecl *VD,
991991
const UninitUse &Use) {
992992
S.Diag(Use.getUser()->getBeginLoc(), diag::warn_uninit_const_reference)
993993
<< VD->getDeclName() << Use.getUser()->getSourceRange();
994-
return true;
995994
}
996995

997996
/// DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
@@ -1533,33 +1532,24 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
15331532
// order of diagnostics when calling flushDiagnostics().
15341533
typedef llvm::MapVector<const VarDecl *, MappedType> UsesMap;
15351534
UsesMap uses;
1536-
UsesMap constRefUses;
15371535

15381536
public:
15391537
UninitValsDiagReporter(Sema &S) : S(S) {}
15401538
~UninitValsDiagReporter() override { flushDiagnostics(); }
15411539

1542-
MappedType &getUses(UsesMap &um, const VarDecl *vd) {
1543-
MappedType &V = um[vd];
1540+
MappedType &getUses(const VarDecl *vd) {
1541+
MappedType &V = uses[vd];
15441542
if (!V.getPointer())
15451543
V.setPointer(new UsesVec());
15461544
return V;
15471545
}
15481546

15491547
void handleUseOfUninitVariable(const VarDecl *vd,
15501548
const UninitUse &use) override {
1551-
getUses(uses, vd).getPointer()->push_back(use);
1552-
}
1553-
1554-
void handleConstRefUseOfUninitVariable(const VarDecl *vd,
1555-
const UninitUse &use) override {
1556-
getUses(constRefUses, vd).getPointer()->push_back(use);
1549+
getUses(vd).getPointer()->push_back(use);
15571550
}
15581551

1559-
void handleSelfInit(const VarDecl *vd) override {
1560-
getUses(uses, vd).setInt(true);
1561-
getUses(constRefUses, vd).setInt(true);
1562-
}
1552+
void handleSelfInit(const VarDecl *vd) override { getUses(vd).setInt(true); }
15631553

15641554
void flushDiagnostics() {
15651555
for (const auto &P : uses) {
@@ -1582,13 +1572,21 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
15821572
// guaranteed to produce them in line/column order, this will provide
15831573
// a stable ordering.
15841574
llvm::sort(*vec, [](const UninitUse &a, const UninitUse &b) {
1575+
// Move ConstRef uses to the back.
1576+
if (a.isConstRefUse() != b.isConstRefUse())
1577+
return b.isConstRefUse();
15851578
// Prefer a more confident report over a less confident one.
15861579
if (a.getKind() != b.getKind())
15871580
return a.getKind() > b.getKind();
15881581
return a.getUser()->getBeginLoc() < b.getUser()->getBeginLoc();
15891582
});
15901583

15911584
for (const auto &U : *vec) {
1585+
if (U.isConstRefUse()) {
1586+
DiagnoseUninitializedConstRefUse(S, vd, U);
1587+
break;
1588+
}
1589+
15921590
// If we have self-init, downgrade all uses to 'may be uninitialized'.
15931591
UninitUse Use = hasSelfInit ? UninitUse(U.getUser(), false) : U;
15941592

@@ -1604,32 +1602,6 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
16041602
}
16051603

16061604
uses.clear();
1607-
1608-
// Flush all const reference uses diags.
1609-
for (const auto &P : constRefUses) {
1610-
const VarDecl *vd = P.first;
1611-
const MappedType &V = P.second;
1612-
1613-
UsesVec *vec = V.getPointer();
1614-
bool hasSelfInit = V.getInt();
1615-
1616-
if (!vec->empty() && hasSelfInit && hasAlwaysUninitializedUse(vec))
1617-
DiagnoseUninitializedUse(S, vd,
1618-
UninitUse(vd->getInit()->IgnoreParenCasts(),
1619-
/* isAlwaysUninit */ true),
1620-
/* alwaysReportSelfInit */ true);
1621-
else {
1622-
for (const auto &U : *vec) {
1623-
if (DiagnoseUninitializedConstRefUse(S, vd, U))
1624-
break;
1625-
}
1626-
}
1627-
1628-
// Release the uses vector.
1629-
delete vec;
1630-
}
1631-
1632-
constRefUses.clear();
16331605
}
16341606

16351607
private:

0 commit comments

Comments
 (0)