Skip to content

Commit 9d9f06f

Browse files
committed
Implement m_eh_typeid matcher.
1 parent a8a614d commit 9d9f06f

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

docs/matchers/exceptions.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
### Exceptions Instructions Matchers functions
22

3-
| Function | Parameters | Return | Description |
4-
| :----------: | :--------: | :---------: | :---------------------------------------------------: |
5-
| m_invoke | | InstMatcher | Build Inst Matcher that match invoke Instruction |
6-
| m_landingpad | | InstMatcher | Build Inst Matcher that match landingpad Instruction |
7-
| m_resume | | InstMatcher | Build Inst Matcher that match resume Instruction |
8-
| m_throw | | InstMatcher | Build Inst Matcher that match call to `__cxa_throw` |
9-
| m_rethrow | | InstMatcher | Build Inst Matcher that match call to `__cxa_rethrow` |
3+
| Function | Parameters | Return | Description |
4+
| :----------: | :--------: | :---------: | :--------------------------------------------------------: |
5+
| m_invoke | | InstMatcher | Build Inst Matcher that match invoke Instruction |
6+
| m_landingpad | | InstMatcher | Build Inst Matcher that match landingpad Instruction |
7+
| m_resume | | InstMatcher | Build Inst Matcher that match resume Instruction |
8+
| m_throw | | InstMatcher | Build Inst Matcher that match call to `__cxa_throw` |
9+
| m_rethrow | | InstMatcher | Build Inst Matcher that match call to `__cxa_rethrow` |
10+
| m_eh_typeid | | InstMatcher | Build Inst Matcher that match call to `llvm.eh.typeid.for` |

src/functions/matchers/exception.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22

33
use crate::ir::types::InstMatcherType;
44
use crate::ir::values::InstMatcherValue;
5+
use crate::matchers::exception::EHTypeIdInstMatcher;
56
use crate::matchers::exception::InvokeInstMatcher;
67
use crate::matchers::exception::LandingPadInstMatcher;
78
use crate::matchers::exception::ResumeInstMatcher;
@@ -21,6 +22,7 @@ pub fn register_exception_inst_matchers_functions(
2122
map.insert("m_resume", match_resume_inst);
2223
map.insert("m_throw", match_throw_inst);
2324
map.insert("m_rethrow", match_rethrow_inst);
25+
map.insert("m_eh_typeid", match_eh_typeid_inst);
2426
}
2527

2628
#[inline(always)]
@@ -66,6 +68,14 @@ pub fn register_exception_inst_matchers_function_signatures(
6668
return_type: Box::new(InstMatcherType),
6769
},
6870
);
71+
72+
map.insert(
73+
"m_eh_typeid",
74+
Signature {
75+
parameters: vec![],
76+
return_type: Box::new(InstMatcherType),
77+
},
78+
);
6979
}
7080

7181
fn match_invoke_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
@@ -92,3 +102,8 @@ fn match_rethrow_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
92102
let matcher = Box::new(RethrowInstMatcher);
93103
Box::new(InstMatcherValue { matcher })
94104
}
105+
106+
fn match_eh_typeid_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
107+
let matcher = Box::new(EHTypeIdInstMatcher);
108+
Box::new(InstMatcherValue { matcher })
109+
}

src/matchers/exception.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use inkwell::llvm_sys::core::LLVMIsAResumeInst;
33
use inkwell::llvm_sys::prelude::LLVMValueRef;
44
use inkwell::llvm_sys::LLVMOpcode;
55

6-
use crate::matchers::matchers_helper::is_call_or_invoke_inst_with_specific_name;
6+
use crate::matchers::matchers_helper::is_call_base_inst_with_specific_name;
77

88
use super::Matcher;
99

@@ -41,18 +41,25 @@ impl Matcher<LLVMValueRef> for ResumeInstMatcher {
4141
pub struct ThrowInstMatcher;
4242

4343
impl Matcher<LLVMValueRef> for ThrowInstMatcher {
44-
#[allow(clippy::not_unsafe_ptr_arg_deref)]
4544
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
46-
is_call_or_invoke_inst_with_specific_name(instruction, "__cxa_throw")
45+
is_call_base_inst_with_specific_name(instruction, "__cxa_throw")
4746
}
4847
}
4948

5049
#[derive(Clone)]
5150
pub struct RethrowInstMatcher;
5251

5352
impl Matcher<LLVMValueRef> for RethrowInstMatcher {
54-
#[allow(clippy::not_unsafe_ptr_arg_deref)]
5553
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
56-
is_call_or_invoke_inst_with_specific_name(instruction, "__cxa_rethrow")
54+
is_call_base_inst_with_specific_name(instruction, "__cxa_rethrow")
55+
}
56+
}
57+
58+
#[derive(Clone)]
59+
pub struct EHTypeIdInstMatcher;
60+
61+
impl Matcher<LLVMValueRef> for EHTypeIdInstMatcher {
62+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
63+
is_call_base_inst_with_specific_name(instruction, "llvm.eh.typeid.for.p0")
5764
}
5865
}

src/matchers/matchers_helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use inkwell::llvm_sys::core::LLVMGetValueName2;
44
use inkwell::llvm_sys::prelude::LLVMValueRef;
55
use inkwell::llvm_sys::LLVMOpcode;
66

7-
pub(crate) fn is_call_or_invoke_inst_with_specific_name(
7+
pub(crate) fn is_call_base_inst_with_specific_name(
88
instruction: &LLVMValueRef,
99
name: &'static str,
1010
) -> bool {

0 commit comments

Comments
 (0)