summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-07-16 04:54:16 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-07-16 04:54:16 +0000
commit84336ba3f875fd7ffb5e5282dfce3649db681b29 (patch)
tree9affce2bd70290832f5d09c8d0f712c13b8d7a3a /clang/lib/Sema
parent37c42a3d02369635c693a225ac61e9063799ef45 (diff)
downloadbcm5719-llvm-84336ba3f875fd7ffb5e5282dfce3649db681b29.tar.gz
bcm5719-llvm-84336ba3f875fd7ffb5e5282dfce3649db681b29.zip
Sema: Fix a bug with #pragma options align=reset, reset against an empty stack
is well defined, it resets to the default alignment. llvm-svn: 108508
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaAttr.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 69f27b0ada7..540ee7a2af1 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -62,18 +62,30 @@ namespace {
/// alignment to the previous value. If \arg Name is non-zero then
/// the first such named record is popped, otherwise the top record
/// is popped. Returns true if the pop succeeded.
- bool pop(IdentifierInfo *Name);
+ bool pop(IdentifierInfo *Name, bool IsReset);
};
} // end anonymous namespace.
-bool PragmaPackStack::pop(IdentifierInfo *Name) {
- if (Stack.empty())
- return false;
-
+bool PragmaPackStack::pop(IdentifierInfo *Name, bool IsReset) {
// If name is empty just pop top.
if (!Name) {
- Alignment = Stack.back().Alignment;
- Stack.pop_back();
+ // An empty stack is a special case...
+ if (Stack.empty()) {
+ // If this isn't a reset, it is always an error.
+ if (!IsReset)
+ return false;
+
+ // Otherwise, it is an error only if some alignment has been set.
+ if (!Alignment)
+ return false;
+
+ // Otherwise, reset to the default alignment.
+ Alignment = 0;
+ } else {
+ Alignment = Stack.back().Alignment;
+ Stack.pop_back();
+ }
+
return true;
}
@@ -122,13 +134,10 @@ void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
- // Reset just pops the top of the stack.
+ // Reset just pops the top of the stack, or resets the current alignment to
+ // default.
if (Kind == Action::POAK_Reset) {
- // Do the pop.
- if (!Context->pop(0)) {
- // If a name was specified then failure indicates the name
- // wasn't found. Otherwise failure indicates the stack was
- // empty.
+ if (!Context->pop(0, /*IsReset=*/true)) {
Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
<< "stack empty";
}
@@ -232,7 +241,7 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name,
Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
// Do the pop.
- if (!Context->pop(Name)) {
+ if (!Context->pop(Name, /*IsReset=*/false)) {
// If a name was specified then failure indicates the name
// wasn't found. Otherwise failure indicates the stack was
// empty.
OpenPOWER on IntegriCloud