summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2016-08-08 16:37:00 +0000
committerHans Wennborg <hans@hanshq.net>2016-08-08 16:37:00 +0000
commitfc87c4533072c50d1aaaa420d0da934d71e09fbf (patch)
tree15663763e3908136756b1a024db4dbc812bcef81 /test
parentadf3fd9ee6e5b878bce1d6b027c327dd7bcc81eb (diff)
Merging r277796, r277797, r277866, r277889 and r277900:
------------------------------------------------------------------------ r277796 | rtrieu | 2016-08-04 19:39:30 -0700 (Thu, 04 Aug 2016) | 6 lines Allow -1 to assign max value to unsigned bitfields. Silence the -Wbitfield-constant-conversion warning for when -1 or other negative values are assigned to unsigned bitfields, provided that the bitfield is wider than the minimum number of bits needed to encode the negative value. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r277797 | rtrieu | 2016-08-04 20:16:36 -0700 (Thu, 04 Aug 2016) | 7 lines Fix crash in template type diffing. When the type being diffed is a type alias, and the orginal type is not a templated type, then there will be no unsugared TemplateSpecializationType. When this happens, exit early from the constructor. Also add assertions to the other iterator accessor to prevent the iterator from being used. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r277866 | rtrieu | 2016-08-05 14:02:34 -0700 (Fri, 05 Aug 2016) | 12 lines Fix false positive in -Wunsequenced and templates. For builtin logical operators, there is a well-defined ordering of argument evaluation. For overloaded operator of the same type, there is no argument evaluation order, similar to other function calls. When both are present, uninstantiated templates with an operator&& is treated as an unresolved function call. Unresolved function calls are treated as normal function calls, and may result in false positives when the builtin logical operator is used. Have the unsequenced checker ignore dependent expressions to avoid this false positive. The check also happens in template instantiations to catch when the overloaded operator is used. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r277889 | rtrieu | 2016-08-05 16:24:47 -0700 (Fri, 05 Aug 2016) | 9 lines Fix two false positives in -Wreturn-stack-address If the return type is a pointer and the function returns the reference to a pointer, don't warn since only the value is returned, not the reference. If a reference function parameter appears in the reference chain, don't warn since binding happens at the caller scope, so addresses returned are not to local stack. This includes default arguments as well. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r277900 | rtrieu | 2016-08-05 18:44:06 -0700 (Fri, 05 Aug 2016) | 2 lines Fix typos from r277797 and unused variable from r277889. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_39@278020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Misc/diag-template-diffing.cpp30
-rw-r--r--test/Sema/bitfield.c2
-rw-r--r--test/Sema/constant-conversion.c12
-rw-r--r--test/SemaCXX/return-stack-addr-2.cpp61
-rw-r--r--test/SemaCXX/warn-unsequenced.cpp55
5 files changed, 158 insertions, 2 deletions
diff --git a/test/Misc/diag-template-diffing.cpp b/test/Misc/diag-template-diffing.cpp
index 90bcf6b2d1..a4f29cc8c7 100644
--- a/test/Misc/diag-template-diffing.cpp
+++ b/test/Misc/diag-template-diffing.cpp
@@ -1455,7 +1455,37 @@ void run() {
}
// CHECK-ELIDE-NOTREE: error: no matching function for call to 'D'
// CHECK-ELIDE-NOTREE: note: candidate function [with x = TypeAlias::X::X1] not viable: no known conversion from 'VectorType<X::X2>' to 'const VectorType<(TypeAlias::X)0>' for 1st argument
+}
+
+namespace TypeAlias2 {
+template <typename T>
+class A {};
+
+template <typename T>
+using A_reg = A<T>;
+void take_reg(A_reg<int>);
+
+template <typename T>
+using A_ptr = A<T> *;
+void take_ptr(A_ptr<int>);
+
+template <typename T>
+using A_ref = const A<T> &;
+void take_ref(A_ref<int>);
+void run(A_reg<float> reg, A_ptr<float> ptr, A_ref<float> ref) {
+ take_reg(reg);
+// CHECK-ELIDE-NOTREE: error: no matching function for call to 'take_reg'
+// CHECK-ELIDE-NOTREE: note: candidate function not viable: no known conversion from 'A_reg<float>' to 'A_reg<int>' for 1st argument
+
+ take_ptr(ptr);
+// CHECK-ELIDE-NOTREE: error: no matching function for call to 'take_ptr'
+// CHECK-ELIDE-NOTREE: note: candidate function not viable: no known conversion from 'A_ptr<float>' to 'A_ptr<int>' for 1st argument
+
+ take_ref(ref);
+// CHECK-ELIDE-NOTREE: error: no matching function for call to 'take_ref'
+// CHECK-ELIDE-NOTREE: note: candidate function not viable: no known conversion from 'const A<float>' to 'const A<int>' for 1st argument
+}
}
// CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated.
diff --git a/test/Sema/bitfield.c b/test/Sema/bitfield.c
index 810dc798ea..d625366e4e 100644
--- a/test/Sema/bitfield.c
+++ b/test/Sema/bitfield.c
@@ -64,7 +64,7 @@ typedef signed Signed;
struct Test5 { unsigned n : 2; } t5;
// Bitfield is unsigned
-struct Test5 sometest5 = {-1}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -1 to 3}}
+struct Test5 sometest5 = {-1};
typedef __typeof__(+t5.n) Signed; // ... but promotes to signed.
typedef __typeof__(t5.n + 0) Signed; // Arithmetic promotes.
diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c
index b717f93253..203e737389 100644
--- a/test/Sema/constant-conversion.c
+++ b/test/Sema/constant-conversion.c
@@ -113,3 +113,15 @@ void test9() {
char array_init[] = { 255, 127, 128, 129, 0 };
}
+
+void test10() {
+ struct S {
+ unsigned a : 4;
+ } s;
+ s.a = -1;
+ s.a = 15;
+ s.a = -8;
+
+ s.a = -9; // expected-warning{{implicit truncation from 'int' to bitfield changes value from -9 to 7}}
+ s.a = 16; // expected-warning{{implicit truncation from 'int' to bitfield changes value from 16 to 0}}
+}
diff --git a/test/SemaCXX/return-stack-addr-2.cpp b/test/SemaCXX/return-stack-addr-2.cpp
index ad27567fcd..47b45957e9 100644
--- a/test/SemaCXX/return-stack-addr-2.cpp
+++ b/test/SemaCXX/return-stack-addr-2.cpp
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s
-// expected-no-diagnostics
namespace PR26599 {
template <typename>
@@ -20,3 +19,63 @@ void *&pointer() {
}
}
+namespace LocalTemporary {
+
+template <class T>
+class QMap {
+public:
+ T value(const T &t = T()) const {
+ return t;
+ }
+};
+
+struct A {};
+
+void test() {
+ QMap<A *> map;
+ map.value();
+}
+
+typedef int* ptr;
+ptr int1(const ptr &p = ptr()) {
+ return (p);
+}
+
+ptr int2(const ptr &p = nullptr) {
+ return p;
+}
+
+ptr int3() {
+ const ptr &p = ptr();
+ return p;
+}
+
+const int *int4(const int &x = 5) {
+ return &x;
+}
+
+const int *int5(const int &x) {
+ return &x;
+}
+
+const int *int6() {
+ const int &x = 11; //expected-note{{binding reference variable 'x' here}}
+ return &x; //expected-warning{{returning address of local temporary object}}
+}
+
+const int *int7(int x) {
+ const int &x2 = x; // expected-note{{binding reference variable 'x2' here}}
+ return &x2; // expected-warning{{address of stack memory associated with local variable 'x' returned}}
+}
+
+const int *int8(const int &x = 5) {
+ const int &x2 = x;
+ return &x2;
+}
+
+const int *int9() {
+ const int &x = 5; // expected-note{{binding reference variable 'x' here}}
+ const int &x2 = x; // expected-note{{binding reference variable 'x2' here}}
+ return &x2; // expected-warning{{returning address of local temporary object}}
+}
+}
diff --git a/test/SemaCXX/warn-unsequenced.cpp b/test/SemaCXX/warn-unsequenced.cpp
index 54e16a5e6d..9e8a5b46c2 100644
--- a/test/SemaCXX/warn-unsequenced.cpp
+++ b/test/SemaCXX/warn-unsequenced.cpp
@@ -113,3 +113,58 @@ void test() {
(__builtin_object_size(&(++a, a), 0) ? 1 : 0) + ++a; // ok
(__builtin_expect(++a, 0) ? 1 : 0) + ++a; // expected-warning {{multiple unsequenced modifications}}
}
+
+namespace templates {
+
+template <typename T>
+struct Bar {
+ T get() { return 0; }
+};
+
+template <typename X>
+struct Foo {
+ int Run();
+ Bar<int> bar;
+};
+
+enum E {e1, e2};
+bool operator&&(E, E);
+
+void foo(int, int);
+
+template <typename X>
+int Foo<X>::Run() {
+ char num = 0;
+
+ // Before instantiation, Clang may consider the builtin operator here as
+ // unresolved function calls, and treat the arguments as unordered when
+ // the builtin operator evaluatation is well-ordered. Waiting until
+ // instantiation to check these expressions will prevent false positives.
+ if ((num = bar.get()) < 5 && num < 10) { }
+ if ((num = bar.get()) < 5 || num < 10) { }
+ if (static_cast<E>((num = bar.get()) < 5) || static_cast<E>(num < 10)) { }
+
+ if (static_cast<E>((num = bar.get()) < 5) && static_cast<E>(num < 10)) { }
+ // expected-warning@-1 {{unsequenced modification and access to 'num'}}
+
+ foo(num++, num++);
+ // expected-warning@-1 2{{multiple unsequenced modifications to 'num'}}
+ return 1;
+}
+
+int x = Foo<int>().Run();
+// expected-note@-1 {{in instantiation of member function 'templates::Foo<int>::Run'}}
+
+
+template <typename T>
+int Run2() {
+ T t = static_cast<T>(0);
+ return (t = static_cast<T>(1)) && t;
+ // expected-warning@-1 {{unsequenced modification and access to 't'}}
+}
+
+int y = Run2<bool>();
+int z = Run2<E>();
+// expected-note@-1{{in instantiation of function template specialization 'templates::Run2<templates::E>' requested here}}
+
+}