Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
c49b333c
Commit
c49b333c
authored
Nov 20, 2018
by
Dale Hamel
Committed by
Alastair Robertson
Nov 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for anonymous struct/union parsing and indirect fields
parent
bb2e6fd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
src/clang_parser.cpp
src/clang_parser.cpp
+1
-1
tests/clang_parser.cpp
tests/clang_parser.cpp
+34
-0
No files found.
src/clang_parser.cpp
View file @
c49b333c
...
...
@@ -57,7 +57,7 @@ static std::string get_parent_struct_name(CXCursor c)
static
int
get_indirect_field_offset
(
CXCursor
c
)
{
int
offset
=
0
;
int
offset
=
0
;
CXCursor
parent
=
get_indirect_field_parent_struct
(
c
);
auto
ident
=
get_clang_string
(
clang_getCursorSpelling
(
c
));
offset
=
clang_Type_getOffsetOf
(
clang_getCursorType
(
parent
),
ident
.
c_str
())
/
8
;
...
...
tests/clang_parser.cpp
View file @
c49b333c
...
...
@@ -188,6 +188,40 @@ TEST(clang_parser, nested_struct_anon)
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"bar"
].
offset
,
0
);
}
TEST
(
clang_parser
,
nested_struct_indirect_fields
)
{
StructMap
structs
;
parse
(
"struct Foo { struct { int x; int y;}; int a; struct { int z; }; }"
,
structs
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
size
(),
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"x"
].
offset
,
0
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"x"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"y"
].
offset
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"y"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"a"
].
offset
,
8
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"a"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"z"
].
offset
,
12
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"z"
].
type
.
size
,
4
);
}
TEST
(
clang_parser
,
nested_struct_anon_union_struct
)
{
StructMap
structs
;
parse
(
"struct Foo { union { long long _xy; struct { int x; int y;}; }; int a; struct { int z; }; }"
,
structs
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
size
(),
5
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"_xy"
].
offset
,
0
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"_xy"
].
type
.
size
,
8
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"x"
].
offset
,
0
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"x"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"y"
].
offset
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"y"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"a"
].
offset
,
8
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"a"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"z"
].
offset
,
12
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"z"
].
type
.
size
,
4
);
}
TEST
(
clang_parser
,
builtin_headers
)
{
// size_t is definied in stddef.h
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment