Skip to content

Commit 6f23819

Browse files
authored
Merge pull request github#17140 from github/jketema/generic-broken
C++ Add IR test for `_Generic`s
2 parents fe00dbc + 2870204 commit 6f23819

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,6 +4179,40 @@ destructors_for_temps.cpp:
41794179
# 103| Type = [IntType] int
41804180
# 103| ValueCategory = prvalue
41814181
# 104| getStmt(1): [ReturnStmt] return ...
4182+
generic.c:
4183+
# 1| [TopLevelFunction] void c11_generic_test(unsigned int, int)
4184+
# 1| <params>:
4185+
# 1| getParameter(0): [Parameter] x
4186+
# 1| Type = [IntType] unsigned int
4187+
# 1| getParameter(1): [Parameter] y
4188+
# 1| Type = [IntType] int
4189+
# 1| getEntryPoint(): [BlockStmt] { ... }
4190+
# 2| getStmt(0): [DeclStmt] declaration
4191+
# 2| getDeclarationEntry(0): [VariableDeclarationEntry] definition of r
4192+
# 2| Type = [IntType] unsigned int
4193+
# 3| getStmt(1): [ExprStmt] ExprStmt
4194+
# 3| getExpr(): [AssignExpr] ... = ...
4195+
# 3| Type = [IntType] unsigned int
4196+
# 3| ValueCategory = prvalue
4197+
# 3| getLValue(): [VariableAccess] r
4198+
# 3| Type = [IntType] unsigned int
4199+
# 3| ValueCategory = lvalue
4200+
# 3| getRValue(): [AddExpr] ... + ...
4201+
# 3| Type = [IntType] unsigned int
4202+
# 3| ValueCategory = prvalue
4203+
# 3| getLeftOperand(): [VariableAccess] x
4204+
# 3| Type = [IntType] unsigned int
4205+
# 3| ValueCategory = prvalue(load)
4206+
# 3| getRightOperand(): [Literal] 1
4207+
# 3| Type = [IntType] int
4208+
# 3| Value = [Literal] 1
4209+
# 3| ValueCategory = prvalue
4210+
# 3| getRightOperand().getFullyConverted(): [CStyleCast] (unsigned int)...
4211+
# 3| Conversion = [IntegralConversion] integral conversion
4212+
# 3| Type = [IntType] unsigned int
4213+
# 3| Value = [CStyleCast] 1
4214+
# 3| ValueCategory = prvalue
4215+
# 4| getStmt(2): [ReturnStmt] return ...
41824216
ir.c:
41834217
# 5| [TopLevelFunction] int getX(MyCoords*)
41844218
# 5| <params>:

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,30 @@ destructors_for_temps.cpp:
29582958
# 102| v102_9(void) = AliasedUse : ~m103_26
29592959
# 102| v102_10(void) = ExitFunction :
29602960

2961+
generic.c:
2962+
# 1| void c11_generic_test(unsigned int, int)
2963+
# 1| Block 0
2964+
# 1| v1_1(void) = EnterFunction :
2965+
# 1| m1_2(unknown) = AliasedDefinition :
2966+
# 1| m1_3(unknown) = InitializeNonLocal :
2967+
# 1| m1_4(unknown) = Chi : total:m1_2, partial:m1_3
2968+
# 1| r1_5(glval<unsigned int>) = VariableAddress[x] :
2969+
# 1| m1_6(unsigned int) = InitializeParameter[x] : &:r1_5
2970+
# 1| r1_7(glval<int>) = VariableAddress[y] :
2971+
# 1| m1_8(int) = InitializeParameter[y] : &:r1_7
2972+
# 2| r2_1(glval<unsigned int>) = VariableAddress[r] :
2973+
# 2| m2_2(unsigned int) = Uninitialized[r] : &:r2_1
2974+
# 3| r3_1(glval<unsigned int>) = VariableAddress[x] :
2975+
# 3| r3_2(unsigned int) = Load[x] : &:r3_1, m1_6
2976+
# 3| r3_3(unsigned int) = Constant[1] :
2977+
# 3| r3_4(unsigned int) = Add : r3_2, r3_3
2978+
# 3| r3_5(glval<unsigned int>) = VariableAddress[r] :
2979+
# 3| m3_6(unsigned int) = Store[r] : &:r3_5, r3_4
2980+
# 4| v4_1(void) = NoOp :
2981+
# 1| v1_9(void) = ReturnVoid :
2982+
# 1| v1_10(void) = AliasedUse : m1_3
2983+
# 1| v1_11(void) = ExitFunction :
2984+
29612985
ir.c:
29622986
# 7| void MyCoordsTest(int)
29632987
# 7| Block 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void c11_generic_test(unsigned int x, int y) {
2+
unsigned int r;
3+
r = _Generic(r, unsigned int: x, int: y) + 1;
4+
}
5+
6+
// // semmle-extractor-options: -std=c11

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,29 @@ destructors_for_temps.cpp:
27322732
# 102| v102_7(void) = AliasedUse : ~m?
27332733
# 102| v102_8(void) = ExitFunction :
27342734

2735+
generic.c:
2736+
# 1| void c11_generic_test(unsigned int, int)
2737+
# 1| Block 0
2738+
# 1| v1_1(void) = EnterFunction :
2739+
# 1| mu1_2(unknown) = AliasedDefinition :
2740+
# 1| mu1_3(unknown) = InitializeNonLocal :
2741+
# 1| r1_4(glval<unsigned int>) = VariableAddress[x] :
2742+
# 1| mu1_5(unsigned int) = InitializeParameter[x] : &:r1_4
2743+
# 1| r1_6(glval<int>) = VariableAddress[y] :
2744+
# 1| mu1_7(int) = InitializeParameter[y] : &:r1_6
2745+
# 2| r2_1(glval<unsigned int>) = VariableAddress[r] :
2746+
# 2| mu2_2(unsigned int) = Uninitialized[r] : &:r2_1
2747+
# 3| r3_1(glval<unsigned int>) = VariableAddress[x] :
2748+
# 3| r3_2(unsigned int) = Load[x] : &:r3_1, ~m?
2749+
# 3| r3_3(unsigned int) = Constant[1] :
2750+
# 3| r3_4(unsigned int) = Add : r3_2, r3_3
2751+
# 3| r3_5(glval<unsigned int>) = VariableAddress[r] :
2752+
# 3| mu3_6(unsigned int) = Store[r] : &:r3_5, r3_4
2753+
# 4| v4_1(void) = NoOp :
2754+
# 1| v1_8(void) = ReturnVoid :
2755+
# 1| v1_9(void) = AliasedUse : ~m?
2756+
# 1| v1_10(void) = ExitFunction :
2757+
27352758
ir.c:
27362759
# 7| void MyCoordsTest(int)
27372760
# 7| Block 0

0 commit comments

Comments
 (0)