Fix a number of issues w.r.t. emission of global for functions and
aliases.
 - Attributes specific to a definition are only set when the
   definition is seen.
 - Alias generation is delayed until the end of the module; necessary
   since the alias may reference forward.
 - Fixes: PR2743, <rdr://6140807&6094512>
 - Improves: <rdr://6095112> (added XFAIL)

Also, print module on verification failures.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55966 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/PR2743-reference-missing-static.c b/test/CodeGen/PR2743-reference-missing-static.c
new file mode 100644
index 0000000..007a22f
--- /dev/null
+++ b/test/CodeGen/PR2743-reference-missing-static.c
@@ -0,0 +1,16 @@
+// RUN: clang -emit-llvm -o %t %s
+// PR2743
+// <rdr://6094512>
+
+/* CodeGen should handle this even if it makes it past
+   sema. Unfortunately this test will become useless once sema starts
+   rejecting this. */
+
+static void e0();
+void f0() { e0(); }
+
+inline void e1();
+void f1() { e1(); }
+
+void e2() __attribute__((weak));
+void f2() { e2(); }
diff --git a/test/CodeGen/rdr-6095112-alias-references-inline.c b/test/CodeGen/rdr-6095112-alias-references-inline.c
new file mode 100644
index 0000000..4805d47
--- /dev/null
+++ b/test/CodeGen/rdr-6095112-alias-references-inline.c
@@ -0,0 +1,6 @@
+// RUN: clang --emit-llvm -o %t %s &&
+// RUN: grep -e "alias" %t
+// XFAIL
+
+static inline int foo () { return 0; }
+int bar () __attribute__ ((alias ("foo")));
diff --git a/test/CodeGen/rdr-6140807-alias-references-forward.c b/test/CodeGen/rdr-6140807-alias-references-forward.c
new file mode 100644
index 0000000..eff69ac
--- /dev/null
+++ b/test/CodeGen/rdr-6140807-alias-references-forward.c
@@ -0,0 +1,14 @@
+// RUN: clang -emit-llvm -o %t %s &&
+// RUN: grep -e "@f = alias" %t | count 1 &&
+// RUN: grep -e "bitcast (i32 (i32)\\* @f to i32 (float)\\*)" %t | count 1
+// <rdar://problem/6140807>
+
+int f(float) __attribute__((weak, alias("x")));
+
+// Make sure we replace uses properly...
+int y() {
+  return f(1.);
+}
+
+int x(int) {
+}