aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-04-28 17:56:11 +0000
committerDouglas Gregor <dgregor@apple.com>2011-04-28 17:56:11 +0000
commita6ce3e6513f56e4d46399da9e35a3165b097f59e (patch)
tree4e286e67bbca0c6bd8ecece4b07c70c01bf630ab
parent25aaf28c5bec71d5d005df67ee78b908ba5940f4 (diff)
When determining whether two types are reference-compatible, check
non-CVR qualifiers as well as CVR qualifiers. For example, don't allow a reference to an integer in address space 1 to bind to an integer in address space 2. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130411 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaOverload.cpp7
-rw-r--r--test/SemaCXX/address-space-references.cpp19
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 5776820ab0..6c529208e4 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -3071,7 +3071,12 @@ Sema::CompareReferenceRelationship(SourceLocation Loc,
// overload resolution, cases for which cv1 is greater
// cv-qualification than cv2 are identified as
// reference-compatible with added qualification (see 13.3.3.2).
- if (T1Quals.getCVRQualifiers() == T2Quals.getCVRQualifiers())
+ //
+ // Note that we also require equivalence of Objective-C GC and address-space
+ // qualifiers when performing these computations, so that e.g., an int in
+ // address space 1 is not reference-compatible with an int in address
+ // space 2.
+ if (T1Quals == T2Quals)
return Ref_Compatible;
else if (T1.isMoreQualifiedThan(T2))
return Ref_Compatible_With_Added_Qualification;
diff --git a/test/SemaCXX/address-space-references.cpp b/test/SemaCXX/address-space-references.cpp
new file mode 100644
index 0000000000..f5a63d24a9
--- /dev/null
+++ b/test/SemaCXX/address-space-references.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef int __attribute__((address_space(1))) int_1;
+typedef int __attribute__((address_space(2))) int_2;
+
+void f0(int_1 &); // expected-note{{candidate function not viable: 1st argument ('int') is in address space 0, but parameter must be in address space 1}} \
+// expected-note{{candidate function not viable: 1st argument ('int_2' (aka '__attribute__((address_space(2))) int')) is in address space 2, but parameter must be in address space 1}}
+void f0(const int_1 &); // expected-note{{candidate function not viable: 1st argument ('int') is in address space 0, but parameter must be in address space 1}} \
+// expected-note{{candidate function not viable: 1st argument ('int_2' (aka '__attribute__((address_space(2))) int')) is in address space 2, but parameter must be in address space 1}}
+
+void test_f0() {
+ int i;
+ static int_1 i1;
+ static int_2 i2;
+
+ f0(i); // expected-error{{no matching function for call to 'f0'}}
+ f0(i1);
+ f0(i2); // expected-error{{no matching function for call to 'f0'}}
+}