[cfe-commits] r108508 - in /cfe/trunk: lib/Sema/SemaAttr.cpp test/Sema/pragma-align-packed.c
Daniel Dunbar
daniel at zuster.org
Thu Jul 15 21:54:16 PDT 2010
Author: ddunbar
Date: Thu Jul 15 23:54:16 2010
New Revision: 108508
URL: http://llvm.org/viewvc/llvm-project?rev=108508&view=rev
Log:
Sema: Fix a bug with #pragma options align=reset, reset against an empty stack
is well defined, it resets to the default alignment.
Modified:
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/test/Sema/pragma-align-packed.c
Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=108508&r1=108507&r2=108508&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Thu Jul 15 23:54:16 2010
@@ -62,18 +62,30 @@
/// 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 @@
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 @@
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.
Modified: cfe/trunk/test/Sema/pragma-align-packed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-align-packed.c?rev=108508&r1=108507&r2=108508&view=diff
==============================================================================
--- cfe/trunk/test/Sema/pragma-align-packed.c (original)
+++ cfe/trunk/test/Sema/pragma-align-packed.c Thu Jul 15 23:54:16 2010
@@ -21,3 +21,10 @@
};
extern int a[sizeof(struct s2) == 5 ? 1 : -1];
#pragma options align=reset
+
+#pragma pack(1)
+struct s3_0 { unsigned char f0; unsigned int f1; };
+int t3_0[sizeof(struct s3_0) == 5 ? 1 : -1];
+#pragma options align=reset
+struct s3_1 { unsigned char f0; unsigned int f1; };
+int t3_1[sizeof(struct s3_1) == 8 ? 1 : -1];
More information about the cfe-commits
mailing list