2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
|
|
|
|
// CHECK: _Z1fPA10_1X
|
2015-08-08 07:25:47 +08:00
|
|
|
// CHECK: _Z1fPFvE
|
2014-01-15 03:35:09 +08:00
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
int __attribute__((overloadable)) f(int x) { return x; }
|
|
|
|
float __attribute__((overloadable)) f(float x) { return x; }
|
|
|
|
double __attribute__((overloadable)) f(double x) { return x; }
|
|
|
|
double _Complex __attribute__((overloadable)) f(double _Complex x) { return x; }
|
|
|
|
typedef short v4hi __attribute__ ((__vector_size__ (8)));
|
|
|
|
v4hi __attribute__((overloadable)) f(v4hi x) { return x; }
|
|
|
|
|
|
|
|
struct X { };
|
|
|
|
void __attribute__((overloadable)) f(struct X (*ptr)[10]) { }
|
|
|
|
|
2009-02-13 09:28:03 +08:00
|
|
|
void __attribute__((overloadable)) f(int x, int y, ...) { }
|
|
|
|
|
2015-08-08 07:25:47 +08:00
|
|
|
void __attribute__((overloadable)) f(void (*x)()) {}
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
int main() {
|
|
|
|
int iv = 17;
|
|
|
|
float fv = 3.0f;
|
|
|
|
double dv = 4.0;
|
|
|
|
double _Complex cdv;
|
|
|
|
v4hi vv;
|
|
|
|
|
|
|
|
iv = f(iv);
|
|
|
|
fv = f(fv);
|
|
|
|
dv = f(dv);
|
|
|
|
cdv = f(cdv);
|
|
|
|
vv = f(vv);
|
|
|
|
}
|
2016-03-23 10:33:58 +08:00
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}void @foo
|
2016-03-23 10:33:58 +08:00
|
|
|
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;
|
|
|
|
}
|
2016-09-03 06:59:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
void ovl_bar(char *) __attribute__((overloadable));
|
|
|
|
void ovl_bar(int) __attribute__((overloadable));
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}void @bar
|
2016-09-03 06:59:57 +08:00
|
|
|
void bar() {
|
|
|
|
char charbuf[1];
|
|
|
|
unsigned char ucharbuf[1];
|
|
|
|
|
|
|
|
// CHECK: call void @_Z7ovl_barPc
|
|
|
|
ovl_bar(charbuf);
|
|
|
|
// CHECK: call void @_Z7ovl_barPc
|
|
|
|
ovl_bar(ucharbuf);
|
|
|
|
}
|
[Sema] Compare bad conversions in overload resolution.
r280553 introduced an issue where we'd emit ambiguity errors for code
like:
```
void foo(int *, int);
void foo(unsigned int *, unsigned int);
void callFoo() {
unsigned int i;
foo(&i, 0); // ambiguous: int->unsigned int is worse than int->int,
// but unsigned int*->unsigned int* is better than
// int*->int*.
}
```
This patch fixes this issue by changing how we handle ill-formed (but
valid) implicit conversions. Candidates with said conversions now always
rank worse than candidates without them, and two candidates are
considered to be equally bad if they both have these conversions for
the same argument.
Additionally, this fixes a case in C++11 where we'd complain about an
ambiguity in a case like:
```
void f(char *, int);
void f(const char *, unsigned);
void g() { f("abc", 0); }
```
...Since conversion to char* from a string literal is considered
ill-formed in C++11 (and deprecated in C++03), but we accept it as an
extension.
llvm-svn: 280847
2016-09-08 04:03:19 +08:00
|
|
|
|
|
|
|
void ovl_baz(int *, int) __attribute__((overloadable));
|
|
|
|
void ovl_baz(unsigned int *, unsigned int) __attribute__((overloadable));
|
|
|
|
void ovl_baz2(int, int *) __attribute__((overloadable));
|
|
|
|
void ovl_baz2(unsigned int, unsigned int *) __attribute__((overloadable));
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}void @baz
|
[Sema] Compare bad conversions in overload resolution.
r280553 introduced an issue where we'd emit ambiguity errors for code
like:
```
void foo(int *, int);
void foo(unsigned int *, unsigned int);
void callFoo() {
unsigned int i;
foo(&i, 0); // ambiguous: int->unsigned int is worse than int->int,
// but unsigned int*->unsigned int* is better than
// int*->int*.
}
```
This patch fixes this issue by changing how we handle ill-formed (but
valid) implicit conversions. Candidates with said conversions now always
rank worse than candidates without them, and two candidates are
considered to be equally bad if they both have these conversions for
the same argument.
Additionally, this fixes a case in C++11 where we'd complain about an
ambiguity in a case like:
```
void f(char *, int);
void f(const char *, unsigned);
void g() { f("abc", 0); }
```
...Since conversion to char* from a string literal is considered
ill-formed in C++11 (and deprecated in C++03), but we accept it as an
extension.
llvm-svn: 280847
2016-09-08 04:03:19 +08:00
|
|
|
void baz() {
|
|
|
|
unsigned int j;
|
|
|
|
// Initial rules for incompatible pointer conversions made this overload
|
|
|
|
// ambiguous.
|
|
|
|
// CHECK: call void @_Z7ovl_bazPjj
|
|
|
|
ovl_baz(&j, 0);
|
|
|
|
// CHECK: call void @_Z7ovl_bazPjj
|
|
|
|
ovl_baz(&j, 0u);
|
|
|
|
|
|
|
|
// CHECK: call void @_Z8ovl_baz2jPj
|
|
|
|
ovl_baz2(0, &j);
|
|
|
|
// CHECK: call void @_Z8ovl_baz2jPj
|
|
|
|
ovl_baz2(0u, &j);
|
|
|
|
}
|