Add a test case for -ffreestanding that redefines malloc.

Warn that complex numbers are an extension in a freestanding C99
implementation.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64568 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def
index 95d7001..570b711 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.def
+++ b/include/clang/Basic/DiagnosticSemaKinds.def
@@ -876,6 +876,9 @@
 DIAG(error_nosetter_property_assignment, ERROR,
      "setter method is needed to assign to object using property"
      " assignment syntax")
+DIAG(ext_freestanding_complex, EXTENSION,
+     "complex numbers are an extension in a freestanding C99 implementation")
+
 
 // Obj-c expressions
 DIAG(warn_class_method_not_found, WARNING,
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index e898782..00bfb13 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -170,8 +170,11 @@
   }
   
   // Handle complex types.
-  if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex)
+  if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex) {
+    if (getLangOptions().Freestanding)
+      Diag(DS.getTypeSpecComplexLoc(), diag::ext_freestanding_complex);
     Result = Context.getComplexType(Result);
+  }
   
   assert(DS.getTypeSpecComplex() != DeclSpec::TSC_imaginary &&
          "FIXME: imaginary types not supported yet!");
diff --git a/test/Sema/implicit-builtin-freestanding.c b/test/Sema/implicit-builtin-freestanding.c
new file mode 100644
index 0000000..f36aa09
--- /dev/null
+++ b/test/Sema/implicit-builtin-freestanding.c
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only -verify -ffreestanding %s
+
+int malloc(int a) { return a; }
+
diff --git a/test/Sema/warn-freestanding-complex.c b/test/Sema/warn-freestanding-complex.c
new file mode 100644
index 0000000..aa59b95
--- /dev/null
+++ b/test/Sema/warn-freestanding-complex.c
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only -ffreestanding -pedantic -verify %s
+
+void foo(float _Complex c) { // expected-warning{{complex numbers are an extension in a freestanding C99 implementation}}
+}