@@ -7884,10 +7884,27 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
7884
7884
friend class ASTContext ;
7885
7885
7886
7886
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
+ }
7887
7902
7888
7903
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) {
7891
7908
Bits.IntegerType .IsNegative = isNegative;
7892
7909
}
7893
7910
@@ -7917,6 +7934,8 @@ class IntegerType final : public TypeBase, public llvm::FoldingSetNode {
7917
7934
static bool classof (const TypeBase *T) {
7918
7935
return T->getKind () == TypeKind::Integer;
7919
7936
}
7937
+
7938
+ const ASTContext &getASTContext () { return Context; }
7920
7939
};
7921
7940
DEFINE_EMPTY_CAN_TYPE_WRAPPER (IntegerType, Type)
7922
7941
0 commit comments