Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ DISABLED_WARNINGS_HARD = \
-Wno-unknown-warning-option

# TODO: Minimize this list.
# TODO(T233149341): Narrow -Wno-volatile to problematic early verisons of
# jsoncpp < 1.9.5 (https://github.com/open-source-parsers/jsoncpp/issues/1193).
# This is currently only a problem on Debian 11.
# TODO(T233149341): Narrow -Wno-restrict to problematic verisons of
# GCC, i.e., 12: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105651
DISABLED_WARNINGS = \
$(DISABLED_WARNINGS_HARD) \
-Wno-array-bounds \
Expand All @@ -32,6 +37,7 @@ DISABLED_WARNINGS = \
-Wno-parentheses \
-Wno-range-loop-analysis \
-Wno-redundant-move \
-Wno-restrict \
-Wno-return-type \
-Wno-shift-count-overflow \
-Wno-sign-compare \
Expand All @@ -46,9 +52,10 @@ DISABLED_WARNINGS = \
-Wno-unused-private-field \
-Wno-unused-result \
-Wno-unused-value \
-Wno-unused-variable
-Wno-unused-variable \
-Wno-volatile

AM_CXXFLAGS = --std=gnu++17 -O3 -Wall -Werror -Wextra $(DISABLED_WARNINGS) -g1
AM_CXXFLAGS = --std=gnu++20 -O3 -Wall -Werror -Wextra $(DISABLED_WARNINGS) -g1

include $(top_srcdir)/Makefile.inc

Expand Down
4 changes: 2 additions & 2 deletions cmake_modules/Commons.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function(print_dirs var name)
endfunction()

macro(set_common_cxx_flags_for_redex)
message(STATUS "Using C++17")
set(CMAKE_CXX_STANDARD 17)
message(STATUS "Using C++20")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC)
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AM_INIT_AUTOMAKE([subdir-objects])
# clear out default cxx flags (was "-O2 -g") so that they don't override
# the flags defined in AM_CXXFLAGS. add "-std" to work around gtest issue
# on macos.
: ${CXXFLAGS="-std=gnu++17"}
: ${CXXFLAGS="-std=gnu++20"}

# Checks for programs.
AC_PROG_CXX
Expand Down Expand Up @@ -97,7 +97,7 @@ AS_IF([test "x$enable_protobuf" = "xyes"], [
CXXFLAGS_ORIG=$CXXFLAGS

# test protobuf header
CXXFLAGS="-std=gnu++17 ${CXXFLAGS_ORIG} -I${withval}"
CXXFLAGS="-std=gnu++20 ${CXXFLAGS_ORIG} -I${withval}"
AC_LANG_PUSH([C++])
AC_CHECK_HEADER([google/protobuf/io/coded_stream.h], [
# library found
Expand Down
2 changes: 0 additions & 2 deletions libredex/RedexResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,12 @@ std::string convert_utf8_to_mutf8(std::string_view input) {
return out.str();
}

#if __cplusplus >= 202002L
std::string convert_utf8_to_mutf8(std::u8string_view input) {
return convert_utf8_to_mutf8(std::string_view(
// reinterpret_cast here is safe because the char8_t has the same size and
// alignment with char.
reinterpret_cast<const char*>(input.data()), input.size()));
}
#endif // __cplusplus >= 202002L

void resources_inlining_find_refs(
const UnorderedMap<uint32_t, uint32_t>& past_refs,
Expand Down
10 changes: 8 additions & 2 deletions libredex/RedexResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ using StringOrReferenceSet =
// Helper for dealing with differences in character encoding between .arsc and
// .pb files.
std::string convert_utf8_to_mutf8(std::string_view input);
#if __cplusplus >= 202002L
// This line is needed because this header is exposed to dependents, which may
// be using C++17.
// This is not 202002L because GCC 10 (shipped in Debian 11) defines __cplusplus
// to be so with -std=gnu++20 flag.
// TODO(T233875592): Change this to 202002L when GCC 11 becomes the minimum
// supported compiler version.
#if __cplusplus >= 201709L
// A convenient wrapper to allow convert_utf8_to_mutf8 to be used with u8"foo"
// string literals.
std::string convert_utf8_to_mutf8(std::u8string_view input);
#endif // __cplusplus >= 202002L
#endif // __cplusplus >= 201709L
// Given a map of a id which holds a reference value, and the id that the
// reference points to, along with all the past found inlinable values, for each
// id in past_refs, if it is inlinable, adds it to inlinable_resources with the
Expand Down
8 changes: 8 additions & 0 deletions service/cse/CommonSubexpressionElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,16 @@ class Analyzer final : public BaseEdgeAwareIRAnalyzer<CseEnvironment> {
m_pre_state_value_ids.insert(id);
} else {
const auto& abs_map = m_shared_state->get_abstract_map();
#if __GNUC__ >= 11 && __GNUC__ <= 14 && !defined(__clang__)
#pragma GCC diagnostic push
// Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731
#pragma GCC diagnostic ignored "-Wrange-loop-construct"
#endif // __GNUC__ >= 11 && __GNUC__ <= 14 && !defined(__clang__)
for (const auto [box_method, unbox_method] :
UnorderedIterable(m_shared_state->get_boxing_map())) {
#if __GNUC__ >= 11 && __GNUC__ <= 14 && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // __GNUC__ >= 11 && __GNUC__ <= 14 && !defined(__clang__)
const DexMethodRef* abs_method = nullptr;
auto abs_it = abs_map.find(unbox_method);
if (abs_it != abs_map.end()) {
Expand Down
9 changes: 5 additions & 4 deletions setup_oss_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ function install_googletest_from_source {
mkdir -p toolchain_install/gtest
pushd toolchain_install/gtest
tar xf "../../dl_cache/gtest/googletest-${GOOGLETEST_MIN_VERSION}.tar.gz" --no-same-owner --strip-components=1
# GoogleTest's string_view matcher requires compiler to support C++17. Older
# GCC versions need to be told to use C++17 with -std=gnu++17.
# GoogleTest's string_view matcher requires compiler to support C++17 or
# later. Older GCC versions need to be explicitly told to use a later C++
# standard.
if [ "$BITNESS" = "32" ] ; then
CFLAGS=-m32 CXXFLAGS="-m32 -std=gnu++17" LDFLAGS=-m32 cmake .
CFLAGS=-m32 CXXFLAGS="-m32 -std=gnu++20" LDFLAGS=-m32 cmake .
else
CXXFLAGS="-std=gnu++17" cmake .
CXXFLAGS="-std=gnu++20" cmake .
fi
cmake --build . --target install
popd
Expand Down
2 changes: 1 addition & 1 deletion test/integ/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DX = @DX@
ANDROID_SDK = @ANDROID_SDK@
ANDROID_PLATFORM_VERSION = @ANDROID_PLATFORM_VERSION@

AM_CXXFLAGS = --std=gnu++17
AM_CXXFLAGS = --std=gnu++20
AM_CPPFLAGS = $(COMMON_INCLUDES) $(COMMON_TEST_INCLUDES)

# Boost.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include $(top_srcdir)/test/Makefile.inc
ANDROID_SDK = @ANDROID_SDK@
ANDROID_PLATFORM_VERSION = @ANDROID_PLATFORM_VERSION@

AM_CXXFLAGS = --std=gnu++17
AM_CXXFLAGS = --std=gnu++20
AM_CPPFLAGS = $(COMMON_INCLUDES) $(COMMON_TEST_INCLUDES)

# Boost.
Expand Down
7 changes: 1 addition & 6 deletions test/unit/RedexResourcesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,8 @@ inline uint32_t to_uint(char c) {
}

TEST(RedexResources, Mutf8Conversion) {
#if __cplusplus >= 202002L
using utf8_string_view = std::u8string_view;
#else
using utf8_string_view = std::string_view;
#endif // __cplusplus >= 202002L
bool be_noisy{false};
auto verify = [&](utf8_string_view input,
auto verify = [&](std::u8string_view input,
const std::vector<uint8_t>& expected_bytes) {
auto converted = resources::convert_utf8_to_mutf8(input);
EXPECT_EQ(converted.size(), expected_bytes.size());
Expand Down
Loading