Skip to content

Commit 3fee26a

Browse files
Merge branch 'llvm:main' into llvmgh-101657
2 parents 517c2e1 + 27271e1 commit 3fee26a

File tree

566 files changed

+10701
-6149
lines changed

Some content is hidden

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

566 files changed

+10701
-6149
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Install clang-format
5656
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
5757
with:
58-
clangformat: 19.1.6
58+
clangformat: 20.1.5
5959

6060
- name: Setup Python env
6161
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0

clang/cmake/caches/Apple-stage1.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "")
1818
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
1919
set(CMAKE_MACOSX_RPATH ON CACHE BOOL "")
2020
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
21-
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
21+
set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
2222
set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
2323
set(CLANG_SPAWN_CC1 ON CACHE BOOL "")
2424
set(CLANG_BOOTSTRAP_PASSTHROUGH

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ Improvements to Clang's diagnostics
575575

576576
- ``-Wswitch`` will now diagnose unhandled enumerators in switches also when
577577
the enumerator is deprecated. Warnings about using deprecated enumerators in
578-
switch cases have moved behind a new ``-Wdeprecated-switch-case`` flag.
578+
switch cases have moved behind a new ``-Wdeprecated-declarations-switch-case``
579+
flag.
579580

580581
For example:
581582

@@ -598,7 +599,7 @@ Improvements to Clang's diagnostics
598599
The warning can be fixed either by adding a ``default:``, or by adding
599600
``case Blue:``. Since the enumerator is deprecated, the latter approach will
600601
trigger a ``'Blue' is deprecated`` warning, which can be turned off with
601-
``-Wno-deprecated-switch-case``.
602+
``-Wno-deprecated-declarations-switch-case``.
602603

603604
Improvements to Clang's time-trace
604605
----------------------------------
@@ -820,6 +821,7 @@ Miscellaneous Clang Crashes Fixed
820821
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
821822

822823
- Fixed crash when ``-print-stats`` is enabled in compiling IR files. (#GH131608)
824+
- Fix code completion crash involving PCH serialzied templates. (#GH139019)
823825

824826
OpenACC Specific Changes
825827
------------------------

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def DeprecatedCopyWithDtor : DiagGroup<"deprecated-copy-with-dtor", [DeprecatedC
234234
def DeprecatedLiteralOperator : DiagGroup<"deprecated-literal-operator">;
235235
// For compatibility with GCC.
236236
def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
237-
def DeprecatedSwitchCase : DiagGroup<"deprecated-switch-case">;
238-
def DeprecatedDeclarations : DiagGroup<"deprecated-declarations", [DeprecatedSwitchCase]>;
237+
def DeprecatedDeclarationsSwitchCase : DiagGroup<"deprecated-declarations-switch-case">;
238+
def DeprecatedDeclarations : DiagGroup<"deprecated-declarations", [DeprecatedDeclarationsSwitchCase]>;
239239
def DeprecatedRedundantConstexprStaticDef : DiagGroup<"deprecated-redundant-constexpr-static-def">;
240240
def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
241241
def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6065,7 +6065,7 @@ def err_undeclared_use : Error<"use of undeclared %0">;
60656065
def warn_deprecated : Warning<"%0 is deprecated">,
60666066
InGroup<DeprecatedDeclarations>;
60676067
def warn_deprecated_switch_case : Warning<warn_deprecated.Summary>,
6068-
InGroup<DeprecatedSwitchCase>;
6068+
InGroup<DeprecatedDeclarationsSwitchCase>;
60696069
def note_from_diagnose_if : Note<"from 'diagnose_if' attribute on %0:">;
60706070
def warn_property_method_deprecated :
60716071
Warning<"property access is using %0 method which is deprecated">,

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class CIRGenerator : public clang::ASTConsumer {
5454
~CIRGenerator() override;
5555
void Initialize(clang::ASTContext &astContext) override;
5656
bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
57+
void CompleteTentativeDefinition(clang::VarDecl *d) override;
58+
5759
mlir::ModuleOp getModule() const;
5860
mlir::MLIRContext &getMLIRContext() { return *mlirContext; };
5961
const mlir::MLIRContext &getMLIRContext() const { return *mlirContext; };

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ struct MissingFeatures {
201201
static bool writebacks() { return false; }
202202
static bool cleanupsToDeactivate() { return false; }
203203
static bool stackBase() { return false; }
204+
static bool deferredDecls() { return false; }
204205

205206
// Missing types
206207
static bool dataMemberType() { return false; }

clang/include/clang/Format/Format.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5536,7 +5536,7 @@ struct FormatStyle {
55365536
parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
55375537
bool AllowUnknownOptions,
55385538
llvm::SourceMgr::DiagHandlerTy DiagHandler,
5539-
void *DiagHandlerCtxt);
5539+
void *DiagHandlerCtxt, bool IsDotHFile);
55405540
};
55415541

55425542
/// Returns a format style complying with the LLVM coding standards:
@@ -5602,13 +5602,15 @@ std::error_code
56025602
parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
56035603
bool AllowUnknownOptions = false,
56045604
llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
5605-
void *DiagHandlerCtx = nullptr);
5605+
void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
56065606

56075607
/// Like above but accepts an unnamed buffer.
56085608
inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
5609-
bool AllowUnknownOptions = false) {
5609+
bool AllowUnknownOptions = false,
5610+
bool IsDotHFile = false) {
56105611
return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
5611-
AllowUnknownOptions);
5612+
AllowUnknownOptions, /*DiagHandler=*/nullptr,
5613+
/*DiagHandlerCtx=*/nullptr, IsDotHFile);
56125614
}
56135615

56145616
/// Gets configuration in a YAML string.

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ class CXXNameMangler {
455455
void mangleSeqID(unsigned SeqID);
456456
void mangleName(GlobalDecl GD);
457457
void mangleType(QualType T);
458-
void mangleCXXRecordDecl(const CXXRecordDecl *Record);
458+
void mangleCXXRecordDecl(const CXXRecordDecl *Record,
459+
bool SuppressSubstitution = false);
459460
void mangleLambdaSig(const CXXRecordDecl *Lambda);
460461
void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false);
461462
void mangleVendorQualifier(StringRef Name);
@@ -3103,11 +3104,12 @@ void CXXNameMangler::mangleType(QualType T) {
31033104
addSubstitution(T);
31043105
}
31053106

3106-
void CXXNameMangler::mangleCXXRecordDecl(const CXXRecordDecl *Record) {
3107+
void CXXNameMangler::mangleCXXRecordDecl(const CXXRecordDecl *Record,
3108+
bool SuppressSubstitution) {
31073109
if (mangleSubstitution(Record))
31083110
return;
31093111
mangleName(Record);
3110-
if (isCompatibleWith(LangOptions::ClangABI::Ver19))
3112+
if (SuppressSubstitution)
31113113
return;
31123114
addSubstitution(Record);
31133115
}
@@ -7557,7 +7559,12 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD,
75577559
// <special-name> ::= TC <type> <offset number> _ <base type>
75587560
CXXNameMangler Mangler(*this, Out);
75597561
Mangler.getStream() << "_ZTC";
7560-
Mangler.mangleCXXRecordDecl(RD);
7562+
// Older versions of clang did not add the record as a substitution candidate
7563+
// here.
7564+
bool SuppressSubstitution =
7565+
getASTContext().getLangOpts().getClangABICompat() <=
7566+
LangOptions::ClangABI::Ver19;
7567+
Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
75617568
Mangler.getStream() << Offset;
75627569
Mangler.getStream() << '_';
75637570
Mangler.mangleCXXRecordDecl(Type);

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,20 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
231231
return;
232232
}
233233
} else {
234-
assert(cast<VarDecl>(global)->isFileVarDecl() &&
235-
"Cannot emit local var decl as global");
234+
const auto *vd = cast<VarDecl>(global);
235+
assert(vd->isFileVarDecl() && "Cannot emit local var decl as global.");
236+
if (vd->isThisDeclarationADefinition() != VarDecl::Definition &&
237+
!astContext.isMSStaticDataMemberInlineDefinition(vd)) {
238+
assert(!cir::MissingFeatures::openMP());
239+
// If this declaration may have caused an inline variable definition to
240+
// change linkage, make sure that it's emitted.
241+
if (astContext.getInlineVariableDefinitionKind(vd) ==
242+
ASTContext::InlineVariableDefinitionKind::Strong)
243+
getAddrOfGlobalVar(vd);
244+
// Otherwise, we can ignore this declaration. The variable will be emitted
245+
// on its first use.
246+
return;
247+
}
236248
}
237249

238250
// TODO(CIR): Defer emitting some global definitions until later
@@ -279,22 +291,23 @@ cir::GlobalOp CIRGenModule::createGlobalOp(CIRGenModule &cgm,
279291
{
280292
mlir::OpBuilder::InsertionGuard guard(builder);
281293

282-
// Some global emissions are triggered while emitting a function, e.g.
283-
// void s() { const char *s = "yolo"; ... }
284-
//
285-
// Be sure to insert global before the current function
286-
CIRGenFunction *curCGF = cgm.curCGF;
287-
if (curCGF)
288-
builder.setInsertionPoint(curCGF->curFn);
289-
290-
g = builder.create<cir::GlobalOp>(loc, name, t);
291-
if (!curCGF) {
292-
if (insertPoint)
293-
cgm.getModule().insert(insertPoint, g);
294+
// If an insertion point is provided, we're replacing an existing global,
295+
// otherwise, create the new global immediately after the last gloabl we
296+
// emitted.
297+
if (insertPoint) {
298+
builder.setInsertionPoint(insertPoint);
299+
} else {
300+
// Group global operations together at the top of the module.
301+
if (cgm.lastGlobalOp)
302+
builder.setInsertionPointAfter(cgm.lastGlobalOp);
294303
else
295-
cgm.getModule().push_back(g);
304+
builder.setInsertionPointToStart(cgm.getModule().getBody());
296305
}
297306

307+
g = builder.create<cir::GlobalOp>(loc, name, t);
308+
if (!insertPoint)
309+
cgm.lastGlobalOp = g;
310+
298311
// Default to private until we can judge based on the initializer,
299312
// since MLIR doesn't allow public declarations.
300313
mlir::SymbolTable::setSymbolVisibility(
@@ -1044,6 +1057,24 @@ StringRef CIRGenModule::getMangledName(GlobalDecl gd) {
10441057
return mangledDeclNames[canonicalGd] = result.first->first();
10451058
}
10461059

1060+
void CIRGenModule::emitTentativeDefinition(const VarDecl *d) {
1061+
assert(!d->getInit() && "Cannot emit definite definitions here!");
1062+
1063+
StringRef mangledName = getMangledName(d);
1064+
mlir::Operation *gv = getGlobalValue(mangledName);
1065+
1066+
// If we already have a definition, not declaration, with the same mangled
1067+
// name, emitting of declaration is not required (and would actually overwrite
1068+
// the emitted definition).
1069+
if (gv && !mlir::cast<cir::GlobalOp>(gv).isDeclaration())
1070+
return;
1071+
1072+
assert(!cir::MissingFeatures::deferredDecls());
1073+
1074+
// The tentative definition is the only definition.
1075+
emitGlobalVarDefinition(d);
1076+
}
1077+
10471078
cir::FuncOp CIRGenModule::getOrCreateCIRFunction(
10481079
StringRef mangledName, mlir::Type funcType, GlobalDecl gd, bool forVTable,
10491080
bool dontDefer, bool isThunk, ForDefinition_t isForDefinition,

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class CIRGenModule : public CIRGenTypeCache {
111111
/// Handling globals
112112
/// -------
113113

114+
mlir::Operation *lastGlobalOp = nullptr;
115+
114116
mlir::Operation *getGlobalValue(llvm::StringRef ref);
115117

116118
/// If the specified mangled name is not in the module, create and return an
@@ -194,6 +196,8 @@ class CIRGenModule : public CIRGenTypeCache {
194196

195197
llvm::StringRef getMangledName(clang::GlobalDecl gd);
196198

199+
void emitTentativeDefinition(const VarDecl *d);
200+
197201
static void setInitializer(cir::GlobalOp &op, mlir::Attribute value);
198202

199203
cir::FuncOp

clang/lib/CIR/CodeGen/CIRGenerator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
6262

6363
return true;
6464
}
65+
66+
void CIRGenerator::CompleteTentativeDefinition(VarDecl *d) {
67+
if (diags.hasErrorOccurred())
68+
return;
69+
70+
cgm->emitTentativeDefinition(d);
71+
}

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "mlir/Interfaces/ControlFlowInterfaces.h"
1919
#include "mlir/Interfaces/FunctionImplementation.h"
20-
#include "mlir/Support/LogicalResult.h"
2120

2221
#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
2322
#include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
@@ -1427,15 +1426,32 @@ OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
14271426
//===----------------------------------------------------------------------===//
14281427
LogicalResult cir::ShiftOp::verify() {
14291428
mlir::Operation *op = getOperation();
1430-
mlir::Type resType = getResult().getType();
1431-
const bool isOp0Vec = mlir::isa<cir::VectorType>(op->getOperand(0).getType());
1432-
const bool isOp1Vec = mlir::isa<cir::VectorType>(op->getOperand(1).getType());
1433-
if (isOp0Vec != isOp1Vec)
1429+
auto op0VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(0).getType());
1430+
auto op1VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(1).getType());
1431+
if (!op0VecTy ^ !op1VecTy)
14341432
return emitOpError() << "input types cannot be one vector and one scalar";
1435-
if (isOp1Vec && op->getOperand(1).getType() != resType) {
1436-
return emitOpError() << "shift amount must have the type of the result "
1437-
<< "if it is vector shift";
1433+
1434+
if (op0VecTy) {
1435+
if (op0VecTy.getSize() != op1VecTy.getSize())
1436+
return emitOpError() << "input vector types must have the same size";
1437+
1438+
auto opResultTy = mlir::dyn_cast<cir::VectorType>(getResult().getType());
1439+
if (!opResultTy)
1440+
return emitOpError() << "the type of the result must be a vector "
1441+
<< "if it is vector shift";
1442+
1443+
auto op0VecEleTy = mlir::cast<cir::IntType>(op0VecTy.getElementType());
1444+
auto op1VecEleTy = mlir::cast<cir::IntType>(op1VecTy.getElementType());
1445+
if (op0VecEleTy.getWidth() != op1VecEleTy.getWidth())
1446+
return emitOpError()
1447+
<< "vector operands do not have the same elements sizes";
1448+
1449+
auto resVecEleTy = mlir::cast<cir::IntType>(opResultTy.getElementType());
1450+
if (op0VecEleTy.getWidth() != resVecEleTy.getWidth())
1451+
return emitOpError() << "vector operands and result type do not have the "
1452+
"same elements sizes";
14381453
}
1454+
14391455
return mlir::success();
14401456
}
14411457

clang/lib/CIR/FrontendAction/CIRGenAction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class CIRGenConsumer : public clang::ASTConsumer {
135135
}
136136
}
137137
}
138+
139+
void CompleteTentativeDefinition(VarDecl *D) override {
140+
Gen->CompleteTentativeDefinition(D);
141+
}
138142
};
139143
} // namespace cir
140144

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5362,11 +5362,11 @@ void Driver::BuildJobs(Compilation &C) const {
53625362
});
53635363
}
53645364

5365-
// If the user passed -Qunused-arguments or there were errors, don't warn
5366-
// about any unused arguments.
5367-
if (Diags.hasErrorOccurred() ||
5368-
C.getArgs().hasArg(options::OPT_Qunused_arguments))
5369-
return;
5365+
// If the user passed -Qunused-arguments or there were errors, don't
5366+
// warn about any unused arguments.
5367+
bool ReportUnusedArguments =
5368+
!Diags.hasErrorOccurred() &&
5369+
!C.getArgs().hasArg(options::OPT_Qunused_arguments);
53705370

53715371
// Claim -fdriver-only here.
53725372
(void)C.getArgs().hasArg(options::OPT_fdriver_only);
@@ -5420,7 +5420,7 @@ void Driver::BuildJobs(Compilation &C) const {
54205420
!C.getActions().empty()) {
54215421
Diag(diag::err_drv_unsupported_opt_for_target)
54225422
<< A->getSpelling() << getTargetTriple();
5423-
} else {
5423+
} else if (ReportUnusedArguments) {
54245424
Diag(clang::diag::warn_drv_unused_argument)
54255425
<< A->getAsString(C.getArgs());
54265426
}

0 commit comments

Comments
 (0)