[llvm] r354051 - Recommit Optional specialization for trivially copyable types
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 15 04:21:33 PST 2019
I've speculatively reverted this (and r354055) in r354126. Because I
suspect this caused Clang to get miscompiled with GCC on Ubuntu 14.04
breaking the Chromium build
(https://bugs.chromium.org/p/chromium/issues/detail?id=932277).
I'd like to keep the revert in for an hour to see if it makes any
difference. We can see if that also affects the
clang-cmake-x86_64-avx2-linux bot.
Thanks,
Hans
On Fri, Feb 15, 2019 at 2:22 AM via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Hi Serge,
>
> I'm not sure how/why, but it seems your commit is causing a test failure on one of the bots:
>
> http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/8308
>
> ******************** TEST 'LLVM :: ThinLTO/X86/funcimport.ll' FAILED ********************
> Script:
> --
> : 'RUN: at line 2'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/opt -module-summary /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll -o /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp.bc
> : 'RUN: at line 3'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/opt -module-summary /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/Inputs/funcimport.ll -o /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc
> : 'RUN: at line 4'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-action=thinlink -o /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp3.bc /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp.bc /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc
> : 'RUN: at line 6'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-index-stats /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp3.bc | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll -check-prefix=STATS
> : 'RUN: at line 11'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-action=promote /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp.bc -thinlto-index=/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp3.bc -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-dis -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll --check-prefix=EXPORTSTATIC
> : 'RUN: at line 24'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-action=import /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc -thinlto-index=/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp3.bc -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-dis -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll --check-prefix=IMPORTGLOB1
> : 'RUN: at line 35'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-action=optimize /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-dis -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll --check-prefix=OPTIMIZED
> : 'RUN: at line 39'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-action=codegen /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-nm -o - | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll --check-prefix=CODEGEN
> : 'RUN: at line 43'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-lto -thinlto-action=run /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp.bc -exported-symbol=_main
> : 'RUN: at line 44'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-nm -o - < /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp.bc.thinlto.o | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll --check-prefix=ALL
> : 'RUN: at line 45'; /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/llvm-nm -o - < /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/test/ThinLTO/X86/Output/funcimport.ll.tmp2.bc.thinlto.o | /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/stage1/bin/FileCheck /home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/test/ThinLTO/X86/funcimport.ll --check-prefix=ALL2
> --
> Exit Code: 1
>
> Command Output (stderr):
> --
> LLVM ERROR: 32-bit absolute addressing is not supported in 64-bit mode
>
> --
>
> Can you please take a look? We hit this on our internal linux build bot which is also running gcc 5.4 on Ubuntu 16.04.5.
>
> Douglas Yung
>
> -----Original Message-----
> From: llvm-commits <llvm-commits-bounces at lists.llvm.org> On Behalf Of Serge Guelton via llvm-commits
> Sent: Thursday, February 14, 2019 11:17
> To: llvm-commits at lists.llvm.org
> Subject: [llvm] r354051 - Recommit Optional specialization for trivially copyable types
>
> Author: serge_sans_paille
> Date: Thu Feb 14 11:17:00 2019
> New Revision: 354051
>
> URL: http://llvm.org/viewvc/llvm-project?rev=354051&view=rev
> Log:
> Recommit Optional specialization for trivially copyable types
>
> Unfortunately the original code gets misscompiled by GCC (at least 8.1), this is a tentative workaround using std::memcpy instead of inplace new for trivially copyable types. I'll revert if it breaks.
>
> Original revision: https://reviews.llvm.org/D57097
>
> Modified:
> llvm/trunk/include/llvm/ADT/Optional.h
> llvm/trunk/unittests/ADT/OptionalTest.cpp
>
> Modified: llvm/trunk/include/llvm/ADT/Optional.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Optional.h?rev=354051&r1=354050&r2=354051&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/Optional.h (original)
> +++ llvm/trunk/include/llvm/ADT/Optional.h Thu Feb 14 11:17:00 2019
> @@ -21,6 +21,7 @@
> #include "llvm/Support/type_traits.h"
> #include <algorithm>
> #include <cassert>
> +#include <cstring>
> #include <new>
> #include <utility>
>
> @@ -109,6 +110,48 @@ template <typename T, bool = is_triviall
> }
> };
>
> +template <typename T> struct OptionalStorage<T, true> {
> + AlignedCharArrayUnion<T> storage;
> + bool hasVal = false;
> +
> + OptionalStorage() = default;
> +
> + OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer)
> + T(y); } OptionalStorage(const OptionalStorage &O) = default;
> + OptionalStorage(T &&y) : hasVal(true) {
> + std::memcpy(storage.buffer, reinterpret_cast<char*>(&y),
> + sizeof(T)); }
> +
> + OptionalStorage(OptionalStorage &&O) = default;
> +
> + OptionalStorage &operator=(T &&y) {
> + hasVal = true;
> + std::memcpy(storage.buffer, reinterpret_cast<char*>(&y), sizeof(T));
> + return *this;
> + }
> + OptionalStorage &operator=(OptionalStorage &&O) = default;
> +
> + OptionalStorage &operator=(const T &y) {
> + hasVal = true;
> + std::memcpy(storage.buffer, reinterpret_cast<char const*>(&y), sizeof(T));
> + return *this;
> + }
> + OptionalStorage &operator=(const OptionalStorage &O) = default;
> +
> + ~OptionalStorage() = default;
> +
> + T *getPointer() {
> + assert(hasVal);
> + return reinterpret_cast<T *>(storage.buffer); } const T
> + *getPointer() const {
> + assert(hasVal);
> + return reinterpret_cast<const T *>(storage.buffer); }
> +
> + void reset() { hasVal = false; }
> +};
> +
> } // namespace optional_detail
>
> template <typename T> class Optional {
>
> Modified: llvm/trunk/unittests/ADT/OptionalTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/OptionalTest.cpp?rev=354051&r1=354050&r2=354051&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/ADT/OptionalTest.cpp (original)
> +++ llvm/trunk/unittests/ADT/OptionalTest.cpp Thu Feb 14 11:17:00 2019
> @@ -18,6 +18,12 @@ using namespace llvm;
>
> namespace {
>
> +static_assert(llvm::is_trivially_copyable<Optional<int>>::value,
> + "trivially copyable");
> +
> +static_assert(llvm::is_trivially_copyable<Optional<std::array<int, 3>>>::value,
> + "trivially copyable");
> +
> struct NonDefaultConstructible {
> static unsigned CopyConstructions;
> static unsigned Destructions;
> @@ -45,6 +51,10 @@ unsigned NonDefaultConstructible::CopyCo unsigned NonDefaultConstructible::Destructions = 0; unsigned NonDefaultConstructible::CopyAssignments = 0;
>
> +static_assert(
> + !llvm::is_trivially_copyable<Optional<NonDefaultConstructible>>::value,
> + "not trivially copyable");
> +
> // Test fixture
> class OptionalTest : public testing::Test { }; @@ -203,6 +213,10 @@ struct MultiArgConstructor { }; unsigned MultiArgConstructor::Destructions = 0;
>
> +static_assert(
> + !llvm::is_trivially_copyable<Optional<MultiArgConstructor>>::value,
> + "not trivially copyable");
> +
> TEST_F(OptionalTest, Emplace) {
> MultiArgConstructor::ResetCounts();
> Optional<MultiArgConstructor> A;
> @@ -250,6 +264,9 @@ unsigned MoveOnly::MoveConstructions = 0 unsigned MoveOnly::Destructions = 0; unsigned MoveOnly::MoveAssignments = 0;
>
> +static_assert(!llvm::is_trivially_copyable<Optional<MoveOnly>>::value,
> + "not trivially copyable");
> +
> TEST_F(OptionalTest, MoveOnlyNull) {
> MoveOnly::ResetCounts();
> Optional<MoveOnly> O;
> @@ -351,6 +368,9 @@ private:
> unsigned Immovable::Constructions = 0;
> unsigned Immovable::Destructions = 0;
>
> +static_assert(!llvm::is_trivially_copyable<Optional<Immovable>>::value,
> + "not trivially copyable");
> +
> TEST_F(OptionalTest, ImmovableEmplace) {
> Optional<Immovable> A;
> Immovable::ResetCounts();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list