[PATCH] D123298: [NFC] [AST] Reduce the size of TemplateParmPosition

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 7 22:53:00 PDT 2022


ChuanqiXu added a comment.

> On the other hand, why not use 16 for both?

I am consistent with @aaron.ballman here.



================
Comment at: clang/include/clang/AST/DeclTemplate.h:1156-1157
 
-  TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {}
+  static constexpr unsigned MaxDepth = (1l << DEPTH_BITWIDTH) - 1;
+  static constexpr unsigned MaxPosition = (1l << POSITION_BITWIDTH) - 1;
+
----------------
I don't find standard way to generate the maximum value for bit fields.. So I choose to calculate it by hand. 


================
Comment at: clang/include/clang/AST/DeclTemplate.h:1163-1164
+  TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {
+    // The input may fill maximum values to show that it is invalid.
+    // Add one here to convert it to zero.
+    assert((D + 1) <= MaxDepth &&
----------------
I find it is possible if ast-dump is going to dump from JSON files.


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

https://reviews.llvm.org/D123298



More information about the cfe-commits mailing list