Skip to content

Commit fa45f81

Browse files
committed
[clang][Serialization][RISCV] Increase the number of reserved predefined type IDs
In D152070 we added many new intrinsic types required for the RISC-V Vector Extension. This was crashing when loading the AST as those types are intrinsically added to the AST (they don't come from the disk). The total number required now by clang exceeds 400 so increasing the value to 500 solves the problem. This value was already increased in D92715 but I assume this has some impact on the on-disk format. Also add a static assert to avoid this happening again in the future. Differential Revision: https://reviews.llvm.org/D153111
1 parent 798b641 commit fa45f81

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,14 +1099,22 @@ enum PredefinedTypeIDs {
10991099
// \brief WebAssembly reference types with auto numeration
11001100
#define WASM_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
11011101
#include "clang/Basic/WebAssemblyReferenceTypes.def"
1102+
// Sentinel value. Considered a predefined type but not useable as one.
1103+
PREDEF_TYPE_LAST_ID
11021104
};
11031105

11041106
/// The number of predefined type IDs that are reserved for
11051107
/// the PREDEF_TYPE_* constants.
11061108
///
11071109
/// Type IDs for non-predefined types will start at
11081110
/// NUM_PREDEF_TYPE_IDs.
1109-
const unsigned NUM_PREDEF_TYPE_IDS = 300;
1111+
const unsigned NUM_PREDEF_TYPE_IDS = 500;
1112+
1113+
// Ensure we do not overrun the predefined types we reserved
1114+
// in the enum PredefinedTypeIDs above.
1115+
static_assert(PREDEF_TYPE_LAST_ID < NUM_PREDEF_TYPE_IDS,
1116+
"Too many enumerators in PredefinedTypeIDs. Review the value of "
1117+
"NUM_PREDEF_TYPE_IDS");
11101118

11111119
/// Record codes for each kind of type.
11121120
///

clang/lib/Serialization/ASTReader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6983,6 +6983,10 @@ QualType ASTReader::GetType(TypeID ID) {
69836983
if (Index < NUM_PREDEF_TYPE_IDS) {
69846984
QualType T;
69856985
switch ((PredefinedTypeIDs)Index) {
6986+
case PREDEF_TYPE_LAST_ID:
6987+
// We should never use this one.
6988+
llvm_unreachable("Invalid predefined type");
6989+
break;
69866990
case PREDEF_TYPE_NULL_ID:
69876991
return QualType();
69886992
case PREDEF_TYPE_VOID_ID:

clang/test/Modules/embed-files-compressed.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// RUN: %clang_cc1 -fmodules -I%t -fmodules-cache-path=%t -fmodule-name=a -emit-module %t/modulemap -fmodules-embed-all-files -o %t/a.pcm
1818
//
1919
// The above embeds ~4.5MB of highly-predictable /s and \ns into the pcm file.
20-
// Check that the resulting file is under 40KB:
20+
// Check that the resulting file is under 60KB:
2121
//
2222
// RUN: wc -c %t/a.pcm | FileCheck --check-prefix=CHECK-SIZE %s
23-
// CHECK-SIZE: {{(^|[^0-9])[123][0-9][0-9][0-9][0-9]($|[^0-9])}}
23+
// CHECK-SIZE: {{(^|[^0-9])[1-5][0-9][0-9][0-9][0-9]($|[^0-9])}}

clang/test/Modules/empty.modulemap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// The module file should be identical each time we produce it.
1414
// RUN: diff %t/base.pcm %t/check.pcm
1515
//
16-
// We expect an empty module to be less than 40KB (and at least 10K, for now).
16+
// We expect an empty module to be less than 60KB (and at least 10K, for now).
1717
// RUN: wc -c %t/base.pcm | FileCheck --check-prefix=CHECK-SIZE %s
18-
// CHECK-SIZE: {{(^|[^0-9])[123][0-9][0-9][0-9][0-9]($|[^0-9])}}
18+
// CHECK-SIZE: {{(^|[^0-9])[1-5][0-9][0-9][0-9][0-9]($|[^0-9])}}
1919

2020
module empty { header "Inputs/empty.h" export * }

0 commit comments

Comments
 (0)