[cfe-commits] r149760 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/Inputs/warn-new-overaligned-3.h test/SemaCXX/warn-new-overaligned-3.cpp

Nick Lewycky nicholas at mxc.ca
Fri Feb 3 19:30:14 PST 2012


Author: nicholas
Date: Fri Feb  3 21:30:14 2012
New Revision: 149760

URL: http://llvm.org/viewvc/llvm-project?rev=149760&view=rev
Log:
Don't warn on use of default allocator with an over-aligned type when the
allocator is given the pointer to allocate into.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/Inputs/warn-new-overaligned-3.h
    cfe/trunk/test/SemaCXX/warn-new-overaligned-3.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=149760&r1=149759&r2=149760&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Feb  3 21:30:14 2012
@@ -1105,7 +1105,7 @@
 
   // 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())){

Modified: cfe/trunk/test/SemaCXX/Inputs/warn-new-overaligned-3.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/Inputs/warn-new-overaligned-3.h?rev=149760&r1=149759&r2=149760&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/Inputs/warn-new-overaligned-3.h (original)
+++ cfe/trunk/test/SemaCXX/Inputs/warn-new-overaligned-3.h Fri Feb  3 21:30:14 2012
@@ -10,3 +10,10 @@
   return 0;
 }
 
+void* operator new(unsigned long, void *) {
+  return 0;
+}
+
+void* operator new[](unsigned long, void *) {
+  return 0;
+}

Modified: cfe/trunk/test/SemaCXX/warn-new-overaligned-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-new-overaligned-3.cpp?rev=149760&r1=149759&r2=149760&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-new-overaligned-3.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-new-overaligned-3.cpp Fri Feb  3 21:30:14 2012
@@ -4,6 +4,7 @@
 // where the header here simulates <new>.
 #include <warn-new-overaligned-3.h>
 
+namespace test1 {
 struct Test {
   template <typename T>
   struct SeparateCacheLines {
@@ -15,6 +16,18 @@
 
 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;
+};
 }





More information about the cfe-commits mailing list