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
47 lines
1.8 KiB
C++
47 lines
1.8 KiB
C++
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fcxx-exceptions -fexceptions -emit-llvm -std=c++98 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
|
|
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fcxx-exceptions -fexceptions -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
|
|
|
|
// Reduced from a crash on boost::interprocess's node_allocator_test.cpp.
|
|
namespace test0 {
|
|
struct A { A(); ~A(); };
|
|
struct V { V(const A &a = A()); ~V(); };
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZN5test04testILi0EEEii
|
|
template<int X> int test(int x) {
|
|
// CHECK: [[RET:%.*]] = alloca i32
|
|
// CHECK-NEXT: [[X:%.*]] = alloca i32
|
|
// CHECK-NEXT: [[Y:%.*]] = alloca [[A:%.*]],
|
|
// CHECK-NEXT: [[Z:%.*]] = alloca [[A]]
|
|
// CHECK-NEXT: [[EXN:%.*]] = alloca i8*
|
|
// CHECK-NEXT: [[SEL:%.*]] = alloca i32
|
|
// CHECK-NEXT: [[V:%.*]] = alloca [[V:%.*]]*,
|
|
// CHECK-NEXT: [[TMP:%.*]] = alloca [[A]]
|
|
// CHECK-NEXT: [[CLEANUPACTIVE:%.*]] = alloca i1
|
|
// CHECK: call void @_ZN5test01AC1Ev([[A]]* [[Y]])
|
|
// CHECK-NEXT: invoke void @_ZN5test01AC1Ev([[A]]* [[Z]])
|
|
// CHECK: [[NEW:%.*]] = invoke noalias nonnull i8* @_Znwm(i64 1)
|
|
// CHECK: store i1 true, i1* [[CLEANUPACTIVE]]
|
|
// CHECK: [[NEWCAST:%.*]] = bitcast i8* [[NEW]] to [[V]]*
|
|
// CHECK-NEXT: invoke void @_ZN5test01AC1Ev([[A]]* [[TMP]])
|
|
// CHECK: invoke void @_ZN5test01VC1ERKNS_1AE([[V]]* [[NEWCAST]], [[A]]* dereferenceable({{[0-9]+}}) [[TMP]])
|
|
// CHECK: store i1 false, i1* [[CLEANUPACTIVE]]
|
|
|
|
// CHECK98-NEXT: invoke void @_ZN5test01AD1Ev([[A]]* [[TMP]])
|
|
// CHECK11-NEXT: call void @_ZN5test01AD1Ev([[A]]* [[TMP]])
|
|
A y;
|
|
try {
|
|
A z;
|
|
V *v = new V();
|
|
|
|
if (x) return 1;
|
|
} catch (int ex) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int test() {
|
|
return test<0>(5);
|
|
}
|
|
}
|