Skip to content

Commit 3202bcc

Browse files
committed
C++: Handle ternary operators whose value category is a prvalue with a load
1 parent c60cb13 commit 3202bcc

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,15 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21552155
not this.elseIsVoid() and tag = ConditionValueFalseStoreTag()
21562156
) and
21572157
opcode instanceof Opcode::Store and
2158-
resultType = this.getResultType()
2158+
(
2159+
not expr.hasLValueToRValueConversion() and
2160+
resultType = this.getResultType()
2161+
or
2162+
expr.hasLValueToRValueConversion() and
2163+
resultType = getTypeForPRValue(expr.getType())
2164+
)
21592165
or
2166+
not expr.hasLValueToRValueConversion() and
21602167
tag = ConditionValueResultLoadTag() and
21612168
opcode instanceof Opcode::Load and
21622169
resultType = this.getResultType()
@@ -2186,8 +2193,15 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21862193
)
21872194
or
21882195
tag = ConditionValueResultTempAddressTag() and
2189-
result = this.getInstruction(ConditionValueResultLoadTag())
2196+
(
2197+
not expr.hasLValueToRValueConversion() and
2198+
result = this.getInstruction(ConditionValueResultLoadTag())
2199+
or
2200+
expr.hasLValueToRValueConversion() and
2201+
result = this.getParent().getChildSuccessor(this)
2202+
)
21902203
or
2204+
not expr.hasLValueToRValueConversion() and
21912205
tag = ConditionValueResultLoadTag() and
21922206
result = this.getParent().getChildSuccessor(this)
21932207
)
@@ -2216,18 +2230,23 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22162230
result = this.getElse().getResult()
22172231
)
22182232
or
2233+
not expr.hasLValueToRValueConversion() and
22192234
tag = ConditionValueResultLoadTag() and
2220-
(
2221-
operandTag instanceof AddressOperandTag and
2222-
result = this.getInstruction(ConditionValueResultTempAddressTag())
2223-
)
2235+
operandTag instanceof AddressOperandTag and
2236+
result = this.getInstruction(ConditionValueResultTempAddressTag())
22242237
)
22252238
}
22262239

22272240
final override predicate hasTempVariable(TempVariableTag tag, CppType type) {
22282241
not this.resultIsVoid() and
22292242
tag = ConditionValueTempVar() and
2230-
type = this.getResultType()
2243+
(
2244+
not expr.hasLValueToRValueConversion() and
2245+
type = this.getResultType()
2246+
or
2247+
expr.hasLValueToRValueConversion() and
2248+
type = getTypeForPRValue(expr.getType())
2249+
)
22312250
}
22322251

22332252
final override IRVariable getInstructionVariable(InstructionTag tag) {
@@ -2242,7 +2261,13 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22422261

22432262
final override Instruction getResult() {
22442263
not this.resultIsVoid() and
2245-
result = this.getInstruction(ConditionValueResultLoadTag())
2264+
(
2265+
expr.hasLValueToRValueConversion() and
2266+
result = this.getInstruction(ConditionValueResultTempAddressTag())
2267+
or
2268+
not expr.hasLValueToRValueConversion() and
2269+
result = this.getInstruction(ConditionValueResultLoadTag())
2270+
)
22462271
}
22472272

22482273
override Instruction getChildSuccessor(TranslatedElement child) {

0 commit comments

Comments
 (0)