Skip to content

Commit 335626f

Browse files
committed
Merge commit '7c402b8b81d2' from llvm.org/main into next
Conflicts: clang/include/clang/AST/Type.h clang/include/clang/Serialization/TypeBitCodes.def clang/lib/AST/ASTContext.cpp clang/lib/CodeGen/CGDebugInfo.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp Note the upstream change has broken a bunch of `-fbounds-safety` tests. To avoid blocking the automerge these will be handled separately in rdar://156543070. rdar://156445808
2 parents 4a9d44e + 7c402b8 commit 335626f

File tree

83 files changed

+1036
-731
lines changed

Some content is hidden

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

83 files changed

+1036
-731
lines changed

clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ TEST_F(TargetDeclTest, OverloadExpr) {
838838
)cpp";
839839
// Sized deallocation is enabled by default in C++14 onwards.
840840
EXPECT_DECLS("CXXDeleteExpr",
841-
"void operator delete(void *, unsigned long) noexcept");
841+
"void operator delete(void *, __size_t) noexcept");
842842
}
843843

844844
TEST_F(TargetDeclTest, DependentExprs) {

clang-tools-extra/clangd/unittests/HoverTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,7 +2794,7 @@ TEST(Hover, All) {
27942794
})cpp",
27952795
[](HoverInfo &HI) {
27962796
HI.Name = "expression";
2797-
HI.Type = "unsigned long";
2797+
HI.Type = {"__size_t", "unsigned long"};
27982798
HI.Value = "1";
27992799
}},
28002800
{
@@ -2804,7 +2804,7 @@ TEST(Hover, All) {
28042804
})cpp",
28052805
[](HoverInfo &HI) {
28062806
HI.Name = "expression";
2807-
HI.Type = "unsigned long";
2807+
HI.Type = {"__size_t", "unsigned long"};
28082808
HI.Value = "1";
28092809
}},
28102810
{

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Potentially Breaking Changes
4646
``endbr64`` instruction at the labels named as possible branch
4747
destinations, so it is not safe to use a register-controlled branch
4848
instruction to branch to one. (In line with gcc.)
49+
- Added a sugar type `PredefinedSugarType` to improve diagnostic messages. (#GH143653)
4950

5051
C/C++ Language Potentially Breaking Changes
5152
-------------------------------------------

clang/include/clang/AST/ASTContext.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ class ASTContext : public RefCountedBase<ASTContext> {
286286
mutable llvm::ContextualFoldingSet<ArrayParameterType, ASTContext &>
287287
ArrayParameterTypes;
288288

289+
/// Store the unique Type corresponding to each Kind.
290+
mutable std::array<Type *,
291+
llvm::to_underlying(PredefinedSugarType::Kind::Last) + 1>
292+
PredefinedSugarTypes{};
293+
289294
/// The set of nested name specifiers.
290295
///
291296
/// This set is managed by the NestedNameSpecifier class.
@@ -1665,6 +1670,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
16651670
/// and bit count.
16661671
QualType getDependentBitIntType(bool Unsigned, Expr *BitsExpr) const;
16671672

1673+
QualType getPredefinedSugarType(PredefinedSugarType::Kind KD) const;
1674+
16681675
/// Gets the struct used to keep track of the extended descriptor for
16691676
/// pointer to blocks.
16701677
QualType getBlockDescriptorExtendedType() const;
@@ -2097,11 +2104,13 @@ class ASTContext : public RefCountedBase<ASTContext> {
20972104
/// <stddef.h>.
20982105
///
20992106
/// The sizeof operator requires this (C99 6.5.3.4p4).
2100-
CanQualType getSizeType() const;
2107+
QualType getSizeType() const;
2108+
2109+
CanQualType getCanonicalSizeType() const;
21012110

21022111
/// Return the unique signed counterpart of
21032112
/// the integer type corresponding to size_t.
2104-
CanQualType getSignedSizeType() const;
2113+
QualType getSignedSizeType() const;
21052114

21062115
/// Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
21072116
/// <stdint.h>.

clang/include/clang/AST/FormatString.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ class FormatSpecifier {
489489

490490
/// For a TypedefType QT, if it is a named integer type such as size_t,
491491
/// assign the appropriate value to LM and return true.
492-
static bool namedTypeToLengthModifier(QualType QT, LengthModifier &LM);
492+
static bool namedTypeToLengthModifier(ASTContext &Ctx, QualType QT,
493+
LengthModifier &LM);
493494
};
494495

495496
} // end analyze_format_string namespace

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,8 @@ DEF_TRAVERSE_TYPE(BitIntType, {})
12181218
DEF_TRAVERSE_TYPE(DependentBitIntType,
12191219
{ TRY_TO(TraverseStmt(T->getNumBitsExpr())); })
12201220

1221+
DEF_TRAVERSE_TYPE(PredefinedSugarType, {})
1222+
12211223
#undef DEF_TRAVERSE_TYPE
12221224

12231225
// ----------------- TypeLoc traversal -----------------
@@ -1542,6 +1544,8 @@ DEF_TRAVERSE_TYPELOC(DependentBitIntType, {
15421544
TRY_TO(TraverseStmt(TL.getTypePtr()->getNumBitsExpr()));
15431545
})
15441546

1547+
DEF_TRAVERSE_TYPELOC(PredefinedSugarType, {})
1548+
15451549
#undef DEF_TRAVERSE_TYPELOC
15461550

15471551
// ----------------- Decl traversal -----------------

clang/include/clang/AST/Type.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,30 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
22612261
unsigned NumExpansions;
22622262
};
22632263

2264+
enum class PredefinedSugarKind {
2265+
/// The "size_t" type.
2266+
SizeT,
2267+
2268+
/// The signed integer type corresponding to "size_t".
2269+
SignedSizeT,
2270+
2271+
/// The "ptrdiff_t" type.
2272+
PtrdiffT,
2273+
2274+
// Indicates how many items the enum has.
2275+
Last = PtrdiffT
2276+
};
2277+
2278+
class PresefinedSugarTypeBitfields {
2279+
friend class PredefinedSugarType;
2280+
2281+
LLVM_PREFERRED_TYPE(TypeBitfields)
2282+
unsigned : NumTypeBits;
2283+
2284+
LLVM_PREFERRED_TYPE(PredefinedSugarKind)
2285+
unsigned Kind : 8;
2286+
};
2287+
22642288
class CountAttributedTypeBitfields {
22652289
friend class CountAttributedType;
22662290

@@ -2314,6 +2338,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
23142338
/* TO_UPSTREAM(BoundsSafety) ON */
23152339
DynamicRangePointerTypeBitfields DynamicRangePointerTypeBits;
23162340
/* TO_UPSTREAM(BoundsSafety) OFF */
2341+
PresefinedSugarTypeBitfields PredefinedSugarTypeBits;
23172342
};
23182343

23192344
private:
@@ -8456,6 +8481,37 @@ class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
84568481
}
84578482
};
84588483

8484+
class PredefinedSugarType final : public Type {
8485+
public:
8486+
friend class ASTContext;
8487+
using Kind = PredefinedSugarKind;
8488+
8489+
private:
8490+
PredefinedSugarType(Kind KD, const IdentifierInfo *IdentName,
8491+
QualType CanonicalType)
8492+
: Type(PredefinedSugar, CanonicalType, TypeDependence::None),
8493+
Name(IdentName) {
8494+
PredefinedSugarTypeBits.Kind = llvm::to_underlying(KD);
8495+
}
8496+
8497+
static StringRef getName(Kind KD);
8498+
8499+
const IdentifierInfo *Name;
8500+
8501+
public:
8502+
bool isSugared() const { return true; }
8503+
8504+
QualType desugar() const { return getCanonicalTypeInternal(); }
8505+
8506+
Kind getKind() const { return Kind(PredefinedSugarTypeBits.Kind); }
8507+
8508+
const IdentifierInfo *getIdentifier() const { return Name; }
8509+
8510+
static bool classof(const Type *T) {
8511+
return T->getTypeClass() == PredefinedSugar;
8512+
}
8513+
};
8514+
84598515
/// A qualifier set is used to build a set of qualifiers.
84608516
class QualifierCollector : public Qualifiers {
84618517
public:

clang/include/clang/AST/TypeLoc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,16 @@ class ObjCProtocolLoc {
28212821
}
28222822
};
28232823

2824+
struct PredefinedSugarTypeLocInfo {}; // Nothing.
2825+
2826+
class PredefinedSugarTypeLoc final
2827+
: public ConcreteTypeLoc<UnqualTypeLoc, PredefinedSugarTypeLoc,
2828+
PredefinedSugarType, PredefinedSugarTypeLocInfo> {
2829+
public:
2830+
void initializeLocal(ASTContext &Context, SourceLocation loc) {}
2831+
SourceRange getLocalSourceRange() const { return {}; }
2832+
};
2833+
28242834
} // namespace clang
28252835

28262836
#endif // LLVM_CLANG_AST_TYPELOC_H

clang/include/clang/AST/TypeProperties.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,3 +1068,12 @@ let Class = DependentBitIntType in {
10681068
return ctx.getDependentBitIntType(isUnsigned, numBitsExpr);
10691069
}]>;
10701070
}
1071+
1072+
let Class = PredefinedSugarType in {
1073+
def : Property<"kind", UInt32> {
1074+
let Read = [{ static_cast<uint32_t>(node->getKind()) }];
1075+
}
1076+
def : Creator<[{
1077+
return ctx.getPredefinedSugarType(static_cast<PredefinedSugarType::Kind>(kind));
1078+
}]>;
1079+
}

clang/include/clang/Basic/TypeNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ def PipeType : TypeNode<Type>;
121121
def AtomicType : TypeNode<Type>;
122122
def BitIntType : TypeNode<Type>;
123123
def DependentBitIntType : TypeNode<Type>, AlwaysDependent;
124+
def PredefinedSugarType : TypeNode<Type>, NeverCanonical;

0 commit comments

Comments
 (0)