From 83dfd324bfa5f302a8cd67fa431ccfc4d5c5dcb7 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Mon, 16 Jun 2025 18:41:36 +0800 Subject: [PATCH] Fix compile issue by strict checker The compiler will complain or report errors for 1. compares between signed and unsigned integers 2. assigns struct by brace list in C++ --- contrib/pax_storage/CMakeLists.txt | 2 +- contrib/pax_storage/doc/README.md | 2 +- .../pax_storage/src/cpp/comm/bitmap_test.cc | 28 ++++---- .../pax_storage/src/cpp/pax_gtest_helper.cc | 64 +++++++++++------- .../pax_storage/src/cpp/pax_gtest_helper.h | 4 ++ .../cpp/storage/micro_partition_stats_test.cc | 36 ++-------- .../src/cpp/storage/orc/orc_test.cc | 67 ++++--------------- 7 files changed, 80 insertions(+), 123 deletions(-) diff --git a/contrib/pax_storage/CMakeLists.txt b/contrib/pax_storage/CMakeLists.txt index 6665fe77cbf..f2f50c71f59 100644 --- a/contrib/pax_storage/CMakeLists.txt +++ b/contrib/pax_storage/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 17) set(TOP_DIR ${PROJECT_SOURCE_DIR}/../..) set(CBDB_INCLUDE_DIR ${TOP_DIR}/src/include) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-function -Wno-redundant-move -Wno-error=redundant-move -Wno-error=ignored-qualifiers -Wuninitialized -Winit-self -Wstrict-aliasing -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered -Wno-sized-deallocation -g") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-function -Wno-error=ignored-qualifiers -Wuninitialized -Winit-self -Wstrict-aliasing -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered -Wno-sized-deallocation -g") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-parameter -Wno-parameter-name") option(USE_MANIFEST_API "Use manifest API" OFF) diff --git a/contrib/pax_storage/doc/README.md b/contrib/pax_storage/doc/README.md index f8670073876..409ffb9f0d8 100644 --- a/contrib/pax_storage/doc/README.md +++ b/contrib/pax_storage/doc/README.md @@ -23,7 +23,7 @@ PAX has the following features: PAX will be built with `--enable-pax` when you build the Cloudberry. Dependency requirements are as follows: -- **C/C++ Compiler**: GCC/GCC-C++ 11 or later +- **C/C++ Compiler**: GCC/GCC-C++ 8 or later - **CMake**: 3.11 or later - **Protobuf**: 3.5.0 or later - **ZSTD (libzstd)**: 1.4.0 or later diff --git a/contrib/pax_storage/src/cpp/comm/bitmap_test.cc b/contrib/pax_storage/src/cpp/comm/bitmap_test.cc index 937a9c08d8b..dd2cc8094e5 100644 --- a/contrib/pax_storage/src/cpp/comm/bitmap_test.cc +++ b/contrib/pax_storage/src/cpp/comm/bitmap_test.cc @@ -36,7 +36,7 @@ TEST_F(BitMapTest, Bitmap8) { Bitmap8 bm(20); ASSERT_TRUE(bm.Empty()); - for (auto i = 0; i <= 128; i++) { + for (uint32 i = 0; i <= 128; i++) { ASSERT_FALSE(bm.Test(i)); // zeros ASSERT_FALSE(bm.Toggle(i)); ASSERT_TRUE(bm.Test(i)); @@ -61,14 +61,14 @@ TEST_F(BitMapTest, Bitmap8) { TEST_F(BitMapTest, Bitmap8SetN) { Bitmap8 bm(10); - const auto nbits = 128; + const uint32 nbits = 128; ASSERT_TRUE(bm.Empty()); - for (auto i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); + for (uint32 i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); auto fn = [&bm, nbits](uint32 index) { bm.ClearAll(); - for (auto i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); + for (uint32 i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); bm.SetN(index); for (uint32 i = 0; i <= index; i++) ASSERT_TRUE(bm.Test(i)); for (uint32 i = index + 1; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); @@ -78,13 +78,13 @@ TEST_F(BitMapTest, Bitmap8SetN) { TEST_F(BitMapTest, Bitmap8ClearN) { Bitmap8 bm(10); - const auto nbits = 128; + const uint32 nbits = 128; ASSERT_TRUE(bm.Empty()); - for (auto i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); + for (uint32 i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); auto fn = [&bm, nbits](uint32 index) { - for (auto i = 0; i <= nbits; i++) { + for (uint32 i = 0; i <= nbits; i++) { bm.Set(i); ASSERT_TRUE(bm.Test(i)); } @@ -99,7 +99,7 @@ TEST_F(BitMapTest, Bitmap64) { Bitmap64 bm(100); ASSERT_TRUE(bm.Empty()); - for (auto i = 0; i <= 128; i++) { + for (uint32 i = 0; i <= 128; i++) { ASSERT_FALSE(bm.Test(i)); // zeros ASSERT_FALSE(bm.Toggle(i)); ASSERT_TRUE(bm.Test(i)); @@ -122,14 +122,14 @@ TEST_F(BitMapTest, Bitmap64) { } TEST_F(BitMapTest, Bitmap64SetN) { Bitmap64 bm(1); - const auto nbits = 512; + const uint32 nbits = 512; ASSERT_TRUE(bm.Empty()); - for (auto i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); + for (uint32 i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); auto fn = [&bm, nbits](uint32 index) { bm.ClearAll(); - for (auto i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); + for (uint32 i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); bm.SetN(index); for (uint32 i = 0; i <= index; i++) ASSERT_TRUE(bm.Test(i)); for (uint32 i = index + 1; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); @@ -139,13 +139,13 @@ TEST_F(BitMapTest, Bitmap64SetN) { TEST_F(BitMapTest, Bitmap64ClearN) { Bitmap64 bm(1); - const auto nbits = 512; + const uint32 nbits = 512; ASSERT_TRUE(bm.Empty()); - for (auto i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); + for (uint32 i = 0; i <= nbits; i++) ASSERT_FALSE(bm.Test(i)); auto fn = [&bm, &nbits](uint32 index) { - for (auto i = 0; i <= nbits; i++) { + for (uint32 i = 0; i <= nbits; i++) { bm.Set(i); ASSERT_TRUE(bm.Test(i)); } diff --git a/contrib/pax_storage/src/cpp/pax_gtest_helper.cc b/contrib/pax_storage/src/cpp/pax_gtest_helper.cc index f95e3549aca..89a8660baf6 100644 --- a/contrib/pax_storage/src/cpp/pax_gtest_helper.cc +++ b/contrib/pax_storage/src/cpp/pax_gtest_helper.cc @@ -63,35 +63,53 @@ void ReleaseTestResourceOwner() { ResourceOwnerDelete(tmp_resource_owner); } +void InitAttribute_text(Form_pg_attribute attr) +{ + memset(attr, 0, sizeof(*attr)); + attr->atttypid = TEXTOID; + attr->attlen = -1; + attr->attbyval = false; + attr->attalign = TYPALIGN_DOUBLE; + attr->attstorage = TYPSTORAGE_PLAIN; + attr->attisdropped = false; + attr->attcollation = DEFAULT_COLLATION_OID; +} + +void InitAttribute_int4(Form_pg_attribute attr) +{ + memset(attr, 0, sizeof(*attr)); + attr->atttypid = INT4OID; + attr->attlen = 4; + attr->attbyval = true; + attr->attalign = TYPALIGN_INT; + attr->attstorage = TYPSTORAGE_PLAIN; + attr->attisdropped = false; + attr->attcollation = InvalidOid; +} + +void InitAttribute_int8(Form_pg_attribute attr) +{ + memset(attr, 0, sizeof(*attr)); + attr->atttypid = INT8OID; + attr->attlen = 8; + attr->attbyval = true; + attr->attalign = TYPALIGN_DOUBLE; + attr->attstorage = TYPSTORAGE_PLAIN; + attr->attisdropped = false; + attr->attcollation = InvalidOid; +} + static TupleDesc CreateTestTupleDesc(int ncols) { Assert(ncols >= COLUMN_NUMS); auto tuple_desc = reinterpret_cast(cbdb::Palloc0( sizeof(TupleDescData) + sizeof(FormData_pg_attribute) * ncols)); tuple_desc->natts = COLUMN_NUMS; - tuple_desc->attrs[0] = {.atttypid = TEXTOID, - .attlen = -1, - .attbyval = false, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = DEFAULT_COLLATION_OID}; - - tuple_desc->attrs[1] = {.atttypid = TEXTOID, - .attlen = -1, - .attbyval = false, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = DEFAULT_COLLATION_OID}; - - tuple_desc->attrs[2] = {.atttypid = INT4OID, - .attlen = 4, - .attbyval = true, - .attalign = TYPALIGN_INT, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = InvalidOid}; + + InitAttribute_text(&tuple_desc->attrs[0]); + InitAttribute_text(&tuple_desc->attrs[1]); + InitAttribute_int4(&tuple_desc->attrs[2]); + return tuple_desc; } diff --git a/contrib/pax_storage/src/cpp/pax_gtest_helper.h b/contrib/pax_storage/src/cpp/pax_gtest_helper.h index b9c2f42eeaa..7a78b5fdf19 100644 --- a/contrib/pax_storage/src/cpp/pax_gtest_helper.h +++ b/contrib/pax_storage/src/cpp/pax_gtest_helper.h @@ -60,4 +60,8 @@ extern void DeleteTestTupleTableSlot(TupleTableSlot *tuple_slot); extern void GenTextBuffer(char *buffer, size_t length); extern std::vector CreateTestSchemaTypes(); + +extern void InitAttribute_text(Form_pg_attribute attr); +extern void InitAttribute_int4(Form_pg_attribute attr); +extern void InitAttribute_int8(Form_pg_attribute attr); } // namespace pax::tests diff --git a/contrib/pax_storage/src/cpp/storage/micro_partition_stats_test.cc b/contrib/pax_storage/src/cpp/storage/micro_partition_stats_test.cc index a589a3971fa..c18aa491432 100644 --- a/contrib/pax_storage/src/cpp/storage/micro_partition_stats_test.cc +++ b/contrib/pax_storage/src/cpp/storage/micro_partition_stats_test.cc @@ -51,36 +51,10 @@ TEST_F(MicroPartitionStatsTest, MicroPartitionStatsInfoCombine) { cbdb::Palloc0(sizeof(TupleDescData) + sizeof(FormData_pg_attribute) * 4)); tuple_desc->natts = 4; - tuple_desc->attrs[0] = {.atttypid = INT4OID, - .attlen = 4, - .attbyval = true, - .attalign = TYPALIGN_INT, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = InvalidOid}; - - tuple_desc->attrs[1] = {.atttypid = TEXTOID, - .attlen = -1, - .attbyval = false, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = DEFAULT_COLLATION_OID}; - - tuple_desc->attrs[2] = {.atttypid = INT4OID, - .attlen = 4, - .attbyval = true, - .attalign = TYPALIGN_INT, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = InvalidOid}; - tuple_desc->attrs[3] = {.atttypid = INT4OID, - .attlen = 4, - .attbyval = true, - .attalign = TYPALIGN_INT, - .attstorage = TYPSTORAGE_PLAIN, - .attisdropped = false, - .attcollation = InvalidOid}; + InitAttribute_int4(&tuple_desc->attrs[0]); + InitAttribute_text(&tuple_desc->attrs[1]); + InitAttribute_int4(&tuple_desc->attrs[2]); + InitAttribute_int4(&tuple_desc->attrs[3]); auto col_stats1_1 = mp_stats_info1.add_columnstats(); auto col_stats1_2 = mp_stats_info1.add_columnstats(); @@ -304,4 +278,4 @@ TEST_F(MicroPartitionStatsTest, MicroPartitionStatsInfoCombine) { ASSERT_EQ(min_datum, cbdb::Int32ToDatum(50)); } -} // namespace pax::tests \ No newline at end of file +} // namespace pax::tests diff --git a/contrib/pax_storage/src/cpp/storage/orc/orc_test.cc b/contrib/pax_storage/src/cpp/storage/orc/orc_test.cc index c7c82d252f6..113dab7ba1e 100644 --- a/contrib/pax_storage/src/cpp/storage/orc/orc_test.cc +++ b/contrib/pax_storage/src/cpp/storage/orc/orc_test.cc @@ -487,16 +487,13 @@ TEST_F(OrcTest, WriteReadTupleWithToast) { pax_min_size_of_external_toast = 1024; tuple_desc->natts = TOAST_COLUMN_NUMS; - tuple_desc->attrs[0] = {.atttypid = TEXTOID, - .attlen = -1, - .attbyval = false, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_EXTENDED, - .attisdropped = false, - .attcollation = DEFAULT_COLLATION_OID}; - tuple_desc->attrs[1] = tuple_desc->attrs[0]; - tuple_desc->attrs[2] = tuple_desc->attrs[0]; - tuple_desc->attrs[3] = tuple_desc->attrs[0]; + InitAttribute_text(&tuple_desc->attrs[0]); + InitAttribute_text(&tuple_desc->attrs[1]); + InitAttribute_text(&tuple_desc->attrs[2]); + InitAttribute_text(&tuple_desc->attrs[3]); + tuple_desc->attrs[0].attstorage = TYPSTORAGE_EXTENDED; + tuple_desc->attrs[1].attstorage = TYPSTORAGE_EXTENDED; + tuple_desc->attrs[2].attstorage = TYPSTORAGE_EXTENDED; // column 4 is external but no compress tuple_desc->attrs[3].attstorage = TYPSTORAGE_EXTERNAL; @@ -763,19 +760,8 @@ TEST_P(OrcEncodingTest, ReadTupleWithEncoding) { cbdb::Palloc0(sizeof(TupleDescData) + sizeof(FormData_pg_attribute) * 2)); tuple_desc->natts = 2; - tuple_desc->attrs[0] = { - .attlen = 8, - .attbyval = true, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - }; - - tuple_desc->attrs[1] = { - .attlen = 8, - .attbyval = true, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - }; + InitAttribute_int8(&tuple_desc->attrs[0]); + InitAttribute_int8(&tuple_desc->attrs[1]); tuple_slot = MakeTupleTableSlot(tuple_desc, &TTSOpsVirtual); bool *fake_is_null = @@ -847,19 +833,8 @@ TEST_P(OrcCompressTest, ReadTupleWithCompress) { cbdb::Palloc0(sizeof(TupleDescData) + sizeof(FormData_pg_attribute) * 2)); tuple_desc->natts = 2; - tuple_desc->attrs[0] = { - .attlen = -1, - .attbyval = false, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - }; - - tuple_desc->attrs[1] = { - .attlen = -1, - .attbyval = false, - .attalign = TYPALIGN_DOUBLE, - .attstorage = TYPSTORAGE_PLAIN, - }; + InitAttribute_text(&tuple_desc->attrs[0]); + InitAttribute_text(&tuple_desc->attrs[1]); tuple_slot = MakeTupleTableSlot(tuple_desc, &TTSOpsVirtual); bool *fake_is_null = @@ -963,11 +938,7 @@ TEST_F(OrcTest, ReadTupleDefaultColumn) { EXPECT_EQ(1UL, reader->GetGroupNums()); TupleTableSlot *tuple_slot_empty = CreateTestTupleTableSlot(false, 4); - tuple_slot_empty->tts_tupleDescriptor->attrs[3] = { - .attlen = 4, - .attbyval = true, - .attstorage = TYPSTORAGE_PLAIN, - }; + InitAttribute_int4(&tuple_slot_empty->tts_tupleDescriptor->attrs[3]); tuple_slot_empty->tts_tupleDescriptor->natts = COLUMN_NUMS + 1; @@ -1071,18 +1042,8 @@ TEST_F(OrcTest, WriteReadBigTuple) { cbdb::Palloc0(sizeof(TupleDescData) + sizeof(FormData_pg_attribute) * 2)); tuple_desc->natts = 2; - tuple_desc->attrs[0] = { - .attlen = 4, - .attbyval = true, - .attalign = TYPALIGN_INT, - .attstorage = TYPSTORAGE_PLAIN, - }; - tuple_desc->attrs[1] = { - .attlen = 4, - .attbyval = true, - .attalign = TYPALIGN_INT, - .attstorage = TYPSTORAGE_PLAIN, - }; + InitAttribute_int4(&tuple_desc->attrs[0]); + InitAttribute_int4(&tuple_desc->attrs[1]); tuple_slot = MakeTupleTableSlot(tuple_desc, &TTSOpsVirtual); bool *fake_is_null =