2017-01-10 02:24:16 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -std=c++98 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
|
|
|
|
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
|
2009-12-11 08:32:37 +08:00
|
|
|
|
2015-08-01 13:31:56 +08:00
|
|
|
typedef __typeof(sizeof(0)) size_t;
|
2009-12-11 08:32:37 +08:00
|
|
|
|
2015-09-30 07:55:17 +08:00
|
|
|
// Declare the reserved global placement new.
|
|
|
|
void *operator new(size_t, void*);
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
// This just shouldn't crash.
|
|
|
|
namespace test0 {
|
|
|
|
struct allocator {
|
|
|
|
allocator();
|
|
|
|
allocator(const allocator&);
|
|
|
|
~allocator();
|
|
|
|
};
|
2009-12-11 08:32:37 +08:00
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
void f();
|
|
|
|
void g(bool b, bool c) {
|
|
|
|
if (b) {
|
|
|
|
if (!c)
|
|
|
|
throw allocator();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test1 {
|
|
|
|
struct A { A(int); A(int, int); ~A(); void *p; };
|
|
|
|
|
|
|
|
A *a() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test11aEv()
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK: [[NEW:%.*]] = call noalias nonnull i8* @_Znwm(i64 8)
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 5)
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
|
|
|
// CHECK: call void @_ZdlPv(i8* [[NEW]])
|
|
|
|
return new A(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
A *b() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test11bEv()
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK: [[NEW:%.*]] = call noalias nonnull i8* @_Znwm(i64 8)
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
|
|
|
// CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[FOO]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
|
|
|
// CHECK: call void @_ZdlPv(i8* [[NEW]])
|
|
|
|
extern int foo();
|
|
|
|
return new A(foo());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct B { B(); ~B(); operator int(); int x; };
|
|
|
|
B makeB();
|
|
|
|
|
|
|
|
A *c() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test11cEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[ACTIVE:%.*]] = alloca i1
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call noalias nonnull i8* @_Znwm(i64 8)
|
|
|
|
// CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test11BC1Ev([[B:%.*]]* [[T0:%.*]])
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[T1:%.*]] = getelementptr inbounds [[B]], [[B]]* [[T0]], i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = load i32, i32* [[T1]], align 4
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T2]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: store i1 false, i1* [[ACTIVE]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
// CHECK11-NEXT: call void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: br i1 [[ISACTIVE]]
|
|
|
|
// CHECK: call void @_ZdlPv(i8* [[NEW]])
|
|
|
|
return new A(B().x);
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:51:46 +08:00
|
|
|
// rdar://11904428
|
|
|
|
// Terminate landing pads should call __cxa_begin_catch first.
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK98: define linkonce_odr hidden void @__clang_call_terminate(i8* %0) [[NI_NR_NUW:#[0-9]+]] comdat
|
2017-01-10 02:24:16 +08:00
|
|
|
// CHECK98-NEXT: [[T0:%.*]] = call i8* @__cxa_begin_catch(i8* %0) [[NUW:#[0-9]+]]
|
|
|
|
// CHECK98-NEXT: call void @_ZSt9terminatev() [[NR_NUW:#[0-9]+]]
|
|
|
|
// CHECK98-NEXT: unreachable
|
2013-02-12 11:51:46 +08:00
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
A *d() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test11dEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[ACTIVE:%.*]] = alloca i1
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call noalias nonnull i8* @_Znwm(i64 8)
|
|
|
|
// CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test11BC1Ev([[B:%.*]]* [[T0:%.*]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T1]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: store i1 false, i1* [[ACTIVE]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
// CHECK11-NEXT: call void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: br i1 [[ISACTIVE]]
|
|
|
|
// CHECK: call void @_ZdlPv(i8* [[NEW]])
|
|
|
|
return new A(B());
|
|
|
|
}
|
|
|
|
|
|
|
|
A *e() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test11eEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[ACTIVE:%.*]] = alloca i1
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call noalias nonnull i8* @_Znwm(i64 8)
|
|
|
|
// CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test11BC1Ev([[B:%.*]]* [[T0:%.*]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: invoke void @_ZN5test11BC1Ev([[B]]* [[T2:%.*]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[T3:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T2]])
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: invoke void @_ZN5test11AC1Eii([[A]]* [[CAST]], i32 [[T1]], i32 [[T3]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: store i1 false, i1* [[ACTIVE]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN5test11BD1Ev([[B]]* [[T2]])
|
|
|
|
// CHECK11-NEXT: call void @_ZN5test11BD1Ev([[B]]* [[T2]])
|
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
// CHECK11: call void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: br i1 [[ISACTIVE]]
|
|
|
|
// CHECK: call void @_ZdlPv(i8* [[NEW]])
|
|
|
|
return new A(B(), B());
|
|
|
|
}
|
|
|
|
A *f() {
|
|
|
|
return new A(makeB().x);
|
|
|
|
}
|
|
|
|
A *g() {
|
|
|
|
return new A(makeB());
|
|
|
|
}
|
|
|
|
A *h() {
|
|
|
|
return new A(makeB(), makeB());
|
2009-12-11 08:32:37 +08:00
|
|
|
}
|
2010-09-14 15:57:04 +08:00
|
|
|
|
|
|
|
A *i() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test11iEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[X:%.*]] = alloca [[A]]*, align 8
|
|
|
|
// CHECK: [[ACTIVE:%.*]] = alloca i1
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK: [[NEW:%.*]] = call noalias nonnull i8* @_Znwm(i64 8)
|
|
|
|
// CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2020-03-25 00:36:19 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test15makeBEv([[B:%.*]]* sret align 4 [[T0:%.*]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T1]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: store i1 false, i1* [[ACTIVE]]
|
|
|
|
// CHECK-NEXT: store [[A]]* [[CAST]], [[A]]** [[X]], align 8
|
2020-03-25 00:36:19 +08:00
|
|
|
// CHECK: invoke void @_ZN5test15makeBEv([[B:%.*]]* sret align 4 [[T2:%.*]])
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[RET:%.*]] = load [[A]]*, [[A]]** [[X]], align 8
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test11BD1Ev([[B]]* [[T2]])
|
|
|
|
// CHECK11: call void @_ZN5test11BD1Ev([[B]]* [[T2]])
|
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
// CHECK11: call void @_ZN5test11BD1Ev([[B]]* [[T0]])
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[RET]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: br i1 [[ISACTIVE]]
|
|
|
|
// CHECK: call void @_ZdlPv(i8* [[NEW]])
|
|
|
|
A *x;
|
|
|
|
return (x = new A(makeB()), makeB(), x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
struct A {
|
|
|
|
A(int); A(int, int); ~A();
|
|
|
|
void *p;
|
|
|
|
void *operator new(size_t);
|
|
|
|
void operator delete(void*, size_t);
|
|
|
|
};
|
|
|
|
|
|
|
|
A *a() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test21aEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[NEW:%.*]] = call i8* @_ZN5test21AnwEm(i64 8)
|
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test21AC1Ei([[A]]* [[CAST]], i32 5)
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test21AdlEPvm(i8* [[NEW]], i64 8)
|
|
|
|
// CHECK11: call void @_ZN5test21AdlEPvm(i8* [[NEW]], i64 8)
|
|
|
|
|
|
|
|
// CHECK98: call void @__clang_call_terminate(i8* {{%.*}}) [[NR_NUW]]
|
2010-09-14 15:57:04 +08:00
|
|
|
return new A(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test3 {
|
|
|
|
struct A {
|
2010-09-17 08:50:28 +08:00
|
|
|
A(int); A(int, int); A(const A&); ~A();
|
2010-09-14 15:57:04 +08:00
|
|
|
void *p;
|
2010-09-17 08:50:28 +08:00
|
|
|
void *operator new(size_t, void*, double);
|
|
|
|
void operator delete(void*, void*, double);
|
2010-09-14 15:57:04 +08:00
|
|
|
};
|
|
|
|
|
2010-09-17 08:50:28 +08:00
|
|
|
void *foo();
|
|
|
|
double bar();
|
|
|
|
A makeA(), *makeAPtr();
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
A *a() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test31aEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[FOO:%.*]] = call i8* @_ZN5test33fooEv()
|
2010-09-17 08:50:28 +08:00
|
|
|
// CHECK: [[BAR:%.*]] = call double @_ZN5test33barEv()
|
|
|
|
// CHECK: [[NEW:%.*]] = call i8* @_ZN5test31AnwEmPvd(i64 8, i8* [[FOO]], double [[BAR]])
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test31AC1Ei([[A]]* [[CAST]], i32 5)
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test31AdlEPvS1_d(i8* [[NEW]], i8* [[FOO]], double [[BAR]])
|
|
|
|
// CHECK11: call void @_ZN5test31AdlEPvS1_d(i8* [[NEW]], i8* [[FOO]], double [[BAR]])
|
|
|
|
|
|
|
|
// CHECK98: call void @__clang_call_terminate(i8* {{%.*}}) [[NR_NUW]]
|
2010-09-14 15:57:04 +08:00
|
|
|
return new(foo(),bar()) A(5);
|
|
|
|
}
|
2010-09-17 08:50:28 +08:00
|
|
|
|
|
|
|
// rdar://problem/8439196
|
|
|
|
A *b(bool cond) {
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test31bEb(i1 zeroext
|
2010-09-17 08:50:28 +08:00
|
|
|
// CHECK: [[SAVED0:%.*]] = alloca i8*
|
|
|
|
// CHECK-NEXT: [[SAVED1:%.*]] = alloca i8*
|
|
|
|
// CHECK-NEXT: [[CLEANUPACTIVE:%.*]] = alloca i1
|
|
|
|
|
|
|
|
// CHECK: [[COND:%.*]] = trunc i8 {{.*}} to i1
|
2011-11-10 18:43:54 +08:00
|
|
|
// CHECK-NEXT: store i1 false, i1* [[CLEANUPACTIVE]]
|
2010-09-17 08:50:28 +08:00
|
|
|
// CHECK-NEXT: br i1 [[COND]]
|
|
|
|
return (cond ?
|
|
|
|
|
|
|
|
// CHECK: [[FOO:%.*]] = call i8* @_ZN5test33fooEv()
|
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test31AnwEmPvd(i64 8, i8* [[FOO]], double [[CONST:.*]])
|
|
|
|
// CHECK-NEXT: store i8* [[NEW]], i8** [[SAVED0]]
|
|
|
|
// CHECK-NEXT: store i8* [[FOO]], i8** [[SAVED1]]
|
|
|
|
// CHECK-NEXT: store i1 true, i1* [[CLEANUPACTIVE]]
|
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2020-03-25 00:36:19 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test35makeAEv([[A]]* sret align 8 [[CAST]])
|
2012-02-17 06:45:48 +08:00
|
|
|
// CHECK: br label
|
2010-09-17 08:50:28 +08:00
|
|
|
// -> cond.end
|
|
|
|
new(foo(),10.0) A(makeA()) :
|
|
|
|
|
2012-02-17 06:45:48 +08:00
|
|
|
// CHECK: [[MAKE:%.*]] = call [[A]]* @_ZN5test38makeAPtrEv()
|
2010-09-17 08:50:28 +08:00
|
|
|
// CHECK: br label
|
|
|
|
// -> cond.end
|
|
|
|
makeAPtr());
|
|
|
|
|
|
|
|
// cond.end:
|
|
|
|
// CHECK: [[RESULT:%.*]] = phi [[A]]* {{.*}}[[CAST]]{{.*}}[[MAKE]]
|
|
|
|
// CHECK: ret [[A]]* [[RESULT]]
|
|
|
|
|
|
|
|
// in the EH path:
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[ISACTIVE:%.*]] = load i1, i1* [[CLEANUPACTIVE]]
|
2010-09-17 08:50:28 +08:00
|
|
|
// CHECK-NEXT: br i1 [[ISACTIVE]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[V0:%.*]] = load i8*, i8** [[SAVED0]]
|
|
|
|
// CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[SAVED1]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN5test31AdlEPvS1_d(i8* [[V0]], i8* [[V1]], double [[CONST]])
|
|
|
|
// CHECK11-NEXT: call void @_ZN5test31AdlEPvS1_d(i8* [[V0]], i8* [[V1]], double [[CONST]])
|
2010-09-17 08:50:28 +08:00
|
|
|
}
|
2010-09-14 15:57:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
struct A {
|
|
|
|
A(int); A(int, int); ~A();
|
|
|
|
void *p;
|
|
|
|
void *operator new(size_t, void*, void*);
|
|
|
|
void operator delete(void*, size_t, void*, void*); // not a match
|
|
|
|
};
|
|
|
|
|
|
|
|
A *a() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test41aEv()
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK: [[FOO:%.*]] = call i8* @_ZN5test43fooEv()
|
|
|
|
// CHECK-NEXT: [[BAR:%.*]] = call i8* @_ZN5test43barEv()
|
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test41AnwEmPvS1_(i64 8, i8* [[FOO]], i8* [[BAR]])
|
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN5test41AC1Ei([[A]]* [[CAST]], i32 5)
|
2010-09-14 15:57:04 +08:00
|
|
|
// CHECK-NEXT: ret [[A]]* [[CAST]]
|
|
|
|
extern void *foo(), *bar();
|
|
|
|
|
|
|
|
return new(foo(),bar()) A(5);
|
|
|
|
}
|
2009-12-11 08:32:37 +08:00
|
|
|
}
|
2011-02-16 16:02:54 +08:00
|
|
|
|
|
|
|
// PR7908
|
|
|
|
namespace test5 {
|
|
|
|
struct T { T(); ~T(); };
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
A(const A &x, const T &t = T());
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
void foo();
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test54testEv()
|
2011-02-16 16:02:54 +08:00
|
|
|
// CHECK: [[EXNSLOT:%.*]] = alloca i8*
|
2011-05-29 05:13:02 +08:00
|
|
|
// CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
|
2011-02-16 16:02:54 +08:00
|
|
|
// CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]], align 1
|
|
|
|
// CHECK-NEXT: [[T:%.*]] = alloca [[T_T:%.*]], align 1
|
|
|
|
// CHECK-NEXT: invoke void @_ZN5test53fooEv()
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[EXN:%.*]] = load i8*, i8** [[EXNSLOT]]
|
2011-02-16 16:02:54 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = call i8* @__cxa_get_exception_ptr(i8* [[EXN]])
|
|
|
|
// CHECK-NEXT: [[SRC:%.*]] = bitcast i8* [[ADJ]] to [[A_T]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN5test51TC1Ev([[T_T]]* [[T]])
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK: invoke void @_ZN5test51AC1ERKS0_RKNS_1TE([[A_T]]* [[A]], [[A_T]]* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[SRC]], [[T_T]]* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[T]])
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test51TD1Ev([[T_T]]* [[T]])
|
|
|
|
// CHECK11: call void @_ZN5test51TD1Ev([[T_T]]* [[T]])
|
|
|
|
|
|
|
|
// CHECK98: call i8* @__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN5test51AD1Ev([[A_T]]* [[A]])
|
|
|
|
|
2011-02-16 16:02:54 +08:00
|
|
|
// CHECK: call void @__cxa_end_catch()
|
|
|
|
void test() {
|
|
|
|
try {
|
|
|
|
foo();
|
|
|
|
} catch (A a) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-25 12:19:13 +08:00
|
|
|
|
|
|
|
// PR9303: invalid assert on this
|
|
|
|
namespace test6 {
|
|
|
|
bool cond();
|
|
|
|
void test() {
|
|
|
|
try {
|
|
|
|
lbl:
|
|
|
|
if (cond()) goto lbl;
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-07 09:52:56 +08:00
|
|
|
|
|
|
|
// PR9298
|
|
|
|
namespace test7 {
|
|
|
|
struct A { A(); ~A(); };
|
|
|
|
struct B {
|
|
|
|
// The throw() operator means that a bad allocation is signalled
|
|
|
|
// with a null return, which means that the initializer is
|
|
|
|
// evaluated conditionally.
|
|
|
|
static void *operator new(size_t size) throw();
|
|
|
|
B(const A&, B*);
|
|
|
|
~B();
|
|
|
|
};
|
|
|
|
|
|
|
|
B *test() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define [[B:%.*]]* @_ZN5test74testEv()
|
2011-03-07 11:12:35 +08:00
|
|
|
// CHECK: [[OUTER_NEW:%.*]] = alloca i1
|
|
|
|
// CHECK-NEXT: alloca [[A:%.*]],
|
|
|
|
// CHECK-NEXT: alloca i8*
|
|
|
|
// CHECK-NEXT: alloca i32
|
|
|
|
// CHECK-NEXT: [[OUTER_A:%.*]] = alloca i1
|
|
|
|
// CHECK-NEXT: alloca i8*
|
|
|
|
// CHECK-NEXT: [[INNER_NEW:%.*]] = alloca i1
|
|
|
|
// CHECK-NEXT: alloca [[A]]
|
|
|
|
// CHECK-NEXT: [[INNER_A:%.*]] = alloca i1
|
|
|
|
|
|
|
|
// Allocate the outer object.
|
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test71BnwEm(
|
|
|
|
// CHECK-NEXT: icmp eq i8* [[NEW]], null
|
|
|
|
|
|
|
|
// These stores, emitted before the outermost conditional branch,
|
|
|
|
// deactivate the temporary cleanups.
|
2011-11-10 18:43:54 +08:00
|
|
|
// CHECK-NEXT: store i1 false, i1* [[OUTER_NEW]]
|
2011-03-07 11:12:35 +08:00
|
|
|
// CHECK-NEXT: store i1 false, i1* [[OUTER_A]]
|
2011-11-10 18:43:54 +08:00
|
|
|
// CHECK-NEXT: store i1 false, i1* [[INNER_NEW]]
|
2011-03-07 11:12:35 +08:00
|
|
|
// CHECK-NEXT: store i1 false, i1* [[INNER_A]]
|
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
|
|
|
|
// We passed the first null check; activate that cleanup and continue.
|
|
|
|
// CHECK: store i1 true, i1* [[OUTER_NEW]]
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
|
|
|
|
// Create the first A temporary and activate that cleanup.
|
|
|
|
// CHECK-NEXT: invoke void @_ZN5test71AC1Ev(
|
|
|
|
// CHECK: store i1 true, i1* [[OUTER_A]]
|
|
|
|
|
|
|
|
// Allocate the inner object.
|
|
|
|
// CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test71BnwEm(
|
|
|
|
// CHECK-NEXT: icmp eq i8* [[NEW]], null
|
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
|
|
|
|
// We passed the second null check; save that pointer, activate
|
|
|
|
// that cleanup, and continue.
|
|
|
|
// CHECK: store i8* [[NEW]]
|
|
|
|
// CHECK-NEXT: store i1 true, i1* [[INNER_NEW]]
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
|
|
|
|
// Build the second A temporary and activate that cleanup.
|
|
|
|
// CHECK-NEXT: invoke void @_ZN5test71AC1Ev(
|
|
|
|
// CHECK: store i1 true, i1* [[INNER_A]]
|
|
|
|
|
|
|
|
// Build the inner B object and deactivate the inner delete cleanup.
|
|
|
|
// CHECK-NEXT: invoke void @_ZN5test71BC1ERKNS_1AEPS0_(
|
|
|
|
// CHECK: store i1 false, i1* [[INNER_NEW]]
|
|
|
|
// CHECK: phi
|
|
|
|
|
|
|
|
// Build the outer B object and deactivate the outer delete cleanup.
|
|
|
|
// CHECK-NEXT: invoke void @_ZN5test71BC1ERKNS_1AEPS0_(
|
|
|
|
// CHECK: store i1 false, i1* [[OUTER_NEW]]
|
|
|
|
// CHECK: phi
|
2012-09-25 14:56:03 +08:00
|
|
|
// CHECK-NEXT: store [[B]]*
|
2011-03-07 11:12:35 +08:00
|
|
|
|
|
|
|
// Destroy the inner A object.
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: load i1, i1* [[INNER_A]]
|
2011-03-07 11:12:35 +08:00
|
|
|
// CHECK-NEXT: br i1
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test71AD1Ev(
|
|
|
|
// CHECK11: call void @_ZN5test71AD1Ev(
|
2011-03-07 11:12:35 +08:00
|
|
|
|
|
|
|
// Destroy the outer A object.
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i1, i1* [[OUTER_A]]
|
2011-03-07 11:12:35 +08:00
|
|
|
// CHECK-NEXT: br i1
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN5test71AD1Ev(
|
|
|
|
// CHECK11: call void @_ZN5test71AD1Ev(
|
2011-03-07 11:12:35 +08:00
|
|
|
|
2011-03-07 09:52:56 +08:00
|
|
|
return new B(A(), new B(A(), 0));
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 08:46:38 +08:00
|
|
|
|
|
|
|
// Just don't crash.
|
|
|
|
namespace test8 {
|
|
|
|
struct A {
|
2011-08-26 13:38:08 +08:00
|
|
|
// Having both of these is required to trigger the assert we're
|
|
|
|
// trying to avoid.
|
2011-08-26 08:46:38 +08:00
|
|
|
A(const A&);
|
2011-08-26 13:38:08 +08:00
|
|
|
A&operator=(const A&);
|
|
|
|
|
2011-08-26 08:46:38 +08:00
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
A makeA();
|
|
|
|
void test() {
|
|
|
|
throw makeA();
|
|
|
|
}
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test84testEv
|
2011-09-07 02:53:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we generate the correct code for the delete[] call which
|
|
|
|
// happens if A::A() throws. (We were previously calling delete[] on
|
|
|
|
// a pointer to the first array element, not the pointer returned by new[].)
|
|
|
|
// PR10870
|
|
|
|
namespace test9 {
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
A* test() {
|
|
|
|
return new A[10];
|
|
|
|
}
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK: define {{%.*}}* @_ZN5test94testEv
|
[clang] Annotating C++'s `operator new` with more attributes
Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.
However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.
Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.
The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.
Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith
Reviewed By: rsmith
Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits
Tags: #llvm, #clang
Differential Revision: https://reviews.llvm.org/D73380
2020-02-26 06:37:17 +08:00
|
|
|
// CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
|
2011-09-07 02:53:03 +08:00
|
|
|
// CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
|
2011-08-26 08:46:38 +08:00
|
|
|
}
|
2012-06-15 13:27:05 +08:00
|
|
|
|
|
|
|
// In a destructor with a function-try-block, a return statement in a
|
|
|
|
// catch handler behaves differently from running off the end of the
|
|
|
|
// catch handler. PR13102.
|
|
|
|
namespace test10 {
|
|
|
|
extern void cleanup();
|
|
|
|
extern bool suppress;
|
|
|
|
|
|
|
|
struct A { ~A(); };
|
|
|
|
A::~A() try { cleanup(); } catch (...) { return; }
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test101AD1Ev(
|
2012-06-15 13:27:05 +08:00
|
|
|
// CHECK: invoke void @_ZN6test107cleanupEv()
|
|
|
|
// CHECK-NOT: rethrow
|
|
|
|
// CHECK: ret void
|
|
|
|
|
|
|
|
struct B { ~B(); };
|
|
|
|
B::~B() try { cleanup(); } catch (...) {}
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test101BD1Ev(
|
2012-06-15 13:27:05 +08:00
|
|
|
// CHECK: invoke void @_ZN6test107cleanupEv()
|
|
|
|
// CHECK: call i8* @__cxa_begin_catch
|
|
|
|
// CHECK-NEXT: invoke void @__cxa_rethrow()
|
|
|
|
// CHECK: unreachable
|
|
|
|
|
|
|
|
struct C { ~C(); };
|
|
|
|
C::~C() try { cleanup(); } catch (...) { if (suppress) return; }
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test101CD1Ev(
|
2012-06-15 13:27:05 +08:00
|
|
|
// CHECK: invoke void @_ZN6test107cleanupEv()
|
|
|
|
// CHECK: call i8* @__cxa_begin_catch
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: load i8, i8* @_ZN6test108suppressE, align 1
|
2012-06-15 13:27:05 +08:00
|
|
|
// CHECK-NEXT: trunc
|
|
|
|
// CHECK-NEXT: br i1
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: call void @__cxa_end_catch()
|
|
|
|
// CHECK98-NEXT: br label
|
|
|
|
// CHECK11: invoke void @__cxa_end_catch()
|
|
|
|
// CHECK11-NEXT: to label
|
|
|
|
|
2012-06-15 13:27:05 +08:00
|
|
|
// CHECK: invoke void @__cxa_rethrow()
|
|
|
|
// CHECK: unreachable
|
|
|
|
}
|
2013-02-01 13:11:40 +08:00
|
|
|
|
|
|
|
// Ensure that an exception in a constructor destroys
|
|
|
|
// already-constructed array members. PR14514
|
|
|
|
namespace test11 {
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
~A() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
A single;
|
|
|
|
A array[2][3];
|
|
|
|
|
|
|
|
C();
|
|
|
|
};
|
|
|
|
|
|
|
|
C::C() {
|
|
|
|
throw 0;
|
|
|
|
}
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test111CC2Ev(
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[THIS:%.*]] = load [[C:%.*]]*, [[C:%.*]]** {{%.*}}
|
2013-02-01 13:11:40 +08:00
|
|
|
// Construct single.
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[SINGLE:%.*]] = getelementptr inbounds [[C]], [[C]]* [[THIS]], i32 0, i32 0
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN6test111AC1Ev([[A:%.*]]* [[SINGLE]])
|
2013-02-01 13:11:40 +08:00
|
|
|
// Construct array.
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ARRAY:%.*]] = getelementptr inbounds [[C]], [[C]]* [[THIS]], i32 0, i32 1
|
|
|
|
// CHECK-NEXT: [[ARRAYBEGIN:%.*]] = getelementptr inbounds [2 x [3 x [[A]]]], [2 x [3 x [[A]]]]* [[ARRAY]], i32 0, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: [[ARRAYEND:%.*]] = getelementptr inbounds [[A]], [[A]]* [[ARRAYBEGIN]], i64 6
|
2013-02-01 13:11:40 +08:00
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[CUR:%.*]] = phi [[A]]* [ [[ARRAYBEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN6test111AC1Ev([[A:%.*]]* [[CUR]])
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEXT]] = getelementptr inbounds [[A]], [[A]]* [[CUR]], i64 1
|
2013-02-01 13:11:40 +08:00
|
|
|
// CHECK-NEXT: [[DONE:%.*]] = icmp eq [[A]]* [[NEXT]], [[ARRAYEND]]
|
|
|
|
// CHECK-NEXT: br i1 [[DONE]],
|
|
|
|
// throw 0;
|
|
|
|
// CHECK: invoke void @__cxa_throw(
|
|
|
|
// Landing pad 1, from constructor in array-initialization loop:
|
|
|
|
// CHECK: landingpad
|
|
|
|
// - First, destroy already-constructed bits of array.
|
|
|
|
// CHECK: [[EMPTY:%.*]] = icmp eq [[A]]* [[ARRAYBEGIN]], [[CUR]]
|
|
|
|
// CHECK-NEXT: br i1 [[EMPTY]]
|
|
|
|
// CHECK: [[AFTER:%.*]] = phi [[A]]* [ [[CUR]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ELT]] = getelementptr inbounds [[A]], [[A]]* [[AFTER]], i64 -1
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN6test111AD1Ev([[A]]* [[ELT]])
|
|
|
|
// CHECK11-NEXT: call void @_ZN6test111AD1Ev([[A]]* [[ELT]])
|
|
|
|
|
2013-02-01 13:11:40 +08:00
|
|
|
// CHECK: [[DONE:%.*]] = icmp eq [[A]]* [[ELT]], [[ARRAYBEGIN]]
|
|
|
|
// CHECK-NEXT: br i1 [[DONE]],
|
|
|
|
// - Next, chain to cleanup for single.
|
|
|
|
// CHECK: br label
|
|
|
|
// Landing pad 2, from throw site.
|
|
|
|
// CHECK: landingpad
|
|
|
|
// - First, destroy all of array.
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[ARRAYBEGIN:%.*]] = getelementptr inbounds [2 x [3 x [[A]]]], [2 x [3 x [[A]]]]* [[ARRAY]], i32 0, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: [[ARRAYEND:%.*]] = getelementptr inbounds [[A]], [[A]]* [[ARRAYBEGIN]], i64 6
|
2013-02-01 13:11:40 +08:00
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[AFTER:%.*]] = phi [[A]]* [ [[ARRAYEND]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ELT]] = getelementptr inbounds [[A]], [[A]]* [[AFTER]], i64 -1
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN6test111AD1Ev([[A]]* [[ELT]])
|
|
|
|
// CHECK11-NEXT: call void @_ZN6test111AD1Ev([[A]]* [[ELT]])
|
|
|
|
|
2013-02-01 13:11:40 +08:00
|
|
|
// CHECK: [[DONE:%.*]] = icmp eq [[A]]* [[ELT]], [[ARRAYBEGIN]]
|
|
|
|
// CHECK-NEXT: br i1 [[DONE]],
|
|
|
|
// - Next, chain to cleanup for single.
|
|
|
|
// CHECK: br label
|
|
|
|
// Finally, the cleanup for single.
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN6test111AD1Ev([[A]]* [[SINGLE]])
|
|
|
|
// CHECK11: call void @_ZN6test111AD1Ev([[A]]* [[SINGLE]])
|
|
|
|
|
2013-02-01 13:11:40 +08:00
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: resume
|
|
|
|
// (After this is a terminate landingpad.)
|
|
|
|
}
|
2013-02-20 15:22:19 +08:00
|
|
|
|
2015-09-30 07:55:17 +08:00
|
|
|
namespace test12 {
|
|
|
|
struct A {
|
|
|
|
void operator delete(void *, void *);
|
|
|
|
A();
|
|
|
|
};
|
|
|
|
|
|
|
|
A *test(void *ptr) {
|
|
|
|
return new (ptr) A();
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN6test124testEPv(
|
|
|
|
// CHECK: [[PTR:%.*]] = load i8*, i8*
|
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[PTR]] to [[A:%.*]]*
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke void @_ZN6test121AC1Ev([[A]]* [[CAST]])
|
2015-09-30 07:55:17 +08:00
|
|
|
// CHECK: ret [[A]]* [[CAST]]
|
2017-01-10 02:24:16 +08:00
|
|
|
|
|
|
|
// CHECK98: invoke void @_ZN6test121AdlEPvS1_(i8* [[PTR]], i8* [[PTR]])
|
|
|
|
// CHECK11: call void @_ZN6test121AdlEPvS1_(i8* [[PTR]], i8* [[PTR]])
|
2015-09-30 07:55:17 +08:00
|
|
|
}
|
|
|
|
|
2017-01-10 02:24:16 +08:00
|
|
|
// CHECK98: attributes [[NI_NR_NUW]] = { noinline noreturn nounwind }
|