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
40 lines
813 B
Plaintext
40 lines
813 B
Plaintext
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
// rdar://problem/9158302
|
|
// This should not use a memmove_collectable in non-GC mode.
|
|
namespace test0 {
|
|
struct A {
|
|
id x;
|
|
};
|
|
|
|
// CHECK: define [[A:%.*]]* @_ZN5test04testENS_1AE(
|
|
// CHECK: alloca
|
|
// CHECK-NEXT: getelementptr
|
|
// CHECK-NEXT: store
|
|
// CHECK-NEXT: [[CALL:%.*]] = call noalias nonnull i8* @_Znwm(
|
|
// CHECK-NEXT: bitcast
|
|
// CHECK-NEXT: bitcast
|
|
// CHECK-NEXT: bitcast
|
|
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(
|
|
// CHECK-NEXT: ret
|
|
A *test(A a) {
|
|
return new A(a);
|
|
}
|
|
}
|
|
|
|
|
|
// rdar://9780211
|
|
@protocol bork
|
|
@end
|
|
|
|
namespace test1 {
|
|
template<typename T> struct RetainPtr {
|
|
RetainPtr() {}
|
|
};
|
|
|
|
|
|
RetainPtr<id<bork> > x;
|
|
RetainPtr<id> y;
|
|
|
|
}
|