Home | History | Annotate | Download | only in TableGen
      1 // RUN: llvm-tblgen %s | FileCheck %s
      2 // XFAIL: vg_leak
      3 
      4 class A {}
      5 class B<A a> {
      6   A ba = a;
      7 }
      8 
      9 multiclass M0<string s> {
     10   def _m0 : B<!cast<A>(s)>;
     11 
     12   // Uncomment to test that !cast will eventually fail if the record it refers
     13   // to does not exist by the time we instantiate this record from the top
     14   // level.
     15   //def _m1 : B<!cast<A>(s#"X")>;
     16 }
     17 
     18 multiclass M1<string s> {
     19   def _r1 : A;
     20   // It would be nice if we could refer to _r1's name without having to pass it
     21   // explicitly via 's'.
     22   defm _m1: M0<s # "_r1">;
     23 }
     24 
     25 multiclass M2 {
     26   def _x : A {
     27     string n = NAME;
     28   }
     29 
     30   def _y : B<!cast<A>(NAME # "_x")>;
     31 
     32   // This used to throw an error during multiclass parsing as NAME was not
     33   // recognized when parsing the template arguments.
     34   defm NAME: M1<NAME>;
     35 }
     36 defm d0: M2;
     37 // CHECK-LABEL: def d0_m1_m0
     38 // CHECK: A ba = d0_r1;
     39 //
     40 // CHECK-LABEL: def d0_x {
     41 // CHECK: string n = "d0";
     42 //
     43 // CHECK-LABEL: def d0_y {
     44 // CHECK: A ba = d0_x;
     45 
     46 // This always works, because d1_r1 is instantiated before d1_m1 which would
     47 // attempt to !cast to it.
     48 defm d1: M1<"d1">;
     49 // CHECK-LABEL: def d1_m1_m0
     50 // CHECK: A ba = d1_r1;
     51