Skip to content

Commit bc1412b

Browse files
committed
C++: Add another example with a type error from binary operations in C code.
1 parent a8ef97c commit bc1412b

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4932,7 +4932,25 @@ ir.c:
49324932
# 103| Type = [IntType] int
49334933
# 103| ValueCategory = prvalue(load)
49344934
# 103| getThen(): [BlockStmt] { ... }
4935-
# 104| getStmt(16): [ReturnStmt] return ...
4935+
# 105| getStmt(16): [DeclStmt] declaration
4936+
# 105| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
4937+
# 105| Type = [IntType] int
4938+
# 105| getVariable().getInitializer(): [Initializer] initializer for x
4939+
# 105| getExpr(): [LTExpr] ... < ...
4940+
# 105| Type = [IntType] int
4941+
# 105| ValueCategory = prvalue
4942+
# 105| getLesserOperand(): [VariableAccess] x1
4943+
# 105| Type = [IntType] int
4944+
# 105| ValueCategory = prvalue(load)
4945+
# 105| getGreaterOperand(): [VariableAccess] x2
4946+
# 105| Type = [IntType] int
4947+
# 105| ValueCategory = prvalue(load)
4948+
# 106| getStmt(17): [IfStmt] if (...) ...
4949+
# 106| getCondition(): [VariableAccess] x
4950+
# 106| Type = [IntType] int
4951+
# 106| ValueCategory = prvalue(load)
4952+
# 106| getThen(): [BlockStmt] { ... }
4953+
# 107| getStmt(18): [ReturnStmt] return ...
49364954
ir.cpp:
49374955
# 1| [TopLevelFunction] void Constants()
49384956
# 1| <params>:

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,8 +3970,28 @@ ir.c:
39703970
# 103| v103_6(void) = NoOp :
39713971
#-----| Goto -> Block 40
39723972

3973-
# 104| Block 40
3974-
# 104| v104_1(void) = NoOp :
3973+
# 105| Block 40
3974+
# 105| r105_1(glval<int>) = VariableAddress[x] :
3975+
# 105| r105_2(glval<int>) = VariableAddress[x1] :
3976+
# 105| r105_3(int) = Load[x1] : &:r105_2, m84_6
3977+
# 105| r105_4(glval<int>) = VariableAddress[x2] :
3978+
# 105| r105_5(int) = Load[x2] : &:r105_4, m84_8
3979+
# 105| r105_6(bool) = CompareLT : r105_3, r105_5
3980+
# 105| m105_7(int) = Store[x] : &:r105_1, r105_6
3981+
# 106| r106_1(glval<int>) = VariableAddress[x] :
3982+
# 106| r106_2(int) = Load[x] : &:r106_1, m105_7
3983+
# 106| r106_3(int) = Constant[0] :
3984+
# 106| r106_4(bool) = CompareNE : r106_2, r106_3
3985+
# 106| v106_5(void) = ConditionalBranch : r106_4
3986+
#-----| False -> Block 42
3987+
#-----| True -> Block 41
3988+
3989+
# 106| Block 41
3990+
# 106| v106_6(void) = NoOp :
3991+
#-----| Goto -> Block 42
3992+
3993+
# 107| Block 42
3994+
# 107| v107_1(void) = NoOp :
39753995
# 84| v84_9(void) = ReturnVoid :
39763996
# 84| v84_10(void) = AliasedUse : m84_3
39773997
# 84| v84_11(void) = ExitFunction :

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ void branch_on_integral_in_c(int x1, int x2) {
101101
int x_1_and_2 = x1 && x2;
102102
if(x_1_and_2) {}
103103
if(!x_1_and_2) {}
104+
105+
int x = x1 < x2;
106+
if(x) {}
104107
}
105108

106109
// semmle-extractor-options: --microsoft

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,8 +3606,28 @@ ir.c:
36063606
# 103| v103_6(void) = NoOp :
36073607
#-----| Goto -> Block 40
36083608

3609-
# 104| Block 40
3610-
# 104| v104_1(void) = NoOp :
3609+
# 105| Block 40
3610+
# 105| r105_1(glval<int>) = VariableAddress[x] :
3611+
# 105| r105_2(glval<int>) = VariableAddress[x1] :
3612+
# 105| r105_3(int) = Load[x1] : &:r105_2, ~m?
3613+
# 105| r105_4(glval<int>) = VariableAddress[x2] :
3614+
# 105| r105_5(int) = Load[x2] : &:r105_4, ~m?
3615+
# 105| r105_6(bool) = CompareLT : r105_3, r105_5
3616+
# 105| mu105_7(int) = Store[x] : &:r105_1, r105_6
3617+
# 106| r106_1(glval<int>) = VariableAddress[x] :
3618+
# 106| r106_2(int) = Load[x] : &:r106_1, ~m?
3619+
# 106| r106_3(int) = Constant[0] :
3620+
# 106| r106_4(bool) = CompareNE : r106_2, r106_3
3621+
# 106| v106_5(void) = ConditionalBranch : r106_4
3622+
#-----| False -> Block 42
3623+
#-----| True -> Block 41
3624+
3625+
# 106| Block 41
3626+
# 106| v106_6(void) = NoOp :
3627+
#-----| Goto -> Block 42
3628+
3629+
# 107| Block 42
3630+
# 107| v107_1(void) = NoOp :
36113631
# 84| v84_8(void) = ReturnVoid :
36123632
# 84| v84_9(void) = AliasedUse : ~m?
36133633
# 84| v84_10(void) = ExitFunction :

0 commit comments

Comments
 (0)