@@ -20,7 +20,9 @@ TEST(ToAPValue, Pointers) {
20
20
" A a[3];\n "
21
21
" };\n "
22
22
" constexpr S d = {{{true, false}, {false, true}, {false, false}}};\n "
23
- " constexpr const bool *b = &d.a[1].z;\n " ;
23
+ " constexpr const bool *b = &d.a[1].z;\n "
24
+ " const void *p = (void*)12;\n "
25
+ " const void *nullp = (void*)0;\n " ;
24
26
25
27
auto AST = tooling::buildASTFromCodeWithArgs (
26
28
Code, {" -fexperimental-new-constant-interpreter" });
@@ -41,15 +43,49 @@ TEST(ToAPValue, Pointers) {
41
43
return Prog.getPtrGlobal (*Prog.getGlobal (D));
42
44
};
43
45
44
- const Pointer &GP = getGlobalPtr (" b" );
45
- const Pointer &P = GP.deref <Pointer>();
46
- ASSERT_TRUE (P.isLive ());
47
- APValue A = P.toAPValue ();
48
- ASSERT_TRUE (A.isLValue ());
49
- ASSERT_TRUE (A.hasLValuePath ());
50
- const auto &Path = A.getLValuePath ();
51
- ASSERT_EQ (Path.size (), 3u );
52
- ASSERT_EQ (A.getLValueBase (), getDecl (" d" ));
46
+ {
47
+ const Pointer &GP = getGlobalPtr (" b" );
48
+ const Pointer &P = GP.deref <Pointer>();
49
+ ASSERT_TRUE (P.isLive ());
50
+ APValue A = P.toAPValue ();
51
+ ASSERT_TRUE (A.isLValue ());
52
+ ASSERT_TRUE (A.hasLValuePath ());
53
+ const auto &Path = A.getLValuePath ();
54
+ ASSERT_EQ (Path.size (), 3u );
55
+ ASSERT_EQ (A.getLValueBase (), getDecl (" d" ));
56
+ // FIXME: Also test all path elements.
57
+ }
58
+
59
+ {
60
+ const ValueDecl *D = getDecl (" p" );
61
+ ASSERT_NE (D, nullptr );
62
+ const Pointer &GP = getGlobalPtr (" p" );
63
+ const Pointer &P = GP.deref <Pointer>();
64
+ ASSERT_TRUE (P.isIntegralPointer ());
65
+ APValue A = P.toAPValue ();
66
+ ASSERT_TRUE (A.isLValue ());
67
+ ASSERT_TRUE (A.getLValueBase ().isNull ());
68
+ APSInt I;
69
+ bool Success = A.toIntegralConstant (I, D->getType (), AST->getASTContext ());
70
+ ASSERT_TRUE (Success);
71
+ ASSERT_EQ (I, 12 );
72
+ }
73
+
74
+ {
75
+ const ValueDecl *D = getDecl (" nullp" );
76
+ ASSERT_NE (D, nullptr );
77
+ const Pointer &GP = getGlobalPtr (" nullp" );
78
+ const Pointer &P = GP.deref <Pointer>();
79
+ ASSERT_TRUE (P.isIntegralPointer ());
80
+ APValue A = P.toAPValue ();
81
+ ASSERT_TRUE (A.isLValue ());
82
+ ASSERT_TRUE (A.getLValueBase ().isNull ());
83
+ ASSERT_TRUE (A.isNullPointer ());
84
+ APSInt I;
85
+ bool Success = A.toIntegralConstant (I, D->getType (), AST->getASTContext ());
86
+ ASSERT_TRUE (Success);
87
+ ASSERT_EQ (I, 0 );
88
+ }
53
89
}
54
90
55
91
TEST (ToAPValue, FunctionPointers) {
0 commit comments