Skip to content

Commit bd9ece0

Browse files
committed
C++: Add dataflow through '__builtin_bit_cast'.
1 parent 48f2fd0 commit bd9ece0

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ predicate conversionFlow(
114114
instrTo.(CheckedConvertOrNullInstruction).getUnaryOperand() = opFrom
115115
or
116116
instrTo.(InheritanceConversionInstruction).getUnaryOperand() = opFrom
117+
or
118+
exists(BuiltInInstruction builtIn |
119+
builtIn = instrTo and
120+
// __builtin_bit_cast
121+
builtIn.getBuiltInOperation() instanceof BuiltInBitCast and
122+
opFrom = builtIn.getAnOperand()
123+
)
117124
)
118125
or
119126
additional = true and

cpp/ql/test/library-tests/dataflow/dataflow-tests/clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ void following_pointers( // $ ast-def=sourceStruct1_ptr ir-def=*cleanArray1 ir-d
5252
sink(stackArray); // $ ast,ir
5353
indirect_sink(stackArray); // $ ast ir=50:25 ir=50:35 ir=51:19
5454
}
55+
56+
void test_bitcast() {
57+
unsigned long x = source();
58+
double d = __builtin_bit_cast(double, x);
59+
sink(d); // $ ir MISSING: ast
60+
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ irFlow
153153
| clang.cpp:50:25:50:30 | call to source | clang.cpp:53:17:53:26 | *stackArray |
154154
| clang.cpp:50:35:50:40 | call to source | clang.cpp:53:17:53:26 | *stackArray |
155155
| clang.cpp:51:19:51:24 | call to source | clang.cpp:53:17:53:26 | *stackArray |
156+
| clang.cpp:57:21:57:28 | call to source | clang.cpp:59:8:59:8 | d |
156157
| dispatch.cpp:9:37:9:42 | call to source | dispatch.cpp:35:16:35:25 | call to notSource1 |
157158
| dispatch.cpp:9:37:9:42 | call to source | dispatch.cpp:43:15:43:24 | call to notSource1 |
158159
| dispatch.cpp:10:37:10:42 | call to source | dispatch.cpp:36:16:36:25 | call to notSource2 |

0 commit comments

Comments
 (0)