From d933922e6963e52c27e828813f1e66a0e5255291 Mon Sep 17 00:00:00 2001 From: sergesanspaille Date: Tue, 19 May 2020 13:12:28 +0000 Subject: [PATCH] Backport ad7211df6f257e39da2e5a11b2456b4488f32a1e, see rhbz#1825593 --- ...ned-behaviour-in-RawComment-getForma.patch | 47 +++++++++++++++++++ clang.spec | 7 ++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 0001-clang-fix-undefined-behaviour-in-RawComment-getForma.patch diff --git a/0001-clang-fix-undefined-behaviour-in-RawComment-getForma.patch b/0001-clang-fix-undefined-behaviour-in-RawComment-getForma.patch new file mode 100644 index 0000000..ccdb423 --- /dev/null +++ b/0001-clang-fix-undefined-behaviour-in-RawComment-getForma.patch @@ -0,0 +1,47 @@ +From ad7211df6f257e39da2e5a11b2456b4488f32a1e Mon Sep 17 00:00:00 2001 +From: Oliver Bruns +Date: Mon, 6 Apr 2020 10:38:30 +0200 +Subject: [PATCH] [clang] fix undefined behaviour in + RawComment::getFormattedText() + +Summary: +Calling `back()` and `pop_back()` on the empty string is undefined +behavior [1,2]. + +The issue manifested itself as an uncaught `std::out_of_range` exception +when running `clangd` compiled on RHEL7 using devtoolset-9. + +[1] https://en.cppreference.com/w/cpp/string/basic_string/back +[2] https://en.cppreference.com/w/cpp/string/basic_string/pop_back + +Fixes: 1ff7c32fc91c607b690d4bb9cf42f406be8dde68 + +Reviewers: teemperor, ioeric, cfe-commits + +Reviewed By: teemperor + +Subscribers: ilya-biryukov, kadircet, usaxena95 + +Tags: #clang + +Differential Revision: https://reviews.llvm.org/D77468 +--- + clang/lib/AST/RawCommentList.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp +index 8552b4fcd2b..a8d15036cab 100644 +--- a/clang/lib/AST/RawCommentList.cpp ++++ b/clang/lib/AST/RawCommentList.cpp +@@ -431,7 +431,7 @@ std::string RawComment::getFormattedText(const SourceManager &SourceMgr, + }; + + auto DropTrailingNewLines = [](std::string &Str) { +- while (Str.back() == '\n') ++ while (!Str.empty() && Str.back() == '\n') + Str.pop_back(); + }; + +-- +2.25.2 + diff --git a/clang.spec b/clang.spec index b714a38..483a76d 100644 --- a/clang.spec +++ b/clang.spec @@ -4,7 +4,7 @@ %global min_ver 0 %global patch_ver 0 #%%global rc_ver 6 -%global baserelease 1 +%global baserelease 2 %global clang_tools_binaries \ %{_bindir}/clang-apply-replacements \ @@ -98,6 +98,7 @@ Source4: https://prereleases.llvm.org/%{version}/hans-gpg-key.asc Patch4: 0002-gtest-reorg.patch Patch11: 0001-ToolChain-Add-lgcc_s-to-the-linker-flags-when-using-.patch Patch13: 0001-Make-funwind-tables-the-default-for-all-archs.patch +Patch14: 0001-clang-fix-undefined-behaviour-in-RawComment-getForma.patch # Not Upstream Patch15: 0001-clang-Don-t-install-static-libraries.patch @@ -250,6 +251,7 @@ pathfix.py -i %{__python3} -pn \ %patch4 -p1 -b .gtest %patch11 -p1 -b .libcxx-fix %patch13 -p2 -b .unwind-all +%patch14 -p2 -b .clangd %patch15 -p2 -b .no-install-static mv ../%{clang_tools_srcdir} tools/extra @@ -469,6 +471,9 @@ LD_LIBRARY_PATH=%{buildroot}%{_libdir} ninja check-all -C _build || \ %endif %changelog +* Tue May 19 2020 sguelton@redhat.com - 10.0.0-2 +- Backport ad7211df6f257e39da2e5a11b2456b4488f32a1e, see rhbz#1825593 + * Thu Mar 26 2020 sguelton@redhat.com - 10.0.0-1 - 10.0.0 final