forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsanitizer-cfi-emit-type-metadata-trait-objects.rs
44 lines (36 loc) · 1.25 KB
/
sanitizer-cfi-emit-type-metadata-trait-objects.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Verifies that type metadata identifiers for trait objects are emitted correctly.
//
// needs-sanitizer-cfi
// compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi
#![crate_type="lib"]
trait Trait1 {
fn foo(&self);
}
struct Type1;
impl Trait1 for Type1 {
fn foo(&self) {
}
}
pub fn foo() {
let a = Type1;
a.foo();
// CHECK-LABEL: define{{.*}}foo{{.*}}!type !{{[0-9]+}}
// CHECK: call <sanitizer_cfi_emit_type_metadata_trait_objects::Type1 as sanitizer_cfi_emit_type_metadata_trait_objects::Trait1>::foo
}
pub fn bar() {
let a = Type1;
let b = &a as &dyn Trait1;
b.foo();
// CHECK-LABEL: define{{.*}}bar{{.*}}!type !{{[0-9]+}}
// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0|%1}}, metadata !"[[TYPE1:[[:print:]]+]]")
}
pub fn baz() {
let a = Type1;
let b = &a as &dyn Trait1;
a.foo();
b.foo();
// CHECK-LABEL: define{{.*}}baz{{.*}}!type !{{[0-9]+}}
// CHECK: call <sanitizer_cfi_emit_type_metadata_trait_objects::Type1 as sanitizer_cfi_emit_type_metadata_trait_objects::Trait1>::foo
// CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0|%1}}, metadata !"[[TYPE1:[[:print:]]+]]")
}
// CHECK: !{{[0-9]+}} = !{i64 0, !"[[TYPE1]]"}