[PATCH] D120770: [C2x] Implement literal suffixes for _BitInt

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 2 12:12:06 PST 2022


erichkeane added inline comments.


================
Comment at: clang/include/clang/Lex/LiteralSupport.h:65
   bool isLong : 1;          // This is *not* set for long long.
   bool isLongLong : 1;
   bool isSizeT : 1;         // 1z, 1uz (C++2b)
----------------
aaron.ballman wrote:
> erichkeane wrote:
> > I can't help but wonder if there are some really good opportunities to merge a bunch of these mutually exclusive ones into an enum...
> > ```
> > enum class SizeType {
> > Long,
> > LongLong,
> > SizeT,
> > Float,
> > Imaginary,
> > Float16,
> > Flaot128,
> > Fract,
> > Accum,
> > BitInt
> > ```
> > 
> > Or something?
> That seems plausible, but perhaps as a follow-up. We're going from 12 bits to 13 with this patch (and correctly a layout issue as a drive-by), so we're not at or near an allocation unit boundary.
SGTM.


================
Comment at: clang/lib/AST/StmtPrinter.cpp:1157
+  if (const auto *BT = Node->getType()->getAs<BitIntType>()) {
+    OS << (BT->isUnsigned() ? "uwb" : "wb");
+    return;
----------------
aaron.ballman wrote:
> erichkeane wrote:
> > Nit: Instead of BT->isUnsigned(), we already have isSigned above.
> Good call!
Isn't this reversed now?


================
Comment at: clang/lib/Sema/SemaExpr.cpp:3995
+        ResultVal = ResultVal.zextOrTrunc(Width);
+        Ty = Context.getBitIntType(Literal.isUnsigned, Width);
+      }
----------------
aaron.ballman wrote:
> erichkeane wrote:
> > I think it is already covered, but do we make sure the literal itself and the suffix match?  That is: -111uwb is invalid?
> We do not, but that's consistent with other suffix confusion: https://godbolt.org/z/rExPGdex3
> 
> (Remember, the `-` isn't part of the literal, that's a unary negation operator applied to the positive literal.)
Oh! TIL!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120770/new/

https://reviews.llvm.org/D120770



More information about the cfe-commits mailing list