summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/overloadable.c30
-rw-r--r--clang/test/Sema/overloadable.c25
-rw-r--r--clang/test/Sema/pass-object-size.c4
3 files changed, 56 insertions, 3 deletions
diff --git a/clang/test/CodeGen/overloadable.c b/clang/test/CodeGen/overloadable.c
index 4946c6d9286..634820cfe74 100644
--- a/clang/test/CodeGen/overloadable.c
+++ b/clang/test/CodeGen/overloadable.c
@@ -29,3 +29,33 @@ int main() {
cdv = f(cdv);
vv = f(vv);
}
+
+// Ensuring that we pick the correct function for taking the address of an
+// overload when conversions are involved.
+
+void addrof_many(int *a) __attribute__((overloadable, enable_if(0, "")));
+void addrof_many(void *a) __attribute__((overloadable));
+void addrof_many(char *a) __attribute__((overloadable));
+
+void addrof_single(int *a) __attribute__((overloadable, enable_if(0, "")));
+void addrof_single(char *a) __attribute__((overloadable, enable_if(0, "")));
+void addrof_single(char *a) __attribute__((overloadable));
+
+// CHECK-LABEL: define void @foo
+void foo() {
+ // CHECK: store void (i8*)* @_Z11addrof_manyPc
+ void (*p1)(char *) = &addrof_many;
+ // CHECK: store void (i8*)* @_Z11addrof_manyPv
+ void (*p2)(void *) = &addrof_many;
+ // CHECK: void (i8*)* @_Z11addrof_manyPc
+ void *vp1 = (void (*)(char *)) & addrof_many;
+ // CHECK: void (i8*)* @_Z11addrof_manyPv
+ void *vp2 = (void (*)(void *)) & addrof_many;
+
+ // CHECK: store void (i8*)* @_Z13addrof_singlePc
+ void (*p3)(char *) = &addrof_single;
+ // CHECK: @_Z13addrof_singlePc
+ void (*p4)(int *) = &addrof_single;
+ // CHECK: @_Z13addrof_singlePc
+ void *vp3 = &addrof_single;
+}
diff --git a/clang/test/Sema/overloadable.c b/clang/test/Sema/overloadable.c
index 3120649dbc0..5d95a317fa3 100644
--- a/clang/test/Sema/overloadable.c
+++ b/clang/test/Sema/overloadable.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wincompatible-pointer-types
int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute only applies to functions}}
void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}}
@@ -99,3 +99,26 @@ void conversions() {
unsigned char *c;
multi_type(c);
}
+
+// Ensure that we allow C-specific type conversions in C
+void fn_type_conversions() {
+ void foo(void *c) __attribute__((overloadable));
+ void foo(char *c) __attribute__((overloadable));
+ void (*ptr1)(void *) = &foo;
+ void (*ptr2)(char *) = &foo;
+ void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@105{{candidate function}} expected-note@106{{candidate function}}
+ void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type '<overloaded function type>'}} expected-note@105{{candidate function}} expected-note@106{{candidate function}}
+
+ void (*specific1)(int *) = (void (*)(void *))&foo; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type 'void (*)(void *)'}}
+ void *specific2 = (void (*)(void *))&foo;
+
+ void disabled(void *c) __attribute__((overloadable, enable_if(0, "")));
+ void disabled(int *c) __attribute__((overloadable, enable_if(c, "")));
+ void disabled(char *c) __attribute__((overloadable, enable_if(1, "The function name lies.")));
+ // To be clear, these should all point to the last overload of 'disabled'
+ void (*dptr1)(char *c) = &disabled;
+ void (*dptr2)(void *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'char *')}}
+ void (*dptr3)(int *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type '<overloaded function type>'}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'int *' but has 'char *')}}
+
+ void *specific_disabled = &disabled;
+}
diff --git a/clang/test/Sema/pass-object-size.c b/clang/test/Sema/pass-object-size.c
index 6f375c0e94d..ddfbbd5fc4e 100644
--- a/clang/test/Sema/pass-object-size.c
+++ b/clang/test/Sema/pass-object-size.c
@@ -38,8 +38,8 @@ void FunctionPtrs() {
void (*p)(void *) = NotOverloaded; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
void (*p2)(void *) = &NotOverloaded; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
- void (*p3)(void *) = IsOverloaded; //expected-error{{initializing 'void (*)(void *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@-6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-5{{type mismatch}}
- void (*p4)(void *) = &IsOverloaded; //expected-error{{initializing 'void (*)(void *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@-7{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-6{{type mismatch}}
+ void (*p3)(void *) = IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@-6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-5{{type mismatch}}
+ void (*p4)(void *) = &IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@-7{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-6{{type mismatch}}
void (*p5)(char *) = IsOverloaded;
void (*p6)(char *) = &IsOverloaded;
OpenPOWER on IntegriCloud