summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-09-19 23:17:44 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-09-19 23:17:44 +0000
commit6b9c41ea68f8ab98d012b3fb6384ded1022c71ea (patch)
tree761bcb81e11e8e9e56f99f75ed8edef411396dae /clang/test
parent1ab5e56324b6b65ee0095ec3400a9aa0836ae7d8 (diff)
downloadbcm5719-llvm-6b9c41ea68f8ab98d012b3fb6384ded1022c71ea.tar.gz
bcm5719-llvm-6b9c41ea68f8ab98d012b3fb6384ded1022c71ea.zip
Add list initialization for complex numbers in C. Essentially, this allows "_Complex float x = {1.0f, 2.0f};". See changes to docs/LanguageExtensions.html for a longer description.
<rdar://problem/9397672>. llvm-svn: 140090
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/complex-init-list.c12
-rw-r--r--clang/test/Sema/array-init.c2
-rw-r--r--clang/test/Sema/complex-init-list.c45
-rw-r--r--clang/test/SemaCXX/complex-init-list.cpp14
4 files changed, 72 insertions, 1 deletions
diff --git a/clang/test/CodeGen/complex-init-list.c b/clang/test/CodeGen/complex-init-list.c
new file mode 100644
index 00000000000..819d4f9432d
--- /dev/null
+++ b/clang/test/CodeGen/complex-init-list.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
+
+// This file tests the clang extension which allows initializing the components
+// of a complex number individually using an initialization list. (There is a
+// extensive description and test in test/Sema/complex-init-list.c.)
+
+_Complex float x = { 1.0f, 1.0f/0.0f };
+// CHECK: @x = global { float, float } { float 1.000000e+00, float 0x7FF0000000000000 }, align 4
+
+_Complex float f(float x, float y) { _Complex float z = { x, y }; return z; }
+// CHECK: define <2 x float> @f
+// CHECK: alloca { float, float } \ No newline at end of file
diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c
index 345ab6981b1..bc958c3eea6 100644
--- a/clang/test/Sema/array-init.c
+++ b/clang/test/Sema/array-init.c
@@ -53,7 +53,7 @@ void func() {
void test() {
int y1[3] = {
- { 1, 2, 3 } // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in scalar initializer}}
+ { 1, 2, 3 } // expected-warning{{excess elements in scalar initializer}}
};
int y3[4][3] = {
{ 1, 3, 5 },
diff --git a/clang/test/Sema/complex-init-list.c b/clang/test/Sema/complex-init-list.c
new file mode 100644
index 00000000000..5b5d7ce1436
--- /dev/null
+++ b/clang/test/Sema/complex-init-list.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+
+// This file tests the clang extension which allows initializing the components
+// of a complex number individually using an initialization list. Basically,
+// if you have an explicit init list for a complex number that contains two
+// initializers, this extension kicks in to turn it into component-wise
+// initialization.
+//
+// This extension is useful because there isn't any way to accurately build
+// a complex number at the moment besides setting the components with
+// __real__ and __imag__, which is inconvenient and not usable for constants.
+// (Of course, there are other extensions we could implement that would
+// allow this, like some sort of __builtin_build_complex.)
+//
+// FIXME: It would be a good idea to have a warnings for implicit
+// real->complex and complex->real conversions; as-is, it's way too easy
+// to get implicit conversions when they are not intended.
+
+// Basic testcase
+_Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{specifying real and imaginary components is an extension}}
+
+
+// Struct for nesting tests
+struct teststruct { _Complex float x; };
+
+
+// Random other valid stuff
+_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} expected-warning {{specifying real and imaginary components is an extension}}
+struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
+_Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
+// FIXME: We need some sort of warning for valid5
+_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} expected-warning {{specifying real and imaginary components is an extension}}
+
+
+// Random invalid stuff
+struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
+
+
+// Check incomplete array sizing
+_Complex float sizetest1[] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
+_Complex float sizecheck1[(sizeof(sizetest1) == sizeof(*sizetest1)*2) ? 1 : -1];
+_Complex float sizetest2[] = { 1.0f, 1.0f, {1.0f, 1.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
+_Complex float sizecheck2[(sizeof(sizetest2) == sizeof(*sizetest2)*3) ? 1 : -1];
diff --git a/clang/test/SemaCXX/complex-init-list.cpp b/clang/test/SemaCXX/complex-init-list.cpp
new file mode 100644
index 00000000000..e75833a37db
--- /dev/null
+++ b/clang/test/SemaCXX/complex-init-list.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+
+// This file tests the clang extension which allows initializing the components
+// of a complex number individually using an initialization list. Basically,
+// if you have an explicit init list for a complex number that contains two
+// initializers, this extension kicks in to turn it into component-wise
+// initialization.
+//
+// See also the testcase for the C version of this extension in
+// test/Sema/complex-init-list.c.
+
+// Basic testcase
+// (No pedantic warning is necessary because _Complex is not part of C++.)
+_Complex float valid1 = { 1.0f, 2.0f };
OpenPOWER on IntegriCloud