Skip to content

Commit f88c153

Browse files
Merge branch 'main' into cleanup_001_range_erase_llvm
2 parents f74fad8 + 52e3f3d commit f88c153

File tree

73 files changed

+5219
-727
lines changed

Some content is hidden

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

73 files changed

+5219
-727
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ Improvements to Clang's diagnostics
371371
372372
- An error is now emitted when a ``musttail`` call is made to a function marked with the ``not_tail_called`` attribute. (#GH133509).
373373

374+
- ``-Whigher-precisision-for-complex-divison`` warns when:
375+
376+
- The divisor is complex.
377+
- When the complex division happens in a higher precision type due to arithmetic promotion.
378+
- When using the divide and assign operator (``/=``).
379+
380+
Fixes #GH131127
381+
374382
Improvements to Clang's time-trace
375383
----------------------------------
376384

@@ -402,6 +410,7 @@ Bug Fixes in This Version
402410
when using the ``INTn_C`` macros. (#GH85995)
403411
- Fixed an assertion failure in the expansion of builtin macros like ``__has_embed()`` with line breaks before the
404412
closing paren. (#GH133574)
413+
- Fixed a crash in error recovery for expressions resolving to templates. (#GH135621)
405414
- Clang no longer accepts invalid integer constants which are too large to fit
406415
into any (standard or extended) integer type when the constant is unevaluated.
407416
Merely forming the token is sufficient to render the program invalid. Code
@@ -544,7 +553,7 @@ Arm and AArch64 Support
544553
^^^^^^^^^^^^^^^^^^^^^^^
545554
- For ARM targets, cc1as now considers the FPU's features for the selected CPU or Architecture.
546555
- The ``+nosimd`` attribute is now fully supported for ARM. Previously, this had no effect when being used with
547-
ARM targets, however this will now disable NEON instructions being generated. The ``simd`` option is
556+
ARM targets, however this will now disable NEON instructions being generated. The ``simd`` option is
548557
also now printed when the ``--print-supported-extensions`` option is used.
549558

550559
- Support for __ptrauth type qualifier has been added.

clang/include/clang/Basic/BuiltinsNVPTX.td

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ def __nvvm_f2bf16_rz : NVPTXBuiltinSMAndPTX<"__bf16(float)", SM_80, PTX70>;
580580
def __nvvm_f2bf16_rz_relu : NVPTXBuiltinSMAndPTX<"__bf16(float)", SM_80, PTX70>;
581581

582582
def __nvvm_f2tf32_rna : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_80, PTX70>;
583+
def __nvvm_f2tf32_rna_satfinite : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_89, PTX81>;
584+
def __nvvm_f2tf32_rn : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_90, PTX78>;
585+
def __nvvm_f2tf32_rn_relu : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_90, PTX78>;
586+
def __nvvm_f2tf32_rn_satfinite : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_100, PTX86>;
587+
def __nvvm_f2tf32_rn_relu_satfinite : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_100, PTX86>;
588+
def __nvvm_f2tf32_rz : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_90, PTX78>;
589+
def __nvvm_f2tf32_rz_relu : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_90, PTX78>;
590+
def __nvvm_f2tf32_rz_satfinite : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_100, PTX86>;
591+
def __nvvm_f2tf32_rz_relu_satfinite : NVPTXBuiltinSMAndPTX<"int32_t(float)", SM_100, PTX86>;
583592

584593
def __nvvm_ff_to_e4m3x2_rn : NVPTXBuiltinSMAndPTX<"short(float, float)", SM_89, PTX81>;
585594
def __nvvm_ff_to_e4m3x2_rn_relu : NVPTXBuiltinSMAndPTX<"short(float, float)", SM_89, PTX81>;
@@ -596,6 +605,28 @@ def __nvvm_e4m3x2_to_f16x2_rn_relu : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(sh
596605
def __nvvm_e5m2x2_to_f16x2_rn : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(short)", SM_89, PTX81>;
597606
def __nvvm_e5m2x2_to_f16x2_rn_relu : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(short)", SM_89, PTX81>;
598607

608+
def __nvvm_ff_to_e2m3x2_rn_satfinite : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
609+
def __nvvm_ff_to_e2m3x2_rn_relu_satfinite : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
610+
def __nvvm_ff_to_e3m2x2_rn_satfinite : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
611+
def __nvvm_ff_to_e3m2x2_rn_relu_satfinite : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
612+
613+
def __nvvm_e2m3x2_to_f16x2_rn : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(short)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
614+
def __nvvm_e2m3x2_to_f16x2_rn_relu : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(short)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
615+
def __nvvm_e3m2x2_to_f16x2_rn : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(short)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
616+
def __nvvm_e3m2x2_to_f16x2_rn_relu : NVPTXBuiltinSMAndPTX<"_Vector<2, __fp16>(short)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
617+
618+
def __nvvm_ff_to_ue8m0x2_rz : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
619+
def __nvvm_ff_to_ue8m0x2_rz_satfinite : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
620+
def __nvvm_ff_to_ue8m0x2_rp : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
621+
def __nvvm_ff_to_ue8m0x2_rp_satfinite : NVPTXBuiltinSMAndPTX<"short(float, float)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
622+
623+
def __nvvm_bf16x2_to_ue8m0x2_rz : NVPTXBuiltinSMAndPTX<"short(_Vector<2, __bf16>)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
624+
def __nvvm_bf16x2_to_ue8m0x2_rz_satfinite : NVPTXBuiltinSMAndPTX<"short(_Vector<2, __bf16>)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
625+
def __nvvm_bf16x2_to_ue8m0x2_rp : NVPTXBuiltinSMAndPTX<"short(_Vector<2, __bf16>)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
626+
def __nvvm_bf16x2_to_ue8m0x2_rp_satfinite : NVPTXBuiltinSMAndPTX<"short(_Vector<2, __bf16>)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
627+
628+
def __nvvm_ue8m0x2_to_bf16x2 : NVPTXBuiltinSMAndPTX<"_Vector<2, __bf16>(short)", SM<"100a", [SM_101a, SM_120a]>, PTX86>;
629+
599630
// FNS
600631
let Attributes = [NoThrow] in {
601632
def __nvvm_fns : NVPTXBuiltinPTX<"unsigned int(unsigned int, unsigned int, int)", PTX60>;

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4401,7 +4401,8 @@ TemplateSpecializationType::TemplateSpecializationType(
44014401
T.getKind() == TemplateName::SubstTemplateTemplateParmPack ||
44024402
T.getKind() == TemplateName::UsingTemplate ||
44034403
T.getKind() == TemplateName::QualifiedTemplate ||
4404-
T.getKind() == TemplateName::DeducedTemplate) &&
4404+
T.getKind() == TemplateName::DeducedTemplate ||
4405+
T.getKind() == TemplateName::AssumedTemplate) &&
44054406
"Unexpected template name for TemplateSpecializationType");
44064407

44074408
auto *TemplateArgs =

clang/lib/Sema/SemaExpr.cpp

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10602,6 +10602,45 @@ static void checkArithmeticNull(Sema &S, ExprResult &LHS, ExprResult &RHS,
1060210602
<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
1060310603
}
1060410604

10605+
static void DetectPrecisionLossInComplexDivision(Sema &S, QualType DivisorTy,
10606+
SourceLocation OpLoc) {
10607+
// If the divisor is real, then this is real/real or complex/real division.
10608+
// Either way there can be no precision loss.
10609+
auto *CT = DivisorTy->getAs<ComplexType>();
10610+
if (!CT)
10611+
return;
10612+
10613+
QualType ElementType = CT->getElementType();
10614+
bool IsComplexRangePromoted = S.getLangOpts().getComplexRange() ==
10615+
LangOptions::ComplexRangeKind::CX_Promoted;
10616+
if (!ElementType->isFloatingType() || !IsComplexRangePromoted)
10617+
return;
10618+
10619+
ASTContext &Ctx = S.getASTContext();
10620+
QualType HigherElementType = Ctx.GetHigherPrecisionFPType(ElementType);
10621+
const llvm::fltSemantics &ElementTypeSemantics =
10622+
Ctx.getFloatTypeSemantics(ElementType);
10623+
const llvm::fltSemantics &HigherElementTypeSemantics =
10624+
Ctx.getFloatTypeSemantics(HigherElementType);
10625+
10626+
if ((llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
10627+
llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) ||
10628+
(HigherElementType == Ctx.LongDoubleTy &&
10629+
!Ctx.getTargetInfo().hasLongDoubleType())) {
10630+
// Retain the location of the first use of higher precision type.
10631+
if (!S.LocationOfExcessPrecisionNotSatisfied.isValid())
10632+
S.LocationOfExcessPrecisionNotSatisfied = OpLoc;
10633+
for (auto &[Type, Num] : S.ExcessPrecisionNotSatisfied) {
10634+
if (Type == HigherElementType) {
10635+
Num++;
10636+
return;
10637+
}
10638+
}
10639+
S.ExcessPrecisionNotSatisfied.push_back(std::make_pair(
10640+
HigherElementType, S.ExcessPrecisionNotSatisfied.size()));
10641+
}
10642+
}
10643+
1060510644
static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS,
1060610645
SourceLocation Loc) {
1060710646
const auto *LUE = dyn_cast<UnaryExprOrTypeTraitExpr>(LHS);
@@ -10696,6 +10735,7 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
1069610735
if (compType.isNull() || !compType->isArithmeticType())
1069710736
return InvalidOperands(Loc, LHS, RHS);
1069810737
if (IsDiv) {
10738+
DetectPrecisionLossInComplexDivision(*this, RHS.get()->getType(), Loc);
1069910739
DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv);
1070010740
DiagnoseDivisionSizeofPointerOrArray(*this, LHS.get(), RHS.get(), Loc);
1070110741
}
@@ -15347,39 +15387,6 @@ static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc,
1534715387
DiagnoseShiftCompare(Self, OpLoc, LHSExpr, RHSExpr);
1534815388
}
1534915389

15350-
static void DetectPrecisionLossInComplexDivision(Sema &S, SourceLocation OpLoc,
15351-
Expr *Operand) {
15352-
if (auto *CT = Operand->getType()->getAs<ComplexType>()) {
15353-
QualType ElementType = CT->getElementType();
15354-
bool IsComplexRangePromoted = S.getLangOpts().getComplexRange() ==
15355-
LangOptions::ComplexRangeKind::CX_Promoted;
15356-
if (ElementType->isFloatingType() && IsComplexRangePromoted) {
15357-
ASTContext &Ctx = S.getASTContext();
15358-
QualType HigherElementType = Ctx.GetHigherPrecisionFPType(ElementType);
15359-
const llvm::fltSemantics &ElementTypeSemantics =
15360-
Ctx.getFloatTypeSemantics(ElementType);
15361-
const llvm::fltSemantics &HigherElementTypeSemantics =
15362-
Ctx.getFloatTypeSemantics(HigherElementType);
15363-
if ((llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
15364-
llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) ||
15365-
(HigherElementType == Ctx.LongDoubleTy &&
15366-
!Ctx.getTargetInfo().hasLongDoubleType())) {
15367-
// Retain the location of the first use of higher precision type.
15368-
if (!S.LocationOfExcessPrecisionNotSatisfied.isValid())
15369-
S.LocationOfExcessPrecisionNotSatisfied = OpLoc;
15370-
for (auto &[Type, Num] : S.ExcessPrecisionNotSatisfied) {
15371-
if (Type == HigherElementType) {
15372-
Num++;
15373-
return;
15374-
}
15375-
}
15376-
S.ExcessPrecisionNotSatisfied.push_back(std::make_pair(
15377-
HigherElementType, S.ExcessPrecisionNotSatisfied.size()));
15378-
}
15379-
}
15380-
}
15381-
}
15382-
1538315390
ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
1538415391
tok::TokenKind Kind,
1538515392
Expr *LHSExpr, Expr *RHSExpr) {
@@ -15390,11 +15397,6 @@ ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
1539015397
// Emit warnings for tricky precedence issues, e.g. "bitfield & 0x4 == 0"
1539115398
DiagnoseBinOpPrecedence(*this, Opc, TokLoc, LHSExpr, RHSExpr);
1539215399

15393-
// Emit warnings if the requested higher precision type equal to the current
15394-
// type precision.
15395-
if (Kind == tok::TokenKind::slash)
15396-
DetectPrecisionLossInComplexDivision(*this, TokLoc, LHSExpr);
15397-
1539815400
BuiltinCountedByRefKind K =
1539915401
BinaryOperator::isAssignmentOp(Opc) ? AssignmentKind : BinaryExprKind;
1540015402

@@ -21111,11 +21113,15 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
2111121113
const bool IsTypeAliasTemplateDecl = isa<TypeAliasTemplateDecl>(Temp);
2111221114

2111321115
NestedNameSpecifier *NNS = ULE->getQualifierLoc().getNestedNameSpecifier();
21114-
TemplateName TN(dyn_cast<TemplateDecl>(Temp));
21115-
if (TN.isNull())
21116+
// FIXME: AssumedTemplate is not very appropriate for error recovery here,
21117+
// as it models only the unqualified-id case, where this case can clearly be
21118+
// qualified. Thus we can't just qualify an assumed template.
21119+
TemplateName TN;
21120+
if (auto *TD = dyn_cast<TemplateDecl>(Temp))
21121+
TN = Context.getQualifiedTemplateName(NNS, ULE->hasTemplateKeyword(),
21122+
TemplateName(TD));
21123+
else
2111621124
TN = Context.getAssumedTemplateName(NameInfo.getName());
21117-
TN = Context.getQualifiedTemplateName(NNS,
21118-
/*TemplateKeyword=*/true, TN);
2111921125

2112021126
Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_type_template)
2112121127
<< TN << ULE->getSourceRange() << IsTypeAliasTemplateDecl;

0 commit comments

Comments
 (0)