forked from OSchip/llvm-project
[NFC] Renaming PackStack to AlignPackStack
This patch renames PackStack and related variable names to also contain align across Clang. As it is right now, Clang already uses one stack to record the information from both #pragma align and #pragma pack. Leaving it as PackStack is confusing, and could cause people to ignore #pragma align when developing code that interacts with PackStack. Differential Revision: https://reviews.llvm.org/D93901
This commit is contained in:
parent
7b9f541c1e
commit
e97071d795
|
@ -568,14 +568,14 @@ public:
|
||||||
// #pragma pack.
|
// #pragma pack.
|
||||||
// Sentinel to represent when the stack is set to mac68k alignment.
|
// Sentinel to represent when the stack is set to mac68k alignment.
|
||||||
static const unsigned kMac68kAlignmentSentinel = ~0U;
|
static const unsigned kMac68kAlignmentSentinel = ~0U;
|
||||||
PragmaStack<unsigned> PackStack;
|
PragmaStack<unsigned> AlignPackStack;
|
||||||
// The current #pragma pack values and locations at each #include.
|
// The current #pragma align/pack values and locations at each #include.
|
||||||
struct PackIncludeState {
|
struct AlignPackIncludeState {
|
||||||
unsigned CurrentValue;
|
unsigned CurrentValue;
|
||||||
SourceLocation CurrentPragmaLocation;
|
SourceLocation CurrentPragmaLocation;
|
||||||
bool HasNonDefaultValue, ShouldWarnOnInclude;
|
bool HasNonDefaultValue, ShouldWarnOnInclude;
|
||||||
};
|
};
|
||||||
SmallVector<PackIncludeState, 8> PackIncludeStack;
|
SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack;
|
||||||
// Segment #pragmas.
|
// Segment #pragmas.
|
||||||
PragmaStack<StringLiteral *> DataSegStack;
|
PragmaStack<StringLiteral *> DataSegStack;
|
||||||
PragmaStack<StringLiteral *> BSSSegStack;
|
PragmaStack<StringLiteral *> BSSSegStack;
|
||||||
|
@ -9721,14 +9721,14 @@ public:
|
||||||
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
|
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
|
||||||
StringRef SlotLabel, Expr *Alignment);
|
StringRef SlotLabel, Expr *Alignment);
|
||||||
|
|
||||||
enum class PragmaPackDiagnoseKind {
|
enum class PragmaAlignPackDiagnoseKind {
|
||||||
NonDefaultStateAtInclude,
|
NonDefaultStateAtInclude,
|
||||||
ChangedStateAtExit
|
ChangedStateAtExit
|
||||||
};
|
};
|
||||||
|
|
||||||
void DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind,
|
void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
|
||||||
SourceLocation IncludeLoc);
|
SourceLocation IncludeLoc);
|
||||||
void DiagnoseUnterminatedPragmaPack();
|
void DiagnoseUnterminatedPragmaAlignPack();
|
||||||
|
|
||||||
/// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
|
/// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
|
||||||
void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
|
void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
|
||||||
|
|
|
@ -681,8 +681,8 @@ public:
|
||||||
|
|
||||||
MODULAR_CODEGEN_DECLS = 60,
|
MODULAR_CODEGEN_DECLS = 60,
|
||||||
|
|
||||||
/// Record code for \#pragma pack options.
|
/// Record code for \#pragma align/pack options.
|
||||||
PACK_PRAGMA_OPTIONS = 61,
|
ALIGN_PACK_PRAGMA_OPTIONS = 61,
|
||||||
|
|
||||||
/// The stack of open #ifs/#ifdefs recorded in a preamble.
|
/// The stack of open #ifs/#ifdefs recorded in a preamble.
|
||||||
PP_CONDITIONAL_STACK = 62,
|
PP_CONDITIONAL_STACK = 62,
|
||||||
|
|
|
@ -869,17 +869,17 @@ private:
|
||||||
llvm::SmallVector<FpPragmaStackEntry, 2> FpPragmaStack;
|
llvm::SmallVector<FpPragmaStackEntry, 2> FpPragmaStack;
|
||||||
llvm::SmallVector<std::string, 2> FpPragmaStrings;
|
llvm::SmallVector<std::string, 2> FpPragmaStrings;
|
||||||
|
|
||||||
/// The pragma pack state.
|
/// The pragma align/pack state.
|
||||||
Optional<unsigned> PragmaPackCurrentValue;
|
Optional<unsigned> PragmaAlignPackCurrentValue;
|
||||||
SourceLocation PragmaPackCurrentLocation;
|
SourceLocation PragmaAlignPackCurrentLocation;
|
||||||
struct PragmaPackStackEntry {
|
struct PragmaAlignPackStackEntry {
|
||||||
unsigned Value;
|
unsigned Value;
|
||||||
SourceLocation Location;
|
SourceLocation Location;
|
||||||
SourceLocation PushLocation;
|
SourceLocation PushLocation;
|
||||||
StringRef SlotLabel;
|
StringRef SlotLabel;
|
||||||
};
|
};
|
||||||
llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
|
llvm::SmallVector<PragmaAlignPackStackEntry, 2> PragmaAlignPackStack;
|
||||||
llvm::SmallVector<std::string, 2> PragmaPackStrings;
|
llvm::SmallVector<std::string, 2> PragmaAlignPackStrings;
|
||||||
|
|
||||||
/// The OpenCL extension settings.
|
/// The OpenCL extension settings.
|
||||||
OpenCLOptions OpenCLExtensions;
|
OpenCLOptions OpenCLExtensions;
|
||||||
|
|
|
@ -120,8 +120,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
IncludeStack.push_back(IncludeLoc);
|
IncludeStack.push_back(IncludeLoc);
|
||||||
S->DiagnoseNonDefaultPragmaPack(
|
S->DiagnoseNonDefaultPragmaAlignPack(
|
||||||
Sema::PragmaPackDiagnoseKind::NonDefaultStateAtInclude, IncludeLoc);
|
Sema::PragmaAlignPackDiagnoseKind::NonDefaultStateAtInclude,
|
||||||
|
IncludeLoc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -130,8 +131,8 @@ public:
|
||||||
if (llvm::timeTraceProfilerEnabled())
|
if (llvm::timeTraceProfilerEnabled())
|
||||||
llvm::timeTraceProfilerEnd();
|
llvm::timeTraceProfilerEnd();
|
||||||
|
|
||||||
S->DiagnoseNonDefaultPragmaPack(
|
S->DiagnoseNonDefaultPragmaAlignPack(
|
||||||
Sema::PragmaPackDiagnoseKind::ChangedStateAtExit,
|
Sema::PragmaAlignPackDiagnoseKind::ChangedStateAtExit,
|
||||||
IncludeStack.pop_back_val());
|
IncludeStack.pop_back_val());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -157,7 +158,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
|
||||||
OriginalLexicalContext(nullptr), MSStructPragmaOn(false),
|
OriginalLexicalContext(nullptr), MSStructPragmaOn(false),
|
||||||
MSPointerToMemberRepresentationMethod(
|
MSPointerToMemberRepresentationMethod(
|
||||||
LangOpts.getMSPointerToMemberRepresentationMethod()),
|
LangOpts.getMSPointerToMemberRepresentationMethod()),
|
||||||
VtorDispStack(LangOpts.getVtorDispMode()), PackStack(0),
|
VtorDispStack(LangOpts.getVtorDispMode()), AlignPackStack(0),
|
||||||
DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
|
DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
|
||||||
CodeSegStack(nullptr), FpPragmaStack(FPOptionsOverride()),
|
CodeSegStack(nullptr), FpPragmaStack(FPOptionsOverride()),
|
||||||
CurInitSeg(nullptr), VisContext(nullptr),
|
CurInitSeg(nullptr), VisContext(nullptr),
|
||||||
|
@ -1038,7 +1039,7 @@ void Sema::ActOnEndOfTranslationUnit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DiagnoseUnterminatedPragmaPack();
|
DiagnoseUnterminatedPragmaAlignPack();
|
||||||
DiagnoseUnterminatedPragmaAttribute();
|
DiagnoseUnterminatedPragmaAttribute();
|
||||||
|
|
||||||
// All delayed member exception specs should be checked or we end up accepting
|
// All delayed member exception specs should be checked or we end up accepting
|
||||||
|
|
|
@ -49,27 +49,28 @@ Sema::PragmaStackSentinelRAII::~PragmaStackSentinelRAII() {
|
||||||
|
|
||||||
void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
|
void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
|
||||||
// If there is no pack value, we don't need any attributes.
|
// If there is no pack value, we don't need any attributes.
|
||||||
if (!PackStack.CurrentValue)
|
if (!AlignPackStack.CurrentValue)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise, check to see if we need a max field alignment attribute.
|
// Otherwise, check to see if we need a max field alignment attribute.
|
||||||
if (unsigned Alignment = PackStack.CurrentValue) {
|
if (unsigned Alignment = AlignPackStack.CurrentValue) {
|
||||||
if (Alignment == Sema::kMac68kAlignmentSentinel)
|
if (Alignment == Sema::kMac68kAlignmentSentinel)
|
||||||
RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
|
RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
|
||||||
else
|
else
|
||||||
RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
|
RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
|
||||||
Alignment * 8));
|
Alignment * 8));
|
||||||
}
|
}
|
||||||
if (PackIncludeStack.empty())
|
if (AlignPackIncludeStack.empty())
|
||||||
return;
|
return;
|
||||||
// The #pragma pack affected a record in an included file, so Clang should
|
// The #pragma align/pack affected a record in an included file, so Clang
|
||||||
// warn when that pragma was written in a file that included the included
|
// should warn when that the pragma was written in a file that included the
|
||||||
// file.
|
// included file.
|
||||||
for (auto &PackedInclude : llvm::reverse(PackIncludeStack)) {
|
for (auto &AlignPackedInclude : llvm::reverse(AlignPackIncludeStack)) {
|
||||||
if (PackedInclude.CurrentPragmaLocation != PackStack.CurrentPragmaLocation)
|
if (AlignPackedInclude.CurrentPragmaLocation !=
|
||||||
|
AlignPackStack.CurrentPragmaLocation)
|
||||||
break;
|
break;
|
||||||
if (PackedInclude.HasNonDefaultValue)
|
if (AlignPackedInclude.HasNonDefaultValue)
|
||||||
PackedInclude.ShouldWarnOnInclude = true;
|
AlignPackedInclude.ShouldWarnOnInclude = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,8 +239,8 @@ void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
|
||||||
// Reset just pops the top of the stack, or resets the current alignment to
|
// Reset just pops the top of the stack, or resets the current alignment to
|
||||||
// default.
|
// default.
|
||||||
Action = Sema::PSK_Pop;
|
Action = Sema::PSK_Pop;
|
||||||
if (PackStack.Stack.empty()) {
|
if (AlignPackStack.Stack.empty()) {
|
||||||
if (PackStack.CurrentValue) {
|
if (AlignPackStack.CurrentValue) {
|
||||||
Action = Sema::PSK_Reset;
|
Action = Sema::PSK_Reset;
|
||||||
} else {
|
} else {
|
||||||
Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
|
Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
|
||||||
|
@ -250,7 +251,7 @@ void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
PackStack.Act(PragmaLoc, Action, StringRef(), Alignment);
|
AlignPackStack.Act(PragmaLoc, Action, StringRef(), Alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action,
|
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action,
|
||||||
|
@ -317,7 +318,7 @@ void Sema::ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
|
||||||
// Show the current alignment, making sure to show the right value
|
// Show the current alignment, making sure to show the right value
|
||||||
// for the default.
|
// for the default.
|
||||||
// FIXME: This should come from the target.
|
// FIXME: This should come from the target.
|
||||||
AlignmentVal = PackStack.CurrentValue;
|
AlignmentVal = AlignPackStack.CurrentValue;
|
||||||
if (AlignmentVal == 0)
|
if (AlignmentVal == 0)
|
||||||
AlignmentVal = 8;
|
AlignmentVal = 8;
|
||||||
if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
|
if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
|
||||||
|
@ -330,61 +331,72 @@ void Sema::ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
|
||||||
if (Action & Sema::PSK_Pop) {
|
if (Action & Sema::PSK_Pop) {
|
||||||
if (Alignment && !SlotLabel.empty())
|
if (Alignment && !SlotLabel.empty())
|
||||||
Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
|
Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
|
||||||
if (PackStack.Stack.empty())
|
if (AlignPackStack.Stack.empty())
|
||||||
Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
|
Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
|
||||||
}
|
}
|
||||||
|
|
||||||
PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
|
AlignPackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind,
|
void Sema::DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
|
||||||
SourceLocation IncludeLoc) {
|
SourceLocation IncludeLoc) {
|
||||||
if (Kind == PragmaPackDiagnoseKind::NonDefaultStateAtInclude) {
|
if (Kind == PragmaAlignPackDiagnoseKind::NonDefaultStateAtInclude) {
|
||||||
SourceLocation PrevLocation = PackStack.CurrentPragmaLocation;
|
SourceLocation PrevLocation = AlignPackStack.CurrentPragmaLocation;
|
||||||
// Warn about non-default alignment at #includes (without redundant
|
// Warn about non-default alignment at #includes (without redundant
|
||||||
// warnings for the same directive in nested includes).
|
// warnings for the same directive in nested includes).
|
||||||
// The warning is delayed until the end of the file to avoid warnings
|
// The warning is delayed until the end of the file to avoid warnings
|
||||||
// for files that don't have any records that are affected by the modified
|
// for files that don't have any records that are affected by the modified
|
||||||
// alignment.
|
// alignment.
|
||||||
bool HasNonDefaultValue =
|
bool HasNonDefaultValue =
|
||||||
PackStack.hasValue() &&
|
AlignPackStack.hasValue() &&
|
||||||
(PackIncludeStack.empty() ||
|
(AlignPackIncludeStack.empty() ||
|
||||||
PackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
|
AlignPackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
|
||||||
PackIncludeStack.push_back(
|
AlignPackIncludeStack.push_back(
|
||||||
{PackStack.CurrentValue,
|
{AlignPackStack.CurrentValue,
|
||||||
PackStack.hasValue() ? PrevLocation : SourceLocation(),
|
AlignPackStack.hasValue() ? PrevLocation : SourceLocation(),
|
||||||
HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
|
HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(Kind == PragmaPackDiagnoseKind::ChangedStateAtExit && "invalid kind");
|
assert(Kind == PragmaAlignPackDiagnoseKind::ChangedStateAtExit &&
|
||||||
PackIncludeState PrevPackState = PackIncludeStack.pop_back_val();
|
"invalid kind");
|
||||||
if (PrevPackState.ShouldWarnOnInclude) {
|
AlignPackIncludeState PrevAlignPackState =
|
||||||
|
AlignPackIncludeStack.pop_back_val();
|
||||||
|
// FIXME: AlignPackStack may contain both #pragma align and #pragma pack
|
||||||
|
// information, diagnostics below might not be accurate if we have mixed
|
||||||
|
// pragmas.
|
||||||
|
if (PrevAlignPackState.ShouldWarnOnInclude) {
|
||||||
// Emit the delayed non-default alignment at #include warning.
|
// Emit the delayed non-default alignment at #include warning.
|
||||||
Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
|
Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
|
||||||
Diag(PrevPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
|
Diag(PrevAlignPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
|
||||||
}
|
}
|
||||||
// Warn about modified alignment after #includes.
|
// Warn about modified alignment after #includes.
|
||||||
if (PrevPackState.CurrentValue != PackStack.CurrentValue) {
|
if (PrevAlignPackState.CurrentValue != AlignPackStack.CurrentValue) {
|
||||||
Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
|
Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
|
||||||
Diag(PackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
|
Diag(AlignPackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::DiagnoseUnterminatedPragmaPack() {
|
void Sema::DiagnoseUnterminatedPragmaAlignPack() {
|
||||||
if (PackStack.Stack.empty())
|
if (AlignPackStack.Stack.empty())
|
||||||
return;
|
return;
|
||||||
bool IsInnermost = true;
|
bool IsInnermost = true;
|
||||||
for (const auto &StackSlot : llvm::reverse(PackStack.Stack)) {
|
|
||||||
|
// FIXME: AlignPackStack may contain both #pragma align and #pragma pack
|
||||||
|
// information, diagnostics below might not be accurate if we have mixed
|
||||||
|
// pragmas.
|
||||||
|
for (const auto &StackSlot : llvm::reverse(AlignPackStack.Stack)) {
|
||||||
Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
|
Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
|
||||||
// The user might have already reset the alignment, so suggest replacing
|
// The user might have already reset the alignment, so suggest replacing
|
||||||
// the reset with a pop.
|
// the reset with a pop.
|
||||||
if (IsInnermost && PackStack.CurrentValue == PackStack.DefaultValue) {
|
if (IsInnermost &&
|
||||||
auto DB = Diag(PackStack.CurrentPragmaLocation,
|
AlignPackStack.CurrentValue == AlignPackStack.DefaultValue) {
|
||||||
|
auto DB = Diag(AlignPackStack.CurrentPragmaLocation,
|
||||||
diag::note_pragma_pack_pop_instead_reset);
|
diag::note_pragma_pack_pop_instead_reset);
|
||||||
SourceLocation FixItLoc = Lexer::findLocationAfterToken(
|
SourceLocation FixItLoc =
|
||||||
PackStack.CurrentPragmaLocation, tok::l_paren, SourceMgr, LangOpts,
|
Lexer::findLocationAfterToken(AlignPackStack.CurrentPragmaLocation,
|
||||||
/*SkipTrailing=*/false);
|
tok::l_paren, SourceMgr, LangOpts,
|
||||||
|
/*SkipTrailing=*/false);
|
||||||
if (FixItLoc.isValid())
|
if (FixItLoc.isValid())
|
||||||
DB << FixItHint::CreateInsertion(FixItLoc, "pop");
|
DB << FixItHint::CreateInsertion(FixItLoc, "pop");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3742,25 +3742,25 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
|
||||||
ForceCUDAHostDeviceDepth = Record[0];
|
ForceCUDAHostDeviceDepth = Record[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PACK_PRAGMA_OPTIONS: {
|
case ALIGN_PACK_PRAGMA_OPTIONS: {
|
||||||
if (Record.size() < 3) {
|
if (Record.size() < 3) {
|
||||||
Error("invalid pragma pack record");
|
Error("invalid pragma pack record");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
PragmaPackCurrentValue = Record[0];
|
PragmaAlignPackCurrentValue = Record[0];
|
||||||
PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]);
|
PragmaAlignPackCurrentLocation = ReadSourceLocation(F, Record[1]);
|
||||||
unsigned NumStackEntries = Record[2];
|
unsigned NumStackEntries = Record[2];
|
||||||
unsigned Idx = 3;
|
unsigned Idx = 3;
|
||||||
// Reset the stack when importing a new module.
|
// Reset the stack when importing a new module.
|
||||||
PragmaPackStack.clear();
|
PragmaAlignPackStack.clear();
|
||||||
for (unsigned I = 0; I < NumStackEntries; ++I) {
|
for (unsigned I = 0; I < NumStackEntries; ++I) {
|
||||||
PragmaPackStackEntry Entry;
|
PragmaAlignPackStackEntry Entry;
|
||||||
Entry.Value = Record[Idx++];
|
Entry.Value = Record[Idx++];
|
||||||
Entry.Location = ReadSourceLocation(F, Record[Idx++]);
|
Entry.Location = ReadSourceLocation(F, Record[Idx++]);
|
||||||
Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
|
Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
|
||||||
PragmaPackStrings.push_back(ReadString(Record, Idx));
|
PragmaAlignPackStrings.push_back(ReadString(Record, Idx));
|
||||||
Entry.SlotLabel = PragmaPackStrings.back();
|
Entry.SlotLabel = PragmaAlignPackStrings.back();
|
||||||
PragmaPackStack.push_back(Entry);
|
PragmaAlignPackStack.push_back(Entry);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -7875,32 +7875,36 @@ void ASTReader::UpdateSema() {
|
||||||
}
|
}
|
||||||
SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth;
|
SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth;
|
||||||
|
|
||||||
if (PragmaPackCurrentValue) {
|
if (PragmaAlignPackCurrentValue) {
|
||||||
// The bottom of the stack might have a default value. It must be adjusted
|
// The bottom of the stack might have a default value. It must be adjusted
|
||||||
// to the current value to ensure that the packing state is preserved after
|
// to the current value to ensure that the packing state is preserved after
|
||||||
// popping entries that were included/imported from a PCH/module.
|
// popping entries that were included/imported from a PCH/module.
|
||||||
bool DropFirst = false;
|
bool DropFirst = false;
|
||||||
if (!PragmaPackStack.empty() &&
|
if (!PragmaAlignPackStack.empty() &&
|
||||||
PragmaPackStack.front().Location.isInvalid()) {
|
PragmaAlignPackStack.front().Location.isInvalid()) {
|
||||||
assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue &&
|
assert(PragmaAlignPackStack.front().Value ==
|
||||||
|
SemaObj->AlignPackStack.DefaultValue &&
|
||||||
"Expected a default alignment value");
|
"Expected a default alignment value");
|
||||||
SemaObj->PackStack.Stack.emplace_back(
|
SemaObj->AlignPackStack.Stack.emplace_back(
|
||||||
PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue,
|
PragmaAlignPackStack.front().SlotLabel,
|
||||||
SemaObj->PackStack.CurrentPragmaLocation,
|
SemaObj->AlignPackStack.CurrentValue,
|
||||||
PragmaPackStack.front().PushLocation);
|
SemaObj->AlignPackStack.CurrentPragmaLocation,
|
||||||
|
PragmaAlignPackStack.front().PushLocation);
|
||||||
DropFirst = true;
|
DropFirst = true;
|
||||||
}
|
}
|
||||||
for (const auto &Entry :
|
for (const auto &Entry :
|
||||||
llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0))
|
llvm::makeArrayRef(PragmaAlignPackStack).drop_front(DropFirst ? 1 : 0))
|
||||||
SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value,
|
SemaObj->AlignPackStack.Stack.emplace_back(
|
||||||
Entry.Location, Entry.PushLocation);
|
Entry.SlotLabel, Entry.Value, Entry.Location, Entry.PushLocation);
|
||||||
if (PragmaPackCurrentLocation.isInvalid()) {
|
if (PragmaAlignPackCurrentLocation.isInvalid()) {
|
||||||
assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue &&
|
assert(*PragmaAlignPackCurrentValue ==
|
||||||
|
SemaObj->AlignPackStack.DefaultValue &&
|
||||||
"Expected a default alignment value");
|
"Expected a default alignment value");
|
||||||
// Keep the current values.
|
// Keep the current values.
|
||||||
} else {
|
} else {
|
||||||
SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue;
|
SemaObj->AlignPackStack.CurrentValue = *PragmaAlignPackCurrentValue;
|
||||||
SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation;
|
SemaObj->AlignPackStack.CurrentPragmaLocation =
|
||||||
|
PragmaAlignPackCurrentLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (FpPragmaCurrentValue) {
|
if (FpPragmaCurrentValue) {
|
||||||
|
|
|
@ -4151,24 +4151,24 @@ void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) {
|
||||||
Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record);
|
Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write the state of 'pragma pack' at the end of the module.
|
/// Write the state of 'pragma align/pack' at the end of the module.
|
||||||
void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) {
|
void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) {
|
||||||
// Don't serialize pragma pack state for modules, since it should only take
|
// Don't serialize pragma align/pack state for modules, since it should only
|
||||||
// effect on a per-submodule basis.
|
// take effect on a per-submodule basis.
|
||||||
if (WritingModule)
|
if (WritingModule)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RecordData Record;
|
RecordData Record;
|
||||||
Record.push_back(SemaRef.PackStack.CurrentValue);
|
Record.push_back(SemaRef.AlignPackStack.CurrentValue);
|
||||||
AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record);
|
AddSourceLocation(SemaRef.AlignPackStack.CurrentPragmaLocation, Record);
|
||||||
Record.push_back(SemaRef.PackStack.Stack.size());
|
Record.push_back(SemaRef.AlignPackStack.Stack.size());
|
||||||
for (const auto &StackEntry : SemaRef.PackStack.Stack) {
|
for (const auto &StackEntry : SemaRef.AlignPackStack.Stack) {
|
||||||
Record.push_back(StackEntry.Value);
|
Record.push_back(StackEntry.Value);
|
||||||
AddSourceLocation(StackEntry.PragmaLocation, Record);
|
AddSourceLocation(StackEntry.PragmaLocation, Record);
|
||||||
AddSourceLocation(StackEntry.PragmaPushLocation, Record);
|
AddSourceLocation(StackEntry.PragmaPushLocation, Record);
|
||||||
AddString(StackEntry.StackSlotLabel, Record);
|
AddString(StackEntry.StackSlotLabel, Record);
|
||||||
}
|
}
|
||||||
Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record);
|
Stream.EmitRecord(ALIGN_PACK_PRAGMA_OPTIONS, Record);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write the state of 'pragma float_control' at the end of the module.
|
/// Write the state of 'pragma float_control' at the end of the module.
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifdef ALIGN_SET_HERE
|
||||||
|
#pragma align = mac68k
|
||||||
|
// expected-note@-1 {{previous '#pragma pack' directive that modifies alignment is here}}
|
||||||
|
// expected-warning@-2 {{unterminated '#pragma pack (push, ...)' at end of file}}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RECORD_ALIGN
|
||||||
|
struct S {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -0,0 +1,19 @@
|
||||||
|
// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack-suspicious-include -I %S/Inputs -DALIGN_SET_HERE -verify %s
|
||||||
|
// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -Wpragma-pack-suspicious-include -I %S/Inputs -DRECORD_ALIGN -verify %s
|
||||||
|
|
||||||
|
#ifdef ALIGN_SET_HERE
|
||||||
|
#pragma align = natural // expected-warning {{unterminated '#pragma pack (push, ...)' at end of file}}
|
||||||
|
// expected-warning@+9 {{the current #pragma pack alignment value is modified in the included file}}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RECORD_ALIGN
|
||||||
|
#pragma align = mac68k
|
||||||
|
// expected-note@-1 {{previous '#pragma pack' directive that modifies alignment is here}}
|
||||||
|
// expected-warning@+3 {{non-default #pragma pack value changes the alignment of struct or union members in the included file}}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pragma-align-pack1.h"
|
||||||
|
|
||||||
|
#ifdef RECORD_ALIGN
|
||||||
|
#pragma align = reset
|
||||||
|
#endif
|
Loading…
Reference in New Issue