C++: Delete incorrect comment and add a bunch of barrier guard tests.

This commit is contained in:
Mathias Vorreiter Pedersen
2025-09-25 12:56:46 +01:00
parent 04ce4057e1
commit c1c1f60241
3 changed files with 59 additions and 23 deletions

View File

@@ -342,25 +342,7 @@ module GuardsInput implements SharedGuards::InputSig<Cpp::Location, Instruction,
/** Gets an expression returned from this function. */
GuardsInput::Expr getAReturnExpr() {
exists(StoreInstruction store |
// We use the `Store` instruction that writes the return value instead of the
// `ReturnValue` instruction since the `ReturnValue` instruction is not always
// dominated by certain guards. For example:
// ```
// if(b) {
// return true;
// } else {
// return false;
// }
// ```
// this will be translated into IR like:
// ```
// if(b) {
// x = true;
// } else {
// x = false;
// }
// return x;
// ```
// A write to the `IRVariable` which represents the return value.
store.getDestinationAddress().(VariableAddressInstruction).getIRVariable() instanceof
IRReturnVariable and
store.getEnclosingFunction() = this and

View File

@@ -135,6 +135,32 @@ bool guarded_wrapper(int x) {
}
}
bool guarded_wrapper_2(int x) {
bool b;
if(guarded(x)) {
b = true;
} else {
b = false;
}
return b;
}
bool guarded_wrapper_3(int x) {
bool b = false;
if(guarded(x)) {
b = true;
}
return b;
}
bool guarded_wrapper_4(int x) {
bool b = false;
if(guarded(x)) {
return true;
}
return b;
}
void test_guarded_wrapper() {
int x = source();
@@ -143,4 +169,23 @@ void test_guarded_wrapper() {
} else {
sink(x); // $ ast,ir
}
}
if(guarded_wrapper_2(x)) {
sink(x); // $ SPURIOUS: ast
} else {
sink(x); // $ ast,ir
}
if(guarded_wrapper_3(x)) {
sink(x); // $ SPURIOUS: ast
} else {
sink(x); // $ ast,ir
}
if(guarded_wrapper_4(x)) {
sink(x); // $ SPURIOUS: ast
} else {
sink(x); // $ ast,ir
}
}

View File

@@ -16,8 +16,14 @@ astFlow
| BarrierGuard.cpp:90:11:90:16 | call to source | BarrierGuard.cpp:101:8:101:8 | x |
| BarrierGuard.cpp:107:11:107:16 | call to source | BarrierGuard.cpp:112:8:112:8 | x |
| BarrierGuard.cpp:116:11:116:16 | call to source | BarrierGuard.cpp:127:8:127:8 | x |
| BarrierGuard.cpp:139:11:139:16 | call to source | BarrierGuard.cpp:142:10:142:10 | x |
| BarrierGuard.cpp:139:11:139:16 | call to source | BarrierGuard.cpp:144:10:144:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:168:10:168:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:170:10:170:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:174:10:174:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:176:10:176:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:180:10:180:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:182:10:182:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:186:10:186:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:188:10:188:10 | x |
| acrossLinkTargets.cpp:19:27:19:32 | call to source | acrossLinkTargets.cpp:12:8:12:8 | x |
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:18:8:18:19 | sourceArray1 |
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:22:8:22:20 | & ... |
@@ -158,7 +164,10 @@ irFlow
| BarrierGuard.cpp:49:10:49:15 | call to source | BarrierGuard.cpp:55:13:55:13 | x |
| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:64:14:64:14 | x |
| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:66:14:66:14 | x |
| BarrierGuard.cpp:139:11:139:16 | call to source | BarrierGuard.cpp:144:10:144:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:170:10:170:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:176:10:176:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:182:10:182:10 | x |
| BarrierGuard.cpp:165:11:165:16 | call to source | BarrierGuard.cpp:188:10:188:10 | x |
| acrossLinkTargets.cpp:19:27:19:32 | call to source | acrossLinkTargets.cpp:12:8:12:8 | x |
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:18:8:18:19 | sourceArray1 |
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:23:17:23:29 | *& ... |