@@ -7884,10 +7884,27 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
78847884 friend class ASTContext ;
78857885
78867886 StringRef Value;
7887+ // Integers may not be canonical, but don't have any structural type
7888+ // components from which to get the ASTContext, so we need to store a
7889+ // reference to it ourselves.
7890+ const ASTContext &Context;
7891+
7892+ static const ASTContext *
7893+ getCanonicalIntegerLiteralContext (StringRef value, const ASTContext &ctx) {
7894+ for (char c : value) {
7895+ // A canonical integer literal consists only of ASCII decimal digits.
7896+ if (c < ' 0' || c > ' 9' ) {
7897+ return nullptr ;
7898+ }
7899+ }
7900+ return &ctx;
7901+ }
78877902
78887903 IntegerType (StringRef value, bool isNegative, const ASTContext &ctx) :
7889- TypeBase (TypeKind::Integer, &ctx, RecursiveTypeProperties()),
7890- Value (value) {
7904+ TypeBase (TypeKind::Integer, getCanonicalIntegerLiteralContext(value, ctx),
7905+ RecursiveTypeProperties ()),
7906+ Value (value),
7907+ Context (ctx) {
78917908 Bits.IntegerType .IsNegative = isNegative;
78927909 }
78937910
@@ -7917,6 +7934,8 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
79177934 static bool classof (const TypeBase *T) {
79187935 return T->getKind () == TypeKind::Integer;
79197936 }
7937+
7938+ const ASTContext &getASTContext () { return Context; }
79207939};
79217940DEFINE_EMPTY_CAN_TYPE_WRAPPER (IntegerType, Type)
79227941
0 commit comments