summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-07-26 21:29:24 +0000
committerHans Wennborg <hans@hanshq.net>2017-07-26 21:29:24 +0000
commitb4ece98a3493c67f5a4959c0c7143b82fad13906 (patch)
treeefbf7ab7a8fdeda9fd698ece6b9159d8afbb36ce /clang/lib
parent3197eb69812f9ff1c0ef4b2a7b894397dec3de24 (diff)
downloadbcm5719-llvm-b4ece98a3493c67f5a4959c0c7143b82fad13906.tar.gz
bcm5719-llvm-b4ece98a3493c67f5a4959c0c7143b82fad13906.zip
Revert r309106 "Recommit r308327 2nd time: Add a warning for missing"
The warning fires on non-suspicious code in Chromium. Reverting until a solution is figured out. > Recommit r308327 2nd time: Add a warning for missing > '#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files > > The first recommit (r308441) caused a "non-default #pragma pack value might > change the alignment of struct or union members in the included file" warning > in LLVM itself. This recommit tweaks the added warning to avoid warnings for > #includes that don't have any records that are affected by the non-default > alignment. This tweak avoids the previously emitted warning in LLVM. > > Original message: > > This commit adds a new -Wpragma-pack warning. It warns in the following cases: > > - When a translation unit is missing terminating #pragma pack (pop) directives. > - When entering an included file if the current alignment value as determined > by '#pragma pack' directives is different from the default alignment value. > - When leaving an included file that changed the state of the current alignment > value. > > rdar://10184173 > > Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 309186
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Parse/ParsePragma.cpp9
-rw-r--r--clang/lib/Sema/Sema.cpp54
-rw-r--r--clang/lib/Sema/SemaAttr.cpp55
-rw-r--r--clang/lib/Serialization/ASTReader.cpp6
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp1
5 files changed, 5 insertions, 120 deletions
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index c5215ffceeb..262743756a6 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -422,20 +422,15 @@ void Parser::HandlePragmaPack() {
assert(Tok.is(tok::annot_pragma_pack));
PragmaPackInfo *Info =
static_cast<PragmaPackInfo *>(Tok.getAnnotationValue());
- SourceLocation PragmaLoc = Tok.getLocation();
+ SourceLocation PragmaLoc = ConsumeAnnotationToken();
ExprResult Alignment;
if (Info->Alignment.is(tok::numeric_constant)) {
Alignment = Actions.ActOnNumericConstant(Info->Alignment);
- if (Alignment.isInvalid()) {
- ConsumeAnnotationToken();
+ if (Alignment.isInvalid())
return;
- }
}
Actions.ActOnPragmaPack(PragmaLoc, Info->Action, Info->SlotLabel,
Alignment.get());
- // Consume the token after processing the pragma to enable pragma-specific
- // #include warnings.
- ConsumeAnnotationToken();
}
void Parser::HandlePragmaMSStruct() {
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 40ffa09de1a..6f0db6ce1c6 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -70,49 +70,6 @@ void Sema::ActOnTranslationUnitScope(Scope *S) {
PushDeclContext(S, Context.getTranslationUnitDecl());
}
-namespace clang {
-namespace sema {
-
-class SemaPPCallbacks : public PPCallbacks {
- Sema *S = nullptr;
- llvm::SmallVector<SourceLocation, 8> IncludeStack;
-
-public:
- void set(Sema &S) { this->S = &S; }
-
- void reset() { S = nullptr; }
-
- virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
- SrcMgr::CharacteristicKind FileType,
- FileID PrevFID) override {
- if (!S)
- return;
- switch (Reason) {
- case EnterFile: {
- SourceManager &SM = S->getSourceManager();
- SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(Loc));
- if (IncludeLoc.isValid()) {
- IncludeStack.push_back(IncludeLoc);
- S->DiagnoseNonDefaultPragmaPack(
- Sema::PragmaPackDiagnoseKind::NonDefaultStateAtInclude, IncludeLoc);
- }
- break;
- }
- case ExitFile:
- if (!IncludeStack.empty())
- S->DiagnoseNonDefaultPragmaPack(
- Sema::PragmaPackDiagnoseKind::ChangedStateAtExit,
- IncludeStack.pop_back_val());
- break;
- default:
- break;
- }
- }
-};
-
-} // end namespace sema
-} // end namespace clang
-
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter)
: ExternalSource(nullptr), isMultiplexExternalSource(false),
@@ -165,12 +122,6 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
// Initilization of data sharing attributes stack for OpenMP
InitDataSharingAttributesStack();
-
- std::unique_ptr<sema::SemaPPCallbacks> Callbacks =
- llvm::make_unique<sema::SemaPPCallbacks>();
- SemaPPCallbackHandler = Callbacks.get();
- PP.addPPCallbacks(std::move(Callbacks));
- SemaPPCallbackHandler->set(*this);
}
void Sema::addImplicitTypedef(StringRef Name, QualType T) {
@@ -355,10 +306,6 @@ Sema::~Sema() {
// Destroys data sharing attributes stack for OpenMP
DestroyDataSharingAttributesStack();
- // Detach from the PP callback handler which outlives Sema since it's owned
- // by the preprocessor.
- SemaPPCallbackHandler->reset();
-
assert(DelayedTypos.empty() && "Uncorrected typos!");
}
@@ -819,7 +766,6 @@ void Sema::ActOnEndOfTranslationUnit() {
CheckDelayedMemberExceptionSpecs();
}
- DiagnoseUnterminatedPragmaPack();
DiagnoseUnterminatedPragmaAttribute();
// All delayed member exception specs should be checked or we end up accepting
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index f7f1f618739..8c13ead6445 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -61,17 +61,6 @@ void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
Alignment * 8));
}
- if (PackIncludeStack.empty())
- return;
- // The #pragma pack affected a record in an included file, so Clang should
- // warn when that pragma was written in a file that included the included
- // file.
- for (auto &PackedInclude : llvm::reverse(PackIncludeStack)) {
- if (PackedInclude.CurrentPragmaLocation != PackStack.CurrentPragmaLocation)
- break;
- if (PackedInclude.HasNonDefaultValue)
- PackedInclude.ShouldWarnOnInclude = true;
- }
}
void Sema::AddMsStructLayoutForRecord(RecordDecl *RD) {
@@ -213,47 +202,6 @@ void Sema::ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
}
-void Sema::DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind,
- SourceLocation IncludeLoc) {
- if (Kind == PragmaPackDiagnoseKind::NonDefaultStateAtInclude) {
- SourceLocation PrevLocation = PackStack.CurrentPragmaLocation;
- // Warn about non-default alignment at #includes (without redundant
- // warnings for the same directive in nested includes).
- // 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
- // alignment.
- bool HasNonDefaultValue =
- PackStack.hasValue() &&
- (PackIncludeStack.empty() ||
- PackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
- PackIncludeStack.push_back(
- {PackStack.CurrentValue,
- PackStack.hasValue() ? PrevLocation : SourceLocation(),
- HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
- return;
- }
-
- assert(Kind == PragmaPackDiagnoseKind::ChangedStateAtExit && "invalid kind");
- PackIncludeState PrevPackState = PackIncludeStack.pop_back_val();
- if (PrevPackState.ShouldWarnOnInclude) {
- // Emit the delayed non-default alignment at #include warning.
- Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
- Diag(PrevPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
- }
- // Warn about modified alignment after #includes.
- if (PrevPackState.CurrentValue != PackStack.CurrentValue) {
- Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
- Diag(PackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
- }
-}
-
-void Sema::DiagnoseUnterminatedPragmaPack() {
- if (PackStack.Stack.empty())
- return;
- for (const auto &StackSlot : llvm::reverse(PackStack.Stack))
- Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
-}
-
void Sema::ActOnPragmaMSStruct(PragmaMSStructKind Kind) {
MSStructPragmaOn = (Kind == PMSST_ON);
}
@@ -301,8 +249,7 @@ void Sema::PragmaStack<ValueType>::Act(SourceLocation PragmaLocation,
return;
}
if (Action & PSK_Push)
- Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
- PragmaLocation);
+ Stack.push_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation));
else if (Action & PSK_Pop) {
if (!StackSlotLabel.empty()) {
// If we've got a label, try to find it and jump there.
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index eb49a90d721..cae99e8bf0a 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3382,7 +3382,6 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
PragmaPackStackEntry Entry;
Entry.Value = Record[Idx++];
Entry.Location = ReadSourceLocation(F, Record[Idx++]);
- Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]);
PragmaPackStrings.push_back(ReadString(Record, Idx));
Entry.SlotLabel = PragmaPackStrings.back();
PragmaPackStack.push_back(Entry);
@@ -7571,14 +7570,13 @@ void ASTReader::UpdateSema() {
"Expected a default alignment value");
SemaObj->PackStack.Stack.emplace_back(
PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue,
- SemaObj->PackStack.CurrentPragmaLocation,
- PragmaPackStack.front().PushLocation);
+ SemaObj->PackStack.CurrentPragmaLocation);
DropFirst = true;
}
for (const auto &Entry :
llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0))
SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value,
- Entry.Location, Entry.PushLocation);
+ Entry.Location);
if (PragmaPackCurrentLocation.isInvalid()) {
assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue &&
"Expected a default alignment value");
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 9a739579b31..a875e627bdf 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4295,7 +4295,6 @@ void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) {
for (const auto &StackEntry : SemaRef.PackStack.Stack) {
Record.push_back(StackEntry.Value);
AddSourceLocation(StackEntry.PragmaLocation, Record);
- AddSourceLocation(StackEntry.PragmaPushLocation, Record);
AddString(StackEntry.StackSlotLabel, Record);
}
Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record);
OpenPOWER on IntegriCloud