Skip to content

Commit 4786377

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

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
@@ -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,18 +2153,23 @@ 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

21502163
final override predicate hasTempVariable(TempVariableTag tag, CppType type) {
21512164
not this.resultIsVoid() and
21522165
tag = ConditionValueTempVar() and
2153-
type = this.getResultType()
2166+
(
2167+
not expr.hasLValueToRValueConversion() and
2168+
type = this.getResultType()
2169+
or
2170+
expr.hasLValueToRValueConversion() and
2171+
type = getTypeForPRValue(expr.getType())
2172+
)
21542173
}
21552174

21562175
final override IRVariable getInstructionVariable(InstructionTag tag) {
@@ -2165,7 +2184,13 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21652184

21662185
final override Instruction getResult() {
21672186
not this.resultIsVoid() and
2168-
result = this.getInstruction(ConditionValueResultLoadTag())
2187+
(
2188+
expr.hasLValueToRValueConversion() and
2189+
result = this.getInstruction(ConditionValueResultTempAddressTag())
2190+
or
2191+
not expr.hasLValueToRValueConversion() and
2192+
result = this.getInstruction(ConditionValueResultLoadTag())
2193+
)
21692194
}
21702195

21712196
override Instruction getChildSuccessor(TranslatedElement child) {

0 commit comments

Comments
 (0)