2010-03-26 02:05:35 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck %s
|
2010-03-25 00:57:01 +08:00
|
|
|
// PR6641
|
|
|
|
|
|
|
|
extern "C" int printf(const char *, ...);
|
|
|
|
|
|
|
|
struct Foo {
|
|
|
|
Foo() : iFoo (2) {
|
|
|
|
printf("%p\n", this);
|
|
|
|
}
|
|
|
|
int iFoo;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef Foo (*T)[3][4];
|
|
|
|
|
|
|
|
T bar() {
|
|
|
|
return new Foo[2][3][4];
|
|
|
|
}
|
|
|
|
|
|
|
|
T bug(int i) {
|
|
|
|
return new Foo[i][3][4];
|
|
|
|
}
|
|
|
|
|
|
|
|
void pr(T a) {
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
printf("%p\n", a[i][j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Foo *test() {
|
|
|
|
return new Foo[5];
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
T f = bar();
|
|
|
|
pr(f);
|
|
|
|
f = bug(3);
|
|
|
|
pr(f);
|
|
|
|
|
|
|
|
Foo * g = test();
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
printf("%d\n", g[i].iFoo);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-26 02:05:35 +08:00
|
|
|
|
[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: call noalias nonnull i8* @_Znam
|
|
|
|
// CHECK: call noalias nonnull i8* @_Znam
|
|
|
|
// CHECK: call noalias nonnull i8* @_Znam
|