Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s |
Anders Carlsson | 3ddcdd5 | 2011-04-11 01:45:29 +0000 | [diff] [blame] | 2 | struct A { virtual ~A(); }; |
| 3 | struct B final : A { }; |
Anders Carlsson | 1741d7b | 2011-04-17 21:49:47 +0000 | [diff] [blame] | 4 | struct C { virtual ~C(); int c; }; |
Anders Carlsson | 3ddcdd5 | 2011-04-11 01:45:29 +0000 | [diff] [blame] | 5 | |
| 6 | // CHECK: @_Z1fP1B |
| 7 | C *f(B* b) { |
| 8 | // CHECK-NOT: call i8* @__dynamic_cast |
| 9 | // CHECK: ret %struct.C* null |
| 10 | return dynamic_cast<C*>(b); |
| 11 | } |
| 12 | |
| 13 | // CHECK: @_Z1fR1B |
| 14 | C &f(B& b) { |
| 15 | // CHECK-NOT: call i8* @__dynamic_cast |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 16 | // CHECK: call void @__cxa_bad_cast() [[NR:#[0-9]+]] |
Anders Carlsson | 3ddcdd5 | 2011-04-11 01:45:29 +0000 | [diff] [blame] | 17 | // CHECK: ret %struct.C* undef |
| 18 | return dynamic_cast<C&>(b); |
| 19 | } |
Sean Hunt | 5ca8639 | 2012-06-19 23:44:55 +0000 | [diff] [blame] | 20 | |
| 21 | void dont_crash() { |
| 22 | (void) dynamic_cast<void*>((A*)0); |
| 23 | (void) dynamic_cast<void*>((B*)0); |
| 24 | } |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 25 | |
| 26 | // CHECK: attributes [[NR]] = { noreturn } |