diff options
author | Hal Finkel <hfinkel@anl.gov> | 2014-07-18 15:52:10 +0000 |
---|---|---|
committer | Hal Finkel <hfinkel@anl.gov> | 2014-07-18 15:52:10 +0000 |
commit | a2347baaec37ba81d64f9b455af3084cf183f127 (patch) | |
tree | 38de0cdf097468df1afb29d2abb642bf7bdab1f1 /clang/test/CodeGenCXX/address-space-ref.cpp | |
parent | b0407ba0716d940d035f5da73f6d3bfbaffecb44 (diff) | |
download | bcm5719-llvm-a2347baaec37ba81d64f9b455af3084cf183f127.tar.gz bcm5719-llvm-a2347baaec37ba81d64f9b455af3084cf183f127.zip |
Mark C++ reference parameters as dereferenceable
Because references must be initialized using some evaluated expression, they
must point to something, and a callee can assume the reference parameter is
dereferenceable. Taking advantage of a new attribute just added to LLVM, mark
them as such.
Because dereferenceability in addrspace(0) implies nonnull in the backend, we
don't need both attributes. However, we need to know the size of the object to
use the dereferenceable attribute, so for incomplete types we still emit only
nonnull.
llvm-svn: 213386
Diffstat (limited to 'clang/test/CodeGenCXX/address-space-ref.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/address-space-ref.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/address-space-ref.cpp b/clang/test/CodeGenCXX/address-space-ref.cpp new file mode 100644 index 00000000000..de6bddca66a --- /dev/null +++ b/clang/test/CodeGenCXX/address-space-ref.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +// For a reference to a complete type, output the dereferenceable attribute (in +// any address space). + +typedef int a __attribute__((address_space(1))); + +a & foo(a &x, a & y) { + return x; +} + +// CHECK: define dereferenceable(4) i32 addrspace(1)* @_Z3fooRU3AS1iS0_(i32 addrspace(1)* dereferenceable(4) %x, i32 addrspace(1)* dereferenceable(4) %y) + +// For a reference to an incomplete type in an alternate address space, output +// neither dereferenceable nor nonnull. + +class bc; +typedef bc b __attribute__((address_space(1))); + +b & bar(b &x, b & y) { + return x; +} + +// CHECK: define %class.bc addrspace(1)* @_Z3barRU3AS12bcS1_(%class.bc addrspace(1)* %x, %class.bc addrspace(1)* %y) + +// For a reference to an incomplete type in addrspace(0), output nonnull. + +bc & bar2(bc &x, bc & y) { + return x; +} + +// CHECK: define nonnull %class.bc* @_Z4bar2R2bcS0_(%class.bc* nonnull %x, %class.bc* nonnull %y) + + |