Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 2 | void *f(); |
| 3 | |
| 4 | template <typename T> T* g() { |
| 5 | if (T* t = f()) |
| 6 | return t; |
| 7 | |
| 8 | return 0; |
| 9 | } |
| 10 | |
| 11 | void h() { |
| 12 | void *a = g<void>(); |
| 13 | } |
| 14 | |
| 15 | struct X { |
| 16 | X(); |
| 17 | ~X(); |
| 18 | operator bool(); |
| 19 | }; |
| 20 | |
| 21 | struct Y { |
| 22 | Y(); |
| 23 | ~Y(); |
| 24 | }; |
| 25 | |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 26 | X getX(); |
| 27 | |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 28 | void if_destruct(int z) { |
| 29 | // Verify that the condition variable is destroyed at the end of the |
| 30 | // "if" statement. |
| 31 | // CHECK: call void @_ZN1XC1Ev |
| 32 | // CHECK: call zeroext i1 @_ZN1XcvbEv |
| 33 | if (X x = X()) { |
| 34 | // CHECK: store i32 18 |
| 35 | z = 18; |
| 36 | } |
| 37 | // CHECK: call void @_ZN1XD1Ev |
| 38 | // CHECK: store i32 17 |
| 39 | z = 17; |
| 40 | |
| 41 | // CHECK: call void @_ZN1XC1Ev |
| 42 | if (X x = X()) |
| 43 | Y y; |
Mike Stump | edc95e7 | 2010-01-13 20:57:29 +0000 | [diff] [blame] | 44 | // CHECK: br |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 45 | // CHECK: call void @_ZN1YC1Ev |
| 46 | // CHECK: call void @_ZN1YD1Ev |
Mike Stump | edc95e7 | 2010-01-13 20:57:29 +0000 | [diff] [blame] | 47 | // CHECK: br |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 48 | // CHECK: call void @_ZN1XD1Ev |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 49 | |
| 50 | // CHECK: call void @_Z4getXv |
| 51 | // CHECK: call zeroext i1 @_ZN1XcvbEv |
| 52 | // CHECK: call void @_ZN1XD1Ev |
| 53 | // CHECK: br |
| 54 | if (getX()) { } |
| 55 | |
| 56 | // CHECK: ret |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 57 | } |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 58 | |
| 59 | struct ConvertibleToInt { |
| 60 | ConvertibleToInt(); |
| 61 | ~ConvertibleToInt(); |
| 62 | operator int(); |
| 63 | }; |
| 64 | |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 65 | ConvertibleToInt getConvToInt(); |
| 66 | |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 67 | void switch_destruct(int z) { |
| 68 | // CHECK: call void @_ZN16ConvertibleToIntC1Ev |
| 69 | switch (ConvertibleToInt conv = ConvertibleToInt()) { |
| 70 | case 0: |
| 71 | break; |
| 72 | |
| 73 | default: |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 74 | // CHECK: {{sw.default:|:5}} |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 75 | // CHECK: store i32 19 |
| 76 | z = 19; |
| 77 | break; |
| 78 | } |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 79 | // CHECK: {{sw.epilog:|:6}} |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 80 | // CHECK: call void @_ZN16ConvertibleToIntD1Ev |
| 81 | // CHECK: store i32 20 |
| 82 | z = 20; |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 83 | |
| 84 | // CHECK: call void @_Z12getConvToIntv |
| 85 | // CHECK: call i32 @_ZN16ConvertibleToIntcviEv |
| 86 | // CHECK: call void @_ZN16ConvertibleToIntD1Ev |
| 87 | switch(getConvToInt()) { |
| 88 | case 0: |
| 89 | break; |
| 90 | } |
| 91 | // CHECK: store i32 27 |
| 92 | z = 27; |
| 93 | // CHECK: ret |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 94 | } |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 95 | |
| 96 | int foo(); |
| 97 | |
| 98 | void while_destruct(int z) { |
| 99 | // CHECK: define void @_Z14while_destructi |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 100 | // CHECK: {{while.cond:|:3}} |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 101 | while (X x = X()) { |
| 102 | // CHECK: call void @_ZN1XC1Ev |
| 103 | |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 104 | // CHECK: {{while.body:|:5}} |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 105 | // CHECK: store i32 21 |
| 106 | z = 21; |
| 107 | |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 108 | // CHECK: {{while.cleanup:|:6}} |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 109 | // CHECK: call void @_ZN1XD1Ev |
| 110 | } |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 111 | // CHECK: {{while.end|:8}} |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 112 | // CHECK: store i32 22 |
| 113 | z = 22; |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 114 | |
| 115 | // CHECK: call void @_Z4getXv |
| 116 | // CHECK: call zeroext i1 @_ZN1XcvbEv |
| 117 | // CHECK: call void @_ZN1XD1Ev |
| 118 | // CHECK: br |
| 119 | while(getX()) { } |
| 120 | |
| 121 | // CHECK: store i32 25 |
| 122 | z = 25; |
| 123 | |
| 124 | // CHECK: ret |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 125 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 126 | |
| 127 | void for_destruct(int z) { |
| 128 | // CHECK: define void @_Z12for_destruct |
Douglas Gregor | 345e7d2 | 2009-11-25 00:29:29 +0000 | [diff] [blame] | 129 | // CHECK: call void @_ZN1YC1Ev |
| 130 | for(Y y = Y(); X x = X(); ++z) |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 131 | // CHECK: {{for.cond:|:4}} |
Douglas Gregor | d975206 | 2009-11-25 01:51:31 +0000 | [diff] [blame] | 132 | // CHECK: call void @_ZN1XC1Ev |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 133 | // CHECK: {{for.body:|:6}} |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 134 | // CHECK: store i32 23 |
| 135 | z = 23; |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 136 | // CHECK: {{for.inc:|:7}} |
| 137 | // CHECK: br label %{{for.cond.cleanup|10}} |
| 138 | // CHECK: {{for.cond.cleanup:|:10}} |
Douglas Gregor | d975206 | 2009-11-25 01:51:31 +0000 | [diff] [blame] | 139 | // CHECK: call void @_ZN1XD1Ev |
Douglas Gregor | 40e6299 | 2010-05-08 16:04:01 +0000 | [diff] [blame] | 140 | // CHECK: {{for.end:|:12}} |
Douglas Gregor | 345e7d2 | 2009-11-25 00:29:29 +0000 | [diff] [blame] | 141 | // CHECK: call void @_ZN1YD1Ev |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 142 | // CHECK: store i32 24 |
| 143 | z = 24; |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 144 | |
| 145 | // CHECK: call void @_Z4getXv |
| 146 | // CHECK: call zeroext i1 @_ZN1XcvbEv |
| 147 | // CHECK: call void @_ZN1XD1Ev |
| 148 | // CHECK: br |
| 149 | // CHECK: call void @_Z4getXv |
| 150 | // CHECK: load |
| 151 | // CHECK: add |
| 152 | // CHECK: call void @_ZN1XD1Ev |
| 153 | int i = 0; |
| 154 | for(; getX(); getX(), ++i) { } |
| 155 | z = 26; |
| 156 | // CHECK: store i32 26 |
| 157 | // CHECK: ret |
| 158 | } |
| 159 | |
| 160 | void do_destruct(int z) { |
| 161 | // CHECK: define void @_Z11do_destruct |
| 162 | do { |
| 163 | // CHECK: store i32 77 |
| 164 | z = 77; |
| 165 | // CHECK: call void @_Z4getXv |
| 166 | // CHECK: call zeroext i1 @_ZN1XcvbEv |
| 167 | // CHECK: call void @_ZN1XD1Ev |
| 168 | // CHECK: br |
| 169 | } while (getX()); |
| 170 | // CHECK: store i32 99 |
| 171 | z = 99; |
| 172 | // CHECK: ret |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 173 | } |