[cfe-commits] r64828 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/AST/ExprConstant.cpp test/CodeGen/alignof.c
Daniel Dunbar
daniel at zuster.org
Tue Feb 17 14:16:19 PST 2009
Author: ddunbar
Date: Tue Feb 17 16:16:19 2009
New Revision: 64828
URL: http://llvm.org/viewvc/llvm-project?rev=64828&view=rev
Log:
Eek! getDeclAlign sometimes returned alignment in bits.
- Renamed to getDeclAlignInBytes since most other query functions
work in bits.
- Fun to track down as isIntegerConstantExpr was getting it right,
but Evaluate() was getting it wrong. Maybe we should assert they
compute the same thing when they succeed?
Added:
cfe/trunk/test/CodeGen/alignof.c
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=64828&r1=64827&r2=64828&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Feb 17 16:16:19 2009
@@ -434,10 +434,10 @@
/// a data type.
unsigned getPreferredTypeAlign(const Type *T);
- /// getDeclAlign - Return the alignment of the specified decl that should be
- /// returned by __alignof(). Note that bitfields do not have a valid
- /// alignment, so this method will assert on them.
- unsigned getDeclAlign(const Decl *D);
+ /// getDeclAlignInBytes - Return the alignment of the specified decl
+ /// that should be returned by __alignof(). Note that bitfields do
+ /// not have a valid alignment, so this method will assert on them.
+ unsigned getDeclAlignInBytes(const Decl *D);
/// getASTRecordLayout - Get or compute information about the layout of the
/// specified record (struct/union/class), which indicates its size and field
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=64828&r1=64827&r2=64828&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Feb 17 16:16:19 2009
@@ -263,7 +263,7 @@
/// getDeclAlign - Return a conservative estimate of the alignment of the
/// specified decl. Note that bitfields do not have a valid alignment, so
/// this method will assert on them.
-unsigned ASTContext::getDeclAlign(const Decl *D) {
+unsigned ASTContext::getDeclAlignInBytes(const Decl *D) {
// FIXME: If attribute(align) is specified on the decl, round up to it.
if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
@@ -275,7 +275,7 @@
while (isa<VariableArrayType>(T) || isa<IncompleteArrayType>(T))
T = cast<ArrayType>(T)->getElementType();
- return getTypeAlign(T);
+ return getTypeAlign(T) / Target.getCharWidth();
}
return 1;
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=64828&r1=64827&r2=64828&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Feb 17 16:16:19 2009
@@ -981,10 +981,10 @@
// alignof decl is always accepted, even if it doesn't make sense: we default
// to 1 in those cases.
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
- return Info.Ctx.getDeclAlign(DRE->getDecl());
+ return Info.Ctx.getDeclAlignInBytes(DRE->getDecl());
if (const MemberExpr *ME = dyn_cast<MemberExpr>(E))
- return Info.Ctx.getDeclAlign(ME->getMemberDecl());
+ return Info.Ctx.getDeclAlignInBytes(ME->getMemberDecl());
return GetAlignOfType(E->getType());
}
Added: cfe/trunk/test/CodeGen/alignof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alignof.c?rev=64828&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/alignof.c (added)
+++ cfe/trunk/test/CodeGen/alignof.c Tue Feb 17 16:16:19 2009
@@ -0,0 +1,12 @@
+// RUN: clang -triple i386-unknown-unknown -O1 -emit-llvm -o %t %s &&
+// RUN: grep 'ret i32 4' %t
+
+enum e0 { E0 };
+struct s0 {
+ enum e0 a:31;
+};
+
+struct s0 t1_tmp;
+int f0() {
+ return __alignof__(t1_tmp);
+}
More information about the cfe-commits
mailing list