Skip to content

Commit 4c2955b

Browse files
committed
C++: Handle ternary operators whose value category is a prvalue with a load
1 parent 8406a54 commit 4c2955b

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,8 +2078,15 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
20782078
not this.elseIsVoid() and tag = ConditionValueFalseStoreTag()
20792079
) and
20802080
opcode instanceof Opcode::Store and
2081-
resultType = this.getResultType()
2081+
(
2082+
not expr.hasLValueToRValueConversion() and
2083+
resultType = this.getResultType()
2084+
or
2085+
expr.hasLValueToRValueConversion() and
2086+
resultType = getTypeForPRValue(expr.getType())
2087+
)
20822088
or
2089+
not expr.hasLValueToRValueConversion() and
20832090
tag = ConditionValueResultLoadTag() and
20842091
opcode instanceof Opcode::Load and
20852092
resultType = this.getResultType()
@@ -2109,8 +2116,15 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21092116
)
21102117
or
21112118
tag = ConditionValueResultTempAddressTag() and
2112-
result = this.getInstruction(ConditionValueResultLoadTag())
2119+
(
2120+
not expr.hasLValueToRValueConversion() and
2121+
result = this.getInstruction(ConditionValueResultLoadTag())
2122+
or
2123+
expr.hasLValueToRValueConversion() and
2124+
result = this.getParent().getChildSuccessor(this)
2125+
)
21132126
or
2127+
not expr.hasLValueToRValueConversion() and
21142128
tag = ConditionValueResultLoadTag() and
21152129
result = this.getParent().getChildSuccessor(this)
21162130
)
@@ -2139,11 +2153,10 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21392153
result = this.getElse().getResult()
21402154
)
21412155
or
2156+
not expr.hasLValueToRValueConversion() and
21422157
tag = ConditionValueResultLoadTag() and
2143-
(
2144-
operandTag instanceof AddressOperandTag and
2145-
result = this.getInstruction(ConditionValueResultTempAddressTag())
2146-
)
2158+
operandTag instanceof AddressOperandTag and
2159+
result = this.getInstruction(ConditionValueResultTempAddressTag())
21472160
)
21482161
}
21492162

@@ -2165,7 +2178,13 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21652178

21662179
final override Instruction getResult() {
21672180
not this.resultIsVoid() and
2168-
result = this.getInstruction(ConditionValueResultLoadTag())
2181+
(
2182+
expr.hasLValueToRValueConversion() and
2183+
result = this.getInstruction(ConditionValueResultTempAddressTag())
2184+
or
2185+
not expr.hasLValueToRValueConversion() and
2186+
result = this.getInstruction(ConditionValueResultLoadTag())
2187+
)
21692188
}
21702189

21712190
override Instruction getChildSuccessor(TranslatedElement child) {

0 commit comments

Comments
 (0)