@@ -3298,6 +3298,28 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
32983298 }
32993299 ForceCUDAHostDeviceDepth = Record[0 ];
33003300 break ;
3301+
3302+ case PACK_PRAGMA_OPTIONS: {
3303+ if (Record.size () < 3 ) {
3304+ Error (" invalid pragma pack record" );
3305+ return Failure;
3306+ }
3307+ PragmaPackCurrentValue = Record[0 ];
3308+ PragmaPackCurrentLocation = ReadSourceLocation (F, Record[1 ]);
3309+ unsigned NumStackEntries = Record[2 ];
3310+ unsigned Idx = 3 ;
3311+ // Reset the stack when importing a new module.
3312+ PragmaPackStack.clear ();
3313+ for (unsigned I = 0 ; I < NumStackEntries; ++I) {
3314+ PragmaPackStackEntry Entry;
3315+ Entry.Value = Record[Idx++];
3316+ Entry.Location = ReadSourceLocation (F, Record[Idx++]);
3317+ PragmaPackStrings.push_back (ReadString (Record, Idx));
3318+ Entry.SlotLabel = PragmaPackStrings.back ();
3319+ PragmaPackStack.push_back (Entry);
3320+ }
3321+ break ;
3322+ }
33013323 }
33023324 }
33033325}
@@ -7419,6 +7441,34 @@ void ASTReader::UpdateSema() {
74197441 PointersToMembersPragmaLocation);
74207442 }
74217443 SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth;
7444+
7445+ if (PragmaPackCurrentValue) {
7446+ // The bottom of the stack might have a default value. It must be adjusted
7447+ // to the current value to ensure that the packing state is preserved after
7448+ // popping entries that were included/imported from a PCH/module.
7449+ bool DropFirst = false ;
7450+ if (!PragmaPackStack.empty () &&
7451+ PragmaPackStack.front ().Location .isInvalid ()) {
7452+ assert (PragmaPackStack.front ().Value == SemaObj->PackStack .DefaultValue &&
7453+ " Expected a default alignment value" );
7454+ SemaObj->PackStack .Stack .emplace_back (
7455+ PragmaPackStack.front ().SlotLabel , SemaObj->PackStack .CurrentValue ,
7456+ SemaObj->PackStack .CurrentPragmaLocation );
7457+ DropFirst = true ;
7458+ }
7459+ for (const auto &Entry :
7460+ llvm::makeArrayRef (PragmaPackStack).drop_front (DropFirst ? 1 : 0 ))
7461+ SemaObj->PackStack .Stack .emplace_back (Entry.SlotLabel , Entry.Value ,
7462+ Entry.Location );
7463+ if (PragmaPackCurrentLocation.isInvalid ()) {
7464+ assert (*PragmaPackCurrentValue == SemaObj->PackStack .DefaultValue &&
7465+ " Expected a default alignment value" );
7466+ // Keep the current values.
7467+ } else {
7468+ SemaObj->PackStack .CurrentValue = *PragmaPackCurrentValue;
7469+ SemaObj->PackStack .CurrentPragmaLocation = PragmaPackCurrentLocation;
7470+ }
7471+ }
74227472}
74237473
74247474IdentifierInfo *ASTReader::get (StringRef Name) {
0 commit comments