@@ -7910,10 +7910,27 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
7910
7910
friend class ASTContext ;
7911
7911
7912
7912
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
+ }
7913
7928
7914
7929
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) {
7917
7934
Bits.IntegerType .IsNegative = isNegative;
7918
7935
}
7919
7936
@@ -7943,6 +7960,8 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
7943
7960
static bool classof (const TypeBase *T) {
7944
7961
return T->getKind () == TypeKind::Integer;
7945
7962
}
7963
+
7964
+ const ASTContext &getASTContext () { return Context; }
7946
7965
};
7947
7966
DEFINE_EMPTY_CAN_TYPE_WRAPPER (IntegerType, Type)
7948
7967
0 commit comments