================
@@ -24,6 +25,74 @@ AST_MATCHER(ImplicitCastExpr, isPartOfExplicitCast) {
AST_MATCHER(Expr, containsErrors) { return Node.containsErrors(); }
} // namespace
+static std::optional<StringRef> getLiteralSuffix(QualType Ty,
+ const ASTContext &Context) {
+ if (!Ty->isIntegerType() || Ty->isBitIntType())
+ return std::nullopt;
+
+ const LangOptions &LangOpts = Context.getLangOpts();
+ const QualType CanonTy = Ty.getCanonicalType();
+
+ if (Context.getIntWidth(CanonTy) <= Context.getIntWidth(Context.IntTy))
+ return std::nullopt;
+
+ if (Context.hasSameType(CanonTy, Context.LongTy))
+ return "l";
+ if (Context.hasSameType(CanonTy, Context.UnsignedLongTy))
+ return "ul";
+
+ const bool HasLongLongLiteralSuffix = LangOpts.CPlusPlus11 || LangOpts.C99;
+ if (!HasLongLongLiteralSuffix)
+ return std::nullopt;
+
+ if (Context.hasSameType(CanonTy, Context.LongLongTy))
+ return "ll";
+ if (Context.hasSameType(CanonTy, Context.UnsignedLongLongTy))
+ return "ull";
+
+ return std::nullopt;
----------------
unterumarmung wrote:
Should we add support for `size_t` literals? maybe in next PR..
https://github.com/llvm/llvm-project/pull/198258
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits