summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprCXX.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-01-24 21:15:41 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-01-24 21:15:41 +0000
commit411fc65b4566e32ef2539de377648a30acf64e94 (patch)
tree074e43440ab3774200fecb5fb00440b2d2e7f8ea /clang/lib/Sema/SemaExprCXX.cpp
parent0bba00dc2f4925bc32dd431f2972576b6d376a65 (diff)
downloadbcm5719-llvm-411fc65b4566e32ef2539de377648a30acf64e94.tar.gz
bcm5719-llvm-411fc65b4566e32ef2539de377648a30acf64e94.zip
Add a new warning, -Wover-aligned, which detects attempts to use the default
allocator to construct an object which declares more alignment than the default allocator actually provides. Fixes PR9527! llvm-svn: 148857
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index bea0954c6f0..919ef06957c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -20,6 +20,7 @@
#include "clang/Sema/Scope.h"
#include "clang/Sema/TemplateDeduction.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/CharUnits.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ExprCXX.h"
@@ -1104,6 +1105,21 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
PlaceArgs = &AllPlaceArgs[0];
}
+ // Warn if the type is over-aligned and is being allocated by global operator
+ // new.
+ if (OperatorNew &&
+ (OperatorNew->isImplicit() ||
+ getSourceManager().isInSystemHeader(OperatorNew->getLocStart()))) {
+ if (unsigned Align = Context.getPreferredTypeAlign(AllocType.getTypePtr())){
+ unsigned SuitableAlign = Context.getTargetInfo().getSuitableAlign();
+ if (Align > SuitableAlign)
+ Diag(StartLoc, diag::warn_overaligned_type)
+ << AllocType
+ << unsigned(Align / Context.getCharWidth())
+ << unsigned(SuitableAlign / Context.getCharWidth());
+ }
+ }
+
bool Init = ConstructorLParen.isValid();
// --- Choosing a constructor ---
CXXConstructorDecl *Constructor = 0;
OpenPOWER on IntegriCloud