Skip to content

Commit 3e2acad

Browse files
committed
Merge branch 'main' into vp-arm-mve-transform
2 parents 38d83bf + 6dba5f6 commit 3e2acad

File tree

137 files changed

+49990
-56712
lines changed

Some content is hidden

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

137 files changed

+49990
-56712
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ Improvements to Clang's diagnostics
278278

279279
- Improve the diagnostics for shadows template parameter to report correct location (#GH129060).
280280

281+
- Improve the ``-Wundefined-func-template`` warning when a function template is not instantiated due to being unreachable in modules.
282+
281283
Improvements to Clang's time-trace
282284
----------------------------------
283285

@@ -340,6 +342,8 @@ Bug Fixes to C++ Support
340342
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
341343
- Clang now properly instantiates destructors for initialized members within non-delegating constructors. (#GH93251)
342344
- Correctly diagnoses if unresolved using declarations shadows template paramters (#GH129411)
345+
- Clang was previously coalescing volatile writes to members of volatile base class subobjects.
346+
The issue has been addressed by propagating qualifiers during derived-to-base conversions in the AST. (#GH127824)
343347

344348
Bug Fixes to AST Handling
345349
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/analyzer/checkers.rst

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,42 @@ Do not attempt to create a std::string from a null pointer
543543
}
544544
}
545545
546+
.. _cplusplus-PureVirtualCall:
547+
548+
cplusplus.PureVirtualCall (C++)
549+
"""""""""""""""""""""""""""""""
550+
551+
When `virtual methods are called during construction and destruction
552+
<https://en.cppreference.com/w/cpp/language/virtual#During_construction_and_destruction>`__
553+
the polymorphism is restricted to the class that's being constructed or
554+
destructed because the more derived contexts are either not yet initialized or
555+
already destructed.
556+
557+
This checker reports situations where this restricted polymorphism causes a
558+
call to a pure virtual method, which is undefined behavior. (See also the
559+
related checker :ref:`optin-cplusplus-VirtualCall` which reports situations
560+
where the restricted polymorphism affects a call and the called method is not
561+
pure virtual – but may be still surprising for the programmer.)
562+
563+
.. code-block:: cpp
564+
565+
struct A {
566+
virtual int getKind() = 0;
567+
568+
A() {
569+
// warn: This calls the pure virtual method A::getKind().
570+
log << "Constructing " << getKind();
571+
}
572+
virtual ~A() {
573+
releaseResources();
574+
}
575+
void releaseResources() {
576+
// warn: This can call the pure virtual method A::getKind() when this is
577+
// called from the destructor.
578+
callSomeFunction(getKind())
579+
}
580+
};
581+
546582
.. _deadcode-checkers:
547583
548584
deadcode
@@ -833,24 +869,40 @@ This checker has several options which can be set from command line (e.g.
833869
834870
optin.cplusplus.VirtualCall (C++)
835871
"""""""""""""""""""""""""""""""""
836-
Check virtual function calls during construction or destruction.
872+
873+
When `virtual methods are called during construction and destruction
874+
<https://en.cppreference.com/w/cpp/language/virtual#During_construction_and_destruction>`__
875+
the polymorphism is restricted to the class that's being constructed or
876+
destructed because the more derived contexts are either not yet initialized or
877+
already destructed.
878+
879+
Although this behavior is well-defined, it can surprise the programmer and
880+
cause unintended behavior, so this checker reports calls that appear to be
881+
virtual calls but can be affected by this restricted polymorphism.
882+
883+
Note that situations where this restricted polymorphism causes a call to a pure
884+
virtual method (which is definitely invalid, triggers undefined behavior) are
885+
**reported by another checker:** :ref:`cplusplus-PureVirtualCall` and **this
886+
checker does not report them**.
837887
838888
.. code-block:: cpp
839889
840-
class A {
841-
public:
890+
struct A {
891+
virtual int getKind();
892+
842893
A() {
843-
f(); // warn
894+
// warn: This calls A::getKind() even if we are constructing an instance
895+
// of a different class that is derived from A.
896+
log << "Constructing " << getKind();
844897
}
845-
virtual void f();
846-
};
847-
848-
class A {
849-
public:
850-
~A() {
851-
this->f(); // warn
898+
virtual ~A() {
899+
releaseResources();
900+
}
901+
void releaseResources() {
902+
// warn: This can be called within ~A() and calls A::getKind() even if
903+
// we are destructing a class that is derived from A.
904+
callSomeFunction(getKind())
852905
}
853-
virtual void f();
854906
};
855907
856908
.. _optin-mpi-MPI-Checker:

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def err_test_module_file_extension_version : Error<
266266
"(%3.%4)">;
267267

268268
def warn_eagerly_load_for_standard_cplusplus_modules : Warning<
269-
"the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules;"
269+
"the form '-fmodule-file=<BMI-path>' is deprecated for standard C++ named modules; "
270270
"consider to use '-fmodule-file=<module-name>=<BMI-path>' instead">,
271271
InGroup<DiagGroup<"eager-load-cxx-named-modules">>;
272272

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,6 +5700,8 @@ def warn_func_template_missing : Warning<"instantiation of function %q0 "
57005700
InGroup<UndefinedFuncTemplate>, DefaultIgnore;
57015701
def note_forward_template_decl : Note<
57025702
"forward declaration of template entity is here">;
5703+
def note_unreachable_template_decl
5704+
: Note<"unreachable declaration of template entity is here">;
57035705
def note_inst_declaration_hint : Note<"add an explicit instantiation "
57045706
"declaration to suppress this warning if %q0 is explicitly instantiated in "
57055707
"another translation unit">;

clang/include/clang/Driver/OffloadBundler.h

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -107,50 +107,20 @@ struct OffloadTargetInfo {
107107
// - Compressed Data (variable length).
108108
class CompressedOffloadBundle {
109109
private:
110-
static inline const size_t MagicSize = 4;
111-
static inline const size_t VersionFieldSize = sizeof(uint16_t);
112-
static inline const size_t MethodFieldSize = sizeof(uint16_t);
113-
// Legacy size fields for V1/V2
114-
static inline const size_t FileSizeFieldSizeV2 = sizeof(uint32_t);
115-
static inline const size_t UncompressedSizeFieldSizeV2 = sizeof(uint32_t);
116-
// New size fields for V3
117-
static inline const size_t FileSizeFieldSizeV3 = sizeof(uint64_t);
118-
static inline const size_t UncompressedSizeFieldSizeV3 = sizeof(uint64_t);
119-
static inline const size_t HashFieldSize = sizeof(uint64_t);
120-
121-
// Keep V1 header size for backward compatibility
122-
static inline const size_t V1HeaderSize =
123-
MagicSize + VersionFieldSize + MethodFieldSize +
124-
UncompressedSizeFieldSizeV2 + HashFieldSize;
125-
126-
// Keep V2 header size for backward compatibility
127-
static inline const size_t V2HeaderSize =
128-
MagicSize + VersionFieldSize + FileSizeFieldSizeV2 + MethodFieldSize +
129-
UncompressedSizeFieldSizeV2 + HashFieldSize;
130-
131-
// Add V3 header size with 64-bit fields
132-
static inline const size_t V3HeaderSize =
133-
MagicSize + VersionFieldSize + FileSizeFieldSizeV3 + MethodFieldSize +
134-
UncompressedSizeFieldSizeV3 + HashFieldSize;
135-
136110
static inline const llvm::StringRef MagicNumber = "CCOB";
137111

138112
public:
139-
static inline const uint16_t DefaultVersion = 2;
113+
struct CompressedBundleHeader {
114+
unsigned Version;
115+
llvm::compression::Format CompressionFormat;
116+
std::optional<size_t> FileSize;
117+
size_t UncompressedFileSize;
118+
uint64_t Hash;
140119

141-
// Helper method to get header size based on version
142-
static size_t getHeaderSize(uint16_t Version) {
143-
switch (Version) {
144-
case 1:
145-
return V1HeaderSize;
146-
case 2:
147-
return V2HeaderSize;
148-
case 3:
149-
return V3HeaderSize;
150-
default:
151-
llvm_unreachable("Unsupported version");
152-
}
153-
}
120+
static llvm::Expected<CompressedBundleHeader> tryParse(llvm::StringRef);
121+
};
122+
123+
static inline const uint16_t DefaultVersion = 2;
154124

155125
static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
156126
compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11268,13 +11268,11 @@ class Sema final : public SemaBase {
1126811268

1126911269
/// Determine whether we would be unable to instantiate this template (because
1127011270
/// it either has no definition, or is in the process of being instantiated).
11271-
bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
11272-
NamedDecl *Instantiation,
11273-
bool InstantiatedFromMember,
11274-
const NamedDecl *Pattern,
11275-
const NamedDecl *PatternDef,
11276-
TemplateSpecializationKind TSK,
11277-
bool Complain = true);
11271+
bool DiagnoseUninstantiableTemplate(
11272+
SourceLocation PointOfInstantiation, NamedDecl *Instantiation,
11273+
bool InstantiatedFromMember, const NamedDecl *Pattern,
11274+
const NamedDecl *PatternDef, TemplateSpecializationKind TSK,
11275+
bool Complain = true, bool *Unreachable = nullptr);
1127811276

1127911277
/// DiagnoseTemplateParameterShadow - Produce a diagnostic complaining
1128011278
/// that the template parameter 'PrevDecl' is being shadowed by a new

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ class ComplexExprEmitter
286286
ComplexPairTy EmitComplexBinOpLibCall(StringRef LibCallName,
287287
const BinOpInfo &Op);
288288

289-
QualType HigherPrecisionTypeForComplexArithmetic(QualType ElementType,
290-
bool IsDivOpCode) {
289+
QualType HigherPrecisionTypeForComplexArithmetic(QualType ElementType) {
291290
ASTContext &Ctx = CGF.getContext();
292291
const QualType HigherElementType =
293292
Ctx.GetHigherPrecisionFPType(ElementType);
@@ -314,7 +313,7 @@ class ComplexExprEmitter
314313
}
315314

316315
QualType getPromotionType(FPOptionsOverride Features, QualType Ty,
317-
bool IsDivOpCode = false) {
316+
bool IsComplexDivisor) {
318317
if (auto *CT = Ty->getAs<ComplexType>()) {
319318
QualType ElementType = CT->getElementType();
320319
bool IsFloatingType = ElementType->isFloatingType();
@@ -325,10 +324,9 @@ class ComplexExprEmitter
325324
Features.getComplexRangeOverride() ==
326325
CGF.getLangOpts().getComplexRange();
327326

328-
if (IsDivOpCode && IsFloatingType && IsComplexRangePromoted &&
327+
if (IsComplexDivisor && IsFloatingType && IsComplexRangePromoted &&
329328
(HasNoComplexRangeOverride || HasMatchingComplexRange))
330-
return HigherPrecisionTypeForComplexArithmetic(ElementType,
331-
IsDivOpCode);
329+
return HigherPrecisionTypeForComplexArithmetic(ElementType);
332330
if (ElementType.UseExcessPrecision(CGF.getContext()))
333331
return CGF.getContext().getComplexType(CGF.getContext().FloatTy);
334332
}
@@ -339,9 +337,10 @@ class ComplexExprEmitter
339337

340338
#define HANDLEBINOP(OP) \
341339
ComplexPairTy VisitBin##OP(const BinaryOperator *E) { \
342-
QualType promotionTy = getPromotionType( \
343-
E->getStoredFPFeaturesOrDefault(), E->getType(), \
344-
(E->getOpcode() == BinaryOperatorKind::BO_Div) ? true : false); \
340+
QualType promotionTy = \
341+
getPromotionType(E->getStoredFPFeaturesOrDefault(), E->getType(), \
342+
(E->getOpcode() == BinaryOperatorKind::BO_Div && \
343+
E->getRHS()->getType()->isAnyComplexType())); \
345344
ComplexPairTy result = EmitBin##OP(EmitBinOps(E, promotionTy)); \
346345
if (!promotionTy.isNull()) \
347346
result = CGF.EmitUnPromotedValue(result, E->getType()); \
@@ -639,7 +638,8 @@ ComplexPairTy ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *E,
639638
QualType promotionTy =
640639
PromotionType.isNull()
641640
? getPromotionType(E->getStoredFPFeaturesOrDefault(),
642-
E->getSubExpr()->getType())
641+
E->getSubExpr()->getType(),
642+
/*IsComplexDivisor=*/false)
643643
: PromotionType;
644644
ComplexPairTy result = VisitPlus(E, promotionTy);
645645
if (!promotionTy.isNull())
@@ -661,7 +661,8 @@ ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E,
661661
QualType promotionTy =
662662
PromotionType.isNull()
663663
? getPromotionType(E->getStoredFPFeaturesOrDefault(),
664-
E->getSubExpr()->getType())
664+
E->getSubExpr()->getType(),
665+
/*IsComplexDivisor=*/false)
665666
: PromotionType;
666667
ComplexPairTy result = VisitMinus(E, promotionTy);
667668
if (!promotionTy.isNull())
@@ -1213,19 +1214,24 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
12131214
OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
12141215
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, OpInfo.FPFeatures);
12151216

1217+
const bool IsComplexDivisor = E->getOpcode() == BO_DivAssign &&
1218+
E->getRHS()->getType()->isAnyComplexType();
1219+
12161220
// Load the RHS and LHS operands.
12171221
// __block variables need to have the rhs evaluated first, plus this should
12181222
// improve codegen a little.
12191223
QualType PromotionTypeCR;
1220-
PromotionTypeCR = getPromotionType(E->getStoredFPFeaturesOrDefault(),
1221-
E->getComputationResultType());
1224+
PromotionTypeCR =
1225+
getPromotionType(E->getStoredFPFeaturesOrDefault(),
1226+
E->getComputationResultType(), IsComplexDivisor);
12221227
if (PromotionTypeCR.isNull())
12231228
PromotionTypeCR = E->getComputationResultType();
12241229
OpInfo.Ty = PromotionTypeCR;
12251230
QualType ComplexElementTy =
12261231
OpInfo.Ty->castAs<ComplexType>()->getElementType();
1227-
QualType PromotionTypeRHS = getPromotionType(
1228-
E->getStoredFPFeaturesOrDefault(), E->getRHS()->getType());
1232+
QualType PromotionTypeRHS =
1233+
getPromotionType(E->getStoredFPFeaturesOrDefault(),
1234+
E->getRHS()->getType(), IsComplexDivisor);
12291235

12301236
// The RHS should have been converted to the computation type.
12311237
if (E->getRHS()->getType()->isRealFloatingType()) {
@@ -1253,8 +1259,9 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
12531259

12541260
// Load from the l-value and convert it.
12551261
SourceLocation Loc = E->getExprLoc();
1256-
QualType PromotionTypeLHS = getPromotionType(
1257-
E->getStoredFPFeaturesOrDefault(), E->getComputationLHSType());
1262+
QualType PromotionTypeLHS =
1263+
getPromotionType(E->getStoredFPFeaturesOrDefault(),
1264+
E->getComputationLHSType(), IsComplexDivisor);
12581265
if (LHSTy->isAnyComplexType()) {
12591266
ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc);
12601267
if (!PromotionTypeLHS.isNull())

0 commit comments

Comments
 (0)