mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: HashCons for throw
This commit is contained in:
@@ -119,6 +119,10 @@ private cached newtype HCBase =
|
||||
or
|
||||
HC_DeleteArrayExpr(HashCons child) {mk_DeleteArrayExpr(child, _)}
|
||||
or
|
||||
HC_ThrowExpr(HashCons child) {mk_ThrowExpr(child, _)}
|
||||
or
|
||||
HC_ReThrowExpr()
|
||||
or
|
||||
// Any expression that is not handled by the cases above is
|
||||
// given a unique number based on the expression itself.
|
||||
HC_Unanalyzable(Expr e) { not analyzableExpr(e,_) }
|
||||
@@ -228,6 +232,8 @@ class HashCons extends HCBase {
|
||||
if this instanceof HC_ClassAggregateLiteral then result = "ClassAggreagateLiteral" else
|
||||
if this instanceof HC_DeleteExpr then result = "DeleteExpr" else
|
||||
if this instanceof HC_DeleteArrayExpr then result = "DeleteArrayExpr" else
|
||||
if this instanceof HC_ThrowExpr then result = "ThrowExpr" else
|
||||
if this instanceof HC_ReThrowExpr then result = "ReThrowExpr" else
|
||||
result = "error"
|
||||
}
|
||||
|
||||
@@ -828,6 +834,23 @@ private predicate mk_ArrayAggregateLiteral(Type t, HC_Array hca, ArrayAggregateL
|
||||
)
|
||||
}
|
||||
|
||||
private predicate analyzableThrowExpr(ThrowExpr te) {
|
||||
strictcount(te.getExpr().getFullyConverted()) = 1
|
||||
}
|
||||
|
||||
private predicate mk_ThrowExpr(HashCons hc, ThrowExpr te) {
|
||||
analyzableThrowExpr(te) and
|
||||
hc.getAnExpr() = te.getExpr().getFullyConverted()
|
||||
}
|
||||
|
||||
private predicate analyzableReThrowExpr(ReThrowExpr rte) {
|
||||
any()
|
||||
}
|
||||
|
||||
private predicate mk_ReThrowExpr(ReThrowExpr te) {
|
||||
any()
|
||||
}
|
||||
|
||||
/** Gets the hash-cons of expression `e`. */
|
||||
cached HashCons hashCons(Expr e) {
|
||||
exists (int val, Type t
|
||||
@@ -946,6 +969,16 @@ cached HashCons hashCons(Expr e) {
|
||||
result = HC_DeleteArrayExpr(child)
|
||||
)
|
||||
or
|
||||
exists(HashCons child
|
||||
| mk_ThrowExpr(child, e) and
|
||||
result = HC_ThrowExpr(child)
|
||||
)
|
||||
or
|
||||
(
|
||||
mk_ReThrowExpr(e) and
|
||||
result = HC_ReThrowExpr()
|
||||
)
|
||||
or
|
||||
(
|
||||
mk_Nullptr(e) and
|
||||
result = HC_Nullptr()
|
||||
@@ -987,5 +1020,7 @@ predicate analyzableExpr(Expr e, string kind) {
|
||||
(analyzableClassAggregateLiteral(e) and kind = "ClassAggregateLiteral") or
|
||||
(analyzableArrayAggregateLiteral(e) and kind = "ArrayAggregateLiteral") or
|
||||
(analyzableDeleteExpr(e) and kind = "DeleteExpr") or
|
||||
(analyzableDeleteArrayExpr(e) and kind = "DeleteArrayExpr")
|
||||
(analyzableDeleteArrayExpr(e) and kind = "DeleteArrayExpr") or
|
||||
(analyzableThrowExpr(e) and kind = "ThrowExpr") or
|
||||
(analyzableReThrowExpr(e) and kind = "ReThrowExpr")
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
| test.cpp:92:11:92:11 | x | 92:c11-c11 93:c10-c10 |
|
||||
| test.cpp:97:3:97:3 | x | 97:c3-c3 98:c3-c3 |
|
||||
| test.cpp:97:3:97:5 | ... ++ | 97:c3-c5 98:c3-c5 |
|
||||
| test.cpp:103:10:103:11 | 1 | 103:c10-c11 104:c7-c7 107:c7-c7 108:c7-c7 10:c16-c16 179:c21-c21 247:c11-c11 248:c11-c11 271:c28-c28 272:c28-c28 274:c19-c19 274:c22-c22 288:c5-c5 292:c5-c5 297:c5-c5 |
|
||||
| test.cpp:103:10:103:11 | 1 | 103:c10-c11 104:c7-c7 107:c7-c7 108:c7-c7 10:c16-c16 179:c21-c21 247:c11-c11 248:c11-c11 271:c28-c28 272:c28-c28 274:c19-c19 274:c22-c22 288:c5-c5 292:c5-c5 297:c5-c5 302:c9-c9 303:c9-c9 |
|
||||
| test.cpp:104:3:104:3 | x | 104:c3-c3 105:c3-c3 106:c3-c3 107:c3-c3 108:c3-c3 |
|
||||
| test.cpp:105:7:105:7 | 2 | 105:c7-c7 106:c7-c7 107:c11-c11 108:c11-c11 21:c16-c16 249:c11-c11 271:c24-c24 271:c31-c31 272:c24-c24 272:c31-c31 273:c24-c24 274:c15-c15 275:c15-c15 275:c19-c19 275:c22-c22 277:c15-c15 278:c15-c15 289:c5-c5 293:c5-c5 296:c5-c5 |
|
||||
| test.cpp:105:7:105:7 | 2 | 105:c7-c7 106:c7-c7 107:c11-c11 108:c11-c11 21:c16-c16 249:c11-c11 271:c24-c24 271:c31-c31 272:c24-c24 272:c31-c31 273:c24-c24 274:c15-c15 275:c15-c15 275:c19-c19 275:c22-c22 277:c15-c15 278:c15-c15 289:c5-c5 293:c5-c5 296:c5-c5 304:c9-c9 305:c9-c9 |
|
||||
| test.cpp:107:7:107:11 | ... + ... | 107:c7-c11 108:c7-c11 |
|
||||
| test.cpp:110:15:110:17 | 1 | 110:c15-c17 111:c9-c11 |
|
||||
| test.cpp:110:15:110:17 | (char *)... | 110:c15-c17 111:c9-c11 |
|
||||
@@ -104,3 +104,6 @@
|
||||
| test.cpp:277:3:277:19 | new[] | 277:c3-c19 278:c3-c19 |
|
||||
| test.cpp:277:3:277:19 | {...} | 277:c3-c19 278:c3-c19 |
|
||||
| test.cpp:287:15:290:3 | {...} | 287:c15-c3 291:c15-c3 |
|
||||
| test.cpp:302:3:302:9 | throw ... | 302:c3-c9 303:c3-c9 |
|
||||
| test.cpp:304:3:304:9 | throw ... | 304:c3-c9 305:c3-c9 |
|
||||
| test.cpp:306:3:306:7 | re-throw exception | 306:c3-c7 307:c3-c7 |
|
||||
|
||||
@@ -297,3 +297,12 @@ void test17() {
|
||||
1
|
||||
};
|
||||
}
|
||||
|
||||
void test18() {
|
||||
throw 1;
|
||||
throw 1;
|
||||
throw 2;
|
||||
throw 2;
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user