Skip to content

Commit ee9b378

Browse files
committed
Implement m_alloca_exception and m_free_exception matchers
1 parent 9d9f06f commit ee9b378

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

docs/matchers/exceptions.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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` |
10-
| m_eh_typeid | | InstMatcher | Build Inst Matcher that match call to `llvm.eh.typeid.for` |
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` |
11+
| m_alloca_exception | | InstMatcher | Build Inst Matcher that match call to `__cxa_allocate_exception` |
12+
| m_free_exception | | InstMatcher | Build Inst Matcher that match call to `__cxa_free_exception` |

src/functions/matchers/exception.rs

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

33
use crate::ir::types::InstMatcherType;
44
use crate::ir::values::InstMatcherValue;
5+
use crate::matchers::exception::AllocaExceptionInstMatcher;
56
use crate::matchers::exception::EHTypeIdInstMatcher;
7+
use crate::matchers::exception::FreeExceptionInstMatcher;
68
use crate::matchers::exception::InvokeInstMatcher;
79
use crate::matchers::exception::LandingPadInstMatcher;
810
use crate::matchers::exception::ResumeInstMatcher;
@@ -23,6 +25,8 @@ pub fn register_exception_inst_matchers_functions(
2325
map.insert("m_throw", match_throw_inst);
2426
map.insert("m_rethrow", match_rethrow_inst);
2527
map.insert("m_eh_typeid", match_eh_typeid_inst);
28+
map.insert("m_alloca_exception", match_alloca_exception_inst);
29+
map.insert("m_free_exception", match_free_exception_inst);
2630
}
2731

2832
#[inline(always)]
@@ -76,6 +80,22 @@ pub fn register_exception_inst_matchers_function_signatures(
7680
return_type: Box::new(InstMatcherType),
7781
},
7882
);
83+
84+
map.insert(
85+
"m_alloca_exception",
86+
Signature {
87+
parameters: vec![],
88+
return_type: Box::new(InstMatcherType),
89+
},
90+
);
91+
92+
map.insert(
93+
"m_free_exception",
94+
Signature {
95+
parameters: vec![],
96+
return_type: Box::new(InstMatcherType),
97+
},
98+
);
7999
}
80100

81101
fn match_invoke_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
@@ -107,3 +127,13 @@ fn match_eh_typeid_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
107127
let matcher = Box::new(EHTypeIdInstMatcher);
108128
Box::new(InstMatcherValue { matcher })
109129
}
130+
131+
fn match_alloca_exception_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
132+
let matcher = Box::new(AllocaExceptionInstMatcher);
133+
Box::new(InstMatcherValue { matcher })
134+
}
135+
136+
fn match_free_exception_inst(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
137+
let matcher = Box::new(FreeExceptionInstMatcher);
138+
Box::new(InstMatcherValue { matcher })
139+
}

src/matchers/exception.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ impl Matcher<LLVMValueRef> for EHTypeIdInstMatcher {
6363
is_call_base_inst_with_specific_name(instruction, "llvm.eh.typeid.for.p0")
6464
}
6565
}
66+
67+
#[derive(Clone)]
68+
pub struct AllocaExceptionInstMatcher;
69+
70+
impl Matcher<LLVMValueRef> for AllocaExceptionInstMatcher {
71+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
72+
is_call_base_inst_with_specific_name(instruction, "__cxa_allocate_exception")
73+
}
74+
}
75+
76+
#[derive(Clone)]
77+
pub struct FreeExceptionInstMatcher;
78+
79+
impl Matcher<LLVMValueRef> for FreeExceptionInstMatcher {
80+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
81+
is_call_base_inst_with_specific_name(instruction, "__cxa_free_exception")
82+
}
83+
}

0 commit comments

Comments
 (0)