16f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
26f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
36f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmanstruct S {
46f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  virtual ~S() { }
56f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman};
66f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
76f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman// PR5706
86f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman// Make sure this doesn't crash; the mangling doesn't matter because the name
96f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman// doesn't have linkage.
106f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmanstatic struct : S { } obj8;
116f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
126f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmanvoid f() {
136f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  // Make sure this doesn't crash; the mangling doesn't matter because the
146f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  // generated vtable/etc. aren't modifiable (although it would be nice for
156f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  // codesize to make it consistent inside inline functions).
166f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  static struct : S { } obj8;
176f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman}
186f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
196f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmaninline int f2() {
206f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  // FIXME: We don't mangle the names of a or x correctly!
216f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  static struct { int a() { static int x; return ++x; } } obj;
226f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  return obj.a();
236f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman}
246f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
256f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmanint f3() { return f2(); }
266f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
276f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmanstruct A {
286f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  typedef struct { int x; } *ptr;
296f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  ptr m;
306f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  int a() {
316f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman    static struct x {
326f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman      // FIXME: We don't mangle the names of a or x correctly!
336f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman      int a(ptr A::*memp) { static int x; return ++x; }
346f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman    } a;
356f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman    return a.a(&A::m);
366f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman  }
376f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman};
386f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedman
396f9f25dfc7bf9cc1ab1282d6d7e9cf7916d8a09cEli Friedmanint f4() { return A().a(); }
406f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson
416f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlssonint f5() {
426f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  static union {
436f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson    int a;
446f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  };
456f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson
466f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  // CHECK: _ZZ2f5vE1a
476f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  return a;
486f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson}
496f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson
506f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlssonint f6() {
516f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  static union {
526f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson    union {
536f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson      int : 1;
546f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson    };
556f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson    int b;
566f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  };
576f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson
586f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  // CHECK: _ZZ2f6vE1b
596f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  return b;
606f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson}
616f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson
626f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlssonint f7() {
636f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  static union {
646f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson    union {
656f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson      int b;
666f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson    } a;
676f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  };
686f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson
696f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  // CHECK: _ZZ2f7vE1a
706f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson  return a.b;
716f7e2f4019860cad19883db44f4d0bfa36d2f552Anders Carlsson}
72cde5a400dbc9655eddf0f383585d3cf67c11c539John McCall
73cde5a400dbc9655eddf0f383585d3cf67c11c539John McCall// This used to cause an assert because the typedef-for-anonymous-tag
74cde5a400dbc9655eddf0f383585d3cf67c11c539John McCall// code was trying to claim the enum for the template.
75cde5a400dbc9655eddf0f383585d3cf67c11c539John McCallenum { T8 };
76cde5a400dbc9655eddf0f383585d3cf67c11c539John McCalltemplate <class T> struct Test8 {
77cde5a400dbc9655eddf0f383585d3cf67c11c539John McCall  typedef T type;
7838ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall  Test8(type t) {} // tested later
79cde5a400dbc9655eddf0f383585d3cf67c11c539John McCall};
80cde5a400dbc9655eddf0f383585d3cf67c11c539John McCalltemplate <class T> void make_test8(T value) { Test8<T> t(value); }
81cde5a400dbc9655eddf0f383585d3cf67c11c539John McCallvoid test8() { make_test8(T8); }
8238ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall
8393ab6bf534fb6c26563c00f28a8fc5581bb71dfdStephen Lin// CHECK-LABEL: define internal void @"_ZNV3$_35test9Ev"(
8438ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCalltypedef volatile struct {
8538ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall  void test9() volatile {}
8638ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall} Test9;
8738ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCallvoid test9() {
8838ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall  Test9 a;
8938ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall  a.test9();
9038ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall}
9138ca4f762aa6e6add4f6bdf6adcddfe1afe37a25John McCall
9293ab6bf534fb6c26563c00f28a8fc5581bb71dfdStephen Lin// CHECK-LABEL: define internal void @"_ZN5Test8I3$_2EC1ES0_"(
93