Skip to content

Commit 711cf1b

Browse files
Merge branch 'llvm:main' into muzasyed/sub
2 parents 50e3616 + c409da2 commit 711cf1b

File tree

230 files changed

+7790
-1571
lines changed

Some content is hidden

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

230 files changed

+7790
-1571
lines changed

clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ static std::optional<TemplateSpecializationTypeLoc>
5454
matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
5555
if (const auto Dep = TheType.getAs<DependentNameTypeLoc>()) {
5656
const IdentifierInfo *Identifier = Dep.getTypePtr()->getIdentifier();
57+
ElaboratedTypeKeyword Keyword = Dep.getTypePtr()->getKeyword();
5758
if (!Identifier || Identifier->getName() != "type" ||
58-
Dep.getTypePtr()->getKeyword() != ElaboratedTypeKeyword::Typename) {
59+
(Keyword != ElaboratedTypeKeyword::Typename &&
60+
Keyword != ElaboratedTypeKeyword::None)) {
5961
return std::nullopt;
6062
}
6163
TheType = Dep.getQualifierLoc().getTypeLoc();
@@ -108,8 +110,10 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
108110

109111
if (const auto *AliasedType =
110112
dyn_cast<DependentNameType>(Specialization->getAliasedType())) {
113+
ElaboratedTypeKeyword Keyword = AliasedType->getKeyword();
111114
if (AliasedType->getIdentifier()->getName() != "type" ||
112-
AliasedType->getKeyword() != ElaboratedTypeKeyword::Typename) {
115+
(Keyword != ElaboratedTypeKeyword::Typename &&
116+
Keyword != ElaboratedTypeKeyword::None)) {
113117
return std::nullopt;
114118
}
115119
} else {

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ to ``float``; see below for more information on this emulation.
10001000
* SPIR (natively)
10011001
* X86 (if SSE2 is available; natively if AVX512-FP16 is also available)
10021002
* RISC-V (natively if Zfh or Zhinx is available)
1003+
* SystemZ (emulated)
10031004

10041005
* ``__bf16`` is supported on the following targets (currently never natively):
10051006

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ Bug Fixes to C++ Support
486486
- Fixes matching of nested template template parameters. (#GH130362)
487487
- Correctly diagnoses template template paramters which have a pack parameter
488488
not in the last position.
489+
- Disallow overloading on struct vs class on dependent types, which is IFNDR, as
490+
this makes the problem diagnosable.
491+
- Improved preservation of the presence or abscence of typename specifier when
492+
printing types in diagnostics.
489493
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
490494
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
491495
- Clang now properly instantiates destructors for initialized members within non-delegating constructors. (#GH93251)

clang/include/clang/AST/Type.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,20 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
28382838
/// immediately following this class.
28392839
template <typename T> const T *getAs() const;
28402840

2841+
/// Look through sugar for an instance of TemplateSpecializationType which
2842+
/// is not a type alias, or null if there is no such type.
2843+
/// This is used when you want as-written template arguments or the template
2844+
/// name for a class template specialization.
2845+
const TemplateSpecializationType *
2846+
getAsNonAliasTemplateSpecializationType() const;
2847+
2848+
const TemplateSpecializationType *
2849+
castAsNonAliasTemplateSpecializationType() const {
2850+
const auto *TST = getAsNonAliasTemplateSpecializationType();
2851+
assert(TST && "not a TemplateSpecializationType");
2852+
return TST;
2853+
}
2854+
28412855
/// Member-template getAsAdjusted<specific type>. Look through specific kinds
28422856
/// of sugar (parens, attributes, etc) for an instance of \<specific type>.
28432857
/// This is used when you need to walk over sugar nodes that represent some

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class TargetInfo : public TransferrableTargetInfo,
235235
bool NoAsmVariants; // True if {|} are normal characters.
236236
bool HasLegalHalfType; // True if the backend supports operations on the half
237237
// LLVM IR type.
238-
bool HalfArgsAndReturns;
238+
bool HalfArgsAndReturns; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half) type.
239239
bool HasFloat128;
240240
bool HasFloat16;
241241
bool HasBFloat16;

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
9595
return getZeroAttr(arrTy);
9696
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
9797
return getConstNullPtrAttr(ptrTy);
98+
if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
99+
return getZeroAttr(recordTy);
98100
if (mlir::isa<cir::BoolType>(ty)) {
99101
return getCIRBoolAttr(false);
100102
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ def CIR_RecordType : CIR_Type<"Record", "record",
499499
std::string getPrefixedName() {
500500
return getKindAsStr() + "." + getName().getValue().str();
501501
}
502+
503+
void complete(llvm::ArrayRef<mlir::Type> members, bool packed,
504+
bool isPadded);
502505
}];
503506

504507
let hasCustomAssemblyFormat = 1;

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ struct MissingFeatures {
103103

104104
// RecordType
105105
static bool recordTypeLayoutInfo() { return false; }
106+
static bool recursiveRecordLayout() { return false; }
107+
static bool skippedLayout() { return false; }
108+
static bool astRecordDeclAttr() { return false; }
109+
static bool cxxSupport() { return false; }
110+
static bool packedRecords() { return false; }
111+
static bool recordPadding() { return false; }
112+
static bool recordZeroInit() { return false; }
113+
static bool zeroSizeRecordMembers() { return false; }
106114

107115
// Misc
108116
static bool cxxABI() { return false; }

clang/lib/AST/ASTContext.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5747,6 +5747,30 @@ ASTContext::getMacroQualifiedType(QualType UnderlyingTy,
57475747
return QualType(newType, 0);
57485748
}
57495749

5750+
static ElaboratedTypeKeyword
5751+
getCanonicalElaboratedTypeKeyword(ElaboratedTypeKeyword Keyword) {
5752+
switch (Keyword) {
5753+
// These are just themselves.
5754+
case ElaboratedTypeKeyword::None:
5755+
case ElaboratedTypeKeyword::Struct:
5756+
case ElaboratedTypeKeyword::Union:
5757+
case ElaboratedTypeKeyword::Enum:
5758+
case ElaboratedTypeKeyword::Interface:
5759+
return Keyword;
5760+
5761+
// These are equivalent.
5762+
case ElaboratedTypeKeyword::Typename:
5763+
return ElaboratedTypeKeyword::None;
5764+
5765+
// These are functionally equivalent, so relying on their equivalence is
5766+
// IFNDR. By making them equivalent, we disallow overloading, which at least
5767+
// can produce a diagnostic.
5768+
case ElaboratedTypeKeyword::Class:
5769+
return ElaboratedTypeKeyword::Struct;
5770+
}
5771+
llvm_unreachable("unexpected keyword kind");
5772+
}
5773+
57505774
QualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword,
57515775
NestedNameSpecifier *NNS,
57525776
const IdentifierInfo *Name) const {
@@ -5758,10 +5782,13 @@ QualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword,
57585782
DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos))
57595783
return QualType(T, 0);
57605784

5785+
ElaboratedTypeKeyword CanonKeyword =
5786+
getCanonicalElaboratedTypeKeyword(Keyword);
5787+
NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS);
5788+
57615789
QualType Canon;
5762-
if (NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS);
5763-
CanonNNS != NNS) {
5764-
Canon = getDependentNameType(Keyword, CanonNNS, Name);
5790+
if (CanonKeyword != Keyword || CanonNNS != NNS) {
5791+
Canon = getDependentNameType(CanonKeyword, CanonNNS, Name);
57655792
[[maybe_unused]] DependentNameType *T =
57665793
DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos);
57675794
assert(!T && "broken canonicalization");
@@ -5800,27 +5827,27 @@ QualType ASTContext::getDependentTemplateSpecializationType(
58005827

58015828
QualType Canon;
58025829
if (!IsCanonical) {
5803-
ElaboratedTypeKeyword CanonKeyword = Keyword != ElaboratedTypeKeyword::None
5804-
? Keyword
5805-
: ElaboratedTypeKeyword::Typename;
5830+
ElaboratedTypeKeyword CanonKeyword =
5831+
getCanonicalElaboratedTypeKeyword(Keyword);
58065832
NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS);
58075833
bool AnyNonCanonArgs = false;
58085834
auto CanonArgs =
58095835
::getCanonicalTemplateArguments(*this, Args, AnyNonCanonArgs);
58105836

5811-
if (AnyNonCanonArgs || CanonNNS != NNS || !Name.hasTemplateKeyword() ||
5812-
CanonKeyword != Keyword) {
5837+
if (CanonKeyword != Keyword || AnyNonCanonArgs || CanonNNS != NNS ||
5838+
!Name.hasTemplateKeyword()) {
58135839
Canon = getDependentTemplateSpecializationType(
58145840
CanonKeyword, {CanonNNS, Name.getName(), /*HasTemplateKeyword=*/true},
5815-
CanonArgs, /*IsCanonical=*/true);
5841+
CanonArgs,
5842+
/*IsCanonical=*/true);
58165843
// Find the insert position again.
58175844
[[maybe_unused]] auto *Nothing =
58185845
DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID,
58195846
InsertPos);
58205847
assert(!Nothing && "canonical type broken");
58215848
}
58225849
} else {
5823-
assert(Keyword != ElaboratedTypeKeyword::None);
5850+
assert(Keyword == getCanonicalElaboratedTypeKeyword(Keyword));
58245851
assert(Name.hasTemplateKeyword());
58255852
assert(NNS == getCanonicalNestedNameSpecifier(NNS));
58265853
#ifndef NDEBUG
@@ -7657,7 +7684,7 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
76577684
if (const auto *DTST = T->getAs<DependentTemplateSpecializationType>()) {
76587685
const DependentTemplateStorage &DTN = DTST->getDependentTemplateName();
76597686
QualType NewT = getDependentTemplateSpecializationType(
7660-
ElaboratedTypeKeyword::Typename,
7687+
ElaboratedTypeKeyword::None,
76617688
{/*NNS=*/nullptr, DTN.getName(), /*HasTemplateKeyword=*/true},
76627689
DTST->template_arguments(), /*IsCanonical=*/true);
76637690
assert(NewT.isCanonical());

clang/lib/AST/Type.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,14 @@ TagDecl *Type::getAsTagDecl() const {
19381938
return nullptr;
19391939
}
19401940

1941+
const TemplateSpecializationType *
1942+
Type::getAsNonAliasTemplateSpecializationType() const {
1943+
const auto *TST = getAs<TemplateSpecializationType>();
1944+
while (TST && TST->isTypeAlias())
1945+
TST = TST->desugar()->getAs<TemplateSpecializationType>();
1946+
return TST;
1947+
}
1948+
19411949
bool Type::hasAttr(attr::Kind AK) const {
19421950
const Type *Cur = this;
19431951
while (const auto *AT = Cur->getAs<AttributedType>()) {

clang/lib/AST/TypeLoc.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -546,37 +546,47 @@ void UnaryTransformTypeLoc::initializeLocal(ASTContext &Context,
546546
Context.getTrivialTypeSourceInfo(getTypePtr()->getBaseType(), Loc));
547547
}
548548

549+
template <class TL>
550+
static void initializeElaboratedKeyword(TL T, SourceLocation Loc) {
551+
T.setElaboratedKeywordLoc(T.getTypePtr()->getKeyword() !=
552+
ElaboratedTypeKeyword::None
553+
? Loc
554+
: SourceLocation());
555+
}
556+
557+
static NestedNameSpecifierLoc
558+
initializeQualifier(ASTContext &Context, NestedNameSpecifier *Qualifier,
559+
SourceLocation Loc) {
560+
if (!Qualifier)
561+
return NestedNameSpecifierLoc();
562+
NestedNameSpecifierLocBuilder Builder;
563+
Builder.MakeTrivial(Context, Qualifier, Loc);
564+
return Builder.getWithLocInContext(Context);
565+
}
566+
549567
void ElaboratedTypeLoc::initializeLocal(ASTContext &Context,
550568
SourceLocation Loc) {
551569
if (isEmpty())
552570
return;
553-
setElaboratedKeywordLoc(Loc);
554-
NestedNameSpecifierLocBuilder Builder;
555-
Builder.MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
556-
setQualifierLoc(Builder.getWithLocInContext(Context));
571+
initializeElaboratedKeyword(*this, Loc);
572+
setQualifierLoc(
573+
initializeQualifier(Context, getTypePtr()->getQualifier(), Loc));
557574
}
558575

559576
void DependentNameTypeLoc::initializeLocal(ASTContext &Context,
560577
SourceLocation Loc) {
561-
setElaboratedKeywordLoc(Loc);
562-
NestedNameSpecifierLocBuilder Builder;
563-
Builder.MakeTrivial(Context, getTypePtr()->getQualifier(), Loc);
564-
setQualifierLoc(Builder.getWithLocInContext(Context));
578+
initializeElaboratedKeyword(*this, Loc);
579+
setQualifierLoc(
580+
initializeQualifier(Context, getTypePtr()->getQualifier(), Loc));
565581
setNameLoc(Loc);
566582
}
567583

568584
void
569585
DependentTemplateSpecializationTypeLoc::initializeLocal(ASTContext &Context,
570586
SourceLocation Loc) {
571-
setElaboratedKeywordLoc(Loc);
572-
if (NestedNameSpecifier *Qualifier =
573-
getTypePtr()->getDependentTemplateName().getQualifier()) {
574-
NestedNameSpecifierLocBuilder Builder;
575-
Builder.MakeTrivial(Context, Qualifier, Loc);
576-
setQualifierLoc(Builder.getWithLocInContext(Context));
577-
} else {
578-
setQualifierLoc(NestedNameSpecifierLoc());
579-
}
587+
initializeElaboratedKeyword(*this, Loc);
588+
setQualifierLoc(initializeQualifier(
589+
Context, getTypePtr()->getDependentTemplateName().getQualifier(), Loc));
580590
setTemplateKeywordLoc(Loc);
581591
setTemplateNameLoc(Loc);
582592
setLAngleLoc(Loc);

clang/lib/Basic/Targets/SystemZ.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,24 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
9393
"-v128:64-a:8:16-n32:64");
9494
}
9595
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
96+
97+
// True if the backend supports operations on the half LLVM IR type.
98+
// By setting this to false, conversions will happen for _Float16 around
99+
// a statement by default, with operations done in float. However, if
100+
// -ffloat16-excess-precision=none is given, no conversions will be made
101+
// and instead the backend will promote each half operation to float
102+
// individually.
103+
HasLegalHalfType = false;
104+
// Support _Float16.
105+
HasFloat16 = true;
106+
96107
HasStrictFP = true;
97108
}
98109

99110
unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override;
100111

112+
bool useFP16ConversionIntrinsics() const override { return false; }
113+
101114
void getTargetDefines(const LangOptions &Opts,
102115
MacroBuilder &Builder) const override;
103116

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_LIB_CIR_CIRGENRECORDLAYOUT_H
10+
#define LLVM_CLANG_LIB_CIR_CIRGENRECORDLAYOUT_H
11+
12+
#include "clang/AST/Decl.h"
13+
#include "clang/CIR/Dialect/IR/CIRTypes.h"
14+
15+
namespace clang::CIRGen {
16+
17+
/// This class handles record and union layout info while lowering AST types
18+
/// to CIR types.
19+
///
20+
/// These layout objects are only created on demand as CIR generation requires.
21+
class CIRGenRecordLayout {
22+
friend class CIRGenTypes;
23+
24+
CIRGenRecordLayout(const CIRGenRecordLayout &) = delete;
25+
void operator=(const CIRGenRecordLayout &) = delete;
26+
27+
private:
28+
/// The CIR type corresponding to this record layout; used when laying it out
29+
/// as a complete object.
30+
cir::RecordType completeObjectType;
31+
32+
/// Map from (non-bit-field) record field to the corresponding cir record type
33+
/// field no. This info is populated by the record builder.
34+
llvm::DenseMap<const clang::FieldDecl *, unsigned> fieldInfo;
35+
36+
public:
37+
CIRGenRecordLayout(cir::RecordType completeObjectType)
38+
: completeObjectType(completeObjectType) {}
39+
40+
/// Return the "complete object" LLVM type associated with
41+
/// this record.
42+
cir::RecordType getCIRType() const { return completeObjectType; }
43+
44+
/// Return cir::RecordType element number that corresponds to the field FD.
45+
unsigned getCIRFieldNo(const clang::FieldDecl *FD) const {
46+
FD = FD->getCanonicalDecl();
47+
assert(fieldInfo.count(FD) && "Invalid field for record!");
48+
return fieldInfo.lookup(FD);
49+
}
50+
};
51+
52+
} // namespace clang::CIRGen
53+
54+
#endif

0 commit comments

Comments
 (0)