Skip to content

Commit 2562f8a

Browse files
authored
Merge pull request github#13844 from jketema/forgotten-paren
C++: Add forgotten parentheses in ternary IR test
2 parents 4656130 + 0bc75ea commit 2562f8a

File tree

4 files changed

+241
-231
lines changed

4 files changed

+241
-231
lines changed

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15030,25 +15030,28 @@ ir.cpp:
1503015030
# 1999| Value = [Literal] 5
1503115031
# 1999| ValueCategory = prvalue
1503215032
# 2000| getStmt(3): [ExprStmt] ExprStmt
15033-
# 2000| getExpr(): [ConditionalExpr] ... ? ... : ...
15033+
# 2000| getExpr(): [AssignExpr] ... = ...
1503415034
# 2000| Type = [IntType] int
1503515035
# 2000| ValueCategory = lvalue
15036-
# 2000| getCondition(): [VariableAccess] a
15037-
# 2000| Type = [BoolType] bool
15038-
# 2000| ValueCategory = prvalue(load)
15039-
# 2000| getThen(): [VariableAccess] x
15036+
# 2000| getLValue(): [ConditionalExpr] ... ? ... : ...
1504015037
# 2000| Type = [IntType] int
1504115038
# 2000| ValueCategory = lvalue
15042-
# 2000| getElse(): [AssignExpr] ... = ...
15043-
# 2000| Type = [IntType] int
15044-
# 2000| ValueCategory = lvalue
15045-
# 2000| getLValue(): [VariableAccess] y
15039+
# 2000| getCondition(): [VariableAccess] a
15040+
# 2000| Type = [BoolType] bool
15041+
# 2000| ValueCategory = prvalue(load)
15042+
# 2000| getThen(): [VariableAccess] x
1504615043
# 2000| Type = [IntType] int
1504715044
# 2000| ValueCategory = lvalue
15048-
# 2000| getRValue(): [Literal] 7
15045+
# 2000| getElse(): [VariableAccess] y
1504915046
# 2000| Type = [IntType] int
15050-
# 2000| Value = [Literal] 7
15051-
# 2000| ValueCategory = prvalue
15047+
# 2000| ValueCategory = lvalue
15048+
# 2000| getRValue(): [Literal] 7
15049+
# 2000| Type = [IntType] int
15050+
# 2000| Value = [Literal] 7
15051+
# 2000| ValueCategory = prvalue
15052+
# 2000| getLValue().getFullyConverted(): [ParenthesisExpr] (...)
15053+
# 2000| Type = [IntType] int
15054+
# 2000| ValueCategory = lvalue
1505215055
# 2001| getStmt(4): [ReturnStmt] return ...
1505315056
# 2003| [CopyAssignmentOperator] TernaryPodObj& TernaryPodObj::operator=(TernaryPodObj const&)
1505415057
# 2003| <params>:
@@ -15151,31 +15154,34 @@ ir.cpp:
1515115154
# 2010| getExpr(): [AssignExpr] ... = ...
1515215155
# 2010| Type = [Struct] TernaryPodObj
1515315156
# 2010| ValueCategory = lvalue
15154-
# 2010| getLValue(): [VariableAccess] z
15157+
# 2010| getLValue(): [AssignExpr] ... = ...
1515515158
# 2010| Type = [Struct] TernaryPodObj
1515615159
# 2010| ValueCategory = lvalue
15157-
# 2010| getRValue(): [ConditionalExpr] ... ? ... : ...
15158-
# 2010| Type = [Struct] TernaryPodObj
15159-
# 2010| ValueCategory = prvalue
15160-
# 2010| getCondition(): [VariableAccess] a
15161-
# 2010| Type = [BoolType] bool
15162-
# 2010| ValueCategory = prvalue(load)
15163-
# 2010| getThen(): [VariableAccess] x
15160+
# 2010| getLValue(): [VariableAccess] z
1516415161
# 2010| Type = [Struct] TernaryPodObj
15165-
# 2010| ValueCategory = prvalue(load)
15166-
# 2010| getElse(): [AssignExpr] ... = ...
15162+
# 2010| ValueCategory = lvalue
15163+
# 2010| getRValue(): [ConditionalExpr] ... ? ... : ...
1516715164
# 2010| Type = [Struct] TernaryPodObj
1516815165
# 2010| ValueCategory = prvalue
15169-
# 2010| getLValue(): [VariableAccess] y
15170-
# 2010| Type = [Struct] TernaryPodObj
15171-
# 2010| ValueCategory = lvalue
15172-
# 2010| getRValue(): [Literal] 0
15166+
# 2010| getCondition(): [VariableAccess] a
15167+
# 2010| Type = [BoolType] bool
15168+
# 2010| ValueCategory = prvalue(load)
15169+
# 2010| getThen(): [VariableAccess] x
1517315170
# 2010| Type = [Struct] TernaryPodObj
15174-
# 2010| Value = [Literal] 0
15175-
# 2010| ValueCategory = prvalue
15176-
# 2010| getRValue().getFullyConverted(): [TemporaryObjectExpr] temporary object
15171+
# 2010| ValueCategory = prvalue(load)
15172+
# 2010| getElse(): [VariableAccess] y
1517715173
# 2010| Type = [Struct] TernaryPodObj
1517815174
# 2010| ValueCategory = prvalue(load)
15175+
# 2010| getRValue(): [Literal] 0
15176+
# 2010| Type = [Struct] TernaryPodObj
15177+
# 2010| Value = [Literal] 0
15178+
# 2010| ValueCategory = prvalue
15179+
# 2010| getLValue().getFullyConverted(): [ParenthesisExpr] (...)
15180+
# 2010| Type = [Struct] TernaryPodObj
15181+
# 2010| ValueCategory = lvalue
15182+
# 2010| getRValue().getFullyConverted(): [TemporaryObjectExpr] temporary object
15183+
# 2010| Type = [Struct] TernaryPodObj
15184+
# 2010| ValueCategory = prvalue(load)
1517915185
# 2011| getStmt(4): [ReturnStmt] return ...
1518015186
# 2013| [CopyAssignmentOperator] TernaryNonPodObj& TernaryNonPodObj::operator=(TernaryNonPodObj const&)
1518115187
# 2013| <params>:
@@ -15339,38 +15345,38 @@ ir.cpp:
1533915345
# 2021| getExpr(): [FunctionCall] call to operator=
1534015346
# 2021| Type = [LValueReferenceType] TernaryNonPodObj &
1534115347
# 2021| ValueCategory = prvalue
15342-
# 2021| getQualifier(): [VariableAccess] z
15343-
# 2021| Type = [Struct] TernaryNonPodObj
15344-
# 2021| ValueCategory = lvalue
15345-
# 2021| getArgument(0): [ConditionalExpr] ... ? ... : ...
15346-
# 2021| Type = [Struct] TernaryNonPodObj
15347-
# 2021| ValueCategory = lvalue
15348-
# 2021| getCondition(): [VariableAccess] a
15349-
# 2021| Type = [BoolType] bool
15350-
# 2021| ValueCategory = prvalue(load)
15351-
# 2021| getThen(): [VariableAccess] x
15348+
# 2021| getQualifier(): [FunctionCall] call to operator=
15349+
# 2021| Type = [LValueReferenceType] TernaryNonPodObj &
15350+
# 2021| ValueCategory = prvalue
15351+
# 2021| getQualifier(): [VariableAccess] z
1535215352
# 2021| Type = [Struct] TernaryNonPodObj
1535315353
# 2021| ValueCategory = lvalue
15354-
# 2021| getElse(): [FunctionCall] call to operator=
15355-
# 2021| Type = [LValueReferenceType] TernaryNonPodObj &
15356-
# 2021| ValueCategory = prvalue
15357-
# 2021| getQualifier(): [VariableAccess] y
15354+
# 2021| getArgument(0): [ConditionalExpr] ... ? ... : ...
15355+
# 2021| Type = [Struct] TernaryNonPodObj
15356+
# 2021| ValueCategory = lvalue
15357+
# 2021| getCondition(): [VariableAccess] a
15358+
# 2021| Type = [BoolType] bool
15359+
# 2021| ValueCategory = prvalue(load)
15360+
# 2021| getThen(): [VariableAccess] x
15361+
# 2021| Type = [Struct] TernaryNonPodObj
15362+
# 2021| ValueCategory = lvalue
15363+
# 2021| getElse(): [VariableAccess] y
1535815364
# 2021| Type = [Struct] TernaryNonPodObj
1535915365
# 2021| ValueCategory = lvalue
15360-
# 2021| getArgument(0): [ConstructorCall] call to TernaryNonPodObj
15361-
# 2021| Type = [VoidType] void
15362-
# 2021| ValueCategory = prvalue
15363-
# 2021| getArgument(0).getFullyConverted(): [ReferenceToExpr] (reference to)
15364-
# 2021| Type = [LValueReferenceType] const TernaryNonPodObj &
15365-
# 2021| ValueCategory = prvalue
15366-
# 2021| getExpr(): [CStyleCast] (const TernaryNonPodObj)...
15367-
# 2021| Conversion = [GlvalueConversion] glvalue conversion
15368-
# 2021| Type = [SpecifiedType] const TernaryNonPodObj
15369-
# 2021| ValueCategory = lvalue
15370-
# 2021| getExpr(): [TemporaryObjectExpr] temporary object
15371-
# 2021| Type = [Struct] TernaryNonPodObj
15372-
# 2021| ValueCategory = lvalue
15373-
# 2021| getElse().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
15366+
# 2021| getArgument(0).getFullyConverted(): [ReferenceToExpr] (reference to)
15367+
# 2021| Type = [LValueReferenceType] const TernaryNonPodObj &
15368+
# 2021| ValueCategory = prvalue
15369+
# 2021| getExpr(): [CStyleCast] (const TernaryNonPodObj)...
15370+
# 2021| Conversion = [GlvalueConversion] glvalue conversion
15371+
# 2021| Type = [SpecifiedType] const TernaryNonPodObj
15372+
# 2021| ValueCategory = lvalue
15373+
# 2021| getArgument(0): [ConstructorCall] call to TernaryNonPodObj
15374+
# 2021| Type = [VoidType] void
15375+
# 2021| ValueCategory = prvalue
15376+
# 2021| getQualifier().getFullyConverted(): [ParenthesisExpr] (...)
15377+
# 2021| Type = [Struct] TernaryNonPodObj
15378+
# 2021| ValueCategory = lvalue
15379+
# 2021| getExpr(): [ReferenceDereferenceExpr] (reference dereference)
1537415380
# 2021| Type = [Struct] TernaryNonPodObj
1537515381
# 2021| ValueCategory = lvalue
1537615382
# 2021| getArgument(0).getFullyConverted(): [ReferenceToExpr] (reference to)
@@ -15380,6 +15386,9 @@ ir.cpp:
1538015386
# 2021| Conversion = [GlvalueConversion] glvalue conversion
1538115387
# 2021| Type = [SpecifiedType] const TernaryNonPodObj
1538215388
# 2021| ValueCategory = lvalue
15389+
# 2021| getExpr(): [TemporaryObjectExpr] temporary object
15390+
# 2021| Type = [Struct] TernaryNonPodObj
15391+
# 2021| ValueCategory = lvalue
1538315392
# 2021| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
1538415393
# 2021| Type = [Struct] TernaryNonPodObj
1538515394
# 2021| ValueCategory = lvalue

cpp/ql/test/library-tests/ir/ir/ir.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ void TernaryTestInt(bool a, int x, int y, int z) {
19971997
z = a ? x : y;
19981998
z = a ? x : 5;
19991999
z = a ? 3 : 5;
2000-
a ? x : y = 7;
2000+
(a ? x : y) = 7;
20012001
}
20022002

20032003
struct TernaryPodObj {
@@ -2007,7 +2007,7 @@ void TernaryTestPodObj(bool a, TernaryPodObj x, TernaryPodObj y, TernaryPodObj z
20072007
z = a ? x : y;
20082008
z = a ? x : TernaryPodObj();
20092009
z = a ? TernaryPodObj() : TernaryPodObj();
2010-
z = a ? x : y = TernaryPodObj();
2010+
(z = a ? x : y) = TernaryPodObj();
20112011
}
20122012

20132013
struct TernaryNonPodObj {
@@ -2018,7 +2018,7 @@ void TernaryTestNonPodObj(bool a, TernaryNonPodObj x, TernaryNonPodObj y, Ternar
20182018
z = a ? x : y;
20192019
z = a ? x : TernaryNonPodObj();
20202020
z = a ? TernaryNonPodObj() : TernaryNonPodObj();
2021-
z = a ? x : y = TernaryNonPodObj();
2021+
(z = a ? x : y) = TernaryNonPodObj();
20222022
}
20232023

20242024
// semmle-extractor-options: -std=c++17 --clang

0 commit comments

Comments
 (0)