From: Nick Lewycky Date: Sat, 4 Feb 2012 03:30:14 +0000 (+0000) Subject: Don't warn on use of default allocator with an over-aligned type when the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=507a8a3fbb2c43247474daa7ccb8dd0a46c32ec5;p=clang Don't warn on use of default allocator with an over-aligned type when the allocator is given the pointer to allocate into. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149760 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index d0e40ba271..793b70789a 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -1105,7 +1105,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, // Warn if the type is over-aligned and is being allocated by global operator // new. - if (OperatorNew && + if (NumPlaceArgs == 0 && OperatorNew && (OperatorNew->isImplicit() || getSourceManager().isInSystemHeader(OperatorNew->getLocStart()))) { if (unsigned Align = Context.getPreferredTypeAlign(AllocType.getTypePtr())){ diff --git a/test/SemaCXX/Inputs/warn-new-overaligned-3.h b/test/SemaCXX/Inputs/warn-new-overaligned-3.h index 024acc299f..d2bd4d5095 100644 --- a/test/SemaCXX/Inputs/warn-new-overaligned-3.h +++ b/test/SemaCXX/Inputs/warn-new-overaligned-3.h @@ -10,3 +10,10 @@ void* operator new[](unsigned long) { return 0; } +void* operator new(unsigned long, void *) { + return 0; +} + +void* operator new[](unsigned long, void *) { + return 0; +} diff --git a/test/SemaCXX/warn-new-overaligned-3.cpp b/test/SemaCXX/warn-new-overaligned-3.cpp index 783c03ec56..c9a57fb650 100644 --- a/test/SemaCXX/warn-new-overaligned-3.cpp +++ b/test/SemaCXX/warn-new-overaligned-3.cpp @@ -4,6 +4,7 @@ // where the header here simulates . #include +namespace test1 { struct Test { template struct SeparateCacheLines { @@ -15,6 +16,18 @@ struct Test { void helper() { Test t; - new Test; // expected-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}} - new Test[10]; // expected-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}} + new Test; // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}} + new Test[10]; // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}} +} +} + +namespace test2 { +struct helper { int i __attribute__((aligned(256))); }; + +struct Placement { + Placement() { + new (d) helper(); + } + helper *d; +}; }