Skip to content

Commit 5ab1bc4

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3057)
2 parents 9f820e0 + 5603cac commit 5ab1bc4

File tree

438 files changed

+50570
-3628
lines changed

Some content is hidden

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

438 files changed

+50570
-3628
lines changed

.clang-tidy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-const-correctness,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,-misc-use-anonymous-namespace,readability-identifier-naming,-misc-include-cleaner'
1+
Checks: >
2+
-*,
3+
clang-diagnostic-*,
4+
llvm-*,
5+
misc-*,
6+
-misc-const-correctness,
7+
-misc-include-cleaner,
8+
-misc-no-recursion,
9+
-misc-non-private-member-variables-in-classes,
10+
-misc-unused-parameters,
11+
-misc-use-anonymous-namespace,
12+
readability-identifier-naming
13+
214
CheckOptions:
315
- key: readability-identifier-naming.ClassCase
416
value: CamelCase

.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: 20.1.5
58+
clangformat: 20.1.8
5959

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

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/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ Bug Fixes to C++ Support
911911
- Fixed a Clang regression in C++20 mode where unresolved dependent call expressions were created inside non-dependent contexts (#GH122892)
912912
- Clang now emits the ``-Wunused-variable`` warning when some structured bindings are unused
913913
and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
914+
- Fixed ``static_cast`` not performing access or ambiguity checks when converting to an rvalue reference to a base class. (#GH121429)
914915
- Declarations using class template argument deduction with redundant
915916
parentheses around the declarator are no longer rejected. (#GH39811)
916917
- Fixed a crash caused by invalid declarations of ``std::initializer_list``. (#GH132256)
@@ -1095,6 +1096,8 @@ RISC-V Support
10951096
CUDA/HIP Language Changes
10961097
^^^^^^^^^^^^^^^^^^^^^^^^^
10971098

1099+
* Provide a __device__ version of std::__glibcxx_assert_fail() in a header wrapper.
1100+
10981101
CUDA Support
10991102
^^^^^^^^^^^^
11001103

clang/include/clang/AST/OpenMPClause.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,8 @@ class OMPAtClause final : public OMPClause {
17761776
}
17771777
};
17781778

1779-
/// This represents 'severity' clause in the '#pragma omp error' directive
1779+
/// This represents the 'severity' clause in the '#pragma omp error' and the
1780+
/// '#pragma omp parallel' directives.
17801781
///
17811782
/// \code
17821783
/// #pragma omp error severity(fatal)
@@ -1856,7 +1857,8 @@ class OMPSeverityClause final : public OMPClause {
18561857
}
18571858
};
18581859

1859-
/// This represents 'message' clause in the '#pragma omp error' directive
1860+
/// This represents the 'message' clause in the '#pragma omp error' and the
1861+
/// '#pragma omp parallel' directives.
18601862
///
18611863
/// \code
18621864
/// #pragma omp error message("GNU compiler required.")

clang/include/clang/Basic/riscv_vector.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ multiclass RVVPseudoVWCVTBuiltin<string IR, string MName, string type_range,
499499
if (PolicyAttrs & RVV_VTA)
500500
Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
501501
}
502-
auto ElemTy = cast<llvm::VectorType>(ResultType)->getElementType();
502+
auto ElemTy = cast<llvm::VectorType>(Ops[1]->getType())->getElementType();
503503
Ops.insert(Ops.begin() + 2, llvm::Constant::getNullValue(ElemTy));
504504
if (IsMasked) {
505505
Ops.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,14 +6532,13 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
65326532
if (DiscardResult)
65336533
return true;
65346534

6535-
if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
6535+
if (const auto *ECD = dyn_cast<EnumConstantDecl>(D))
65366536
return this->emitConst(ECD->getInitVal(), E);
6537-
} else if (const auto *BD = dyn_cast<BindingDecl>(D)) {
6538-
return this->visit(BD->getBinding());
6539-
} else if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
6537+
if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
65406538
const Function *F = getFunction(FuncDecl);
65416539
return F && this->emitGetFnPtr(F, E);
6542-
} else if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6540+
}
6541+
if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
65436542
if (std::optional<unsigned> Index = P.getOrCreateGlobal(D)) {
65446543
if (!this->emitGetPtrGlobal(*Index, E))
65456544
return false;
@@ -6560,21 +6559,25 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
65606559
// value.
65616560
bool IsReference = D->getType()->isReferenceType();
65626561

6563-
// Check for local/global variables and parameters.
6562+
// Local variables.
65646563
if (auto It = Locals.find(D); It != Locals.end()) {
65656564
const unsigned Offset = It->second.Offset;
65666565
if (IsReference)
65676566
return this->emitGetLocal(classifyPrim(E), Offset, E);
65686567
return this->emitGetPtrLocal(Offset, E);
6569-
} else if (auto GlobalIndex = P.getGlobal(D)) {
6568+
}
6569+
// Global variables.
6570+
if (auto GlobalIndex = P.getGlobal(D)) {
65706571
if (IsReference) {
65716572
if (!Ctx.getLangOpts().CPlusPlus11)
65726573
return this->emitGetGlobal(classifyPrim(E), *GlobalIndex, E);
65736574
return this->emitGetGlobalUnchecked(classifyPrim(E), *GlobalIndex, E);
65746575
}
65756576

65766577
return this->emitGetPtrGlobal(*GlobalIndex, E);
6577-
} else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
6578+
}
6579+
// Function parameters.
6580+
if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
65786581
if (auto It = this->Params.find(PVD); It != this->Params.end()) {
65796582
if (IsReference || !It->second.IsPtr)
65806583
return this->emitGetParam(classifyPrim(E), It->second.Offset, E);
@@ -6600,20 +6603,25 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
66006603
return this->visitDeclRef(D, E);
66016604
};
66026605

6603-
// Handle lambda captures.
6606+
// Lambda captures.
66046607
if (auto It = this->LambdaCaptures.find(D);
66056608
It != this->LambdaCaptures.end()) {
66066609
auto [Offset, IsPtr] = It->second;
66076610

66086611
if (IsPtr)
66096612
return this->emitGetThisFieldPtr(Offset, E);
66106613
return this->emitGetPtrThisField(Offset, E);
6611-
} else if (const auto *DRE = dyn_cast<DeclRefExpr>(E);
6612-
DRE && DRE->refersToEnclosingVariableOrCapture()) {
6614+
}
6615+
6616+
if (const auto *DRE = dyn_cast<DeclRefExpr>(E);
6617+
DRE && DRE->refersToEnclosingVariableOrCapture()) {
66136618
if (const auto *VD = dyn_cast<VarDecl>(D); VD && VD->isInitCapture())
66146619
return revisit(VD);
66156620
}
66166621

6622+
if (const auto *BD = dyn_cast<BindingDecl>(D))
6623+
return this->visit(BD->getBinding());
6624+
66176625
// Avoid infinite recursion.
66186626
if (D == InitializingDecl)
66196627
return this->emitDummyPtr(D, E);
@@ -6666,7 +6674,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
66666674
if (VD->evaluateValue())
66676675
return revisit(VD);
66686676

6669-
if (!D->getType()->isReferenceType())
6677+
if (!IsReference)
66706678
return this->emitDummyPtr(D, E);
66716679

66726680
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -576,23 +576,14 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
576576
if (!Ptr.isConst() || Ptr.isMutable())
577577
return true;
578578

579-
// The This pointer is writable in constructors and destructors,
580-
// even if isConst() returns true.
581-
// TODO(perf): We could be hitting this code path quite a lot in complex
582-
// constructors. Is there a better way to do this?
583-
if (S.Current->getFunction()) {
584-
for (const InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
585-
if (const Function *Func = Frame->getFunction();
586-
Func && (Func->isConstructor() || Func->isDestructor()) &&
587-
Ptr.block() == Frame->getThis().block()) {
588-
return true;
589-
}
590-
}
591-
}
592-
593579
if (!Ptr.isBlockPointer())
594580
return false;
595581

582+
// The This pointer is writable in constructors and destructors,
583+
// even if isConst() returns true.
584+
if (llvm::find(S.InitializingBlocks, Ptr.block()))
585+
return true;
586+
596587
const QualType Ty = Ptr.getType();
597588
const SourceInfo &Loc = S.Current->getSource(OpPC);
598589
S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
@@ -1524,6 +1515,9 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
15241515
return false;
15251516
if (Func->isDestructor() && !CheckDestructor(S, OpPC, ThisPtr))
15261517
return false;
1518+
1519+
if (Func->isConstructor() || Func->isDestructor())
1520+
S.InitializingBlocks.push_back(ThisPtr.block());
15271521
}
15281522

15291523
if (!Func->isFullyCompiled())
@@ -1550,16 +1544,21 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
15501544
// Note that we cannot assert(CallResult.hasValue()) here since
15511545
// Ret() above only sets the APValue if the curent frame doesn't
15521546
// have a caller set.
1553-
if (Interpret(S)) {
1554-
NewFrame.release(); // Frame was delete'd already.
1555-
assert(S.Current == FrameBefore);
1556-
return true;
1547+
bool Success = Interpret(S);
1548+
// Remove initializing block again.
1549+
if (Func->isConstructor() || Func->isDestructor())
1550+
S.InitializingBlocks.pop_back();
1551+
1552+
if (!Success) {
1553+
// Interpreting the function failed somehow. Reset to
1554+
// previous state.
1555+
S.Current = FrameBefore;
1556+
return false;
15571557
}
15581558

1559-
// Interpreting the function failed somehow. Reset to
1560-
// previous state.
1561-
S.Current = FrameBefore;
1562-
return false;
1559+
NewFrame.release(); // Frame was delete'd already.
1560+
assert(S.Current == FrameBefore);
1561+
return true;
15631562
}
15641563

15651564
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,

clang/lib/AST/ByteCode/InterpState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ class InterpState final : public State, public SourceMapper {
190190
std::pair<const Expr *, const LifetimeExtendedTemporaryDecl *>>
191191
SeenGlobalTemporaries;
192192

193+
/// List of blocks we're currently running either constructors or destructors
194+
/// for.
195+
llvm::SmallVector<const Block *> InitializingBlocks;
196+
193197
mutable llvm::BumpPtrAllocator Allocator;
194198
};
195199

clang/lib/Sema/SemaCast.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr,
264264
// %2: Destination Type
265265
static TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
266266
QualType DestType, bool CStyle,
267-
CastKind &Kind,
267+
SourceRange OpRange, CastKind &Kind,
268268
CXXCastPath &BasePath,
269269
unsigned &msg);
270270
static TryCastResult
@@ -1426,8 +1426,8 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
14261426
// C++11 [expr.static.cast]p3:
14271427
// A glvalue of type "cv1 T1" can be cast to type "rvalue reference to cv2
14281428
// T2" if "cv2 T2" is reference-compatible with "cv1 T1".
1429-
tcr = TryLValueToRValueCast(Self, SrcExpr.get(), DestType, CStyle, Kind,
1430-
BasePath, msg);
1429+
tcr = TryLValueToRValueCast(Self, SrcExpr.get(), DestType, CStyle, OpRange,
1430+
Kind, BasePath, msg);
14311431
if (tcr != TC_NotApplicable)
14321432
return tcr;
14331433

@@ -1619,8 +1619,8 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
16191619
/// Tests whether a conversion according to N2844 is valid.
16201620
TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
16211621
QualType DestType, bool CStyle,
1622-
CastKind &Kind, CXXCastPath &BasePath,
1623-
unsigned &msg) {
1622+
SourceRange OpRange, CastKind &Kind,
1623+
CXXCastPath &BasePath, unsigned &msg) {
16241624
// C++11 [expr.static.cast]p3:
16251625
// A glvalue of type "cv1 T1" can be cast to type "rvalue reference to
16261626
// cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1".
@@ -1633,7 +1633,6 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
16331633

16341634
// Because we try the reference downcast before this function, from now on
16351635
// this is the only cast possibility, so we issue an error if we fail now.
1636-
// FIXME: Should allow casting away constness if CStyle.
16371636
QualType FromType = SrcExpr->getType();
16381637
QualType ToType = R->getPointeeType();
16391638
if (CStyle) {
@@ -1657,13 +1656,12 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
16571656

16581657
if (RefConv & Sema::ReferenceConversions::DerivedToBase) {
16591658
Kind = CK_DerivedToBase;
1660-
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
1661-
/*DetectVirtual=*/true);
1662-
if (!Self.IsDerivedFrom(SrcExpr->getBeginLoc(), SrcExpr->getType(),
1663-
R->getPointeeType(), Paths))
1664-
return TC_NotApplicable;
1665-
1666-
Self.BuildBasePathArray(Paths, BasePath);
1659+
if (Self.CheckDerivedToBaseConversion(FromType, ToType,
1660+
SrcExpr->getBeginLoc(), OpRange,
1661+
&BasePath, CStyle)) {
1662+
msg = 0;
1663+
return TC_Failed;
1664+
}
16671665
} else
16681666
Kind = CK_NoOp;
16691667

0 commit comments

Comments
 (0)