diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-02-14 01:52:20 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-02-14 01:52:20 +0000 |
commit | 902a0238aa1514832a0d88661c9d7ccf112b71e0 (patch) | |
tree | b8f1416976d83e831505038bf401ff6881b1dcf2 /clang/test | |
parent | ce27e42d47bbc136cf1deb1859e10e9e8da5b501 (diff) | |
download | bcm5719-llvm-902a0238aa1514832a0d88661c9d7ccf112b71e0.tar.gz bcm5719-llvm-902a0238aa1514832a0d88661c9d7ccf112b71e0.zip |
DR1748: the reserved placement allocation functions have undefined behavior if
they're given a null pointer as an argument, so we do not need to emit null
checks on their results.
llvm-svn: 229213
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGenCXX/debug-info-line.cpp | 3 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/new.cpp | 49 |
2 files changed, 41 insertions, 11 deletions
diff --git a/clang/test/CodeGenCXX/debug-info-line.cpp b/clang/test/CodeGenCXX/debug-info-line.cpp index 923f183d543..98b99d55b3c 100644 --- a/clang/test/CodeGenCXX/debug-info-line.cpp +++ b/clang/test/CodeGenCXX/debug-info-line.cpp @@ -113,7 +113,7 @@ inline void *operator new(decltype(sizeof(1)), void *p) noexcept { return p; } // CHECK-LABEL: define void f10() { void *void_src(); - ( // CHECK: icmp {{.*}} !dbg [[DBG_F10_ICMP:.*]] + ( // CHECK: store {{.*}} !dbg [[DBG_F10_STORE:!.*]] #line 1100 new (void_src()) int(src())); @@ -305,7 +305,6 @@ void f24() { // CHECK: [[DBG_F7]] = !MDLocation(line: 800, // CHECK: [[DBG_F8]] = !MDLocation(line: 900, // CHECK: [[DBG_F9]] = !MDLocation(line: 1000, -// CHECK: [[DBG_F10_ICMP]] = !MDLocation(line: 1100, // CHECK: [[DBG_F10_STORE]] = !MDLocation(line: 1100, // CHECK: [[DBG_GLBL_CTOR_B]] = !MDLocation(line: 1200, // CHECK: [[DBG_GLBL_DTOR_B]] = !MDLocation(line: 1200, diff --git a/clang/test/CodeGenCXX/new.cpp b/clang/test/CodeGenCXX/new.cpp index 862161b1938..5138c1bdb56 100644 --- a/clang/test/CodeGenCXX/new.cpp +++ b/clang/test/CodeGenCXX/new.cpp @@ -36,6 +36,10 @@ void *operator new[](size_t, const std::nothrow_t &) throw(); void operator delete(void *, const std::nothrow_t &) throw(); void operator delete[](void *, const std::nothrow_t &) throw(); +// Declare some other placemenet operators. +void *operator new(size_t, void*, bool) throw(); +void *operator new[](size_t, void*, bool) throw(); + void t2(int* a) { int* b = new (a) int; } @@ -191,20 +195,31 @@ void f() { namespace test15 { struct A { A(); ~A(); }; - // CHECK-LABEL: define void @_ZN6test155test0EPv( + // CHECK-LABEL: define void @_ZN6test156test0aEPv( // CHECK: [[P:%.*]] = load i8* - // CHECK-NEXT: icmp eq i8* [[P]], null - // CHECK-NEXT: br i1 + // CHECK-NOT: icmp eq i8* [[P]], null + // CHECK-NOT: br i1 // CHECK: [[T0:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[T0]]) - void test0(void *p) { + void test0a(void *p) { new (p) A(); } - // CHECK-LABEL: define void @_ZN6test155test1EPv( - // CHECK: [[P:%.*]] = load i8** + // CHECK-LABEL: define void @_ZN6test156test0bEPv( + // CHECK: [[P0:%.*]] = load i8* + // CHECK: [[P:%.*]] = call i8* @_ZnwmPvb(i64 1, i8* [[P0]] // CHECK-NEXT: icmp eq i8* [[P]], null // CHECK-NEXT: br i1 + // CHECK: [[T0:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* + // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[T0]]) + void test0b(void *p) { + new (p, true) A(); + } + + // CHECK-LABEL: define void @_ZN6test156test1aEPv( + // CHECK: [[P:%.*]] = load i8** + // CHECK-NOT: icmp eq i8* [[P]], null + // CHECK-NOT: br i1 // CHECK: [[BEGIN:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 5 // CHECK-NEXT: br label @@ -213,10 +228,28 @@ namespace test15 { // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]]* [[CUR]], i64 1 // CHECK-NEXT: [[DONE:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]] // CHECK-NEXT: br i1 [[DONE]] - void test1(void *p) { + void test1a(void *p) { new (p) A[5]; } + // CHECK-LABEL: define void @_ZN6test156test1bEPv( + // CHECK: [[P0:%.*]] = load i8** + // CHECK: [[P:%.*]] = call i8* @_ZnamPvb(i64 13, i8* [[P0]] + // CHECK-NEXT: icmp eq i8* [[P]], null + // CHECK-NEXT: br i1 + // CHECK: [[AFTER_COOKIE:%.*]] = getelementptr inbounds i8* [[P]], i64 8 + // CHECK: [[BEGIN:%.*]] = bitcast i8* [[AFTER_COOKIE]] to [[A:%.*]]* + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 5 + // CHECK-NEXT: br label + // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: call void @_ZN6test151AC1Ev([[A]]* [[CUR]]) + // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]]* [[CUR]], i64 1 + // CHECK-NEXT: [[DONE:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]] + // CHECK-NEXT: br i1 [[DONE]] + void test1b(void *p) { + new (p, true) A[5]; + } + // TODO: it's okay if all these size calculations get dropped. // FIXME: maybe we should try to throw on overflow? // CHECK-LABEL: define void @_ZN6test155test2EPvi( @@ -225,8 +258,6 @@ namespace test15 { // CHECK-NEXT: [[T1:%.*]] = icmp slt i64 [[T0]], 0 // CHECK-NEXT: [[T2:%.*]] = select i1 [[T1]], i64 -1, i64 [[T0]] // CHECK-NEXT: [[P:%.*]] = load i8* - // CHECK-NEXT: icmp eq i8* [[P]], null - // CHECK-NEXT: br i1 // CHECK: [[BEGIN:%.*]] = bitcast i8* [[P]] to [[A:%.*]]* // CHECK-NEXT: [[ISEMPTY:%.*]] = icmp eq i64 [[T0]], 0 // CHECK-NEXT: br i1 [[ISEMPTY]], |