diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-16 19:47:09 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-16 19:47:09 +0000 |
commit | 2410013d9382b8129702fa3a3bf19a370ae7afc3 (patch) | |
tree | df038b6418b19d03437950dcee799c1483c6246a /test | |
parent | 0a5fb09b599c1bdea3cd11168bb8f4ff4040316e (diff) | |
download | src-2410013d9382b8129702fa3a3bf19a370ae7afc3.tar.gz src-2410013d9382b8129702fa3a3bf19a370ae7afc3.zip |
Vendor import of clang trunk r303197:vendor/clang/clang-trunk-r303197
Notes
Notes:
svn path=/vendor/clang/dist/; revision=318370
svn path=/vendor/clang/clang-trunk-r303197/; revision=318371; tag=vendor/clang/clang-trunk-r303197
Diffstat (limited to 'test')
94 files changed, 1974 insertions, 187 deletions
diff --git a/test/Analysis/builtin-assume.c b/test/Analysis/builtin-assume.c new file mode 100644 index 000000000000..00d651d9e3be --- /dev/null +++ b/test/Analysis/builtin-assume.c @@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s + +void clang_analyzer_eval(int); + +void f(int i) { + __builtin_assume(i < 10); + clang_analyzer_eval(i < 15); // expected-warning {{TRUE}} +} diff --git a/test/CXX/drs/dr20xx.cpp b/test/CXX/drs/dr20xx.cpp new file mode 100644 index 000000000000..b97a9a46bc85 --- /dev/null +++ b/test/CXX/drs/dr20xx.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors \ +// RUN: -Wno-variadic-macros -Wno-c11-extensions +// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors + +// expected-no-diagnostics + +#if __cplusplus < 201103L +#define static_assert(...) _Static_assert(__VA_ARGS__) +#endif + +namespace dr2094 { // dr2094: 5.0 + struct A { int n; }; + struct B { volatile int n; }; + static_assert(__is_trivially_copyable(volatile int), ""); + static_assert(__is_trivially_copyable(const volatile int), ""); + static_assert(__is_trivially_copyable(const volatile int[]), ""); + static_assert(__is_trivially_copyable(A), ""); + static_assert(__is_trivially_copyable(volatile A), ""); + static_assert(__is_trivially_copyable(const volatile A), ""); + static_assert(__is_trivially_copyable(const volatile A[]), ""); + static_assert(__is_trivially_copyable(B), ""); + + static_assert(__is_trivially_constructible(A, A const&), ""); + static_assert(__is_trivially_constructible(B, B const&), ""); + + static_assert(__is_trivially_assignable(A, const A&), ""); + static_assert(__is_trivially_assignable(B, const B&), ""); +} diff --git a/test/CXX/drs/dr4xx.cpp b/test/CXX/drs/dr4xx.cpp index 3ea226a745f6..a55bb91be558 100644 --- a/test/CXX/drs/dr4xx.cpp +++ b/test/CXX/drs/dr4xx.cpp @@ -1202,16 +1202,15 @@ namespace dr495 { // dr495: 3.5 long n2 = s2; } -namespace dr496 { // dr496: no +namespace dr496 { // dr496: sup dr2094 struct A { int n; }; struct B { volatile int n; }; int check1[ __is_trivially_copyable(const int) ? 1 : -1]; - int check2[!__is_trivially_copyable(volatile int) ? 1 : -1]; + // This checks the dr2094 behavior, not dr496 + int check2[ __is_trivially_copyable(volatile int) ? 1 : -1]; int check3[ __is_trivially_constructible(A, const A&) ? 1 : -1]; - // FIXME: This is wrong. int check4[ __is_trivially_constructible(B, const B&) ? 1 : -1]; int check5[ __is_trivially_assignable(A, const A&) ? 1 : -1]; - // FIXME: This is wrong. int check6[ __is_trivially_assignable(B, const B&) ? 1 : -1]; } diff --git a/test/CodeCompletion/member-access.cpp b/test/CodeCompletion/member-access.cpp index 66872272ee6d..53af121951bb 100644 --- a/test/CodeCompletion/member-access.cpp +++ b/test/CodeCompletion/member-access.cpp @@ -66,3 +66,83 @@ struct Bar { // Make sure this also doesn't crash // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:47:14 %s + + +template<typename T> +class BaseTemplate { +public: + T baseTemplateFunction(); + + T baseTemplateField; +}; + +template<typename T, typename S> +class TemplateClass: public Base1 , public BaseTemplate<T> { +public: + T function() { } + T field; + + void overload1(const T &); + void overload1(const S &); +}; + +template<typename T, typename S> +void completeDependentMembers(TemplateClass<T, S> &object, + TemplateClass<int, S> *object2) { + object.field; + object2->field; +// CHECK-CC2: baseTemplateField : [#T#][#BaseTemplate<T>::#]baseTemplateField +// CHECK-CC2: baseTemplateFunction : [#T#][#BaseTemplate<T>::#]baseTemplateFunction() +// CHECK-CC2: field : [#T#]field +// CHECK-CC2: function : [#T#]function() +// CHECK-CC2: member1 : [#int#][#Base1::#]member1 +// CHECK-CC2: member2 : [#float#][#Base1::#]member2 +// CHECK-CC2: overload1 : [#void#]overload1(<#const T &#>) +// CHECK-CC2: overload1 : [#void#]overload1(<#const S &#>) + +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:92:10 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:93:12 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s +} + + +void completeDependentSpecializedMembers(TemplateClass<int, double> &object, + TemplateClass<int, double> *object2) { + object.field; + object2->field; +// CHECK-CC3: baseTemplateField : [#int#][#BaseTemplate<int>::#]baseTemplateField +// CHECK-CC3: baseTemplateFunction : [#int#][#BaseTemplate<int>::#]baseTemplateFunction() +// CHECK-CC3: field : [#int#]field +// CHECK-CC3: function : [#int#]function() +// CHECK-CC3: member1 : [#int#][#Base1::#]member1 +// CHECK-CC3: member2 : [#float#][#Base1::#]member2 +// CHECK-CC3: overload1 : [#void#]overload1(<#const int &#>) +// CHECK-CC3: overload1 : [#void#]overload1(<#const double &#>) + +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:110:10 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:111:12 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s +} + +template <typename T> +class Template { +public: + BaseTemplate<int> o1; + BaseTemplate<T> o2; + + void function() { + o1.baseTemplateField; +// CHECK-CC4: BaseTemplate : BaseTemplate:: +// CHECK-CC4: baseTemplateField : [#int#]baseTemplateField +// CHECK-CC4: baseTemplateFunction : [#int#]baseTemplateFunction() +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:132:8 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s + o2.baseTemplateField; +// CHECK-CC5: BaseTemplate : BaseTemplate:: +// CHECK-CC5: baseTemplateField : [#T#]baseTemplateField +// CHECK-CC5: baseTemplateFunction : [#T#]baseTemplateFunction() +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:137:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s + this->o1; +// CHECK-CC6: [#void#]function() +// CHECK-CC6: o1 : [#BaseTemplate<int>#]o1 +// CHECK-CC6: o2 : [#BaseTemplate<T>#]o2 +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:142:11 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s + } +}; diff --git a/test/CodeGen/asan-globals-gc.cpp b/test/CodeGen/asan-globals-gc.cpp index 6d64f41dda8d..58ce5f067563 100644 --- a/test/CodeGen/asan-globals-gc.cpp +++ b/test/CodeGen/asan-globals-gc.cpp @@ -1,5 +1,16 @@ -// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITH-GC -// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC + +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-data-sections -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC + +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-data-sections -emit-llvm -o - -triple x86_64-apple-macosx11 %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - -triple x86_64-apple-macosx11 %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple x86_64-apple-macosx11 %s | FileCheck %s --check-prefix=WITHOUT-GC int global; diff --git a/test/CodeGen/asan-no-globals-no-comdat.cpp b/test/CodeGen/asan-no-globals-no-comdat.cpp new file mode 100644 index 000000000000..4637346f9c41 --- /dev/null +++ b/test/CodeGen/asan-no-globals-no-comdat.cpp @@ -0,0 +1,11 @@ +// Test that on Linux asan constructor is placed in a comdat iff globals-gc is on. +// Even if there are no globals in the module. + +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -fsanitize-address-globals-dead-stripping -fno-integrated-as -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC + +// WITH-GC: define internal void @asan.module_ctor() comdat { +// WITHOUT-GC: define internal void @asan.module_ctor() { diff --git a/test/CodeGen/mips-aggregate-arg.c b/test/CodeGen/mips-aggregate-arg.c new file mode 100644 index 000000000000..ccf30df7c22a --- /dev/null +++ b/test/CodeGen/mips-aggregate-arg.c @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple mipsel-unknown-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefix=O32 %s +// RUN: %clang_cc1 -triple mips64el-unknown-linux-gnu -S -emit-llvm -o - %s -target-abi n32 | FileCheck -check-prefix=N32-N64 %s +// RUN: %clang_cc1 -triple mips64el-unknown-linux-gnu -S -emit-llvm -o - %s -target-abi n64 | FileCheck -check-prefix=N32-N64 %s + +struct t1 { + char t1[10]; +}; + +struct t2 { + char t2[20]; +}; + +struct t3 { + char t3[65]; +}; + +extern struct t1 g1; +extern struct t2 g2; +extern struct t3 g3; +extern void f1(struct t1); +extern void f2(struct t2); +extern void f3(struct t3); + +void f() { + +// O32: call void @f1(i32 inreg %{{[0-9]+}}, i32 inreg %{{[0-9]+}}, i16 inreg %{{[0-9]+}}) +// O32: call void @f2(%struct.t2* byval align 4 %{{.*}}) +// O32: call void @f3(%struct.t3* byval align 4 %{{.*}}) + +// N32-N64: call void @f1(i64 inreg %{{[0-9]+}}, i16 inreg %{{[0-9]+}}) +// N32-N64: call void @f2(i64 inreg %{{[0-9]+}}, i64 inreg %{{[0-9]+}}, i32 inreg %{{[0-9]+}}) +// N32-N64: call void @f3(%struct.t3* byval align 8 %{{.*}}) + + f1(g1); + f2(g2); + f3(g3); +} + diff --git a/test/CodeGen/sanitize-recover.c b/test/CodeGen/sanitize-recover.c index d714d58c7f26..6358d9d04aa1 100644 --- a/test/CodeGen/sanitize-recover.c +++ b/test/CodeGen/sanitize-recover.c @@ -7,12 +7,12 @@ void test() { extern volatile unsigned x, y, z; - // RECOVER: uadd.with.overflow.i32 - // RECOVER: ubsan_handle_add_overflow( + // RECOVER: uadd.with.overflow.i32{{.*}}, !nosanitize + // RECOVER: ubsan_handle_add_overflow({{.*}}, !nosanitize // RECOVER-NOT: unreachable - // ABORT: uadd.with.overflow.i32 - // ABORT: ubsan_handle_add_overflow_abort( - // ABORT: unreachable + // ABORT: uadd.with.overflow.i32{{.*}}, !nosanitize + // ABORT: ubsan_handle_add_overflow_abort({{.*}}, !nosanitize + // ABORT: unreachable{{.*}}, !nosanitize x = y + z; } diff --git a/test/CodeGen/sparcv8-inline-asm.c b/test/CodeGen/sparcv8-inline-asm.c new file mode 100644 index 000000000000..711a2a0afbb0 --- /dev/null +++ b/test/CodeGen/sparcv8-inline-asm.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | FileCheck %s + +// CHECK: define float @fabsf(float %a) +// CHECK: %{{.*}} = call float asm sideeffect "fabss $1, $0;", "=e,f"(float %{{.*}}) #1 +float fabsf(float a) { + float res; + __asm __volatile__("fabss %1, %0;" + : /* reg out*/ "=e"(res) + : /* reg in */ "f"(a)); + return res; +} diff --git a/test/CodeGen/thinlto_backend.ll b/test/CodeGen/thinlto_backend.ll index 813bb62c1a29..86f30c0374fc 100644 --- a/test/CodeGen/thinlto_backend.ll +++ b/test/CodeGen/thinlto_backend.ll @@ -12,10 +12,10 @@ ; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc' -; Ensure we ignore empty index file under -ignore-empty-index-file, and run -; non-ThinLTO compilation which would not import f2 +; Ensure we ignore empty index file, and run non-ThinLTO compilation which +; would not import f2 ; RUN: touch %t4.thinlto.bc -; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=%t4.thinlto.bc -mllvm -ignore-empty-index-file +; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=%t4.thinlto.bc ; RUN: llvm-nm %t4.o | FileCheck --check-prefix=CHECK-OBJ-IGNORE-EMPTY %s ; CHECK-OBJ-IGNORE-EMPTY: T f1 ; CHECK-OBJ-IGNORE-EMPTY: U f2 diff --git a/test/CodeGen/x86_64-mno-sse.c b/test/CodeGen/x86_64-mno-sse.c new file mode 100644 index 000000000000..43a695ae3cd3 --- /dev/null +++ b/test/CodeGen/x86_64-mno-sse.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple x86_64-linux -target-feature -sse -target-feature -sse2 -S -o /dev/null -verify %s +// REQUIRES: x86-registered-target + +double f1(void) { // expected-error {{SSE register return with SSE disabled}} + return 1.4; +} +extern double g; +void f2(void) { // expected-error {{SSE register return with SSE disabled}} + g = f1(); +} +void take_double(double); +void pass_double(void) { + // FIXME: Still asserts. + //take_double(1.5); +} diff --git a/test/CodeGen/xray-customevent.cpp b/test/CodeGen/xray-customevent.cpp new file mode 100644 index 000000000000..359d92df938a --- /dev/null +++ b/test/CodeGen/xray-customevent.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @_Z16alwaysInstrumentv +[[clang::xray_always_instrument]] void alwaysInstrument() { + static constexpr char kPhase[] = "instrument"; + __xray_customevent(kPhase, 10); + // CHECK: call void @llvm.xray.customevent(i8*{{.*}}, i32 10) +} + +// CHECK-LABEL: @_Z15neverInstrumentv +[[clang::xray_never_instrument]] void neverInstrument() { + static constexpr char kPhase[] = "never"; + __xray_customevent(kPhase, 5); + // CHECK-NOT: call void @llvm.xray.customevent(i8*{{.*}}, i32 5) +} + +// CHECK-LABEL: @_Z21conditionalInstrumenti +[[clang::xray_always_instrument]] void conditionalInstrument(int v) { + static constexpr char kTrue[] = "true"; + static constexpr char kUntrue[] = "untrue"; + if (v % 2) + __xray_customevent(kTrue, 4); + else + __xray_customevent(kUntrue, 6); + + // CHECK: call void @llvm.xray.customevent(i8*{{.*}}, i32 4) + // CHECK: call void @llvm.xray.customevent(i8*{{.*}}, i32 6) +} diff --git a/test/CodeGenCXX/array-default-argument.cpp b/test/CodeGenCXX/array-default-argument.cpp new file mode 100644 index 000000000000..a07e3908392a --- /dev/null +++ b/test/CodeGenCXX/array-default-argument.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s -triple %itanium_abi_triple | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - %s -triple %itanium_abi_triple -std=c++98 -fexceptions -fcxx-exceptions | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-EH + +struct A { + A(); + ~A(); +}; + +struct B { + B(A = A()); + ~B(); +}; + +void f(); +// CHECK-LABEL: define void @_Z1gv() +void g() { + // CHECK: br label %[[LOOP:.*]] + + // [[LOOP]]: + // CHECK: {{call|invoke}} {{.*}} @_ZN1AC1Ev([[TEMPORARY:.*]]) + // CHECK-EH: unwind label %[[PARTIAL_ARRAY_LPAD:.*]] + // CHECK: {{call|invoke}} {{.*}} @_ZN1BC1E1A({{.*}}, [[TEMPORARY]]) + // CHECK-EH: unwind label %[[A_AND_PARTIAL_ARRAY_LPAD:.*]] + // CHECK: {{call|invoke}} {{.*}} @_ZN1AD1Ev([[TEMPORARY]]) + // CHECK-EH: unwind label %[[PARTIAL_ARRAY_LPAD]] + // CHECK: getelementptr {{.*}}, i{{[0-9]*}} 1 + // CHECK: icmp eq + // CHECK: br i1 {{.*}} label %[[LOOP]] + B b[5]; + + // CHECK: {{call|invoke}} void @_Z1fv() + f(); + + // CHECK-NOT: @_ZN1AD1Ev( + // CHECK: {{call|invoke}} {{.*}} @_ZN1BD1Ev( +} diff --git a/test/CodeGenCXX/linetable-virtual-variadic.cpp b/test/CodeGenCXX/linetable-virtual-variadic.cpp index 6f966416867a..cd746cdfdfe2 100644 --- a/test/CodeGenCXX/linetable-virtual-variadic.cpp +++ b/test/CodeGenCXX/linetable-virtual-variadic.cpp @@ -12,8 +12,10 @@ void Derived::VariadicFunction(...) { } // CHECK: define void @_ZN7Derived16VariadicFunctionEz({{.*}} !dbg ![[SP:[0-9]+]] // CHECK: ret void, !dbg ![[LOC:[0-9]+]] -// CHECK-LABEL: define void @_ZT{{.+}}N7Derived16VariadicFunctionEz( -// CHECK: ret void, !dbg ![[LOC:[0-9]+]] +// CHECK: define void @_ZT{{.+}}N7Derived16VariadicFunctionEz({{.*}} !dbg ![[SP_I:[0-9]+]] +// CHECK: ret void, !dbg ![[LOC_I:[0-9]+]] // // CHECK: ![[SP]] = distinct !DISubprogram(name: "VariadicFunction" // CHECK: ![[LOC]] = !DILocation({{.*}}scope: ![[SP]]) +// CHECK: ![[SP_I]] = distinct !DISubprogram(name: "VariadicFunction" +// CHECK: ![[LOC_I]] = !DILocation({{.*}}scope: ![[SP_I]]) diff --git a/test/CodeGenCXX/vla.cpp b/test/CodeGenCXX/vla.cpp index 4e22bba7d719..957a9f9568b3 100644 --- a/test/CodeGenCXX/vla.cpp +++ b/test/CodeGenCXX/vla.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s template<typename T> struct S { @@ -54,3 +54,60 @@ void test0(void *array, int n) { // CHECK-NEXT: ret void } + + +void test2(int b) { + // CHECK-LABEL: define void {{.*}}test2{{.*}}(i32 %b) + int varr[b]; + // get the address of %b by checking the first store that stores it + //CHECK: store i32 %b, i32* [[PTR_B:%.*]] + + // get the size of the VLA by getting the first load of the PTR_B + //CHECK: [[VLA_NUM_ELEMENTS_PREZEXT:%.*]] = load i32, i32* [[PTR_B]] + //CHECK-NEXT: [[VLA_NUM_ELEMENTS_PRE:%.*]] = zext i32 [[VLA_NUM_ELEMENTS_PREZEXT]] + + b = 15; + //CHECK: store i32 15, i32* [[PTR_B]] + + // Now get the sizeof, and then divide by the element size + + + //CHECK: [[VLA_SIZEOF:%.*]] = mul nuw i64 4, [[VLA_NUM_ELEMENTS_PRE]] + //CHECK-NEXT: [[VLA_NUM_ELEMENTS_POST:%.*]] = udiv i64 [[VLA_SIZEOF]], 4 + //CHECK-NEXT: [[VLA_END_PTR:%.*]] = getelementptr inbounds i32, i32* {{%.*}}, i64 [[VLA_NUM_ELEMENTS_POST]] + //CHECK-NEXT: store i32* [[VLA_END_PTR]], i32** %__end + for (int d : varr) 0; +} + +void test3(int b, int c) { + // CHECK-LABEL: define void {{.*}}test3{{.*}}(i32 %b, i32 %c) + int varr[b][c]; + // get the address of %b by checking the first store that stores it + //CHECK: store i32 %b, i32* [[PTR_B:%.*]] + //CHECK-NEXT: store i32 %c, i32* [[PTR_C:%.*]] + + // get the size of the VLA by getting the first load of the PTR_B + //CHECK: [[VLA_DIM1_PREZEXT:%.*]] = load i32, i32* [[PTR_B]] + //CHECK-NEXT: [[VLA_DIM1_PRE:%.*]] = zext i32 [[VLA_DIM1_PREZEXT]] + //CHECK: [[VLA_DIM2_PREZEXT:%.*]] = load i32, i32* [[PTR_C]] + //CHECK-NEXT: [[VLA_DIM2_PRE:%.*]] = zext i32 [[VLA_DIM2_PREZEXT]] + + b = 15; + c = 15; + //CHECK: store i32 15, i32* [[PTR_B]] + //CHECK: store i32 15, i32* [[PTR_C]] + // Now get the sizeof, and then divide by the element size + + // multiply the two dimensions, then by the element type and then divide by the sizeof dim2 + //CHECK: [[VLA_DIM1_X_DIM2:%.*]] = mul nuw i64 [[VLA_DIM1_PRE]], [[VLA_DIM2_PRE]] + //CHECK-NEXT: [[VLA_SIZEOF:%.*]] = mul nuw i64 4, [[VLA_DIM1_X_DIM2]] + //CHECK-NEXT: [[VLA_SIZEOF_DIM2:%.*]] = mul nuw i64 4, [[VLA_DIM2_PRE]] + //CHECK-NEXT: [[VLA_NUM_ELEMENTS:%.*]] = udiv i64 [[VLA_SIZEOF]], [[VLA_SIZEOF_DIM2]] + //CHECK-NEXT: [[VLA_END_INDEX:%.*]] = mul nsw i64 [[VLA_NUM_ELEMENTS]], [[VLA_DIM2_PRE]] + //CHECK-NEXT: [[VLA_END_PTR:%.*]] = getelementptr inbounds i32, i32* {{%.*}}, i64 [[VLA_END_INDEX]] + //CHECK-NEXT: store i32* [[VLA_END_PTR]], i32** %__end + + for (auto &d : varr) 0; +} + + diff --git a/test/CodeGenObjC/arc-blocks.m b/test/CodeGenObjC/arc-blocks.m index 69cd7bb297b2..b84d141037e0 100644 --- a/test/CodeGenObjC/arc-blocks.m +++ b/test/CodeGenObjC/arc-blocks.m @@ -752,6 +752,16 @@ void test19(void (^b)(void)) { // CHECK-NEXT: call void @objc_release(i8* [[X]]) // CHECK-NEXT: ret void +// CHECK-UNOPT-LABEL: define void @test20( +// CHECK-UNOPT: [[XADDR:%.*]] = alloca i8* +// CHECK-UNOPT-NEXT: [[BLOCK:%.*]] = alloca <[[BLOCKTY:.*]]> +// CHECK-UNOPT: [[CAPTUREFIELD:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCK]], i32 0, i32 5 +// CHECK-UNOPT: [[BLOCKCAPTURED:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCK]], i32 0, i32 5 +// CHECK-UNOPT: [[CAPTURED:%.*]] = load i8*, i8** [[XADDR]] +// CHECK-UNOPT: [[RETAINED:%.*]] = call i8* @objc_retain(i8* [[CAPTURED]]) +// CHECK-UNOPT: store i8* [[RETAINED]], i8** [[BLOCKCAPTURED]] +// CHECK-UNOPT: call void @objc_storeStrong(i8** [[CAPTUREFIELD]], i8* null) + // CHECK-LABEL: define internal void @__copy_helper_block // CHECK: [[BLOCKSOURCE:%.*]] = bitcast i8* %{{.*}} to <[[BLOCKTY]]>* // CHECK: [[CAPTUREFIELD:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCKSOURCE]], i32 0, i32 5 diff --git a/test/CodeGenObjC/arc-foreach.m b/test/CodeGenObjC/arc-foreach.m index e3b3f1aa5ce4..77cb068187fa 100644 --- a/test/CodeGenObjC/arc-foreach.m +++ b/test/CodeGenObjC/arc-foreach.m @@ -68,7 +68,8 @@ void test0(NSArray *array) { // CHECK-LP64: [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 // CHECK-LP64-NEXT: [[T1:%.*]] = load i8*, i8** [[X]] -// CHECK-LP64-NEXT: store i8* [[T1]], i8** [[T0]] +// CHECK-LP64-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]] // CHECK-LP64-NEXT: [[BLOCK1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] // CHECK-LP64-NEXT: call void @use_block(void ()* [[BLOCK1]]) // CHECK-LP64-NEXT: call void @objc_storeStrong(i8** [[D0]], i8* null) @@ -209,7 +210,8 @@ NSArray *array4; // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5 // CHECK-LP64: [[BC:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5 // CHECK-LP64: [[T1:%.*]] = load [[TY]]*, [[TY]]** [[SELF_ADDR]] -// CHECK-LP64: store [[TY]]* [[T1]], [[TY]]** [[BC]], align 8 +// CHECK-LP64: [[T2:%.*]] = bitcast [[TY]]* [[T1]] to i8* +// CHECK-LP64: call i8* @objc_retain(i8* [[T2]]) // CHECK-LP64-OPT-LABEL: define internal void @"\01-[I1 foo2]"( // CHECK-LP64-OPT: [[TY:%.*]]* %self diff --git a/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl b/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl index c0b30095a679..7baee5eee391 100644 --- a/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl +++ b/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl @@ -58,16 +58,16 @@ kernel void kernel1( // CHECK-DAG: !DILocalVariable(name: "FuncVar4", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]]) int *FuncVar4 = Tmp1; - // CHECK-DAG: !DILocalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]]) - global int *constant FuncVar5 = KernelArg0; - // CHECK-DAG: !DILocalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]]) - constant int *constant FuncVar6 = KernelArg1; - // CHECK-DAG: !DILocalVariable(name: "FuncVar7", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]]) - local int *constant FuncVar7 = KernelArg2; - // CHECK-DAG: !DILocalVariable(name: "FuncVar8", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]]) - private int *constant FuncVar8 = Tmp0; - // CHECK-DAG: !DILocalVariable(name: "FuncVar9", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]]) - int *constant FuncVar9 = Tmp1; + // CHECK-DAG: distinct !DIGlobalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]], isLocal: true, isDefinition: true) + global int *constant FuncVar5 = 0; + // CHECK-DAG: distinct !DIGlobalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]], isLocal: true, isDefinition: true) + constant int *constant FuncVar6 = 0; + // CHECK-DAG: distinct !DIGlobalVariable(name: "FuncVar7", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_LOCAL]], isLocal: true, isDefinition: true) + local int *constant FuncVar7 = 0; + // CHECK-DAG: distinct !DIGlobalVariable(name: "FuncVar8", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_PRIVATE]], isLocal: true, isDefinition: true) + private int *constant FuncVar8 = 0; + // CHECK-DAG: distinct !DIGlobalVariable(name: "FuncVar9", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]], isLocal: true, isDefinition: true) + int *constant FuncVar9 = 0; // CHECK-DAG: distinct !DIGlobalVariable(name: "FuncVar10", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[DWARF_ADDRESS_SPACE_NONE]], isLocal: true, isDefinition: true) global int *local FuncVar10; FuncVar10 = KernelArg0; diff --git a/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl b/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl index a962d3c75aaf..c0a4c21ce760 100644 --- a/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl +++ b/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl @@ -80,21 +80,21 @@ kernel void kernel1( // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(4)** {{.*}}, metadata ![[FUNCVAR4]], metadata ![[PRIVATE]]), !dbg !{{[0-9]+}} int *FuncVar4 = Tmp1; - // CHECK-DAG: ![[FUNCVAR5:[0-9]+]] = !DILocalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}) - // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE:[0-9]+]]), !dbg !{{[0-9]+}} - global int *constant FuncVar5 = KernelArg0; - // CHECK-DAG: ![[FUNCVAR6:[0-9]+]] = !DILocalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}) - // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(2)** {{.*}}, metadata ![[FUNCVAR6]], metadata ![[NONE]]), !dbg !{{[0-9]+}} - constant int *constant FuncVar6 = KernelArg1; - // CHECK-DAG: ![[FUNCVAR7:[0-9]+]] = !DILocalVariable(name: "FuncVar7", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}) - // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(3)** {{.*}}, metadata ![[FUNCVAR7]], metadata ![[NONE]]), !dbg !{{[0-9]+}} - local int *constant FuncVar7 = KernelArg2; - // CHECK-DAG: ![[FUNCVAR8:[0-9]+]] = !DILocalVariable(name: "FuncVar8", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}) - // CHECK-DAG: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[FUNCVAR8]], metadata ![[NONE]]), !dbg !{{[0-9]+}} - private int *constant FuncVar8 = Tmp0; - // CHECK-DAG: ![[FUNCVAR9:[0-9]+]] = !DILocalVariable(name: "FuncVar9", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}) - // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(4)** {{.*}}, metadata ![[FUNCVAR9]], metadata ![[NONE]]), !dbg !{{[0-9]+}} - int *constant FuncVar9 = Tmp1; + // CHECK-DAG: ![[FUNCVAR5:[0-9]+]] = distinct !DIGlobalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: true, isDefinition: true) + // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FUNCVAR5]]) + global int *constant FuncVar5 = 0; + // CHECK-DAG: ![[FUNCVAR6:[0-9]+]] = distinct !DIGlobalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: true, isDefinition: true) + // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FUNCVAR6]]) + constant int *constant FuncVar6 = 0; + // CHECK-DAG: ![[FUNCVAR7:[0-9]+]] = distinct !DIGlobalVariable(name: "FuncVar7", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: true, isDefinition: true) + // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FUNCVAR7]]) + local int *constant FuncVar7 = 0; + // CHECK-DAG: ![[FUNCVAR8:[0-9]+]] = distinct !DIGlobalVariable(name: "FuncVar8", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: true, isDefinition: true) + // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FUNCVAR8]]) + private int *constant FuncVar8 = 0; + // CHECK-DAG: ![[FUNCVAR9:[0-9]+]] = distinct !DIGlobalVariable(name: "FuncVar9", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: true, isDefinition: true) + // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FUNCVAR9]]) + int *constant FuncVar9 = 0; // CHECK-DAG: ![[FUNCVAR10:[0-9]+]] = distinct !DIGlobalVariable(name: "FuncVar10", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, isLocal: true, isDefinition: true) // CHECK-DAG: !DIGlobalVariableExpression(var: ![[FUNCVAR10]], expr: ![[LOCAL]]) diff --git a/test/CodeGenOpenCL/constant-addr-space-globals.cl b/test/CodeGenOpenCL/constant-addr-space-globals.cl index 4f0d1ea23e56..7bb970527c26 100644 --- a/test/CodeGenOpenCL/constant-addr-space-globals.cl +++ b/test/CodeGenOpenCL/constant-addr-space-globals.cl @@ -11,10 +11,11 @@ kernel void test(global float *out) { // but create a copy in the original address space (unless a variable itself is // in the constant address space). -void foo(constant const int *p1, const int *p2, const int *p3); +void foo(constant int* p, constant const int *p1, const int *p2, const int *p3); // CHECK: @k.arr1 = internal addrspace(2) constant [3 x i32] [i32 1, i32 2, i32 3] // CHECK: @k.arr2 = private unnamed_addr addrspace(2) constant [3 x i32] [i32 4, i32 5, i32 6] // CHECK: @k.arr3 = private unnamed_addr addrspace(2) constant [3 x i32] [i32 7, i32 8, i32 9] +// CHECK: @k.var1 = internal addrspace(2) constant i32 1 kernel void k(void) { // CHECK-NOT: %arr1 = alloca [3 x i32] constant const int arr1[] = {1, 2, 3}; @@ -23,5 +24,8 @@ kernel void k(void) { // CHECK: %arr3 = alloca [3 x i32] int arr3[] = {7, 8, 9}; - foo(arr1, arr2, arr3); + constant int var1 = 1; + + // CHECK: call spir_func void @foo(i32 addrspace(2)* @k.var1, i32 addrspace(2)* getelementptr inbounds ([3 x i32], [3 x i32] addrspace(2)* @k.arr1, i32 0, i32 0) + foo(&var1, arr1, arr2, arr3); } diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 05e239c74243..41f573aa7316 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -30,7 +30,7 @@ // RUN: %clang -target x86_64-pc-win32 -fsanitize-coverage=bb %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COVERAGE-WIN64 // CHECK-COVERAGE-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib" -// RUN: %clang -target x86_64-linux-gnu -fsanitize=integer %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-INTEGER +// RUN: %clang -target x86_64-linux-gnu -fsanitize=integer %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-INTEGER -implicit-check-not="-fsanitize-address-use-after-scope" // CHECK-INTEGER: "-fsanitize={{((signed-integer-overflow|unsigned-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent),?){5}"}} // RUN: %clang -fsanitize=bounds -### -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOUNDS @@ -126,6 +126,13 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-WITHOUT-USE-AFTER-SCOPE // CHECK-ASAN-WITHOUT-USE-AFTER-SCOPE: -cc1{{.*}}address-use-after-scope +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-globals-dead-stripping %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS +// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS +// RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS +// CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping +// CHECK-NO-ASAN-GLOBALS-NOT: -cc1{{.*}}-fsanitize-address-globals-dead-stripping + // RUN: %clang -target x86_64-linux-gnu -fsanitize-memory-track-origins -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ONLY-TRACK-ORIGINS // CHECK-ONLY-TRACK-ORIGINS: warning: argument unused during compilation: '-fsanitize-memory-track-origins' diff --git a/test/Driver/myriad-toolchain.c b/test/Driver/myriad-toolchain.c index 971e5d3e6961..7bd215bf1a48 100644 --- a/test/Driver/myriad-toolchain.c +++ b/test/Driver/myriad-toolchain.c @@ -54,9 +54,11 @@ // -fno-split-dwarf-inlining is consumed but not passed to moviCompile. // RUN: %clang -target shave-myriad -c -### %s -g -fno-inline-functions \ // RUN: -fno-inline-functions-called-once -Os -Wall -MF dep.d -fno-split-dwarf-inlining \ -// RUN: -ffunction-sections 2>&1 | FileCheck %s -check-prefix=PASSTHRU_OPTIONS +// RUN: -ffunction-sections -Xclang -xclangflag -mllvm -llvm-flag 2>&1 \ +// RUN: | FileCheck %s -check-prefix=PASSTHRU_OPTIONS // PASSTHRU_OPTIONS: "-g" "-fno-inline-functions" "-fno-inline-functions-called-once" // PASSTHRU_OPTIONS: "-Os" "-Wall" "-MF" "dep.d" "-ffunction-sections" +// PASSTHRU_OPTIONS: "-Xclang" "-xclangflag" "-mllvm" "-llvm-flag" // RUN: %clang -target shave-myriad -c %s -o foo.o -### -MD -MF dep.d 2>&1 \ // RUN: | FileCheck %s -check-prefix=MDMF diff --git a/test/Driver/wasm-toolchain.c b/test/Driver/wasm-toolchain.c index d0b029303891..3be60df92672 100644 --- a/test/Driver/wasm-toolchain.c +++ b/test/Driver/wasm-toolchain.c @@ -27,18 +27,18 @@ // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK: lld{{.*}}" "-flavor" "ld" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" +// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" // A basic C link command-line with optimization. WebAssembly is somewhat // special in enabling --gc-sections by default. // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_OPT: lld{{.*}}" "-flavor" "ld" "--gc-sections" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" +// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" // Ditto, but ensure that a user --no-gc-sections comes after the // default --gc-sections. // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo -Wl,--no-gc-sections %s 2>&1 | FileCheck -check-prefix=NO_GC_SECTIONS %s // NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "ld" "--gc-sections" "-L/foo/lib32" "crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" +// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" "crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out" diff --git a/test/FixIt/fixit-availability.c b/test/FixIt/fixit-availability.c index fa641b4b98c6..038dee08b13c 100644 --- a/test/FixIt/fixit-availability.c +++ b/test/FixIt/fixit-availability.c @@ -5,6 +5,6 @@ int function(void); void use() { function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (__builtin_available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (__builtin_available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n } else {\n // Fallback on earlier versions\n }" } diff --git a/test/FixIt/fixit-availability.mm b/test/FixIt/fixit-availability.mm index 6bf8f49ddc0d..d044a73efdb9 100644 --- a/test/FixIt/fixit-availability.mm +++ b/test/FixIt/fixit-availability.mm @@ -7,58 +7,58 @@ void anotherFunction(int function); int use() { function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n } else {\n // Fallback on earlier versions\n }" int y = function(), x = 0; -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:29-[[@LINE-2]]:29}:"\n } else {\n // Fallback on earlier versions\n }" x += function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:19-[[@LINE-2]]:19}:"\n } else {\n // Fallback on earlier versions\n }" if (1) { x = function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:20-[[@LINE-2]]:20}:"\n } else {\n // Fallback on earlier versions\n }" } anotherFunction(function()); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:31-[[@LINE-2]]:31}:"\n } else {\n // Fallback on earlier versions\n }" if (function()) { -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE+1]]:4-[[@LINE+1]]:4}:"\n } else {\n // Fallback on earlier versions\n }" } while (function()) - // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " + // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE+1]]:6-[[@LINE+1]]:6}:"\n } else {\n // Fallback on earlier versions\n }" ; do function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n } else {\n // Fallback on earlier versions\n }" while (1); for (int i = 0; i < 10; ++i) function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n } else {\n // Fallback on earlier versions\n }" switch (x) { case 0: function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n } else {\n // Fallback on earlier versions\n }" case 2: anotherFunction(1); function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n } else {\n // Fallback on earlier versions\n }" break; default: function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n } else {\n // Fallback on earlier versions\n }" break; } return function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:21-[[@LINE-2]]:21}:"\n } else {\n // Fallback on earlier versions\n }" } @@ -72,39 +72,39 @@ int use() { void useInMacros() { MYFUNCTION(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n } else {\n // Fallback on earlier versions\n }" MACRO_ARGUMENT_SEMI(function()) -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:34-[[@LINE-2]]:34}:"\n } else {\n // Fallback on earlier versions\n }" MACRO_ARGUMENT(function()); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:30-[[@LINE-2]]:30}:"\n } else {\n // Fallback on earlier versions\n }" MACRO_ARGUMENT_2(function()); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:32-[[@LINE-2]]:32}:"\n } else {\n // Fallback on earlier versions\n }" INNER_MACRO -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n } else {\n // Fallback on earlier versions\n }" } void wrapDeclStmtUses() { int x = 0, y = function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE+13]]:22-[[@LINE+13]]:22}:"\n } else {\n // Fallback on earlier versions\n }" { int z = function(); if (z) { } -// CHECK: fix-it:{{.*}}:{[[@LINE-4]]:5-[[@LINE-4]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-4]]:5-[[@LINE-4]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:6-[[@LINE-2]]:6}:"\n } else {\n // Fallback on earlier versions\n }" } if (y) int z = function(); -// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n " +// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:24-[[@LINE-2]]:24}:"\n } else {\n // Fallback on earlier versions\n }" anotherFunction(y); anotherFunction(x); diff --git a/test/Import/conflicting-struct/Inputs/S1.cpp b/test/Import/conflicting-struct/Inputs/S1.cpp new file mode 100644 index 000000000000..a99dba8c7821 --- /dev/null +++ b/test/Import/conflicting-struct/Inputs/S1.cpp @@ -0,0 +1,6 @@ +class T; + +class S { + T *t; + int a; +}; diff --git a/test/Import/conflicting-struct/Inputs/S2.cpp b/test/Import/conflicting-struct/Inputs/S2.cpp new file mode 100644 index 000000000000..de2cb6cd03c7 --- /dev/null +++ b/test/Import/conflicting-struct/Inputs/S2.cpp @@ -0,0 +1,7 @@ +class U { + int b; +}; + +class T { + U u; +}; diff --git a/test/Import/conflicting-struct/test.cpp b/test/Import/conflicting-struct/test.cpp new file mode 100644 index 000000000000..5aad567cd794 --- /dev/null +++ b/test/Import/conflicting-struct/test.cpp @@ -0,0 +1,7 @@ +// RUN: clang-import-test --import %S/Inputs/S1.cpp --import %S/Inputs/S2.cpp -expression %s +void expr() { + S MyS; + T MyT; + MyS.a = 3; + MyT.u.b = 2; +} diff --git a/test/Index/Core/index-dependent-source.cpp b/test/Index/Core/index-dependent-source.cpp new file mode 100644 index 000000000000..8c097b935a37 --- /dev/null +++ b/test/Index/Core/index-dependent-source.cpp @@ -0,0 +1,143 @@ +// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s + +int invalid; + +class Base { + void baseFunction(); + + int baseField; + + static void staticBaseFunction(); +}; + +template<typename T> +class BaseTemplate { +public: + T baseTemplateFunction(); + + T baseTemplateField; + + static T baseTemplateVariable; +}; + +template<typename T, typename S> +class TemplateClass: public Base , public BaseTemplate<T> { +public: + ~TemplateClass(); + + T function() { } + + static void staticFunction() { } + + T field; + + static T variable; + + struct Struct { }; + + enum Enum { EnumValue }; + + using TypeAlias = S; + typedef T Typedef; + + void overload1(const T &); + void overload1(const S &); +}; + +template<typename T, typename S> +void indexSimpleDependentDeclarations(const TemplateClass<T, S> &object) { + // Valid instance members: + object.function(); +// CHECK: [[@LINE-1]]:10 | instance-method/C++ | function | c:@ST>2#T#T@TemplateClass@F@function# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 + object.field; +// CHECK: [[@LINE-1]]:10 | field/C++ | field | c:@ST>2#T#T@TemplateClass@FI@field | <no-cgname> | Ref,RelCont | rel: 1 + object.baseFunction(); +// CHECK: [[@LINE-1]]:10 | instance-method/C++ | baseFunction | c:@S@Base@F@baseFunction# | __ZN4Base12baseFunctionEv | Ref,Call,RelCall,RelCont | rel: 1 + object.baseField; +// CHECK: [[@LINE-1]]:10 | field/C++ | baseField | c:@S@Base@FI@baseField | <no-cgname> | Ref,RelCont | rel: 1 + object.baseTemplateFunction(); +// CHECK: [[@LINE-1]]:10 | instance-method/C++ | baseTemplateFunction | c:@ST>1#T@BaseTemplate@F@baseTemplateFunction# | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 + object.baseTemplateField; +// CHECK: [[@LINE-1]]:10 | field/C++ | baseTemplateField | c:@ST>1#T@BaseTemplate@FI@baseTemplateField | <no-cgname> | Ref,RelCont | rel: 1 + + // Invalid instance members: + object.variable; +// CHECK-NOT: [[@LINE-1]]:10 + object.staticFunction(); +// CHECK-NOT: [[@LINE-1]]:10 + object.Struct; +// CHECK-NOT: [[@LINE-1]]:10 + object.EnumValue; +// CHECK-NOT: [[@LINE-1]]:10 + + // Valid static members: + TemplateClass<T, S>::staticFunction(); +// CHECK: [[@LINE-1]]:24 | static-method/C++ | staticFunction | c:@ST>2#T#T@TemplateClass@F@staticFunction#S | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 + TemplateClass<T, S>::variable; +// CHECK: [[@LINE-1]]:24 | static-property/C++ | variable | c:@ST>2#T#T@TemplateClass@variable | __ZN13TemplateClass8variableE | Ref,RelCont | rel: 1 + TemplateClass<T, S>::staticBaseFunction(); +// CHECK: [[@LINE-1]]:24 | static-method/C++ | staticBaseFunction | c:@S@Base@F@staticBaseFunction#S | __ZN4Base18staticBaseFunctionEv | Ref,Call,RelCall,RelCont | rel: 1 + TemplateClass<T, S>::baseTemplateVariable; +// CHECK: [[@LINE-1]]:24 | static-property/C++ | baseTemplateVariable | c:@ST>1#T@BaseTemplate@baseTemplateVariable | __ZN12BaseTemplate20baseTemplateVariableE | Ref,RelCont | rel: 1 + TemplateClass<T, S>::EnumValue; +// CHECK: [[@LINE-1]]:24 | enumerator/C | EnumValue | c:@ST>2#T#T@TemplateClass@E@Enum@EnumValue | <no-cgname> | Ref,RelCont | rel: 1 + TemplateClass<T, S>::Struct(); +// CHECK: [[@LINE-1]]:24 | struct/C | Struct | c:@ST>2#T#T@TemplateClass@S@Struct | <no-cgname> | Ref,Call,RelCall,RelCont | rel: 1 + + // Invalid static members: + TemplateClass<T, S>::field; +// CHECK-NOT: [[@LINE-1]]:24 + TemplateClass<T, S>::function(); +// CHECK-NOT: [[@LINE-1]]:24 + + // Valid type names: + typename TemplateClass<T, S>::Struct Val; +// CHECK: [[@LINE-1]]:33 | struct/C | Struct | c:@ST>2#T#T@TemplateClass@S@Struct | <no-cgname> | Ref,RelCont | rel: 1 + typename TemplateClass<T, S>::Enum EnumVal; +// CHECK: [[@LINE-1]]:33 | enum/C | Enum | c:@ST>2#T#T@TemplateClass@E@Enum | <no-cgname> | Ref,RelCont | rel: 1 + typename TemplateClass<T, S>::TypeAlias Val2; +// CHECK: [[@LINE-1]]:33 | type-alias/C++ | TypeAlias | c:@ST>2#T#T@TemplateClass@TypeAlias | <no-cgname> | Ref,RelCont | rel: 1 + typename TemplateClass<T, S>::Typedef Val3; +// CHECK: [[@LINE-1]]:33 | type-alias/C | Typedef | c:{{.*}}index-dependent-source.cpp@ST>2#T#T@TemplateClass@T@Typedef | <no-cgname> | Ref,RelCont | rel: 1 + + // Invalid type names: + typename TemplateClass<T, S>::field Val4; +// CHECK-NOT: [[@LINE-1]]:33 + typename TemplateClass<T, S>::staticFunction Val5; +// CHECK-NOT: [[@LINE-1]]:33 + + + object.invalid; +// CHECK-NOT: [[@LINE-1]]:10 + TemplateClass<T, S>::invalid; +// CHECK-NOT: [[@LINE-1]]:24 +} + +template<typename T, typename S, typename Y> +void indexDependentOverloads(const TemplateClass<T, S> &object) { + object.overload1(T()); +// CHECK-NOT: [[@LINE-1]] + object.overload1(S()); +// CHECK-NOT: [[@LINE-1]] + object.overload1(Y()); +// CHECK-NOT: [[@LINE-1]] +} + +template<typename T> struct UndefinedTemplateClass; + +template<typename T> +void undefinedTemplateLookup(UndefinedTemplateClass<T> &x) { +// Shouldn't crash! + x.lookup; + typename UndefinedTemplateClass<T>::Type y; +} + +template<typename T> +struct UserOfUndefinedTemplateClass: UndefinedTemplateClass<T> { }; + +template<typename T> +void undefinedTemplateLookup2(UserOfUndefinedTemplateClass<T> &x) { +// Shouldn't crash! + x.lookup; + typename UserOfUndefinedTemplateClass<T>::Type y; +} diff --git a/test/Index/Core/index-instantiated-source.cpp b/test/Index/Core/index-instantiated-source.cpp new file mode 100644 index 000000000000..f61795da540c --- /dev/null +++ b/test/Index/Core/index-instantiated-source.cpp @@ -0,0 +1,39 @@ +// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s +// References to declarations in instantiations should be canonicalized: + +template<typename T> +class BaseTemplate { +public: + T baseTemplateFunction(); +// CHECK: [[@LINE-1]]:5 | instance-method/C++ | baseTemplateFunction | c:@ST>1#T@BaseTemplate@F@baseTemplateFunction# + + T baseTemplateField; +// CHECK: [[@LINE-1]]:5 | field/C++ | baseTemplateField | c:@ST>1#T@BaseTemplate@FI@baseTemplateField +}; + +template<typename T, typename S> +class TemplateClass: public BaseTemplate<T> { +public: + T function() { return T(); } +// CHECK: [[@LINE-1]]:5 | instance-method/C++ | function | c:@ST>2#T#T@TemplateClass@F@function# + + static void staticFunction() { } +// CHECK: [[@LINE-1]]:15 | static-method/C++ | staticFunction | c:@ST>2#T#T@TemplateClass@F@staticFunction#S + + T field; +// CHECK: [[@LINE-1]]:5 | field/C++ | field | c:@ST>2#T#T@TemplateClass@FI@field +}; + +void canonicalizeInstaniationReferences(TemplateClass<int, float> &object) { + (void)object.function(); +// CHECK: [[@LINE-1]]:16 | instance-method/C++ | function | c:@ST>2#T#T@TemplateClass@F@function# | <no-cgname> + (void)object.field; +// CHECK: [[@LINE-1]]:16 | field/C++ | field | c:@ST>2#T#T@TemplateClass@FI@field | <no-cgname> | Ref,RelCont | rel: 1 + (void)object.baseTemplateFunction(); +// CHECK: [[@LINE-1]]:16 | instance-method/C++ | baseTemplateFunction | c:@ST>1#T@BaseTemplate@F@baseTemplateFunction# | <no-cgname> + (void)object.baseTemplateField; +// CHECK: [[@LINE-1]]:16 | field/C++ | baseTemplateField | c:@ST>1#T@BaseTemplate@FI@baseTemplateField | <no-cgname> | Ref,RelCont | rel: 1 + + TemplateClass<int, float>::staticFunction(); +// CHECK: [[@LINE-1]]:30 | static-method/C++ | staticFunction | c:@ST>2#T#T@TemplateClass@F@staticFunction#S | <no-cgname +} diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 6f902610e673..9248e86ff697 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -287,3 +287,55 @@ class PartialSpecilizationClass<Cls, Cls> : Cls { }; // CHECK-NEXT: [[@LINE-5]]:7 | class(Gen)/C++ | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass | <no-cgname> | Ref | rel: 0 // CHECK-NEXT: [[@LINE-6]]:33 | class/C++ | Cls | c:@S@Cls | <no-cgname> | Ref | rel: 0 // CHECK-NEXT: [[@LINE-7]]:38 | class/C++ | Cls | c:@S@Cls | <no-cgname> | Ref | rel: 0 + +template<typename T, int x> +void functionSp() { } + +struct Record { + constexpr static int C = 2; +}; + +template<> +void functionSp<SpecializationDecl<Cls>, Record::C>() { +// CHECK: [[@LINE-1]]:6 | function(Gen,TS)/C++ | functionSp | c:@F@functionSp<#$@S@SpecializationDecl>#$@S@Cls#VI2># | __Z10functionSpI18SpecializationDeclI3ClsELi2EEvv | Def,RelSpecialization | rel: 1 +// CHECK: RelSpecialization | functionSp | c:@FT@>2#T#NIfunctionSp#v# +// CHECK: [[@LINE-3]]:17 | class(Gen)/C++ | SpecializationDecl | c:@ST>1#T@SpecializationDecl | <no-cgname> | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-4]]:36 | class/C++ | Cls | c:@S@Cls | <no-cgname> | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-5]]:50 | static-property/C++ | C | c:@S@Record@C | __ZN6Record1CE | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-6]]:42 | struct/C++ | Record | c:@S@Record | <no-cgname> | Ref,RelCont | rel: 1 +} + +template<typename T, int x> +class ClassWithCorrectSpecialization { }; + +template<> +class ClassWithCorrectSpecialization<SpecializationDecl<Cls>, Record::C> { }; +// CHECK: [[@LINE-1]]:38 | class(Gen)/C++ | SpecializationDecl | c:@ST>1#T@SpecializationDecl | <no-cgname> | Ref | rel: 0 +// CHECK: [[@LINE-2]]:57 | class/C++ | Cls | c:@S@Cls | <no-cgname> | Ref | rel: 0 +// CHECK: [[@LINE-3]]:71 | static-property/C++ | C | c:@S@Record@C | __ZN6Record1CE | Ref,Read | rel: 0 +// CHECK: [[@LINE-4]]:63 | struct/C++ | Record | c:@S@Record | <no-cgname> | Ref | rel: 0 + +namespace ns { +// CHECK: [[@LINE-1]]:11 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Decl | rel: 0 +namespace inner { +// CHECK: [[@LINE-1]]:11 | namespace/C++ | inner | c:@N@ns@N@inner | <no-cgname> | Decl,RelChild | rel: 1 +void func(); + +} +namespace innerAlias = inner; +// CHECK: [[@LINE-1]]:11 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | <no-cgname> | Decl,RelChild | rel: 1 +// CHECK: [[@LINE-2]]:24 | namespace/C++ | inner | c:@N@ns@N@inner | <no-cgname> | Ref,RelCont | rel: 1 +} + +namespace namespaceAlias = ::ns::innerAlias; +// CHECK: [[@LINE-1]]:11 | namespace-alias/C++ | namespaceAlias | c:@NA@namespaceAlias | <no-cgname> | Decl | rel: 0 +// CHECK: [[@LINE-2]]:30 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-3]]:34 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | <no-cgname> | Ref,RelCont | rel: 1 + +void ::ns::inner::func() { +// CHECK: [[@LINE-1]]:8 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-2]]:12 | namespace/C++ | inner | c:@N@ns@N@inner | <no-cgname> | Ref,RelCont | rel: 1 + ns::innerAlias::func(); +// CHECK: [[@LINE-1]]:3 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-2]]:7 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | <no-cgname> | Ref,RelCont | rel: 1 +} diff --git a/test/Index/complete-available.m b/test/Index/complete-available.m new file mode 100644 index 000000000000..8267dbdddc5c --- /dev/null +++ b/test/Index/complete-available.m @@ -0,0 +1,20 @@ +/* The run lines are below, because this test is line- and + column-number sensitive. */ +void atAvailable() { + if (@available(macOS 10.10, *)) { + + } + if (__builtin_available(iOS 8, *)) { + } +} + +// RUN: c-index-test -code-completion-at=%s:4:18 %s | FileCheck -check-prefix=CHECK %s +// RUN: c-index-test -code-completion-at=%s:7:27 %s | FileCheck -check-prefix=CHECK %s +// CHECK: {TypedText iOS} (40) +// CHECK: {TypedText iOSApplicationExtension} (40) +// CHECK: {TypedText macOS} (40) +// CHECK: {TypedText macOSApplicationExtension} (40) +// CHECK: {TypedText tvOS} (40) +// CHECK: {TypedText tvOSApplicationExtension} (40) +// CHECK: {TypedText watchOS} (40) +// CHECK: {TypedText watchOSApplicationExtension} (40) diff --git a/test/Index/get-cursor.m b/test/Index/get-cursor.m index af277d45fdf4..e85d49fb0c3e 100644 --- a/test/Index/get-cursor.m +++ b/test/Index/get-cursor.m @@ -154,6 +154,12 @@ SomeT someVar; typedef MY_TYPE2(SomeT2) { int x; }; SomeT2 someVar2; +#define GEN_DECL(mod_name) __attribute__((external_source_symbol(language="Swift", defined_in=mod_name, generated_declaration))) + +GEN_DECL("some_module") +@interface ExtCls +-(void)method; +@end // RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s // CHECK-PROP: ObjCPropertyDecl=foo1:4:26 @@ -226,3 +232,8 @@ SomeT2 someVar2; // CHECK-TRANSPARENT: 147:1 TypeRef=TokenPaste_t:144:9 Extent=[147:1 - 147:13] Spelling=TokenPaste_t ([147:1 - 147:13]) // CHECK-TRANSPARENT: 151:1 TypeRef=SomeT:150:17 (Transparent: struct SomeT) Extent=[151:1 - 151:6] Spelling=SomeT ([151:1 - 151:6]) // CHECK-TRANSPARENT: 155:1 TypeRef=SomeT2:154:18 Extent=[155:1 - 155:7] Spelling=SomeT2 ([155:1 - 155:7]) + +// RUN: c-index-test -cursor-at=%s:160:12 -cursor-at=%s:161:8 %s | FileCheck -check-prefix=CHECK-EXTERNAL %s +// CHECK-EXTERNAL: 160:12 ObjCInterfaceDecl=ExtCls:160:12 (external lang: Swift, defined: some_module, gen: 1) +// CHECK-EXTERNAL: 161:8 ObjCInstanceMethodDecl=method:161:8 (external lang: Swift, defined: some_module, gen: 1) +C
\ No newline at end of file diff --git a/test/Misc/warning-flags.c b/test/Misc/warning-flags.c index be02e12e2cbb..5172d3b15a90 100644 --- a/test/Misc/warning-flags.c +++ b/test/Misc/warning-flags.c @@ -6,8 +6,8 @@ This test serves two purposes: (1) It documents all existing warnings that currently have no associated -W flag, and ensures that the list never grows. - If take an existing warning and add a flag, this test will fail. To - fix this test, simply remove that warning from the list below. + If you take an existing warning and add a flag, this test will fail. + To fix this test, simply remove that warning from the list below. (2) It prevents us adding new warnings to Clang that have no -W flag. All new warnings should have -W flags. diff --git a/test/Modules/DebugInfoNamespace.cpp b/test/Modules/DebugInfoNamespace.cpp new file mode 100644 index 000000000000..33add085d8a6 --- /dev/null +++ b/test/Modules/DebugInfoNamespace.cpp @@ -0,0 +1,19 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=standalone \ +// RUN: -dwarf-ext-refs -fmodules \ +// RUN: -fmodule-format=obj -fimplicit-module-maps \ +// RUN: -triple %itanium_abi_triple -fmodules-cache-path=%t \ +// RUN: %s -I %S/Inputs/DebugInfoNamespace -I %t -emit-llvm -o - \ +// RUN: | FileCheck %s + +#include "A.h" +#include "B.h" +using namespace N; +B b; + +// Verify that the forward decl of B is in module B. +// +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "B", +// CHECK-SAME: scope: ![[N:[0-9]+]] +// CHECK: ![[N]] = !DINamespace(name: "N", scope: ![[B:[0-9]+]]) +// CHECK: ![[B]] = !DIModule(scope: null, name: "B", diff --git a/test/Modules/DebugInfoSubmoduleImport.c b/test/Modules/DebugInfoSubmoduleImport.c index 1b31aada9c6a..b608d300d5fe 100644 --- a/test/Modules/DebugInfoSubmoduleImport.c +++ b/test/Modules/DebugInfoSubmoduleImport.c @@ -2,6 +2,11 @@ // RUN: %clang_cc1 -fmodules -fmodule-format=obj -debug-info-kind=limited -dwarf-ext-refs \ // RUN: -fimplicit-module-maps -x c -fmodules-cache-path=%t -I %S/Inputs \ // RUN: %s -emit-llvm -debugger-tuning=lldb -o - | FileCheck %s +// +// RUN: %clang_cc1 -fmodules -fmodule-format=obj -debug-info-kind=limited -dwarf-ext-refs \ +// RUN: -fimplicit-module-maps -x c -fmodules-cache-path=%t -I %S/Inputs \ +// RUN: -fmodules-local-submodule-visibility \ +// RUN: %s -emit-llvm -debugger-tuning=lldb -o - | FileCheck %s #include "DebugSubmoduleA.h" #include "DebugSubmoduleB.h" diff --git a/test/Modules/Inputs/DebugInfoNamespace/A.h b/test/Modules/Inputs/DebugInfoNamespace/A.h new file mode 100644 index 000000000000..dc5a1cd26ab6 --- /dev/null +++ b/test/Modules/Inputs/DebugInfoNamespace/A.h @@ -0,0 +1,3 @@ +namespace N { + struct A {}; +} diff --git a/test/Modules/Inputs/DebugInfoNamespace/B.h b/test/Modules/Inputs/DebugInfoNamespace/B.h new file mode 100644 index 000000000000..c9033a54d4e5 --- /dev/null +++ b/test/Modules/Inputs/DebugInfoNamespace/B.h @@ -0,0 +1,3 @@ +namespace N { + struct B {}; +} diff --git a/test/Modules/Inputs/DebugInfoNamespace/module.modulemap b/test/Modules/Inputs/DebugInfoNamespace/module.modulemap new file mode 100644 index 000000000000..9300fcf98c64 --- /dev/null +++ b/test/Modules/Inputs/DebugInfoNamespace/module.modulemap @@ -0,0 +1,8 @@ +module A { + header "A.h" + export * +} +module B { + header "B.h" + export * +} diff --git a/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/Headers/B.h b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/Headers/B.h new file mode 100644 index 000000000000..761540b09cb3 --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/Headers/B.h @@ -0,0 +1 @@ +// B.h diff --git a/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/Headers/Sub.h b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/Headers/Sub.h new file mode 100644 index 000000000000..fd86e3cf872f --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/Headers/Sub.h @@ -0,0 +1,2 @@ +// Sub.h +#import "B.h" diff --git a/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h new file mode 100644 index 000000000000..4ab49b798c63 --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h @@ -0,0 +1 @@ +// BPriv.h diff --git a/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h new file mode 100644 index 000000000000..f6ac6188d65f --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h @@ -0,0 +1 @@ +#import "BPriv.h" diff --git a/test/Modules/Inputs/MainA.framework/Headers/A.h b/test/Modules/Inputs/MainA.framework/Headers/A.h new file mode 100644 index 000000000000..975f1f0437bb --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Headers/A.h @@ -0,0 +1 @@ +// A.h diff --git a/test/Modules/Inputs/MainA.framework/Headers/Main.h b/test/Modules/Inputs/MainA.framework/Headers/Main.h new file mode 100644 index 000000000000..cb8cc00a0c45 --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Headers/Main.h @@ -0,0 +1,2 @@ +// Main.h +#import "A.h" diff --git a/test/Modules/Inputs/MainA.framework/Modules/module.modulemap b/test/Modules/Inputs/MainA.framework/Modules/module.modulemap new file mode 100644 index 000000000000..4b0b5e955386 --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Modules/module.modulemap @@ -0,0 +1,12 @@ +framework module MainA { + umbrella header "Main.h" + + module * { export * } + export * + + framework module Sub { + umbrella header "Sub.h" + module * { export * } + export * + } +} diff --git a/test/Modules/Inputs/MainA.framework/Modules/module.private.modulemap b/test/Modules/Inputs/MainA.framework/Modules/module.private.modulemap new file mode 100644 index 000000000000..a8dc5c2be5f0 --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/Modules/module.private.modulemap @@ -0,0 +1,12 @@ +framework module MainA_Private { + umbrella header "MainPriv.h" + + module * { export * } + export * + + explicit framework module Sub { + umbrella header "SubPriv.h" + module * { export * } + export * + } +} diff --git a/test/Modules/Inputs/MainA.framework/PrivateHeaders/APriv.h b/test/Modules/Inputs/MainA.framework/PrivateHeaders/APriv.h new file mode 100644 index 000000000000..6ac683c39c55 --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/PrivateHeaders/APriv.h @@ -0,0 +1 @@ +// APriv.h diff --git a/test/Modules/Inputs/MainA.framework/PrivateHeaders/MainPriv.h b/test/Modules/Inputs/MainA.framework/PrivateHeaders/MainPriv.h new file mode 100644 index 000000000000..68103017ad0b --- /dev/null +++ b/test/Modules/Inputs/MainA.framework/PrivateHeaders/MainPriv.h @@ -0,0 +1 @@ +#import "APriv.h" diff --git a/test/Modules/Inputs/SameHeader/A.h b/test/Modules/Inputs/SameHeader/A.h new file mode 100644 index 000000000000..bebe9c31c28e --- /dev/null +++ b/test/Modules/Inputs/SameHeader/A.h @@ -0,0 +1,3 @@ +#ifndef __A_h__ +#define __A_h__ +#endif diff --git a/test/Modules/Inputs/SameHeader/B.h b/test/Modules/Inputs/SameHeader/B.h new file mode 100644 index 000000000000..c3fe49cd854f --- /dev/null +++ b/test/Modules/Inputs/SameHeader/B.h @@ -0,0 +1,4 @@ +#ifndef __B_h__ +#define __B_h__ +#include "C.h" +#endif diff --git a/test/Modules/Inputs/SameHeader/C.h b/test/Modules/Inputs/SameHeader/C.h new file mode 100644 index 000000000000..33c3316a6517 --- /dev/null +++ b/test/Modules/Inputs/SameHeader/C.h @@ -0,0 +1,12 @@ +#ifndef __C_h__ +#define __C_h__ +int c = 1; + +struct aaa { + int b; +}; + +typedef struct fd_set { + char c; +}; +#endif diff --git a/test/Modules/Inputs/SameHeader/module.modulemap b/test/Modules/Inputs/SameHeader/module.modulemap new file mode 100644 index 000000000000..d0283a71ac97 --- /dev/null +++ b/test/Modules/Inputs/SameHeader/module.modulemap @@ -0,0 +1,11 @@ +module X { + module A { + header "A.h" + export * + } + module B { + header "B.h" + export * + } + export * +} diff --git a/test/Modules/find-privateheaders.m b/test/Modules/find-privateheaders.m index c5e82ac70da2..5720a73f9be8 100644 --- a/test/Modules/find-privateheaders.m +++ b/test/Modules/find-privateheaders.m @@ -1,2 +1,13 @@ -// RUN: %clang_cc1 -fmodules -fsyntax-only -F%S/Inputs %s +// RUN: rm -rf %t.cache +// RUN: %clang_cc1 -fmodules -fsyntax-only -F%S/Inputs -fimplicit-module-maps \ +// RUN: -fmodules-cache-path=%t.cache -Wno-private-module -DBUILD_PUBLIC -verify %s +// RUN: rm -rf %t.cache +// RUN: %clang_cc1 -fmodules -fsyntax-only -F%S/Inputs -fimplicit-module-maps \ +// RUN: -fmodules-cache-path=%t.cache -Wno-private-module -verify %s +//expected-no-diagnostics + +#ifdef BUILD_PUBLIC #import "Main/Main.h" +#else +#import "MainA/MainPriv.h" +#endif diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index 294e925627c6..58814dd6b3fb 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -1078,6 +1078,39 @@ S<X> s; #endif } +namespace MultipleTypedefs { +#if defined(FIRST) +typedef int B1; +typedef B1 A1; +struct S1 { + A1 x; +}; +#elif defined(SECOND) +typedef int A1; +struct S1 { + A1 x; +}; +#else +S1 s1; +#endif + +#if defined(FIRST) +struct T2 { int x; }; +typedef T2 B2; +typedef B2 A2; +struct S2 { + T2 x; +}; +#elif defined(SECOND) +struct T2 { int x; }; +typedef T2 A2; +struct S2 { + T2 x; +}; +#else +S2 s2; +#endif +} // Keep macros contained to one file. #ifdef FIRST diff --git a/test/Modules/preprocess-module.cpp b/test/Modules/preprocess-module.cpp index a3b789238388..64af00c471df 100644 --- a/test/Modules/preprocess-module.cpp +++ b/test/Modules/preprocess-module.cpp @@ -19,6 +19,11 @@ // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm +// Check that we can load the original module map in the same compilation (this +// could happen if we had a redundant -fmodule-map-file= in the original +// build). +// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -fmodule-map-file=%S/Inputs/preprocess/module.modulemap -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o /dev/null + // Check the module we built works. // RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -verify // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -verify diff --git a/test/Modules/redefinition-same-header.m b/test/Modules/redefinition-same-header.m new file mode 100644 index 000000000000..f1c6cbbcaa2e --- /dev/null +++ b/test/Modules/redefinition-same-header.m @@ -0,0 +1,20 @@ +// RUN: rm -rf %t.tmp +// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SameHeader -fmodules \ +// RUN: -fimplicit-module-maps -fmodules-cache-path=%t.tmp %s -verify + +// expected-error@Inputs/SameHeader/C.h:3 {{redefinition of 'c'}} +// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}} +// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}} +// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}} + +// expected-error@Inputs/SameHeader/C.h:5 {{redefinition of 'aaa'}} +// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}} +// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}} +// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}} + +// expected-error@Inputs/SameHeader/C.h:9 {{redefinition of 'fd_set'}} +// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}} +// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}} +// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}} +#include "A.h" // maps to a modular +#include "C.h" // textual include diff --git a/test/OpenMP/report_default_DSA.cpp b/test/OpenMP/report_default_DSA.cpp new file mode 100644 index 000000000000..d14cd5cbe9a4 --- /dev/null +++ b/test/OpenMP/report_default_DSA.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 %s + +void foo(int x, int n) { + double vec[n]; + for (int iter = 0; iter < x; iter++) { +#pragma omp target teams distribute parallel for map( \ + from \ + : vec [0:n]) default(none) + // expected-error@+1 {{variable 'n' must have explicitly specified data sharing attributes}} + for (int ii = 0; ii < n; ii++) { + // expected-error@+3 {{variable 'iter' must have explicitly specified data sharing attributes}} + // expected-error@+2 {{variable 'vec' must have explicitly specified data sharing attributes}} + // expected-error@+1 {{variable 'x' must have explicitly specified data sharing attributes}} + vec[ii] = iter + ii + x; + } + } +} + diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp index d50eee0623c5..e241701f50df 100644 --- a/test/PCH/cxx-templates.cpp +++ b/test/PCH/cxx-templates.cpp @@ -108,3 +108,11 @@ namespace cyclic_module_load { template int local_extern::f<int[]>(); // expected-note {{in instantiation of}} #endif template int local_extern::g<int[]>(); + +namespace MemberSpecializationLocation { +#ifndef NO_ERRORS + // expected-note@cxx-templates.h:* {{previous}} + template<> float A<int>::n; // expected-error {{redeclaration of 'n' with a different type}} +#endif + int k = A<int>::n; +} diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h index c4a844727691..68b252e7974e 100644 --- a/test/PCH/cxx-templates.h +++ b/test/PCH/cxx-templates.h @@ -358,3 +358,6 @@ namespace rdar15468709c { } } +namespace MemberSpecializationLocation { + template<typename T> struct A { static int n; }; +} diff --git a/test/Parser/objc-available.m b/test/Parser/objc-available.m index a170721240ce..49bc53930655 100644 --- a/test/Parser/objc-available.m +++ b/test/Parser/objc-available.m @@ -21,6 +21,12 @@ void f() { (void)@available; // expected-error{{expected '('}} } +void prettyPlatformNames() { + (void)@available(iOS 8, tvOS 10, watchOS 3, macOS 10.11, *); + (void)__builtin_available(iOSApplicationExtension 8, tvOSApplicationExtension 10, + watchOSApplicationExtension 3, macOSApplicationExtension 10.11, *); +} + #if __has_builtin(__builtin_available) #error expected // expected-error@-1 {{expected}} diff --git a/test/Preprocessor/predefined-arch-macros.c b/test/Preprocessor/predefined-arch-macros.c index a0eb8cbcca9a..08f4d2573f40 100644 --- a/test/Preprocessor/predefined-arch-macros.c +++ b/test/Preprocessor/predefined-arch-macros.c @@ -1601,6 +1601,7 @@ // CHECK_BDVER1_M32: #define __AES__ 1 // CHECK_BDVER1_M32: #define __AVX__ 1 // CHECK_BDVER1_M32: #define __FMA4__ 1 +// CHECK_BDVER1_M32: #define __LWP__ 1 // CHECK_BDVER1_M32: #define __LZCNT__ 1 // CHECK_BDVER1_M32: #define __MMX__ 1 // CHECK_BDVER1_M32: #define __PCLMUL__ 1 @@ -1630,6 +1631,7 @@ // CHECK_BDVER1_M64: #define __AES__ 1 // CHECK_BDVER1_M64: #define __AVX__ 1 // CHECK_BDVER1_M64: #define __FMA4__ 1 +// CHECK_BDVER1_M64: #define __LWP__ 1 // CHECK_BDVER1_M64: #define __LZCNT__ 1 // CHECK_BDVER1_M64: #define __MMX__ 1 // CHECK_BDVER1_M64: #define __PCLMUL__ 1 @@ -1664,6 +1666,7 @@ // CHECK_BDVER2_M32: #define __F16C__ 1 // CHECK_BDVER2_M32: #define __FMA4__ 1 // CHECK_BDVER2_M32: #define __FMA__ 1 +// CHECK_BDVER2_M32: #define __LWP__ 1 // CHECK_BDVER2_M32: #define __LZCNT__ 1 // CHECK_BDVER2_M32: #define __MMX__ 1 // CHECK_BDVER2_M32: #define __PCLMUL__ 1 @@ -1697,6 +1700,7 @@ // CHECK_BDVER2_M64: #define __F16C__ 1 // CHECK_BDVER2_M64: #define __FMA4__ 1 // CHECK_BDVER2_M64: #define __FMA__ 1 +// CHECK_BDVER2_M64: #define __LWP__ 1 // CHECK_BDVER2_M64: #define __LZCNT__ 1 // CHECK_BDVER2_M64: #define __MMX__ 1 // CHECK_BDVER2_M64: #define __PCLMUL__ 1 @@ -1733,6 +1737,7 @@ // CHECK_BDVER3_M32: #define __FMA4__ 1 // CHECK_BDVER3_M32: #define __FMA__ 1 // CHECK_BDVER3_M32: #define __FSGSBASE__ 1 +// CHECK_BDVER3_M32: #define __LWP__ 1 // CHECK_BDVER3_M32: #define __LZCNT__ 1 // CHECK_BDVER3_M32: #define __MMX__ 1 // CHECK_BDVER3_M32: #define __PCLMUL__ 1 @@ -1768,6 +1773,7 @@ // CHECK_BDVER3_M64: #define __FMA4__ 1 // CHECK_BDVER3_M64: #define __FMA__ 1 // CHECK_BDVER3_M64: #define __FSGSBASE__ 1 +// CHECK_BDVER3_M64: #define __LWP__ 1 // CHECK_BDVER3_M64: #define __LZCNT__ 1 // CHECK_BDVER3_M64: #define __MMX__ 1 // CHECK_BDVER3_M64: #define __PCLMUL__ 1 @@ -1807,6 +1813,7 @@ // CHECK_BDVER4_M32: #define __FMA4__ 1 // CHECK_BDVER4_M32: #define __FMA__ 1 // CHECK_BDVER4_M32: #define __FSGSBASE__ 1 +// CHECK_BDVER4_M32: #define __LWP__ 1 // CHECK_BDVER4_M32: #define __LZCNT__ 1 // CHECK_BDVER4_M32: #define __MMX__ 1 // CHECK_BDVER4_M32: #define __PCLMUL__ 1 @@ -1843,6 +1850,7 @@ // CHECK_BDVER4_M64: #define __FMA4__ 1 // CHECK_BDVER4_M64: #define __FMA__ 1 // CHECK_BDVER4_M64: #define __FSGSBASE__ 1 +// CHECK_BDVER4_M64: #define __LWP__ 1 // CHECK_BDVER4_M64: #define __LZCNT__ 1 // CHECK_BDVER4_M64: #define __MMX__ 1 // CHECK_BDVER4_M64: #define __PCLMUL__ 1 diff --git a/test/Preprocessor/x86_target_features.c b/test/Preprocessor/x86_target_features.c index a201900ba762..ce3835f91f42 100644 --- a/test/Preprocessor/x86_target_features.c +++ b/test/Preprocessor/x86_target_features.c @@ -272,6 +272,14 @@ // AESNOSSE2-NOT: #define __SSE2__ 1 // AESNOSSE2-NOT: #define __SSE3__ 1 +// RUN: %clang -target i386-unknown-unknown -march=pentiumpro -mlwp -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=LWP %s + +// LWP: #define __LWP__ 1 + +// RUN: %clang -target i386-unknown-unknown -march=bdver1 -mno-lwp -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=NOLWP %s + +// NOLWP-NOT: #define __LWP__ 1 + // RUN: %clang -target i386-unknown-unknown -march=pentiumpro -msha -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=SHA %s // SHA: #define __SHA__ 1 diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c index f5e17d211910..49d8085651d4 100644 --- a/test/Sema/overloadable.c +++ b/test/Sema/overloadable.c @@ -151,3 +151,18 @@ void dropping_qualifiers_is_incompatible() { foo(ccharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@148{{candidate function}} expected-note@149{{candidate function}} foo(vcharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@148{{candidate function}} expected-note@149{{candidate function}} } + +// Bug: we used to treat `__typeof__(foo)` as though it was `__typeof__(&foo)` +// if `foo` was overloaded with only one function that could have its address +// taken. +void typeof_function_is_not_a_pointer() { + void not_a_pointer(void *) __attribute__((overloadable)); + void not_a_pointer(char *__attribute__((pass_object_size(1)))) + __attribute__((overloadable)); + + __typeof__(not_a_pointer) *fn; + + void take_fn(void (*)(void *)); + // if take_fn is passed a void (**)(void *), we'll get a warning. + take_fn(fn); +} diff --git a/test/Sema/redefinition-same-header.c b/test/Sema/redefinition-same-header.c new file mode 100644 index 000000000000..be5bd1d71c92 --- /dev/null +++ b/test/Sema/redefinition-same-header.c @@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: echo 'int yyy = 42;' > %t/a.h +// RUN: %clang_cc1 -fsyntax-only %s -I%t -verify + +// expected-error@a.h:1 {{redefinition of 'yyy'}} +// expected-note@a.h:1 {{unguarded header; consider using #ifdef guards or #pragma once}} +// expected-note-re@redefinition-same-header.c:11 {{'{{.*}}a.h' included multiple times, additional include site here}} +// expected-note-re@redefinition-same-header.c:12 {{'{{.*}}a.h' included multiple times, additional include site here}} + +#include "a.h" +#include "a.h" + +int foo() { return yyy; } diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index 59f022dfe528..78007015dcae 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -80,3 +80,10 @@ int h() { g(x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}} (x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}} } + +__attribute__((overloadable)) void func_overloadable(int); +__attribute__((overloadable)) void func_overloadable(float); + +void overloadable_callexpr(int arg) { + func_overloadable(ar); //expected-error{{use of undeclared identifier}} +} diff --git a/test/Sema/vector-cast.c b/test/Sema/vector-cast.c index ea4acfac6a0b..cf23eb2742c4 100644 --- a/test/Sema/vector-cast.c +++ b/test/Sema/vector-cast.c @@ -53,9 +53,8 @@ void f4() { float2 f2; double d, a, b, c; float64x2_t v = {0.0, 1.0}; - // FIXME: These diagnostics are inaccurate: should complain that 'double' to vector 'float2' involves truncation - f2 += d; // expected-error {{cannot convert between vector values of different size ('float2' (vector of 2 'float' values) and 'double')}} - d += f2; // expected-error {{cannot convert between vector values of different size}} + f2 += d; // expected-error {{cannot convert between scalar type 'double' and vector type 'float2' (vector of 2 'float' values) as implicit conversion would cause truncation}} + d += f2; // expected-error {{assigning to 'double' from incompatible type 'float2' (vector of 2 'float' values)}} a = 3.0 + vget_low_f64(v); b = vget_low_f64(v) + 3.0; c = vget_low_f64(v); diff --git a/test/Sema/vector-gcc-compat.c b/test/Sema/vector-gcc-compat.c new file mode 100644 index 000000000000..9eb0569b25f0 --- /dev/null +++ b/test/Sema/vector-gcc-compat.c @@ -0,0 +1,330 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -Weverything -triple x86_64-apple-darwin10 + +// Test the compatibility of clang's vector extensions with gcc's vector +// extensions for C. Notably &&, ||, ?: and ! are not available. +typedef long long v2i64 __attribute__((vector_size(16))); +typedef int v2i32 __attribute__((vector_size(8))); +typedef short v2i16 __attribute__((vector_size(4))); +typedef char v2i8 __attribute__((vector_size(2))); + +typedef unsigned long long v2u64 __attribute__((vector_size(16))); +typedef unsigned int v2u32 __attribute__((vector_size(8))); +typedef unsigned short v2u16 __attribute__((vector_size(4))); +typedef unsigned char v2u8 __attribute__((vector_size(2))); + +typedef float v4f32 __attribute__((vector_size(16))); +typedef double v2f64 __attribute__((vector_size(16))); +typedef double v4f64 __attribute__((vector_size(32))); +typedef int v4i32 __attribute((vector_size(16))); + +void arithmeticTest(void); +void logicTest(void); +void comparisonTest(void); +void floatTestSignedType(char a, short b, int c, long long d); +void floatTestUnsignedType(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d); +void floatTestConstant(void); +void intTestType(char a, short b, int c, long long d); +void intTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d); +void uintTestType(char a, short b, int c, long long d); +void uintTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d); +void uintTestConstant(v2u64 v2u64_a, v2u32 v2u32_a, v2u16 v2u16_a, v2u8 v2u8_a); +void intTestConstant(v2i64 v2i64_a, v2i32 v2i32_a, v2i16 v2i16_a, v2i8 v2i8_a); + +void arithmeticTest(void) { + v2i64 v2i64_a = (v2i64){0, 1}; + v2i64 v2i64_r; + + v2i64_r = v2i64_a + 1; + v2i64_r = v2i64_a - 1; + v2i64_r = v2i64_a * 1; + v2i64_r = v2i64_a / 1; + v2i64_r = v2i64_a % 1; + + v2i64_r = 1 + v2i64_a; + v2i64_r = 1 - v2i64_a; + v2i64_r = 1 * v2i64_a; + v2i64_r = 1 / v2i64_a; + v2i64_r = 1 % v2i64_a; + + v2i64_a += 1; + v2i64_a -= 1; + v2i64_a *= 1; + v2i64_a /= 1; + v2i64_a %= 1; +} + +void comparisonTest(void) { + v2i64 v2i64_a = (v2i64){0, 1}; + v2i64 v2i64_r; + + v2i64_r = v2i64_a == 1; + v2i64_r = v2i64_a != 1; + v2i64_r = v2i64_a < 1; + v2i64_r = v2i64_a > 1; + v2i64_r = v2i64_a <= 1; + v2i64_r = v2i64_a >= 1; + + v2i64_r = 1 == v2i64_a; + v2i64_r = 1 != v2i64_a; + v2i64_r = 1 < v2i64_a; + v2i64_r = 1 > v2i64_a; + v2i64_r = 1 <= v2i64_a; + v2i64_r = 1 >= v2i64_a; +} + +void logicTest(void) { + v2i64 v2i64_a = (v2i64){0, 1}; + v2i64 v2i64_b = (v2i64){2, 1}; + v2i64 v2i64_c = (v2i64){3, 1}; + v2i64 v2i64_r; + + v2i64_r = !v2i64_a; // expected-error {{invalid argument type 'v2i64' (vector of 2 'long long' values) to unary expression}} + v2i64_r = ~v2i64_a; + + v2i64_r = v2i64_a ? v2i64_b : v2i64_c; // expected-error {{used type 'v2i64' (vector of 2 'long long' values) where arithmetic or pointer type is required}} + + v2i64_r = v2i64_a & 1; + v2i64_r = v2i64_a | 1; + v2i64_r = v2i64_a ^ 1; + + v2i64_r = 1 & v2i64_a; + v2i64_r = 1 | v2i64_a; + v2i64_r = 1 ^ v2i64_a; + + v2i64_a &= 1; + v2i64_a |= 1; + v2i64_a ^= 1; + + v2i64_r = v2i64_a && 1; // expected-error {{logical expression with vector type 'v2i64' (vector of 2 'long long' values) and non-vector type 'int' is only supported in C++}} + v2i64_r = v2i64_a || 1; // expected-error {{logical expression with vector type 'v2i64' (vector of 2 'long long' values) and non-vector type 'int' is only supported in C++}} + + v2i64_r = v2i64_a && v2i64_a; // expected-error {{logical expression with vector types 'v2i64' (vector of 2 'long long' values) and 'v2i64' is only supported in C++}} + v2i64_r = v2i64_a || v2i64_a; // expected-error {{logical expression with vector types 'v2i64' (vector of 2 'long long' values) and 'v2i64' is only supported in C++}} + + v2i64_r = v2i64_a << 1; + v2i64_r = v2i64_a >> 1; + + v2i64_r = 1 << v2i64_a; + v2i64_r = 1 >> v2i64_a; + + v2i64_a <<= 1; + v2i64_a >>= 1; +} + +// For operations with floating point types, we check that interger constants +// can be respresented, or failing that checking based on the integer types. +void floatTestConstant(void) { + // Test that constants added to floats must be expressible as floating point + // numbers. + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4f32_a = v4f32_a + 1; + v4f32_a = v4f32_a + 0xFFFFFF; + v4f32_a = v4f32_a + (-1567563LL); + v4f32_a = v4f32_a + (16777208); + v4f32_a = v4f32_a + (16777219); // expected-error {{cannot convert between scalar type 'int' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} +} + +void floatTestConstantComparison(void); +void doubleTestConstantComparison(void); + +void floatTestConstantComparison(void) { + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4i32 v4i32_r; + v4i32_r = v4f32_a > 0.4f; + v4i32_r = v4f32_a >= 0.4f; + v4i32_r = v4f32_a < 0.4f; + v4i32_r = v4f32_a <= 0.4f; + v4i32_r = v4f32_a == 0.4f; // expected-warning {{comparing floating point with == or != is unsafe}} + v4i32_r = v4f32_a != 0.4f; // expected-warning {{comparing floating point with == or != is unsafe}} +} + +void doubleTestConstantComparison(void) { + v2f64 v2f64_a = {0.4, 0.4}; + v2i64 v2i64_r; + v2i64_r = v2f64_a > 0.4; + v2i64_r = v2f64_a >= 0.4; + v2i64_r = v2f64_a < 0.4; + v2i64_r = v2f64_a <= 0.4; + v2i64_r = v2f64_a == 0.4; // expected-warning {{comparing floating point with == or != is unsafe}} + v2i64_r = v2f64_a != 0.4; // expected-warning {{comparing floating point with == or != is unsafe}} +} + +void floatTestUnsignedType(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d) { + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4f64 v4f64_b = {0.4, 0.4, 0.4, 0.4}; + + v4f32_a = v4f32_a + a; + v4f32_a = v4f32_a + b; + v4f32_a = v4f32_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + v4f32_a = v4f32_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + + v4f64_b = v4f64_b + a; + v4f64_b = v4f64_b + b; + v4f64_b = v4f64_b + c; + v4f64_b = v4f64_b + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v4f64' (vector of 4 'double' values) as implicit conversion would cause truncation}} +} + +void floatTestSignedType(char a, short b, int c, long long d) { + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4f64 v4f64_b = {0.4, 0.4, 0.4, 0.4}; + + v4f32_a = v4f32_a + a; + v4f32_a = v4f32_a + b; + v4f32_a = v4f32_a + c; // expected-error {{cannot convert between scalar type 'int' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + v4f32_a = v4f32_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + + v4f64_b = v4f64_b + a; + v4f64_b = v4f64_b + b; + v4f64_b = v4f64_b + c; + v4f64_b = v4f64_b + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v4f64' (vector of 4 'double' values) as implicit conversion would cause truncation}} +} + +void intTestType(char a, short b, int c, long long d) { + v2i64 v2i64_a = {1, 2}; + v2i32 v2i32_a = {1, 2}; + v2i16 v2i16_a = {1, 2}; + v2i8 v2i8_a = {1, 2}; + + v2i64_a = v2i64_a + d; + v2i64_a = v2i64_a + c; + v2i64_a = v2i64_a + b; + v2i64_a = v2i64_a + a; + + v2i32_a = v2i32_a + d; // expected-warning {{implicit conversion loses integer precision: 'long long' to 'v2i32' (vector of 2 'int' values)}} + v2i32_a = v2i32_a + c; + v2i32_a = v2i32_a + b; + v2i32_a = v2i32_a + a; + + v2i16_a = v2i16_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2i16' (vector of 2 'short' values) as implicit conversion would cause truncation}} + v2i16_a = v2i16_a + c; // expected-warning {{implicit conversion loses integer precision: 'int' to 'v2i16' (vector of 2 'short' values)}} + v2i16_a = v2i16_a + b; + v2i16_a = v2i16_a + a; + + v2i8_a = v2i8_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + c; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + b; // expected-warning {{implicit conversion loses integer precision: 'short' to 'v2i8' (vector of 2 'char' values)}} + v2i8_a = v2i8_a + a; +} + +void intTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d) { + v2i64 v2i64_a = {1, 2}; + v2i32 v2i32_a = {1, 2}; + v2i16 v2i16_a = {1, 2}; + v2i8 v2i8_a = {1, 2}; + + v2i64_a = v2i64_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2i64' (vector of 2 'long long' values) as implicit conversion would cause truncation}} + + v2i64_a = v2i64_a + c; + v2i64_a = v2i64_a + b; + v2i64_a = v2i64_a + a; + + v2i32_a = v2i32_a + d; // expected-warning {{implicit conversion loses integer precision: 'unsigned long long' to 'v2i32' (vector of 2 'int' values)}} + v2i32_a = v2i32_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2i32' (vector of 2 'int' values) as implicit conversion would cause truncation}} + v2i32_a = v2i32_a + b; + v2i32_a = v2i32_a + a; + + v2i16_a = v2i16_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2i16' (vector of 2 'short' values) as implicit conversion would cause truncation}} + v2i16_a = v2i16_a + c; // expected-warning {{implicit conversion loses integer precision: 'unsigned int' to 'v2i16' (vector of 2 'short' values)}} + v2i16_a = v2i16_a + b; // expected-error {{cannot convert between scalar type 'unsigned short' and vector type 'v2i16' (vector of 2 'short' values) as implicit conversion would cause truncation}} + v2i16_a = v2i16_a + a; + + v2i8_a = v2i8_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + b; // expected-warning {{implicit conversion loses integer precision: 'unsigned short' to 'v2i8' (vector of 2 'char' values)}} + v2i8_a = v2i8_a + a; // expected-error {{cannot convert between scalar type 'unsigned char' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} +} + +void uintTestType(char a, short b, int c, long long d) { + v2u64 v2u64_a = {1, 2}; + v2u32 v2u32_a = {1, 2}; + v2u16 v2u16_a = {1, 2}; + v2u8 v2u8_a = {1, 2}; + + v2u64_a = v2u64_a + d; // expected-warning {{implicit conversion changes signedness: 'long long' to 'v2u64' (vector of 2 'unsigned long long' values)}} + v2u64_a = v2u64_a + c; // expected-warning {{implicit conversion changes signedness: 'int' to 'v2u64' (vector of 2 'unsigned long long' values)}} + v2u64_a = v2u64_a + b; // expected-warning {{implicit conversion changes signedness: 'short' to 'v2u64' (vector of 2 'unsigned long long' values)}} + v2u64_a = v2u64_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u64' (vector of 2 'unsigned long long' values)}} + + v2u32_a = v2u32_a + d; // expected-warning {{implicit conversion loses integer precision: 'long long' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + c; // expected-warning {{implicit conversion changes signedness: 'int' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + b; // expected-warning {{implicit conversion changes signedness: 'short' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u32' (vector of 2 'unsigned int' values)}} + + v2u16_a = v2u16_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2u16' (vector of 2 'unsigned short' values) as implicit conversion would cause truncation}} + v2u16_a = v2u16_a + c; // expected-warning {{implicit conversion loses integer precision: 'int' to 'v2u16' (vector of 2 'unsigned short' values)}} + v2u16_a = v2u16_a + b; // expected-warning {{implicit conversion changes signedness: 'short' to 'v2u16' (vector of 2 'unsigned short' values)}} + v2u16_a = v2u16_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u16' (vector of 2 'unsigned short' values)}} + + v2u8_a = v2u8_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + c; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + b; // expected-warning {{implicit conversion loses integer precision: 'short' to 'v2u8' (vector of 2 'unsigned char' values)}} + v2u8_a = v2u8_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u8' (vector of 2 'unsigned char' values)}} +} + +void uintTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d) { + v2u64 v2u64_a = {1, 2}; + v2u32 v2u32_a = {1, 2}; + v2u16 v2u16_a = {1, 2}; + v2u8 v2u8_a = {1, 2}; + + v2u64_a = v2u64_a + d; + v2u64_a = v2u64_a + c; + v2u64_a = v2u64_a + b; + v2u64_a = v2u64_a + a; + + v2u32_a = v2u32_a + d; // expected-warning {{implicit conversion loses integer precision: 'unsigned long long' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + c; + v2u32_a = v2u32_a + b; + v2u32_a = v2u32_a + a; + + v2u16_a = v2u16_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2u16' (vector of 2 'unsigned short' values) as implicit conversion would cause truncation}} + v2u16_a = v2u16_a + c; // expected-warning {{implicit conversion loses integer precision: 'unsigned int' to 'v2u16' (vector of 2 'unsigned short' values)}} + v2u16_a = v2u16_a + b; + v2u16_a = v2u16_a + a; + + v2u8_a = v2u8_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + b; // expected-warning {{implicit conversion loses integer precision: 'unsigned short' to 'v2u8' (vector of 2 'unsigned char' values)}} + v2u8_a = v2u8_a + a; +} + +void uintTestConstant(v2u64 v2u64_a, v2u32 v2u32_a, v2u16 v2u16_a, + v2u8 v2u8_a) { + v2u64_a = v2u64_a + 0xFFFFFFFFFFFFFFFF; + v2u32_a = v2u32_a + 0xFFFFFFFF; + v2u16_a = v2u16_a + 0xFFFF; + v2u8_a = v2u8_a + 0xFF; + + v2u32_a = v2u32_a + 0x1FFFFFFFF; // expected-warning {{implicit conversion from 'long' to 'v2u32' (vector of 2 'unsigned int' values) changes value from 8589934591 to 4294967295}} + v2u16_a = v2u16_a + 0x1FFFF; // expected-warning {{implicit conversion from 'int' to 'v2u16' (vector of 2 'unsigned short' values) changes value from 131071 to 65535}} + v2u8_a = v2u8_a + 0x1FF; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} +} + +void intTestConstant(v2i64 v2i64_a, v2i32 v2i32_a, v2i16 v2i16_a, v2i8 v2i8_a) { + // Legal upper bounds. + v2i64_a = v2i64_a + (long long)0x7FFFFFFFFFFFFFFF; + v2i32_a = v2i32_a + (int)0x7FFFFFFF; + v2i16_a = v2i16_a + (short)0x7FFF; + v2i8_a = v2i8_a + (char)0x7F; + + // Legal lower bounds. + v2i64_a = v2i64_a + (-9223372036854775807); + v2i32_a = v2i32_a + (-2147483648); + v2i16_a = v2i16_a + (-32768); + v2i8_a = v2i8_a + (-128); + + // One increment/decrement more than the type can hold + v2i32_a = v2i32_a + 2147483648; // expected-warning {{implicit conversion from 'long' to 'v2i32' (vector of 2 'int' values) changes value from 2147483648 to -2147483648}} + v2i16_a = v2i16_a + 32768; // expected-warning {{implicit conversion from 'int' to 'v2i16' (vector of 2 'short' values) changes value from 32768 to -32768}} + v2i8_a = v2i8_a + 128; // expected-warning {{implicit conversion from 'int' to 'v2i8' (vector of 2 'char' values) changes value from 128 to -128}} + + v2i32_a = v2i32_a + (-2147483649); // expected-warning {{implicit conversion from 'long' to 'v2i32' (vector of 2 'int' values) changes value from -2147483649 to 2147483647}} + v2i16_a = v2i16_a + (-32769); // expected-warning {{implicit conversion from 'int' to 'v2i16' (vector of 2 'short' values) changes value from -32769 to 32767}} + v2i8_a = v2i8_a + (-129); // expected-error {{cannot convert between scalar type 'int' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} +} diff --git a/test/Sema/vector-gcc-compat.cpp b/test/Sema/vector-gcc-compat.cpp new file mode 100644 index 000000000000..12da314c325f --- /dev/null +++ b/test/Sema/vector-gcc-compat.cpp @@ -0,0 +1,328 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -Weverything -std=c++11 -triple x86_64-apple-darwin10 + +// Test the compatibility of clang++'s vector extensions with g++'s vector +// extensions. In comparison to the extensions available in C, the !, ?:, && and +// || operators work on vector types. + +typedef long long v2i64 __attribute__((vector_size(16))); // expected-warning {{'long long' is incompatible with C++98}} +typedef int v2i32 __attribute__((vector_size(8))); +typedef short v2i16 __attribute__((vector_size(4))); +typedef char v2i8 __attribute__((vector_size(2))); + +typedef unsigned long long v2u64 __attribute__((vector_size(16))); // expected-warning {{'long long' is incompatible with C++98}} +typedef unsigned int v2u32 __attribute__((vector_size(8))); +typedef unsigned short v2u16 __attribute__((vector_size(4))); +typedef unsigned char v2u8 __attribute__((vector_size(2))); + +typedef float v4f32 __attribute__((vector_size(16))); +typedef double v2f64 __attribute__((vector_size(16))); +typedef double v4f64 __attribute__((vector_size(32))); +typedef int v4i32 __attribute((vector_size(16))); + +void arithmeticTest(void); +void logicTest(void); +void comparisonTest(void); +void floatTestSignedType(char a, short b, int c, long long d); // expected-warning {{'long long' is incompatible with C++98}} +void floatTestUnsignedType(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d); // expected-warning {{'long long' is incompatible with C++98}} +void floatTestConstant(void); +void intTestType(char a, short b, int c, long long d); // expected-warning {{'long long' is incompatible with C++98}} +void intTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d); // expected-warning {{'long long' is incompatible with C++98}} +void uintTestType(char a, short b, int c, long long d); // expected-warning {{'long long' is incompatible with C++98}} +void uintTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d); // expected-warning {{'long long' is incompatible with C++98}} +void uintTestConstant(v2u64 v2u64_a, v2u32 v2u32_a, v2u16 v2u16_a, v2u8 v2u8_a); +void intTestConstant(v2i64 v2i64_a, v2i32 v2i32_a, v2i16 v2i16_a, v2i8 v2i8_a); + +void arithmeticTest(void) { + v2i64 v2i64_a = (v2i64){0, 1}; // expected-warning {{compound literals are a C99-specific feature}} + v2i64 v2i64_r; + + v2i64_r = v2i64_a + 1; + v2i64_r = v2i64_a - 1; + v2i64_r = v2i64_a * 1; + v2i64_r = v2i64_a / 1; + v2i64_r = v2i64_a % 1; + + v2i64_r = 1 + v2i64_a; + v2i64_r = 1 - v2i64_a; + v2i64_r = 1 * v2i64_a; + v2i64_r = 1 / v2i64_a; + v2i64_r = 1 % v2i64_a; + + v2i64_a += 1; + v2i64_a -= 1; + v2i64_a *= 1; + v2i64_a /= 1; + v2i64_a %= 1; +} + +void comparisonTest(void) { + v2i64 v2i64_a = (v2i64){0, 1}; // expected-warning {{compound literals are a C99-specific feature}} + v2i64 v2i64_r; + + v2i64_r = v2i64_a == 1; + v2i64_r = v2i64_a != 1; + v2i64_r = v2i64_a < 1; + v2i64_r = v2i64_a > 1; + v2i64_r = v2i64_a <= 1; + v2i64_r = v2i64_a >= 1; + + v2i64_r = 1 == v2i64_a; + v2i64_r = 1 != v2i64_a; + v2i64_r = 1 < v2i64_a; + v2i64_r = 1 > v2i64_a; + v2i64_r = 1 <= v2i64_a; + v2i64_r = 1 >= v2i64_a; +} + +void logicTest(void) { + v2i64 v2i64_a = (v2i64){0, 1}; // expected-warning {{compound literals are a C99-specific feature}} + v2i64 v2i64_b = (v2i64){2, 1}; // expected-warning {{compound literals are a C99-specific feature}} + v2i64 v2i64_c = (v2i64){3, 1}; // expected-warning {{compound literals are a C99-specific feature}} + v2i64 v2i64_r; + + v2i64_r = !v2i64_a; // expected-error {{invalid argument type 'v2i64' (vector of 2 'long long' values) to unary expression}} + v2i64_r = ~v2i64_a; + + v2i64_r = v2i64_a ? v2i64_b : v2i64_c; // expected-error {{value of type 'v2i64' (vector of 2 'long long' values) is not contextually convertible to 'bool'}} + + v2i64_r = v2i64_a & 1; + v2i64_r = v2i64_a | 1; + v2i64_r = v2i64_a ^ 1; + + v2i64_r = 1 & v2i64_a; + v2i64_r = 1 | v2i64_a; + v2i64_r = 1 ^ v2i64_a; + v2i64_a &= 1; + v2i64_a |= 1; + v2i64_a ^= 1; + + v2i64_r = v2i64_a && 1; + v2i64_r = v2i64_a || 1; + + v2i64_r = v2i64_a << 1; + v2i64_r = v2i64_a >> 1; + + v2i64_r = 1 << v2i64_a; + v2i64_r = 1 >> v2i64_a; + + v2i64_a <<= 1; + v2i64_a >>= 1; +} + +// For operations with floating point types, we check that interger constants +// can be respresented, or failing that checking based on the integer types. +void floatTestConstant(void) { + // Test that constants added to floats must be expressible as floating point + // numbers. + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4f32_a = v4f32_a + 1; + v4f32_a = v4f32_a + 0xFFFFFF; + v4f32_a = v4f32_a + (-1567563LL); // expected-warning {{'long long' is incompatible with C++98}} + v4f32_a = v4f32_a + (16777208); + v4f32_a = v4f32_a + (16777219); // expected-error {{cannot convert between scalar type 'int' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} +} + +void floatTestConstantComparison(void); +void doubleTestConstantComparison(void); + +void floatTestConstantComparison(void) { + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4i32 v4i32_r; + v4i32_r = v4f32_a > 0.4f; + v4i32_r = v4f32_a >= 0.4f; + v4i32_r = v4f32_a < 0.4f; + v4i32_r = v4f32_a <= 0.4f; + v4i32_r = v4f32_a == 0.4f; // expected-warning {{comparing floating point with == or != is unsafe}} + v4i32_r = v4f32_a != 0.4f; // expected-warning {{comparing floating point with == or != is unsafe}} +} + +void doubleTestConstantComparison(void) { + v2f64 v2f64_a = {0.4, 0.4}; + v2i64 v2i64_r; + v2i64_r = v2f64_a > 0.4; + v2i64_r = v2f64_a >= 0.4; + v2i64_r = v2f64_a < 0.4; + v2i64_r = v2f64_a <= 0.4; + v2i64_r = v2f64_a == 0.4; // expected-warning {{comparing floating point with == or != is unsafe}} + v2i64_r = v2f64_a != 0.4; // expected-warning {{comparing floating point with == or != is unsafe}} +} + +void floatTestUnsignedType(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d) { // expected-warning {{'long long' is incompatible with C++98}} + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4f64 v4f64_b = {0.4, 0.4, 0.4, 0.4}; + + v4f32_a = v4f32_a + a; + v4f32_a = v4f32_a + b; + v4f32_a = v4f32_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + v4f32_a = v4f32_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + + v4f64_b = v4f64_b + a; + v4f64_b = v4f64_b + b; + v4f64_b = v4f64_b + c; + v4f64_b = v4f64_b + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v4f64' (vector of 4 'double' values) as implicit conversion would cause truncation}} +} + +void floatTestSignedType(char a, short b, int c, long long d) { // expected-warning {{'long long' is incompatible with C++98}} + v4f32 v4f32_a = {0.4f, 0.4f, 0.4f, 0.4f}; + v4f64 v4f64_b = {0.4, 0.4, 0.4, 0.4}; + + v4f32_a = v4f32_a + a; + v4f32_a = v4f32_a + b; + v4f32_a = v4f32_a + c; // expected-error {{cannot convert between scalar type 'int' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + v4f32_a = v4f32_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v4f32' (vector of 4 'float' values) as implicit conversion would cause truncation}} + + v4f64_b = v4f64_b + a; + v4f64_b = v4f64_b + b; + v4f64_b = v4f64_b + c; + v4f64_b = v4f64_b + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v4f64' (vector of 4 'double' values) as implicit conversion would cause truncation}} +} + +void intTestType(char a, short b, int c, long long d) { // expected-warning {{'long long' is incompatible with C++98}} + v2i64 v2i64_a = {1, 2}; + v2i32 v2i32_a = {1, 2}; + v2i16 v2i16_a = {1, 2}; + v2i8 v2i8_a = {1, 2}; + + v2i64_a = v2i64_a + d; + v2i64_a = v2i64_a + c; + v2i64_a = v2i64_a + b; + v2i64_a = v2i64_a + a; + + v2i32_a = v2i32_a + d; // expected-warning {{implicit conversion loses integer precision: 'long long' to 'v2i32' (vector of 2 'int' values)}} + v2i32_a = v2i32_a + c; + v2i32_a = v2i32_a + b; + v2i32_a = v2i32_a + a; + + v2i16_a = v2i16_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2i16' (vector of 2 'short' values) as implicit conversion would cause truncation}} + v2i16_a = v2i16_a + c; // expected-warning {{implicit conversion loses integer precision: 'int' to 'v2i16' (vector of 2 'short' values)}} + v2i16_a = v2i16_a + b; + v2i16_a = v2i16_a + a; + + v2i8_a = v2i8_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + c; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + b; // expected-warning {{implicit conversion loses integer precision: 'short' to 'v2i8' (vector of 2 'char' values)}} + v2i8_a = v2i8_a + a; +} + +void intTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d) { // expected-warning {{'long long' is incompatible with C++98}} + v2i64 v2i64_a = {1, 2}; + v2i32 v2i32_a = {1, 2}; + v2i16 v2i16_a = {1, 2}; + v2i8 v2i8_a = {1, 2}; + + v2i64_a = v2i64_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2i64' (vector of 2 'long long' values) as implicit conversion would cause truncation}} + + v2i64_a = v2i64_a + c; + v2i64_a = v2i64_a + b; + v2i64_a = v2i64_a + a; + + v2i32_a = v2i32_a + d; // expected-warning {{implicit conversion loses integer precision: 'unsigned long long' to 'v2i32' (vector of 2 'int' values)}} + v2i32_a = v2i32_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2i32' (vector of 2 'int' values) as implicit conversion would cause truncation}} + v2i32_a = v2i32_a + b; + v2i32_a = v2i32_a + a; + + v2i16_a = v2i16_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2i16' (vector of 2 'short' values) as implicit conversion would cause truncation}} + v2i16_a = v2i16_a + c; // expected-warning {{implicit conversion loses integer precision: 'unsigned int' to 'v2i16' (vector of 2 'short' values)}} + v2i16_a = v2i16_a + b; // expected-error {{cannot convert between scalar type 'unsigned short' and vector type 'v2i16' (vector of 2 'short' values) as implicit conversion would cause truncation}} + v2i16_a = v2i16_a + a; + + v2i8_a = v2i8_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} + v2i8_a = v2i8_a + b; // expected-warning {{implicit conversion loses integer precision: 'unsigned short' to 'v2i8' (vector of 2 'char' values)}} + v2i8_a = v2i8_a + a; // expected-error {{cannot convert between scalar type 'unsigned char' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} +} + +void uintTestType(char a, short b, int c, long long d) { // expected-warning {{'long long' is incompatible with C++98}} + v2u64 v2u64_a = {1, 2}; + v2u32 v2u32_a = {1, 2}; + v2u16 v2u16_a = {1, 2}; + v2u8 v2u8_a = {1, 2}; + + v2u64_a = v2u64_a + d; // expected-warning {{implicit conversion changes signedness: 'long long' to 'v2u64' (vector of 2 'unsigned long long' values)}} + v2u64_a = v2u64_a + c; // expected-warning {{implicit conversion changes signedness: 'int' to 'v2u64' (vector of 2 'unsigned long long' values)}} + v2u64_a = v2u64_a + b; // expected-warning {{implicit conversion changes signedness: 'short' to 'v2u64' (vector of 2 'unsigned long long' values)}} + v2u64_a = v2u64_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u64' (vector of 2 'unsigned long long' values)}} + + v2u32_a = v2u32_a + d; // expected-warning {{implicit conversion loses integer precision: 'long long' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + c; // expected-warning {{implicit conversion changes signedness: 'int' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + b; // expected-warning {{implicit conversion changes signedness: 'short' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u32' (vector of 2 'unsigned int' values)}} + + v2u16_a = v2u16_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2u16' (vector of 2 'unsigned short' values) as implicit conversion would cause truncation}} + v2u16_a = v2u16_a + c; // expected-warning {{implicit conversion loses integer precision: 'int' to 'v2u16' (vector of 2 'unsigned short' values)}} + v2u16_a = v2u16_a + b; // expected-warning {{implicit conversion changes signedness: 'short' to 'v2u16' (vector of 2 'unsigned short' values)}} + v2u16_a = v2u16_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u16' (vector of 2 'unsigned short' values)}} + + v2u8_a = v2u8_a + d; // expected-error {{cannot convert between scalar type 'long long' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + c; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + b; // expected-warning {{implicit conversion loses integer precision: 'short' to 'v2u8' (vector of 2 'unsigned char' values)}} + v2u8_a = v2u8_a + a; // expected-warning {{implicit conversion changes signedness: 'char' to 'v2u8' (vector of 2 'unsigned char' values)}} +} + +void uintTestTypeUnsigned(unsigned char a, unsigned short b, unsigned int c, + unsigned long long d) { // expected-warning {{'long long' is incompatible with C++98}} + v2u64 v2u64_a = {1, 2}; + v2u32 v2u32_a = {1, 2}; + v2u16 v2u16_a = {1, 2}; + v2u8 v2u8_a = {1, 2}; + + v2u64_a = v2u64_a + d; + v2u64_a = v2u64_a + c; + v2u64_a = v2u64_a + b; + v2u64_a = v2u64_a + a; + + v2u32_a = v2u32_a + d; // expected-warning {{implicit conversion loses integer precision: 'unsigned long long' to 'v2u32' (vector of 2 'unsigned int' values)}} + v2u32_a = v2u32_a + c; + v2u32_a = v2u32_a + b; + v2u32_a = v2u32_a + a; + + v2u16_a = v2u16_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2u16' (vector of 2 'unsigned short' values) as implicit conversion would cause truncation}} + v2u16_a = v2u16_a + c; // expected-warning {{implicit conversion loses integer precision: 'unsigned int' to 'v2u16' (vector of 2 'unsigned short' values)}} + v2u16_a = v2u16_a + b; + v2u16_a = v2u16_a + a; + + v2u8_a = v2u8_a + d; // expected-error {{cannot convert between scalar type 'unsigned long long' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + c; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} + v2u8_a = v2u8_a + b; // expected-warning {{implicit conversion loses integer precision: 'unsigned short' to 'v2u8' (vector of 2 'unsigned char' values)}} + v2u8_a = v2u8_a + a; +} + +void uintTestConstant(v2u64 v2u64_a, v2u32 v2u32_a, v2u16 v2u16_a, + v2u8 v2u8_a) { + v2u64_a = v2u64_a + 0xFFFFFFFFFFFFFFFF; + v2u32_a = v2u32_a + 0xFFFFFFFF; + v2u16_a = v2u16_a + 0xFFFF; + v2u8_a = v2u8_a + 0xFF; + + v2u32_a = v2u32_a + 0x1FFFFFFFF; // expected-warning {{implicit conversion from 'long' to 'v2u32' (vector of 2 'unsigned int' values) changes value from 8589934591 to 4294967295}} + v2u16_a = v2u16_a + 0x1FFFF; // expected-warning {{implicit conversion from 'int' to 'v2u16' (vector of 2 'unsigned short' values) changes value from 131071 to 65535}} + v2u8_a = v2u8_a + 0x1FF; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2u8' (vector of 2 'unsigned char' values) as implicit conversion would cause truncation}} +} + +void intTestConstant(v2i64 v2i64_a, v2i32 v2i32_a, v2i16 v2i16_a, v2i8 v2i8_a) { + // Legal upper bounds. + v2i64_a = v2i64_a + static_cast<long long>(0x7FFFFFFFFFFFFFFF); // expected-warning {{'long long' is incompatible with C++98}} + v2i32_a = v2i32_a + static_cast<int>(0x7FFFFFFF); + v2i16_a = v2i16_a + static_cast<short>(0x7FFF); + v2i8_a = v2i8_a + static_cast<char>(0x7F); + + // Legal lower bounds. + v2i64_a = v2i64_a + (-9223372036854775807); + v2i32_a = v2i32_a + (-2147483648); + v2i16_a = v2i16_a + (-32768); + v2i8_a = v2i8_a + (-128); + + // One increment/decrement more than the type can hold + v2i32_a = v2i32_a + 2147483648; // expected-warning {{implicit conversion from 'long' to 'v2i32' (vector of 2 'int' values) changes value from 2147483648 to -2147483648}} + v2i16_a = v2i16_a + 32768; // expected-warning {{implicit conversion from 'int' to 'v2i16' (vector of 2 'short' values) changes value from 32768 to -32768}} + v2i8_a = v2i8_a + 128; // expected-warning {{implicit conversion from 'int' to 'v2i8' (vector of 2 'char' values) changes value from 128 to -128}} + + v2i32_a = v2i32_a + (-2147483649); // expected-warning {{implicit conversion from 'long' to 'v2i32' (vector of 2 'int' values) changes value from -2147483649 to 2147483647}} + v2i16_a = v2i16_a + (-32769); // expected-warning {{implicit conversion from 'int' to 'v2i16' (vector of 2 'short' values) changes value from -32769 to 32767}} + v2i8_a = v2i8_a + (-129); // expected-error {{cannot convert between scalar type 'int' and vector type 'v2i8' (vector of 2 'char' values) as implicit conversion would cause truncation}} +} diff --git a/test/Sema/vector-ops.c b/test/Sema/vector-ops.c index 9cdd9d2f1748..575f38b972f5 100644 --- a/test/Sema/vector-ops.c +++ b/test/Sema/vector-ops.c @@ -13,11 +13,11 @@ void test1(v2u v2ua, v2s v2sa, v2f v2fa) { (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}} // Comparison operators - v2ua = (v2ua==v2sa); // expected-warning{{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2ua = (v2ua==v2sa); // expected-warning{{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values}} v2sa = (v2ua==v2sa); // Arrays - int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values)}} + int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}} int array2[17]; // FIXME: error message below needs type! (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}} @@ -28,108 +28,108 @@ void test1(v2u v2ua, v2s v2sa, v2f v2fa) { } void testLogicalVecVec(v2u v2ua, v2s v2sa, v2f v2fa) { - // Logical operators - v2ua = v2ua && v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2ua = v2ua || v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2ua = v2ua && v2ua; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2u'}} + v2ua = v2ua || v2ua; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2u'}} - v2ua = v2sa && v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2ua = v2sa || v2ua; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2ua = v2sa && v2ua; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2u' (vector of 2 'unsigned int' values)}} + v2ua = v2sa || v2ua; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2u' (vector of 2 'unsigned int' values)}} - v2ua = v2ua && v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2ua = v2ua || v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2ua = v2ua && v2fa; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2f' (vector of 2 'float' values)}} + v2ua = v2ua || v2fa; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2f' (vector of 2 'float' values)}} - v2ua = v2sa && v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2ua = v2sa || v2fa; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2ua = v2sa && v2fa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2f' (vector of 2 'float' values)}} + v2ua = v2sa || v2fa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2f' (vector of 2 'float' values)}} - v2sa = v2sa && v2sa; - v2sa = v2sa || v2sa; + v2sa = v2sa && v2sa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2s'}} + v2sa = v2sa || v2sa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2s'}} - v2sa = v2ua && v2ua; - v2sa = v2ua || v2ua; + v2sa = v2ua && v2ua; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2u'}} + v2sa = v2ua || v2ua; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2u'}} - v2sa = v2sa && v2ua; - v2sa = v2sa || v2ua; + v2sa = v2sa && v2ua; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2u' (vector of 2 'unsigned int' values)}} + v2sa = v2sa || v2ua; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2u' (vector of 2 'unsigned int' values)}} - v2sa = v2sa && v2fa; - v2sa = v2sa || v2fa; + v2sa = v2sa && v2fa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2f' (vector of 2 'float' values)}} + v2sa = v2sa || v2fa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2f' (vector of 2 'float' values)}} - v2sa = v2ua && v2fa; - v2sa = v2ua || v2fa; + v2sa = v2ua && v2fa; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2f' (vector of 2 'float' values)}} + v2sa = v2ua || v2fa; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2f' (vector of 2 'float' values)}} - v2fa = v2fa && v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2fa = v2fa || v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2fa = v2fa && v2fa; // expected-error {{logical expression with vector types 'v2f' (vector of 2 'float' values) and 'v2f'}} + v2fa = v2fa || v2fa; // expected-error {{logical expression with vector types 'v2f' (vector of 2 'float' values) and 'v2f'}} - v2fa = v2sa && v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2fa = v2sa || v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2fa = v2sa && v2fa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2f' (vector of 2 'float' values)}} + v2fa = v2sa || v2fa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2f' (vector of 2 'float' values)}} - v2fa = v2ua && v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2fa = v2ua || v2fa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2fa = v2ua && v2fa; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2f' (vector of 2 'float' values)}} + v2fa = v2ua || v2fa; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2f' (vector of 2 'float' values)}} - v2fa = v2ua && v2ua; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2fa = v2ua || v2ua; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2fa = v2ua && v2ua; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2u'}} + v2fa = v2ua || v2ua; // expected-error {{logical expression with vector types 'v2u' (vector of 2 'unsigned int' values) and 'v2u'}} - v2fa = v2sa && v2sa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2fa = v2sa || v2sa; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2fa = v2sa && v2sa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2s'}} + v2fa = v2sa || v2sa; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2s'}} - v2fa = v2sa && v2ua; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} - v2fa = v2sa || v2ua; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}} + v2fa = v2sa && v2ua; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2u' (vector of 2 'unsigned int' values)}} + v2fa = v2sa || v2ua; // expected-error {{logical expression with vector types 'v2s' (vector of 2 'int' values) and 'v2u' (vector of 2 'unsigned int' values)}} } void testLogicalVecScalar(v2u v2ua, v2s v2sa, v2f v2fa) { - unsigned u1; - v2ua = v2ua && u1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} - v2ua = v2ua || u1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} + v2ua = v2ua && u1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'unsigned int' is only supported in C++}} + v2ua = v2ua || u1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'unsigned int' is only supported in C++}} - v2sa = v2sa && u1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} - v2sa = v2sa || u1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} + v2sa = v2sa && u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2s' (vector of 2 'int' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} + v2sa = v2sa || u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2s' (vector of 2 'int' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} - v2ua = v2sa && u1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} - v2ua = v2sa || u1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} - v2sa = v2ua && u1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} - v2sa = v2ua || u1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'unsigned int')}} + v2ua = v2sa && u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2s' (vector of 2 'int' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} + v2ua = v2sa || u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2s' (vector of 2 'int' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'unsigned int')}} + v2sa = v2ua && u1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'unsigned int' is only supported in C++}} + v2sa = v2ua || u1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'unsigned int' is only supported in C++}} - v2ua = v2fa && u1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} - v2ua = v2fa || u1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} + v2ua = v2fa && u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} + v2ua = v2fa || u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} - v2sa = v2fa && u1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} - v2sa = v2fa || u1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'unsigned int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} + v2sa = v2fa && u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} + v2sa = v2fa || u1; // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'unsigned int')}} int s1; - v2ua = v2ua && s1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'int')}} - v2ua = v2ua || s1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'int')}} + v2ua = v2ua && s1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'int' is only supported in C++}} + v2ua = v2ua || s1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'int' is only supported in C++}} - v2sa = v2sa && s1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'int')}} - v2sa = v2sa || s1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'int')}} + v2sa = v2sa && s1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'int' is only supported in C++}} + v2sa = v2sa || s1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'int' is only supported in C++}} - v2ua = v2sa && s1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'int')}} - v2ua = v2sa || s1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'int')}} - v2sa = v2ua && s1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'int')}} - v2sa = v2ua || s1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'int')}} + v2ua = v2sa && s1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'int' is only supported in C++}} + v2ua = v2sa || s1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'int' is only supported in C++}} - v2ua = v2fa && s1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int')}} - v2ua = v2fa || s1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int')}} + v2sa = v2ua && s1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'int' is only supported in C++}} + v2sa = v2ua || s1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'int' is only supported in C++}} - v2sa = v2fa && s1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int')}} - v2sa = v2fa || s1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'int')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int')}} + v2ua = v2fa && s1; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int'}} + v2ua = v2fa || s1; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int'}} + + v2sa = v2fa && s1; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int'}} + v2sa = v2fa || s1; // expected-error {{cannot convert between scalar type 'int' and vector type 'v2f' (vector of 2 'float' values) as implicit conversion would cause truncation}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'int'}} float f1; - v2ua = v2ua && f1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'float')}} - v2ua = v2ua || f1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'float')}} + v2ua = v2ua && f1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'float' is only supported in C++}} + v2ua = v2ua || f1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'float' is only supported in C++}} + + v2sa = v2sa && f1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'float' is only supported in C++}} + v2sa = v2sa || f1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'float' is only supported in C++}} - v2sa = v2sa && f1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'float')}} - v2sa = v2sa || f1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'float')}} + v2ua = v2sa && f1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'float' is only supported in C++}} + v2ua = v2sa || f1; // expected-error {{logical expression with vector type 'v2s' (vector of 2 'int' values) and non-vector type 'float' is only supported in C++}} - v2ua = v2sa && f1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'float')}} - v2ua = v2sa || f1; // expected-error {{cannot convert between vector values of different size ('v2s' (vector of 2 'int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2s' (vector of 2 'int' values) and 'float')}} - v2sa = v2ua && f1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'float')}} - v2sa = v2ua || f1; // expected-error {{cannot convert between vector values of different size ('v2u' (vector of 2 'unsigned int' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2u' (vector of 2 'unsigned int' values) and 'float')}} + v2sa = v2ua && f1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'float' is only supported in C++}} + v2sa = v2ua || f1; // expected-error {{logical expression with vector type 'v2u' (vector of 2 'unsigned int' values) and non-vector type 'float' is only supported in C++}} - v2ua = v2fa && f1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'float')}} - v2ua = v2fa || f1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'float')}} + v2ua = v2fa && f1; // expected-error {{logical expression with vector type 'v2f' (vector of 2 'float' values) and non-vector type 'float' is only supported in C++}} + v2ua = v2fa || f1; // expected-error {{logical expression with vector type 'v2f' (vector of 2 'float' values) and non-vector type 'float' is only supported in C++}} - v2sa = v2fa && f1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'float')}} - v2sa = v2fa || f1; // expected-error {{cannot convert between vector values of different size ('v2f' (vector of 2 'float' values) and 'float')}} expected-error {{invalid operands to binary expression ('v2f' (vector of 2 'float' values) and 'float')}} + v2sa = v2fa && f1; // expected-error {{logical expression with vector type 'v2f' (vector of 2 'float' values) and non-vector type 'float' is only supported in C++}} + v2sa = v2fa || f1; // expected-error {{logical expression with vector type 'v2f' (vector of 2 'float' values) and non-vector type 'float' is only supported in C++}} } diff --git a/test/Sema/zvector.c b/test/Sema/zvector.c index d1cf1aa01f4b..740163fcd9d5 100644 --- a/test/Sema/zvector.c +++ b/test/Sema/zvector.c @@ -326,14 +326,14 @@ void foo(void) bc = bc + sc2; // expected-error {{incompatible type}} bc = sc + bc2; // expected-error {{incompatible type}} - sc = sc + sc_scalar; // expected-error {{cannot convert}} - sc = sc + uc_scalar; // expected-error {{cannot convert}} - sc = sc_scalar + sc; // expected-error {{cannot convert}} - sc = uc_scalar + sc; // expected-error {{cannot convert}} - uc = uc + sc_scalar; // expected-error {{cannot convert}} - uc = uc + uc_scalar; // expected-error {{cannot convert}} - uc = sc_scalar + uc; // expected-error {{cannot convert}} - uc = uc_scalar + uc; // expected-error {{cannot convert}} + sc = sc + sc_scalar; + sc = sc + uc_scalar; // expected-error {{cannot convert between scalar type 'unsigned char' and vector type '__vector signed char' (vector of 16 'signed char' values) as implicit conversion would cause truncation}} + sc = sc_scalar + sc; + sc = uc_scalar + sc; // expected-error {{cannot convert between scalar type 'unsigned char' and vector type '__vector signed char' (vector of 16 'signed char' values) as implicit conversion would cause truncation}} + uc = uc + sc_scalar; // expected-error {{implicit conversion changes signedness: 'signed char' to '__vector unsigned char' (vector of 16 'unsigned char' values)}} + uc = uc + uc_scalar; + uc = sc_scalar + uc; // expected-error {{implicit conversion changes signedness: 'signed char' to '__vector unsigned char' (vector of 16 'unsigned char' values)}} + uc = uc_scalar + uc; ss = ss + ss2; us = us + us2; @@ -368,10 +368,10 @@ void foo(void) sc += sl2; // expected-error {{cannot convert}} sc += fd2; // expected-error {{cannot convert}} - sc += sc_scalar; // expected-error {{cannot convert}} - sc += uc_scalar; // expected-error {{cannot convert}} - uc += sc_scalar; // expected-error {{cannot convert}} - uc += uc_scalar; // expected-error {{cannot convert}} + sc += sc_scalar; + sc += uc_scalar; // expected-error {{cannot convert between scalar type 'unsigned char' and vector type '__vector signed char' (vector of 16 'signed char' values) as implicit conversion would cause truncation}} + uc += sc_scalar; // expected-error {{implicit conversion changes signedness: 'signed char' to '__vector unsigned char' (vector of 16 'unsigned char' values)}} + uc += uc_scalar; ss += ss2; us += us2; diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index c5de33cedb90..102ff1e80d03 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -302,3 +302,22 @@ namespace PR14073 { struct S2 { union { union { int n; }; char c; }; S2() : n(n) {} }; // expected-warning {{field 'n' is uninitialized when used here}} struct S3 { struct { int n; }; S3() : n(n) {} }; // expected-warning {{field 'n' is uninitialized when used here}} } + +namespace PR10758 { +struct A; +struct B { + B (A const &); // expected-note 2 {{candidate constructor not viable: no known conversion from 'const PR10758::B' to 'const PR10758::A &' for 1st argument}} + B (B &); // expected-note 2 {{candidate constructor not viable: 1st argument ('const PR10758::B') would lose const qualifier}} +}; +struct A { + A (B); // expected-note 2 {{passing argument to parameter here}} +}; + +B f(B const &b) { + return b; // expected-error {{no matching constructor for initialization of 'PR10758::B'}} +} + +A f2(const B &b) { + return b; // expected-error {{no matching constructor for initialization of 'PR10758::B'}} +} +} diff --git a/test/SemaCXX/cxx1y-generic-lambdas.cpp b/test/SemaCXX/cxx1y-generic-lambdas.cpp index 1993c6e1853d..9f3c77591a86 100644 --- a/test/SemaCXX/cxx1y-generic-lambdas.cpp +++ b/test/SemaCXX/cxx1y-generic-lambdas.cpp @@ -986,3 +986,10 @@ class Enclosing3 { ); }; } + +namespace PR32638 { + //https://bugs.llvm.org/show_bug.cgi?id=32638 + void test() { + [](auto x) noexcept(noexcept(x)) { } (0); + } +}
\ No newline at end of file diff --git a/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/test/SemaCXX/cxx1y-variable-templates_top_level.cpp index b4963646838c..a78548b6f128 100644 --- a/test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ b/test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -9,7 +9,7 @@ #endif template<typename T> -T pi = T(3.1415926535897932385); // expected-note {{template is declared here}} +T pi = T(3.1415926535897932385); // expected-note 2{{declared here}} template<typename T> CONST T cpi = T(3.1415926535897932385); // expected-note {{template is declared here}} @@ -58,10 +58,9 @@ namespace use_in_top_level_funcs { namespace shadow { void foo() { int ipi0 = pi<int>; - int pi; + int pi; // expected-note {{found}} int a = pi; - int ipi = pi<int>; // expected-error {{expected '(' for function-style cast or type construction}} \ - // expected-error {{expected expression}} + int ipi = pi<int>; // expected-error {{'pi' does not name a template but is followed by template arguments; did you mean '::pi'?}} } } diff --git a/test/SemaCXX/enable_if.cpp b/test/SemaCXX/enable_if.cpp index 9a06d3866110..93014f50d508 100644 --- a/test/SemaCXX/enable_if.cpp +++ b/test/SemaCXX/enable_if.cpp @@ -499,3 +499,17 @@ void run() { } } } + +namespace TypeOfFn { + template <typename T, typename U> + struct is_same; + + template <typename T> struct is_same<T, T> { + enum { value = 1 }; + }; + + void foo(int a) __attribute__((enable_if(a, ""))); + void foo(float a) __attribute__((enable_if(1, ""))); + + static_assert(is_same<__typeof__(foo)*, decltype(&foo)>::value, ""); +} diff --git a/test/SemaCXX/for-range-examples.cpp b/test/SemaCXX/for-range-examples.cpp index 08a9982c6378..d6b527ff8a50 100644 --- a/test/SemaCXX/for-range-examples.cpp +++ b/test/SemaCXX/for-range-examples.cpp @@ -241,3 +241,37 @@ namespace pr18587 { } } } + +namespace PR32933 { +// https://bugs.llvm.org/show_bug.cgi?id=32933 +void foo () +{ + int b = 1, a[b]; + a[0] = 0; + [&] { for (int c : a) 0; } (); +} + + +int foo(int b) { + int varr[b][(b+=8)]; + b = 15; + [&] { + int i = 0; + for (auto &c : varr) + { + c[0] = ++b; + } + [&] { + int i = 0; + for (auto &c : varr) { + int j = 0; + for(auto &c2 : c) { + ++j; + } + ++i; + } + }(); + }(); + return b; +} +}
\ No newline at end of file diff --git a/test/SemaCXX/invalid-member-expr.cpp b/test/SemaCXX/invalid-member-expr.cpp index 172be6b8266d..fd50d328da67 100644 --- a/test/SemaCXX/invalid-member-expr.cpp +++ b/test/SemaCXX/invalid-member-expr.cpp @@ -53,9 +53,7 @@ namespace test3 { namespace rdar11293995 { struct Length { - explicit Length(PassRefPtr<CalculationValue>); // expected-error {{unknown type name}} \ - expected-error {{expected ')'}} \ - expected-note {{to match this '('}} + explicit Length(PassRefPtr<CalculationValue>); // expected-error {{no template named 'PassRefPtr}} expected-error {{undeclared identifier 'CalculationValue'}} }; struct LengthSize { diff --git a/test/SemaCXX/modules-ts.cppm b/test/SemaCXX/modules-ts.cppm index 16695f6463a8..d1d7aaa96e6c 100644 --- a/test/SemaCXX/modules-ts.cppm +++ b/test/SemaCXX/modules-ts.cppm @@ -17,7 +17,8 @@ static int m; // ok, internal linkage, so no redefinition error int n; #if TEST >= 2 // expected-error@-2 {{redefinition of '}} -// expected-note@-3 {{previous}} +// expected-note@-3 {{unguarded header; consider using #ifdef guards or #pragma once}} +// expected-note-re@modules-ts.cppm:1 {{'{{.*}}modules-ts.cppm' included multiple times, additional include site here}} #endif #if TEST == 0 diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index 9da59b93c503..919122576222 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -1256,7 +1256,7 @@ void is_trivially_copyable2() int t33[F(__is_trivially_copyable(ExtDefaulted))]; int t34[T(__is_trivially_copyable(const int))]; - int t35[F(__is_trivially_copyable(volatile int))]; + int t35[T(__is_trivially_copyable(volatile int))]; } struct CStruct { diff --git a/test/SemaCXX/typo-correction.cpp b/test/SemaCXX/typo-correction.cpp index c59ee618f929..2d78f06c5d33 100644 --- a/test/SemaCXX/typo-correction.cpp +++ b/test/SemaCXX/typo-correction.cpp @@ -524,13 +524,16 @@ namespace shadowed_template { template <typename T> class Fizbin {}; // expected-note {{'::shadowed_template::Fizbin' declared here}} class Baz { int Fizbin(); - // TODO: Teach the parser to recover from the typo correction instead of - // continuing to treat the template name as an implicit-int declaration. - Fizbin<int> qux; // expected-error {{unknown type name 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}} \ - // expected-error {{expected member name or ';' after declaration specifiers}} + Fizbin<int> qux; // expected-error {{no template named 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}} }; } +namespace no_correct_template_id_to_non_template { + struct Frobnatz {}; // expected-note {{declared here}} + Frobnats fn; // expected-error {{unknown type name 'Frobnats'; did you mean 'Frobnatz'?}} + Frobnats<int> fni; // expected-error-re {{no template named 'Frobnats'{{$}}}} +} + namespace PR18852 { void func() { struct foo { diff --git a/test/SemaCXX/vector-no-lax.cpp b/test/SemaCXX/vector-no-lax.cpp index a85f7f9db060..3cedcb1e8ce5 100644 --- a/test/SemaCXX/vector-no-lax.cpp +++ b/test/SemaCXX/vector-no-lax.cpp @@ -4,6 +4,6 @@ typedef int __attribute__((vector_size (16))) vSInt32; vSInt32 foo (vUInt32 a) { vSInt32 b = { 0, 0, 0, 0 }; - b += a; // expected-error{{cannot convert between vector values}} + b += a; // expected-error{{cannot convert between vector type 'vUInt32' (vector of 4 'unsigned int' values) and vector type 'vSInt32' (vector of 4 'int' values) as implicit conversion would cause truncation}} return b; } diff --git a/test/SemaCXX/warn-unused-filescoped.cpp b/test/SemaCXX/warn-unused-filescoped.cpp index 18defee7d04a..93c6bbd7edc9 100644 --- a/test/SemaCXX/warn-unused-filescoped.cpp +++ b/test/SemaCXX/warn-unused-filescoped.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s #ifdef HEADER @@ -65,7 +65,7 @@ namespace { template <> void TS<int>::m() { } // expected-warning{{unused}} template <typename T> - void tf() { } + void tf() { } // expected-warning{{unused}} template <> void tf<int>() { } // expected-warning{{unused}} struct VS { @@ -200,6 +200,18 @@ void bar() { void func() __attribute__((used)); } static void func() {} } +namespace test9 { +template<typename T> +static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}} +} + +namespace test10 { +#if __cplusplus >= 201103L +template<class T> +constexpr T pi = T(3.14); // expected-warning {{unused}} +#endif +} + namespace pr19713 { #if __cplusplus >= 201103L // FIXME: We should warn on both of these. diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m index ad67a34edb00..a7f0745ddbad 100644 --- a/test/SemaObjC/method-bad-param.m +++ b/test/SemaObjC/method-bad-param.m @@ -20,6 +20,12 @@ } @end +// Ensure that this function is properly marked as a failure. +void func_with_bad_call(bar* b, foo* f) { + [b cccccc:5]; // expected-warning {{instance method '-cccccc:' not found}} + // expected-note@-17 {{receiver is instance of class declared here}} +} + void somefunc(foo x) {} // expected-error {{interface type 'foo' cannot be passed by value; did you forget * in 'foo'}} foo somefunc2() {} // expected-error {{interface type 'foo' cannot be returned by value; did you forget * in 'foo'}} diff --git a/test/SemaObjC/unguarded-availability.m b/test/SemaObjC/unguarded-availability.m index ae921f4a27b3..071a21ea1b3f 100644 --- a/test/SemaObjC/unguarded-availability.m +++ b/test/SemaObjC/unguarded-availability.m @@ -8,7 +8,7 @@ int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been explicitly marked partial here}} #ifdef OBJCPP -// expected-note@+2 2 {{marked partial here}} +// expected-note@+2 6 {{marked partial here}} #endif int func_10_12() AVAILABLE_10_12; // expected-note 6 {{'func_10_12' has been explicitly marked partial here}} @@ -48,7 +48,7 @@ void star_case() { } else func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}} - if (@available(macos 10.11, *)) { + if (@available(macOS 10.11, *)) { if (@available(ios 8, *)) { func_10_11(); func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}} @@ -176,7 +176,7 @@ int instantiate_with_availability_attr() { } int instantiate_availability() { - if (@available(macos 10.12, *)) + if (@available(macOS 10.12, *)) with_availability_attr<int_10_12>(); else with_availability_attr<int_10_12>(); // expected-warning{{'with_availability_attr<int>' is only available on macOS 10.11 or newer}} expected-warning{{'int_10_12' is only available on macOS 10.12 or newer}} expected-note 2 {{enclose}} @@ -188,4 +188,19 @@ auto topLevelLambda = [] () { func_10_12(); }; +void functionInFunction() { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + struct DontWarnTwice { + void f() { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + } + }; + void([] () { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + }); + (void)(^ { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + }); +} + #endif diff --git a/test/SemaObjCXX/interface-return-type.mm b/test/SemaObjCXX/interface-return-type.mm new file mode 100644 index 000000000000..9fff8610ae0d --- /dev/null +++ b/test/SemaObjCXX/interface-return-type.mm @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify + +@class NSObject; +template<typename T> struct C { + static T f(); // expected-error {{interface type 'NSObject' cannot be returned by value; did you forget * in 'NSObject'?}} +}; +int g() { NSObject *x = C<NSObject>::f(); }//expected-error {{no member named 'f' in 'C<NSObject>'}} expected-note {{in instantiation of template class 'C<NSObject>' requested here}} diff --git a/test/SemaObjCXX/is-base-of.mm b/test/SemaObjCXX/is-base-of.mm new file mode 100644 index 000000000000..9cf16661b0c5 --- /dev/null +++ b/test/SemaObjCXX/is-base-of.mm @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s + +@interface NSObj +@end + +@interface NSChild : NSObj +@end + +static_assert(__is_base_of(NSObj, NSChild), ""); +static_assert(!__is_base_of(NSChild, NSObj), ""); + +static_assert(__is_base_of(NSObj, NSObj), ""); + +static_assert(!__is_base_of(NSObj *, NSChild *), ""); +static_assert(!__is_base_of(NSChild *, NSObj *), ""); + +static_assert(__is_base_of(const volatile NSObj, NSChild), ""); +static_assert(__is_base_of(NSObj, const volatile NSChild), ""); + +@class NSForward; // expected-note{{forward declaration of class}} + +static_assert(!__is_base_of(NSForward, NSObj), ""); +static_assert(!__is_base_of(NSObj, NSForward), ""); // expected-error{{incomplete type 'NSForward'}} + +static_assert(!__is_base_of(id, NSObj), ""); diff --git a/test/SemaOpenCL/array-init.cl b/test/SemaOpenCL/array-init.cl new file mode 100644 index 000000000000..d9691d86dd81 --- /dev/null +++ b/test/SemaOpenCL/array-init.cl @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// expected-no-diagnostics
+
+__kernel void k1(queue_t q1, queue_t q2) {
+ queue_t q[] = {q1, q2};
+}
+
+__kernel void k2(read_only pipe int p) {
+ reserve_id_t i1 = reserve_read_pipe(p, 1);
+ reserve_id_t i2 = reserve_read_pipe(p, 1);
+ reserve_id_t i[] = {i1, i2};
+}
+
+event_t create_event();
+__kernel void k3() {
+ event_t e1 = create_event();
+ event_t e2 = create_event();
+ event_t e[] = {e1, e2};
+}
+
diff --git a/test/SemaOpenCL/storageclass.cl b/test/SemaOpenCL/storageclass.cl index a93f8244dcbd..f457cfd1d3f6 100644 --- a/test/SemaOpenCL/storageclass.cl +++ b/test/SemaOpenCL/storageclass.cl @@ -5,7 +5,7 @@ constant int G2 = 0; int G3 = 0; // expected-error{{program scope variable must reside in constant address space}} global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}} -void kernel foo() { +void kernel foo(int x) { // static is not allowed at local scope before CL2.0 static int S1 = 5; // expected-error{{variables in function scope cannot be declared static}} static constant int S2 = 5; // expected-error{{variables in function scope cannot be declared static}} @@ -15,6 +15,12 @@ void kernel foo() { auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}} global int L4; // expected-error{{function scope variable cannot be declared in global address space}} + + constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}} + global int *constant L6 = &G4; + private int *constant L7 = &x; // expected-error {{initializer element is not a compile-time constant}} + constant int *constant L8 = &L1; + local int *constant L9 = &L2; // expected-error {{initializer element is not a compile-time constant}} } static void kernel bar() { // expected-error{{kernel functions cannot be declared static}} @@ -29,4 +35,7 @@ void f() { } global int L3; // expected-error{{function scope variable cannot be declared in global address space}} extern constant float L4; + extern local float L5; // expected-error{{extern variable must reside in constant address space}} + static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}} + static int L7; // expected-error{{variables in function scope cannot be declared static}} } diff --git a/test/SemaTemplate/deduction-crash.cpp b/test/SemaTemplate/deduction-crash.cpp index ff7421a910bd..c94c9db94e06 100644 --- a/test/SemaTemplate/deduction-crash.cpp +++ b/test/SemaTemplate/deduction-crash.cpp @@ -2,7 +2,7 @@ // Note that the error count below doesn't matter. We just want to // make sure that the parser doesn't crash. -// CHECK: 16 errors +// CHECK: 17 errors // PR7511 template<a> diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp index d3e249db7ee2..b5b042c64a71 100644 --- a/test/SemaTemplate/default-arguments.cpp +++ b/test/SemaTemplate/default-arguments.cpp @@ -207,3 +207,19 @@ Y<false> y2; } // end ns1 } // end ns PR26134 + +namespace friends { + namespace ns { + template<typename> struct A { + template<typename> friend void f(); + template<typename> friend struct X; + }; + template<typename = int> void f(); // expected-warning 0-1{{extension}} + template<typename = int> struct X; + A<int> a; + } + namespace ns { + void g() { f(); } + X<int> *p; + } +} diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index 010716dd1426..42d9f4d332a9 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -95,7 +95,7 @@ namespace PR7622 { struct basic_streambuf; template<typename,typename> - struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \ + struct basic_streambuf{friend bob<>()}; // expected-error{{no template named 'bob'}} \ // expected-error{{expected member name or ';' after declaration specifiers}} template struct basic_streambuf<int>; } diff --git a/test/SemaTemplate/explicit-specialization-member.cpp b/test/SemaTemplate/explicit-specialization-member.cpp index f302836c7e4b..c0c36808b492 100644 --- a/test/SemaTemplate/explicit-specialization-member.cpp +++ b/test/SemaTemplate/explicit-specialization-member.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -fcxx-exceptions template<typename T> struct X0 { typedef T* type; @@ -57,3 +57,12 @@ template<typename T> struct Helper { template<typename T> void Helper<T>::func<2>() {} // expected-error {{cannot specialize a member}} \ // expected-error {{no function template matches}} } + +namespace SpecLoc { + template <typename T> struct A { + static int n; // expected-note {{previous}} + static void f(); // expected-note {{previous}} + }; + template<> float A<int>::n; // expected-error {{different type}} + template<> void A<int>::f() throw(); // expected-error {{does not match}} +} diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 6afc7091260d..a41248ee1b8e 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -347,8 +347,7 @@ template <typename T> struct B : A<T> { }; template <typename T> struct C : A<T> { // Incorrect form. - NameFromBase<T> m; // expected-error {{unknown type name 'NameFromBase'}} - //expected-error@-1 {{expected member name or ';' after declaration specifiers}} + NameFromBase<T> m; // expected-error {{no template named 'NameFromBase'}} }; } diff --git a/test/SemaTemplate/typo-template-name.cpp b/test/SemaTemplate/typo-template-name.cpp new file mode 100644 index 000000000000..fe5201a8e26c --- /dev/null +++ b/test/SemaTemplate/typo-template-name.cpp @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -std=c++1z %s -verify -Wno-unused + +namespace InExpr { + namespace A { + void typo_first_a(); // expected-note {{found}} + template<typename T> void typo_first_b(); // expected-note 2{{declared here}} + } + void testA() { A::typo_first_a<int>(); } // expected-error {{'typo_first_a' does not name a template but is followed by template arguments; did you mean 'typo_first_b'?}} + + namespace B { + void typo_first_b(); // expected-note {{found}} + } + void testB() { B::typo_first_b<int>(); } // expected-error {{'typo_first_b' does not name a template but is followed by template arguments; did you mean 'A::typo_first_b'?}} + + struct Base { + template<typename T> static void foo(); // expected-note 4{{declared here}} + int n; + }; + struct Derived : Base { + void foo(); // expected-note {{found}} + }; + // We probably don't want to suggest correcting to .Base::foo<int> + void testMember() { Derived().foo<int>(); } // expected-error-re {{does not name a template but is followed by template arguments{{$}}}} + + struct Derived2 : Base { + void goo(); // expected-note {{found}} + }; + void testMember2() { Derived2().goo<int>(); } // expected-error {{member 'goo' of 'InExpr::Derived2' is not a template; did you mean 'foo'?}} + + void no_correction() { + int foo; // expected-note 3{{found}} + + foo<int>(); // expected-error {{'foo' does not name a template but is followed by template arguments; did you mean 'Base::foo'?}} + foo<>(); // expected-error {{'foo' does not name a template but is followed by template arguments; did you mean 'Base::foo'?}} + foo<Base *>(); // expected-error {{'foo' does not name a template but is followed by template arguments; did you mean 'Base::foo'?}} + + // These are valid expressions. + foo<foo; // expected-warning {{self-comparison}} + foo<int()>(0); + foo<int(), true>(false); + foo<Base{}.n; + } +} |