Mercurial > hg > CbC > CbC_llvm
diff clang/test/Frontend/noderef.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 1d019706d866 |
children |
line wrap: on
line diff
--- a/clang/test/Frontend/noderef.cpp Tue Jun 15 19:13:43 2021 +0900 +++ b/clang/test/Frontend/noderef.cpp Tue Jun 15 19:15:29 2021 +0900 @@ -6,6 +6,11 @@ #define NODEREF __attribute__((noderef)) +// Stub out types for 'typeid' to work. +namespace std { +class type_info {}; +} // namespace std + void Normal() { int NODEREF i; // expected-warning{{'noderef' can only be used on an array or pointer type}} int NODEREF *i_ptr; // expected-note 2 {{i_ptr declared here}} @@ -80,12 +85,40 @@ int member; int NODEREF *member2; int NODEREF member3; // expected-warning{{'noderef' can only be used on an array or pointer type}} + int *member4; + + int func() { return member; } + virtual int func_virt() { return member; } + + A(NODEREF int *x) : member4(x) {} // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} }; +class Child : public A {}; + void MemberPointer() { int NODEREF A::*var = &A::member; // expected-warning{{'noderef' can only be used on an array or pointer type}} } +int MethodCall(NODEREF A *a) { // expected-note{{a declared here}} + return a->func(); // expected-warning{{dereferencing a; was declared with a 'noderef' type}} +} + +int ChildCall(NODEREF Child *child) { // expected-note{{child declared here}} + return child->func(); // expected-warning{{dereferencing child; was declared with a 'noderef' type}} +} + +std::type_info TypeIdPolymorphic(NODEREF A *a) { // expected-note{{a declared here}} + return typeid(*a); // expected-warning{{dereferencing a; was declared with a 'noderef' type}} +} + +class SimpleClass { + int a; +}; + +std::type_info TypeIdNonPolymorphic(NODEREF SimpleClass *simple) { + return typeid(*simple); +} + template <class Ty> class B { Ty NODEREF *member; @@ -100,3 +133,53 @@ int NODEREF *glob_ptr; // expected-note{{glob_ptr declared here}} int glob_int = *glob_ptr; // expected-warning{{dereferencing glob_ptr; was declared with a 'noderef' type}} + +void cast_from_void_ptr(NODEREF void *x) { + int *a = static_cast<int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} + + // Allow regular C-style casts and C-style through reinterpret_casts to be holes + int *b = reinterpret_cast<int *>(x); + int *c = (int *)x; +} + +void conversion_sequences() { + NODEREF int *x; + int *x2 = x; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} + int *x3 = static_cast<int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} + int *x4 = reinterpret_cast<int *>(x); + + // Functional cast - This is exactly equivalent to a C-style cast. + typedef int *INT_PTR; + int *x5 = INT_PTR(x); + + NODEREF Child *child; + Child *child2 = dynamic_cast<Child *>(child); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +int *static_cast_from_same_ptr_type(NODEREF int *x) { + return static_cast<int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +A *dynamic_cast_up(NODEREF Child *child) { + return dynamic_cast<A *>(child); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +Child *dynamic_cast_down(NODEREF A *a) { + return dynamic_cast<Child *>(a); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +A *dynamic_cast_side(NODEREF A *a) { + return dynamic_cast<A *>(a); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +void *dynamic_cast_to_void_ptr(NODEREF A *a) { + return dynamic_cast<void *>(a); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +int *const_cast_check(NODEREF const int *x) { + return const_cast<int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +} + +const int *const_cast_check(NODEREF int *x) { + return const_cast<const int *>(x); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} +}