diff options
author | James Y Knight <jyknight@google.com> | 2015-07-17 18:21:37 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2015-07-17 18:21:37 +0000 |
commit | 53c7616e2e6aa3bcef0123c1890f8fdeb0e760ab (patch) | |
tree | 7e9e1de25a2500e592ba668b4405ce2a07ba1378 /clang/lib/AST/Expr.cpp | |
parent | 5a6d5bc17b385293e3337b9f2082151594f972f9 (diff) | |
download | bcm5719-llvm-53c7616e2e6aa3bcef0123c1890f8fdeb0e760ab.tar.gz bcm5719-llvm-53c7616e2e6aa3bcef0123c1890f8fdeb0e760ab.zip |
Fix alignment issues in Clang.
Some const-correctness changes snuck in here too, since they were in the
area of code I was modifying.
This seems to make Clang actually work without Bus Error on
32bit-sparc.
Follow-up patches will factor out a trailing-object helper class, to
make classes using the idiom of appending objects to other objects
easier to understand, and to ensure (with static_assert) that required
alignment guarantees continue to hold.
Differential Revision: http://reviews.llvm.org/D10272
llvm-svn: 242554
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r-- | clang/lib/AST/Expr.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 2e066b2c42c..6c048f96d45 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -399,10 +399,15 @@ DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, Size += sizeof(NestedNameSpecifierLoc); if (FoundD) Size += sizeof(NamedDecl *); - if (TemplateArgs) + if (TemplateArgs) { + Size = llvm::RoundUpToAlignment(Size, + llvm::alignOf<ASTTemplateKWAndArgsInfo>()); Size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); - else if (TemplateKWLoc.isValid()) + } else if (TemplateKWLoc.isValid()) { + Size = llvm::RoundUpToAlignment(Size, + llvm::alignOf<ASTTemplateKWAndArgsInfo>()); Size += ASTTemplateKWAndArgsInfo::sizeFor(0); + } void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, @@ -420,8 +425,11 @@ DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext &Context, Size += sizeof(NestedNameSpecifierLoc); if (HasFoundDecl) Size += sizeof(NamedDecl *); - if (HasTemplateKWAndArgsInfo) + if (HasTemplateKWAndArgsInfo) { + Size = llvm::RoundUpToAlignment(Size, + llvm::alignOf<ASTTemplateKWAndArgsInfo>()); Size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); + } void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); return new (Mem) DeclRefExpr(EmptyShell()); @@ -3939,7 +3947,8 @@ DesignatedInitExpr::Create(const ASTContext &C, Designator *Designators, SourceLocation ColonOrEqualLoc, bool UsesColonSyntax, Expr *Init) { void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + - sizeof(Stmt *) * (IndexExprs.size() + 1), 8); + sizeof(Stmt *) * (IndexExprs.size() + 1), + llvm::alignOf<DesignatedInitExpr>()); return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, ColonOrEqualLoc, UsesColonSyntax, IndexExprs, Init); |