mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:26:23 -04:00
fix(lib): address strict aliasing violations in TreeCursor type
This commit is contained in:
parent
04bac19343
commit
6b7e298549
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
|
@ -211,7 +211,7 @@ jobs:
|
|||
make -j CFLAGS="$CFLAGS" CC=$CC AR=$AR
|
||||
env:
|
||||
PLATFORM: ${{ matrix.platform }}
|
||||
CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types
|
||||
CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -Werror=strict-aliasing -Wstrict-aliasing=2
|
||||
|
||||
- name: Build C library (CMake)
|
||||
if: "!matrix.cross && !matrix.vm"
|
||||
|
|
|
|||
2
.github/workflows/wasm_exports.yml
vendored
2
.github/workflows/wasm_exports.yml
vendored
|
|
@ -31,7 +31,7 @@ jobs:
|
|||
- name: Build C library (make)
|
||||
run: make -j CFLAGS="$CFLAGS"
|
||||
env:
|
||||
CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types
|
||||
CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -Werror=strict-aliasing -Wstrict-aliasing=2
|
||||
|
||||
- name: Build Wasm Library
|
||||
working-directory: lib/binding_web
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ if(MSVC)
|
|||
else()
|
||||
target_compile_options(tree-sitter PRIVATE
|
||||
-Wall -Wextra -Wshadow -Wpedantic
|
||||
-Werror=incompatible-pointer-types)
|
||||
-Werror=incompatible-pointer-types
|
||||
-Werror=strict-aliasing -Wstrict-aliasing=2)
|
||||
endif()
|
||||
|
||||
if(TREE_SITTER_FEATURE_WASM)
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -22,7 +22,7 @@ OBJ := $(SRC:.c=.o)
|
|||
|
||||
# define default flags, and override to append mandatory flags
|
||||
ARFLAGS := rcs
|
||||
CFLAGS ?= -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types
|
||||
CFLAGS ?= -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -Werror=strict-aliasing -Wstrict-aliasing=2
|
||||
override CFLAGS += -std=c11 -fPIC -fvisibility=hidden
|
||||
override CFLAGS += -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_DARWIN_C_SOURCE
|
||||
override CFLAGS += -Ilib/src -Ilib/src/wasm -Ilib/include
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
#include "./language.h"
|
||||
#include "./tree.h"
|
||||
|
||||
_Static_assert(
|
||||
sizeof(TreeCursor) <= sizeof(TSTreeCursor),
|
||||
"TreeCursor must fit within TSTreeCursor"
|
||||
);
|
||||
|
||||
typedef struct {
|
||||
Subtree parent;
|
||||
const TSTree *tree;
|
||||
|
|
@ -153,8 +158,10 @@ static inline bool ts_tree_cursor_child_iterator_previous(
|
|||
// TSTreeCursor - lifecycle
|
||||
|
||||
TSTreeCursor ts_tree_cursor_new(TSNode node) {
|
||||
TSTreeCursor self = {NULL, NULL, {0, 0, 0}};
|
||||
ts_tree_cursor_init((TreeCursor *)&self, node);
|
||||
TreeCursor cursor = {0};
|
||||
ts_tree_cursor_init(&cursor, node);
|
||||
TSTreeCursor self = {0};
|
||||
memcpy(&self, &cursor, sizeof(cursor));
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
@ -697,12 +704,13 @@ const char *ts_tree_cursor_current_field_name(const TSTreeCursor *_self) {
|
|||
|
||||
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *_cursor) {
|
||||
const TreeCursor *cursor = (const TreeCursor *)_cursor;
|
||||
TSTreeCursor res = {NULL, NULL, {0, 0}};
|
||||
TreeCursor *copy = (TreeCursor *)&res;
|
||||
copy->tree = cursor->tree;
|
||||
copy->root_alias_symbol = cursor->root_alias_symbol;
|
||||
array_init(©->stack);
|
||||
array_push_all(©->stack, &cursor->stack);
|
||||
TreeCursor copy = {0};
|
||||
copy.tree = cursor->tree;
|
||||
copy.root_alias_symbol = cursor->root_alias_symbol;
|
||||
array_init(©.stack);
|
||||
array_push_all(©.stack, &cursor->stack);
|
||||
TSTreeCursor res = {0};
|
||||
memcpy(&res, ©, sizeof(copy));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue