Skip to content

Commit fb33c4e

Browse files
committed
-ftree-vrp better diagnostics on -Os builds; -fno-inline-functions for -O2; fix struct init in HCI bleio
1 parent bbbd621 commit fb33c4e

File tree

7 files changed

+39
-31
lines changed

7 files changed

+39
-31
lines changed

devices/ble_hci/common-hal/_bleio/att.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,21 +1010,22 @@ void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, ui
10101010
}
10111011

10121012
int att_read_group_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid, uint8_t response_buffer[]) {
1013-
struct __packed {
1013+
1014+
typedef struct __packed {
10141015
struct bt_att_hdr h;
10151016
struct bt_att_read_group_req r;
1016-
} req = { {
1017-
.code = BT_ATT_OP_READ_GROUP_REQ,
1018-
}, {
1019-
.start_handle = start_handle,
1020-
.end_handle = end_handle,
1021-
}
1022-
};
1023-
req.r.uuid[0] = uuid & 0xff;
1024-
req.r.uuid[1] = uuid >> 8;
1017+
} req_t;
10251018

1019+
uint8_t req_bytes[sizeof(req_t) + sizeof(uuid)];
1020+
req_t *req = (req_t *) req_bytes;
10261021

1027-
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer);
1022+
req->h.code = BT_ATT_OP_READ_GROUP_REQ;
1023+
req->r.start_handle = start_handle;
1024+
req->r.end_handle = end_handle;
1025+
req->r.uuid[0] = uuid & 0xff;
1026+
req->r.uuid[1] = uuid >> 8;
1027+
1028+
return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer);
10281029
}
10291030

10301031
STATIC void process_read_group_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
@@ -1305,20 +1306,21 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
13051306
}
13061307

13071308
int att_read_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t type, uint8_t response_buffer[]) {
1308-
struct __packed {
1309+
typedef struct __packed {
13091310
struct bt_att_hdr h;
13101311
struct bt_att_read_type_req r;
1311-
} req = { {
1312-
.code = BT_ATT_OP_READ_TYPE_REQ,
1313-
}, {
1314-
.start_handle = start_handle,
1315-
.end_handle = end_handle,
1316-
}
1317-
};
1318-
req.r.uuid[0] = type & 0xff;
1319-
req.r.uuid[1] = type >> 8;
1312+
} req_t;
13201313

1321-
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer);
1314+
uint8_t req_bytes[sizeof(req_t) + sizeof(type)];
1315+
req_t *req = (req_t *) req_bytes;
1316+
1317+
req->h.code = BT_ATT_OP_READ_TYPE_REQ;
1318+
req->r.start_handle = start_handle;
1319+
req->r.end_handle = end_handle;
1320+
req->r.uuid[0] = type & 0xff;
1321+
req->r.uuid[1] = type >> 8;
1322+
1323+
return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer);
13221324
}
13231325

13241326
STATIC void process_read_type_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {

ports/atmel-samd/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,31 @@ endif
9494

9595
ifeq ($(CHIP_FAMILY), samd51)
9696
PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x
97-
OPTIMIZATION_FLAGS ?= -Os
97+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
9898
# TinyUSB defines
9999
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD51 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
100100
endif
101101

102102
ifeq ($(CHIP_FAMILY), same51)
103103
PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x
104-
OPTIMIZATION_FLAGS ?= -Os
104+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
105105
# TinyUSB defines
106106
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
107107
endif
108108

109109
ifeq ($(CHIP_FAMILY), same54)
110110
PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x
111-
OPTIMIZATION_FLAGS ?= -Os
111+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
112112
# TinyUSB defines
113113
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
114114
endif
115115

116116
# option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk
117117
CFLAGS += $(OPTIMIZATION_FLAGS)
118118

119+
# Add -ftree-vrp optimization and checking to all builds. It's not enabled for -Os by default.
120+
CFLAGS += -ftree-vrp
121+
119122
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
120123
#Debugging/Optimization
121124
ifeq ($(DEBUG), 1)

ports/cxd56/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ CFLAGS += \
122122
-fdata-sections \
123123
-Wall \
124124

125-
OPTIMIZATION_FLAGS ?= -O2
125+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
126126

127127
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
128128
CFLAGS += $(OPTIMIZATION_FLAGS)

ports/litex/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ ifeq ($(DEBUG), 1)
8080
OPTIMIZATION_FLAGS ?= -Og
8181
else
8282
CFLAGS += -DNDEBUG -ggdb3
83-
OPTIMIZATION_FLAGS ?= -O2
83+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
8484
# TODO: Test with -flto
8585
### CFLAGS += -flto
8686
endif

ports/mimxrt10xx/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ INC += \
7575

7676
# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt.
7777

78-
CFLAGS += -Os -DNDEBUG -ffreestanding
78+
CFLAGS += -Os -ftree-vrp -DNDEBUG -ffreestanding
7979

8080
# TinyUSB defines
8181
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024
@@ -108,7 +108,7 @@ CFLAGS += \
108108
-g3 -Wno-unused-parameter \
109109
-ffunction-sections -fdata-sections -fstack-usage
110110

111-
OPTIMIZATION_FLAGS ?= -O2
111+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
112112

113113
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
114114
CFLAGS += $(OPTIMIZATION_FLAGS)

ports/nrf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ifeq ($(DEBUG), 1)
8989
CFLAGS += -ggdb3
9090
OPTIMIZATION_FLAGS = -Og
9191
else
92-
OPTIMIZATION_FLAGS ?= -O2
92+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
9393
CFLAGS += -DNDEBUG -ggdb3
9494
CFLAGS += -flto -flto-partition=none
9595
endif

ports/stm/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ifeq ($(DEBUG), 1)
8686
CFLAGS += -fno-inline -fno-ipa-sra
8787
else
8888
CFLAGS += -DNDEBUG
89-
OPTIMIZATION_FLAGS ?= -O2
89+
OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions
9090
CFLAGS += -ggdb3
9191
# TODO: Test with -flto
9292
# CFLAGS += -flto
@@ -95,6 +95,9 @@ endif
9595
# to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
9696
CFLAGS += $(OPTIMIZATION_FLAGS)
9797

98+
# Add -ftree-vrp optimization and checking to all builds. It's not enabled for -Os by default.
99+
CFLAGS += -ftree-vrp
100+
98101
# MCU Series is defined by the HAL package and doesn't need to be specified here
99102
C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)
100103

0 commit comments

Comments
 (0)