@@ -7910,10 +7910,27 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
79107910 friend class ASTContext ;
79117911
79127912 StringRef Value;
7913+ // Integers may not be canonical, but don't have any structural type
7914+ // components from which to get the ASTContext, so we need to store a
7915+ // reference to it ourselves.
7916+ const ASTContext &Context;
7917+
7918+ static const ASTContext *
7919+ getCanonicalIntegerLiteralContext (StringRef value, const ASTContext &ctx) {
7920+ for (char c : value) {
7921+ // A canonical integer literal consists only of ASCII decimal digits.
7922+ if (c < ' 0' || c > ' 9' ) {
7923+ return nullptr ;
7924+ }
7925+ }
7926+ return &ctx;
7927+ }
79137928
79147929 IntegerType (StringRef value, bool isNegative, const ASTContext &ctx) :
7915- TypeBase (TypeKind::Integer, &ctx, RecursiveTypeProperties()),
7916- Value (value) {
7930+ TypeBase (TypeKind::Integer, getCanonicalIntegerLiteralContext(value, ctx),
7931+ RecursiveTypeProperties ()),
7932+ Value (value),
7933+ Context (ctx) {
79177934 Bits.IntegerType .IsNegative = isNegative;
79187935 }
79197936
@@ -7943,6 +7960,8 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
79437960 static bool classof (const TypeBase *T) {
79447961 return T->getKind () == TypeKind::Integer;
79457962 }
7963+
7964+ const ASTContext &getASTContext () { return Context; }
79467965};
79477966DEFINE_EMPTY_CAN_TYPE_WRAPPER (IntegerType, Type)
79487967
0 commit comments