Author: rogfer01 Date: Wed Aug 17 01:52:15 2016 New Revision: 278908 URL: http://llvm.org/viewvc/llvm-project?rev=278908&view=rev Log: Add missing tests
Change r278483 was missing the tests Differential Revision: https://reviews.llvm.org/D20561 Added: cfe/trunk/test/Sema/address-packed-member-memops.c cfe/trunk/test/Sema/address-packed.c cfe/trunk/test/SemaCXX/address-packed-member-memops.cpp cfe/trunk/test/SemaCXX/address-packed.cpp Added: cfe/trunk/test/Sema/address-packed-member-memops.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address-packed-member-memops.c?rev=278908&view=auto ============================================================================== --- cfe/trunk/test/Sema/address-packed-member-memops.c (added) +++ cfe/trunk/test/Sema/address-packed-member-memops.c Wed Aug 17 01:52:15 2016 @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +struct B { + int x, y, z, w; +} b; + +struct __attribute__((packed)) A { + struct B b; +} a; + +typedef __typeof__(sizeof(int)) size_t; + +void *memcpy(void *dest, const void *src, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); + +int x; + +void foo(void) { + memcpy(&a.b, &b, sizeof(b)); + memmove(&a.b, &b, sizeof(b)); + memset(&a.b, 0, sizeof(b)); + x = memcmp(&a.b, &b, sizeof(b)); +} Added: cfe/trunk/test/Sema/address-packed.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address-packed.c?rev=278908&view=auto ============================================================================== --- cfe/trunk/test/Sema/address-packed.c (added) +++ cfe/trunk/test/Sema/address-packed.c Wed Aug 17 01:52:15 2016 @@ -0,0 +1,163 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#include <stdint.h> + +extern void f1(int *); +extern void f2(char *); + +struct Ok { + char c; + int x; +}; + +struct __attribute__((packed)) Arguable { + char c0; + int x; + char c1; +}; + +union __attribute__((packed)) UnionArguable { + char c; + int x; +}; + +typedef struct Arguable ArguableT; + +struct Arguable *get_arguable(); + +void to_void(void *); + +void g0(void) { + { + struct Ok ok; + f1(&ok.x); // no-warning + f2(&ok.c); // no-warning + } + { + struct Arguable arguable; + f2(&arguable.c0); // no-warning + f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} + f2(&arguable.c1); // no-warning + + f1((int *)(void *)&arguable.x); // no-warning + to_void(&arguable.x); // no-warning + void *p = &arguable.x; // no-warning; + to_void(p); + } + { + union UnionArguable arguable; + f2(&arguable.c); // no-warning + f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'UnionArguable'}} + + f1((int *)(void *)&arguable.x); // no-warning + to_void(&arguable.x); // no-warning + } + { + ArguableT arguable; + f2(&arguable.c0); // no-warning + f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} + f2(&arguable.c1); // no-warning + + f1((int *)(void *)&arguable.x); // no-warning + to_void(&arguable.x); // no-warning + } + { + struct Arguable *arguable = get_arguable(); + f2(&arguable->c0); // no-warning + f1(&arguable->x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} + f2(&arguable->c1); // no-warning + + f1((int *)(void *)&arguable->x); // no-warning + to_void(&arguable->c1); // no-warning + } + { + ArguableT *arguable = get_arguable(); + f2(&(arguable->c0)); // no-warning + f1(&(arguable->x)); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} + f2(&(arguable->c1)); // no-warning + + f1((int *)(void *)&(arguable->x)); // no-warning + to_void(&(arguable->c1)); // no-warning + } +} + +struct S1 { + char c; + int i __attribute__((packed)); +}; + +int *g1(struct S1 *s1) { + return &s1->i; // expected-warning {{packed member 'i' of class or structure 'S1'}} +} + +struct S2_i { + int i; +}; +struct __attribute__((packed)) S2 { + char c; + struct S2_i inner; +}; + +int *g2(struct S2 *s2) { + return &s2->inner.i; // expected-warning {{packed member 'inner' of class or structure 'S2'}} +} + +struct S2_a { + char c; + struct S2_i inner __attribute__((packed)); +}; + +int *g2_a(struct S2_a *s2_a) { + return &s2_a->inner.i; // expected-warning {{packed member 'inner' of class or structure 'S2_a'}} +} + +struct __attribute__((packed)) S3 { + char c; + struct { + int i; + } inner; +}; + +int *g3(struct S3 *s3) { + return &s3->inner.i; // expected-warning {{packed member 'inner' of class or structure 'S3'}} +} + +struct S4 { + char c; + struct __attribute__((packed)) { + int i; + } inner; +}; + +int *g4(struct S4 *s4) { + return &s4->inner.i; // expected-warning {{packed member 'i' of class or structure 'S4::(anonymous)'}} +} + +struct S5 { + char c; + struct { + char c1; + int i __attribute__((packed)); + } inner; +}; + +int *g5(struct S5 *s5) { + return &s5->inner.i; // expected-warning {{packed member 'i' of class or structure 'S5::(anonymous)'}} +} + +struct __attribute__((packed, aligned(2))) AlignedTo2 { + int x; +}; + +char *g6(struct AlignedTo2 *s) { + return (char *)&s->x; // no-warning +} + +struct __attribute__((packed, aligned(2))) AlignedTo2Bis { + int x; +}; + +struct AlignedTo2Bis* g7(struct AlignedTo2 *s) +{ + return (struct AlignedTo2Bis*)&s->x; // no-warning +} Added: cfe/trunk/test/SemaCXX/address-packed-member-memops.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/address-packed-member-memops.cpp?rev=278908&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/address-packed-member-memops.cpp (added) +++ cfe/trunk/test/SemaCXX/address-packed-member-memops.cpp Wed Aug 17 01:52:15 2016 @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +struct B { + int x, y, z, w; +} b; + +struct __attribute__((packed)) A { + struct B b; +} a; + +typedef __typeof__(sizeof(int)) size_t; + +extern "C" { +void *memcpy(void *dest, const void *src, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); +} + +int x; + +void foo() { + memcpy(&a.b, &b, sizeof(b)); + memmove(&a.b, &b, sizeof(b)); + memset(&a.b, 0, sizeof(b)); + x = memcmp(&a.b, &b, sizeof(b)); +} Added: cfe/trunk/test/SemaCXX/address-packed.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/address-packed.cpp?rev=278908&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/address-packed.cpp (added) +++ cfe/trunk/test/SemaCXX/address-packed.cpp Wed Aug 17 01:52:15 2016 @@ -0,0 +1,114 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +extern void f1(int *); +extern void f2(char *); + +struct __attribute__((packed)) Arguable { + int x; + char c; + static void foo(); +}; + +extern void f3(void()); + +namespace Foo { +struct __attribute__((packed)) Arguable { + char c; + int x; + static void foo(); +}; +} + +struct Arguable *get_arguable(); + +void f4(int &); + +void to_void(void *); + +template <typename... T> +void sink(T...); + +void g0() { + { + Foo::Arguable arguable; + f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Foo::Arguable'}} + f2(&arguable.c); // no-warning + f3(&arguable.foo); // no-warning + + to_void(&arguable.x); // no-warning + void *p1 = &arguable.x; // no-warning + void *p2 = static_cast<void *>(&arguable.x); // no-warning + void *p3 = reinterpret_cast<void *>(&arguable.x); // no-warning + void *p4 = (void *)&arguable.x; // no-warning + sink(p1, p2, p3, p4); + } + { + Arguable arguable1; + Arguable &arguable(arguable1); + f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} + f2(&arguable.c); // no-warning + f3(&arguable.foo); // no-warning + } + { + Arguable *arguable1; + Arguable *&arguable(arguable1); + f1(&arguable->x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}} + f2(&arguable->c); // no-warning + f3(&arguable->foo); // no-warning + } +} + +struct __attribute__((packed)) A { + int x; + char c; + + int *f0() { + return &this->x; // expected-warning {{packed member 'x' of class or structure 'A'}} + } + + int *g0() { + return &x; // expected-warning {{packed member 'x' of class or structure 'A'}} + } + + char *h0() { + return &c; // no-warning + } +}; + +struct B : A { + int *f1() { + return &this->x; // expected-warning {{packed member 'x' of class or structure 'A'}} + } + + int *g1() { + return &x; // expected-warning {{packed member 'x' of class or structure 'A'}} + } + + char *h1() { + return &c; // no-warning + } +}; + +template <typename Ty> +class __attribute__((packed)) S { + Ty X; + +public: + const Ty *get() const { + return &X; // expected-warning {{packed member 'X' of class or structure 'S<int>'}} + // expected-warning@-1 {{packed member 'X' of class or structure 'S<float>'}} + } +}; + +template <typename Ty> +void h(Ty *); + +void g1() { + S<int> s1; + s1.get(); // expected-note {{in instantiation of member function 'S<int>::get'}} + + S<char> s2; + s2.get(); + + S<float> s3; + s3.get(); // expected-note {{in instantiation of member function 'S<float>::get'}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits