[llvm-branch-commits] [libcxxabi] 61aec69 - [libcxxabi] Add macro for changing functions to support the relative vtables ABI

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T10:50:05-08:00
New Revision: 61aec69a65dec949f3d2556c4d0efaa87869e1ee

URL: 
https://github.com/llvm/llvm-project/commit/61aec69a65dec949f3d2556c4d0efaa87869e1ee
DIFF: 
https://github.com/llvm/llvm-project/commit/61aec69a65dec949f3d2556c4d0efaa87869e1ee.diff

LOG: [libcxxabi] Add macro for changing functions to support the relative 
vtables ABI

Under the relative vtables ABI, __dynamic_cast will not work since it assumes
the vtable pointer is 2 ptrdiff_ts away from the start of the vtable (8-byte
offset to top + 8-byte pointer to typeinfo) when it is actually 8 bytes away
(4-byte offset to top + 4-byte offset to typeinfo). This adjusts the logic under
__dynamic_cast and other areas vtable calculations are done to support this ABI
when it's used.

Differential Revision: https://reviews.llvm.org/D77606

Added: 


Modified: 
libcxxabi/src/private_typeinfo.cpp

Removed: 




diff  --git a/libcxxabi/src/private_typeinfo.cpp 
b/libcxxabi/src/private_typeinfo.cpp
index 3e8bdae32e41..c77ad669c49e 100644
--- a/libcxxabi/src/private_typeinfo.cpp
+++ b/libcxxabi/src/private_typeinfo.cpp
@@ -61,6 +61,16 @@ is_equal(const std::type_info* x, const std::type_info* y, 
bool use_strcmp)
 return x == y || strcmp(x->name(), y->name()) == 0;
 }
 
+static inline ptr
diff _t update_offset_to_base(const char* vtable,
+  ptr
diff _t offset_to_base) {
+#if __has_feature(cxx_abi_relative_vtable)
+  // VTable components are 32 bits in the relative vtables ABI.
+  return *reinterpret_cast(vtable + offset_to_base);
+#else
+  return *reinterpret_cast(vtable + offset_to_base);
+#endif
+}
+
 namespace __cxxabiv1
 {
 
@@ -297,7 +307,7 @@ 
__base_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
 if (__offset_flags & __virtual_mask)
 {
 const char* vtable = *static_cast(adjustedPtr);
-offset_to_base = *reinterpret_cast(vtable + offset_to_base);
+offset_to_base = update_offset_to_base(vtable, offset_to_base);
 }
 }
 __base_type->has_unambiguous_public_base(
@@ -615,10 +625,26 @@ __dynamic_cast(const void *static_ptr, const 
__class_type_info *static_type,
 // Possible future optimization:  Take advantage of src2dst_offset
 
 // Get (dynamic_ptr, dynamic_type) from static_ptr
+#if __has_feature(cxx_abi_relative_vtable)
+// The vtable address will point to the first virtual function, which is 8
+// bytes after the start of the vtable (4 for the offset from top + 4 for 
the typeinfo component).
+const int32_t* vtable =
+*reinterpret_cast(static_ptr);
+int32_t offset_to_derived = vtable[-2];
+const void* dynamic_ptr = static_cast(static_ptr) + 
offset_to_derived;
+
+// The typeinfo component is now a relative offset to a proxy.
+int32_t offset_to_ti_proxy = vtable[-1];
+const uint8_t* ptr_to_ti_proxy =
+reinterpret_cast(vtable) + offset_to_ti_proxy;
+const __class_type_info* dynamic_type =
+*(reinterpret_cast(ptr_to_ti_proxy));
+#else
 void **vtable = *static_cast(static_ptr);
 ptr
diff _t offset_to_derived = reinterpret_cast(vtable[-2]);
 const void* dynamic_ptr = static_cast(static_ptr) + 
offset_to_derived;
 const __class_type_info* dynamic_type = static_cast(vtable[-1]);
+#endif
 
 // Initialize answer to nullptr.  This will be changed from the search
 //results if a non-null answer is found.  Regardless, this is what will
@@ -1267,7 +1293,7 @@ 
__base_class_type_info::search_above_dst(__dynamic_cast_info* info,
 if (__offset_flags & __virtual_mask)
 {
 const char* vtable = *static_cast(current_ptr);
-offset_to_base = *reinterpret_cast(vtable + offset_to_base);
+offset_to_base = update_offset_to_base(vtable, offset_to_base);
 }
 __base_type->search_above_dst(info, dst_ptr,
   static_cast(current_ptr) + 
offset_to_base,
@@ -1287,7 +1313,7 @@ 
__base_class_type_info::search_below_dst(__dynamic_cast_info* info,
 if (__offset_flags & __virtual_mask)
 {
 const char* vtable = *static_cast(current_ptr);
-offset_to_base = *reinterpret_cast(vtable + offset_to_base);
+offset_to_base = update_offset_to_base(vtable, offset_to_base);
 }
 __base_type->search_below_dst(info,
   static_cast(current_ptr) + 
offset_to_base,



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] cf8ff75 - [clang][RelativeVTablesABI] Use dso_local_equivalent rather than emitting stubs

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T16:02:35-08:00
New Revision: cf8ff75bade763b054476321dcb82dcb2e7744c7

URL: 
https://github.com/llvm/llvm-project/commit/cf8ff75bade763b054476321dcb82dcb2e7744c7
DIFF: 
https://github.com/llvm/llvm-project/commit/cf8ff75bade763b054476321dcb82dcb2e7744c7.diff

LOG: [clang][RelativeVTablesABI] Use dso_local_equivalent rather than emitting 
stubs

Thanks to D77248, we can bypass the use of stubs altogether and use PLT
relocations if they are available for the target. LLVM and LLD support the
R_AARCH64_PLT32 relocation, so we can also guarantee a static PLT relocation on 
AArch64.
Not emitting these stubs saves a lot of extra binary size.

Differential Revision: https://reviews.llvm.org/D83812

Added: 


Modified: 
clang/lib/CodeGen/CGVTables.cpp

clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/diamond-inheritance.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/inheritted-virtual-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/inline-virtual-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/inlined-key-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/override-pure-virtual-method.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/overriden-virtual-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-flag.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp

Removed: 
clang/test/CodeGenCXX/RelativeVTablesABI/no-stub-when-dso-local.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/stub-linkages.cpp



diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 75afc860cc47..bef9a293b7ed 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -641,7 +641,7 @@ void 
CodeGenVTables::addRelativeComponent(ConstantArrayBuilder &builder,
 
   llvm::Constant *target;
   if (auto *func = dyn_cast(globalVal)) {
-target = getOrCreateRelativeStub(func, stubLinkage, isCompleteDtor);
+target = llvm::DSOLocalEquivalent::get(func);
   } else {
 llvm::SmallString<16> rttiProxyName(globalVal->getName());
 rttiProxyName.append(".rtti_proxy");
@@ -669,74 +669,6 @@ void 
CodeGenVTables::addRelativeComponent(ConstantArrayBuilder &builder,
   /*position=*/vtableAddressPoint);
 }
 
-llvm::Function *CodeGenVTables::getOrCreateRelativeStub(
-llvm::Function *func, llvm::GlobalValue::LinkageTypes stubLinkage,
-bool isCompleteDtor) const {
-  // A complete object destructor can later be substituted in the vtable for an
-  // appropriate base object destructor when optimizations are enabled. This 
can
-  // happen for child classes that don't have their own destructor. In the case
-  // where a parent virtual destructor is not guaranteed to be in the same
-  // linkage unit as the child vtable, it's possible for an external reference
-  // for this destructor to be substituted into the child vtable, preventing it
-  // from being in rodata. If this function is a complete virtual destructor, 
we
-  // can just force a stub to be emitted for it.
-  if (func->isDSOLocal() && !isCompleteDtor)
-return func;
-
-  llvm::SmallString<16> stubName(func->getName());
-  stubName.append(".stub");
-
-  // Instead of taking the offset between the vtable and virtual function
-  // directly, we emit a dso_local stub that just contains a tail call to the
-  // original virtual function and take the offset between that and the
-  // vtable. We do this because there are some cases where the original
-  // function that would've been inserted into the vtable is not dso_local
-  // which may require some kind of dynamic relocation which prevents the
-  // vtable from being readonly. On x86_64, taking the offset between the
-  // function and the vtable gets lowered to the offset between the PLT entry
-  // for the function and the vtable which gives us a PLT32 reloc. On AArch64,
-  // right now only CALL26 and JUMP26 instructions generate PLT relocations,
-  // so we manifest them with stubs that are just jumps to the original
-  // function.
-  auto &module = CGM.getModule();
-  llvm::Function *stub = module.getFunction(stubName

[llvm-branch-commits] [llvm] 4d7f3d6 - [llvm] Fix for failing test from cf8ff75bade763b054476321dcb82dcb2e7744c7

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T17:22:28-08:00
New Revision: 4d7f3d68f1735ad343a15604559e7d55ac14bfb5

URL: 
https://github.com/llvm/llvm-project/commit/4d7f3d68f1735ad343a15604559e7d55ac14bfb5
DIFF: 
https://github.com/llvm/llvm-project/commit/4d7f3d68f1735ad343a15604559e7d55ac14bfb5.diff

LOG: [llvm] Fix for failing test from cf8ff75bade763b054476321dcb82dcb2e7744c7

Handle null values when handling operand changes for DSOLocalEquivalent.

Added: 


Modified: 
llvm/lib/IR/Constants.cpp

Removed: 




diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 7ebe461fd0c2..eba8c8eeaa87 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1862,6 +1862,11 @@ Value *DSOLocalEquivalent::handleOperandChangeImpl(Value 
*From, Value *To) {
   return NewEquiv;
   }
 
+  // If the argument is replaced with a null value, just replace this constant
+  // with a null value.
+  if (cast(To)->isNullValue())
+return To;
+
   // The replacement could be a bitcast or an alias to another function. We can
   // replace it with a bitcast to the dso_local_equivalent of that function.
   auto *Func = cast(To->stripPointerCastsAndAliases());



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 7c2bc3b - [clang][Fuchsia] Add relative-vtables multilib

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T18:17:38-08:00
New Revision: 7c2bc3b71dc072987d43a2a86609871bd01f981f

URL: 
https://github.com/llvm/llvm-project/commit/7c2bc3b71dc072987d43a2a86609871bd01f981f
DIFF: 
https://github.com/llvm/llvm-project/commit/7c2bc3b71dc072987d43a2a86609871bd01f981f.diff

LOG: [clang][Fuchsia] Add relative-vtables multilib

This adds a multilib for Fuchsia that is built with the relative vtables
ABI.

Added: 

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables/libc++.so

Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.cpp

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 6e9ae85e7318..74c393fa7a8b 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -211,14 +211,24 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
+set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
+
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LLVM_BUILD_COMPILER_RT
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS
 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS}
 -Xclang -fexperimental-relative-c++-abi-vtables" CACHE STRING "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXX_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;asan+noexcept;relative-vtables;relative-vtables+noexcept" CACHE 
STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 79d3a8d554de..29ad3f0dbf80 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -210,6 +210,13 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   .flag("+fsanitize=address")
   .flag("-fexceptions")
   .flag("+fno-exceptions"));
+  // Use the relative vtables ABI.
+  Multilibs.push_back(Multilib("relative-vtables", {}, {}, 4)
+  .flag("+fexperimental-relative-c++-abi-vtables"));
+  Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 5)
+  .flag("+fexperimental-relative-c++-abi-vtables")
+  .flag("-fexceptions")
+  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
@@ -222,6 +229,13 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, 
true),
   "fexceptions", Flags);
   addMultilibFlag(getSanitizerArgs().needsAsanRt(), "fsanitize=address", 
Flags);
+
+  addMultilibFlag(
+  Args.hasFlag(options::OPT_fexperimental_relative_cxx_abi_vtables,
+   options::OPT_fno_experimental_relative_cxx_abi_vtables,
+   /*default=*/false),

[llvm-branch-commits] [clang] a160189 - Revert "[clang][Fuchsia] Add relative-vtables multilib"

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T18:20:01-08:00
New Revision: a160189c5dfaa6b3d7c3db71991e50eebea9a63d

URL: 
https://github.com/llvm/llvm-project/commit/a160189c5dfaa6b3d7c3db71991e50eebea9a63d
DIFF: 
https://github.com/llvm/llvm-project/commit/a160189c5dfaa6b3d7c3db71991e50eebea9a63d.diff

LOG: Revert "[clang][Fuchsia] Add relative-vtables multilib"

This reverts commit 7c2bc3b71dc072987d43a2a86609871bd01f981f.

Forgot to add the ifferential revision.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.cpp

Removed: 

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables/libc++.so



diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 74c393fa7a8b..6e9ae85e7318 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -211,24 +211,14 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
-set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LLVM_BUILD_COMPILER_RT
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS
 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS}
 -Xclang -fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXX_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
-
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;asan+noexcept;relative-vtables;relative-vtables+noexcept" CACHE 
STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 29ad3f0dbf80..79d3a8d554de 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -210,13 +210,6 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   .flag("+fsanitize=address")
   .flag("-fexceptions")
   .flag("+fno-exceptions"));
-  // Use the relative vtables ABI.
-  Multilibs.push_back(Multilib("relative-vtables", {}, {}, 4)
-  .flag("+fexperimental-relative-c++-abi-vtables"));
-  Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 5)
-  .flag("+fexperimental-relative-c++-abi-vtables")
-  .flag("-fexceptions")
-  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
@@ -229,13 +222,6 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, 
true),
   "fexceptions", Flags);
   addMultilibFlag(getSanitizerArgs().needsAsanRt(), "fsanitize=address", 
Flags);
-
-  addMultilibFlag(
-  Args.hasFlag(options::OPT_fexperimental_relative_cxx_abi_vtables,
-   options::OPT_fno_experimental_relative_cxx_abi_vtables,
-

[llvm-branch-commits] [clang] fdbd84c - [clang][Fuchsia] Add relative-vtables multilib

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T18:21:10-08:00
New Revision: fdbd84c6c819d4462546961f6086c1524d5d5ae8

URL: 
https://github.com/llvm/llvm-project/commit/fdbd84c6c819d4462546961f6086c1524d5d5ae8
DIFF: 
https://github.com/llvm/llvm-project/commit/fdbd84c6c819d4462546961f6086c1524d5d5ae8.diff

LOG: [clang][Fuchsia] Add relative-vtables multilib

This adds multilibs for Fuchsia that is built with the relative vtables ABI,
one with and another without exceptions.

Differential Revision: https://reviews.llvm.org/D85576

Added: 

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables/libc++.so

Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.cpp

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 6e9ae85e7318..74c393fa7a8b 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -211,14 +211,24 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
+set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
+
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LLVM_BUILD_COMPILER_RT
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS
 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS}
 -Xclang -fexperimental-relative-c++-abi-vtables" CACHE STRING "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXX_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;asan+noexcept;relative-vtables;relative-vtables+noexcept" CACHE 
STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 79d3a8d554de..29ad3f0dbf80 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -210,6 +210,13 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   .flag("+fsanitize=address")
   .flag("-fexceptions")
   .flag("+fno-exceptions"));
+  // Use the relative vtables ABI.
+  Multilibs.push_back(Multilib("relative-vtables", {}, {}, 4)
+  .flag("+fexperimental-relative-c++-abi-vtables"));
+  Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 5)
+  .flag("+fexperimental-relative-c++-abi-vtables")
+  .flag("-fexceptions")
+  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
@@ -222,6 +229,13 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, 
true),
   "fexceptions", Flags);
   addMultilibFlag(getSanitizerArgs().needsAsanRt(), "fsanitize=address", 
Flags);
+
+  addMultilibFlag(
+  Args.hasFlag(options::OPT_fexperimental_relative_cxx_abi_vtables,
+  

[llvm-branch-commits] [clang] 7bc944c - Revert "[clang][Fuchsia] Add relative-vtables multilib"

2020-11-30 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-11-30T19:21:35-08:00
New Revision: 7bc944c102c2bdb009da4fe7d53dda15ea19ee71

URL: 
https://github.com/llvm/llvm-project/commit/7bc944c102c2bdb009da4fe7d53dda15ea19ee71
DIFF: 
https://github.com/llvm/llvm-project/commit/7bc944c102c2bdb009da4fe7d53dda15ea19ee71.diff

LOG: Revert "[clang][Fuchsia] Add relative-vtables multilib"

This reverts commit fdbd84c6c819d4462546961f6086c1524d5d5ae8.

Reverting due to failing CI builders for Fuchsia's toolchain:
https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-linux-x64/b8862150211240186992?

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.cpp

Removed: 

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables/libc++.so



diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 74c393fa7a8b..6e9ae85e7318 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -211,24 +211,14 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
-set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LLVM_BUILD_COMPILER_RT
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS
 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS}
 -Xclang -fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXX_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
-
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;asan+noexcept;relative-vtables;relative-vtables+noexcept" CACHE 
STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 29ad3f0dbf80..79d3a8d554de 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -210,13 +210,6 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   .flag("+fsanitize=address")
   .flag("-fexceptions")
   .flag("+fno-exceptions"));
-  // Use the relative vtables ABI.
-  Multilibs.push_back(Multilib("relative-vtables", {}, {}, 4)
-  .flag("+fexperimental-relative-c++-abi-vtables"));
-  Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 5)
-  .flag("+fexperimental-relative-c++-abi-vtables")
-  .flag("-fexceptions")
-  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
@@ -229,13 +222,6 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, 
true),
   "fexceptions", Flags);
   addMultilibFlag(getSanitizerArgs().needsAsanRt(), "fsanitize=address", 
Flags);
-
-  addMultilibFlag(
-  Args.hasFlag(options::OPT_fexperime

[llvm-branch-commits] [llvm] 19bdc8e - [llvm] Fix for failing test from fdbd84c6c819d4462546961f6086c1524d5d5ae8

2020-12-01 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-12-01T15:47:55-08:00
New Revision: 19bdc8e5a307f6eb209d4f91620d70bd2f80219e

URL: 
https://github.com/llvm/llvm-project/commit/19bdc8e5a307f6eb209d4f91620d70bd2f80219e
DIFF: 
https://github.com/llvm/llvm-project/commit/19bdc8e5a307f6eb209d4f91620d70bd2f80219e.diff

LOG: [llvm] Fix for failing test from fdbd84c6c819d4462546961f6086c1524d5d5ae8

When handling a DSOLocalEquivalent operand change:

- Remove assertion checking that the `To` type and current type are the
  same type. This is not always a requirement.
- Add a missing bitcast from an old DSOLocalEquivalent to the type of
  the new one.

Added: 


Modified: 
llvm/lib/IR/Constants.cpp

Removed: 




diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index eba8c8eeaa87..64b58559e787 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1851,7 +1851,6 @@ void DSOLocalEquivalent::destroyConstantImpl() {
 
 Value *DSOLocalEquivalent::handleOperandChangeImpl(Value *From, Value *To) {
   assert(From == getGlobalValue() && "Changing value does not match operand.");
-  assert(To->getType() == getType() && "Mismatched types");
   assert(isa(To) && "Can only replace the operands with a constant");
 
   // The replacement is with another global value.
@@ -1859,7 +1858,7 @@ Value *DSOLocalEquivalent::handleOperandChangeImpl(Value 
*From, Value *To) {
 DSOLocalEquivalent *&NewEquiv =
 getContext().pImpl->DSOLocalEquivalents[ToObj];
 if (NewEquiv)
-  return NewEquiv;
+  return llvm::ConstantExpr::getBitCast(NewEquiv, getType());
   }
 
   // If the argument is replaced with a null value, just replace this constant



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 1e91803 - Recommit "[clang][Fuchsia] Add relative-vtables multilib"

2020-12-01 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-12-01T17:03:13-08:00
New Revision: 1e91803c671a105f1eabce0e496766b512242f1d

URL: 
https://github.com/llvm/llvm-project/commit/1e91803c671a105f1eabce0e496766b512242f1d
DIFF: 
https://github.com/llvm/llvm-project/commit/1e91803c671a105f1eabce0e496766b512242f1d.diff

LOG: Recommit "[clang][Fuchsia] Add relative-vtables multilib"

This recommits fdbd84c6c819d4462546961f6086c1524d5d5ae8 whose initial
build issues were fixed in 19bdc8e5a307f6eb209d4f91620d70bd2f80219e.

Added: 

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/relative-vtables/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+noexcept/libc++.so

clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables/libc++.so

Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.cpp

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 6e9ae85e7318..74c393fa7a8b 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -211,14 +211,24 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
 
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
+set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables_CMAKE_CXX_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
+
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LLVM_BUILD_COMPILER_RT
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS
 
"${RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_CMAKE_CXX_FLAGS}
 -Xclang -fexperimental-relative-c++-abi-vtables" CACHE STRING "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+relative-vtables+noexcept_LIBCXX_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;asan+noexcept;relative-vtables;relative-vtables+noexcept" CACHE 
STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 79d3a8d554de..29ad3f0dbf80 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -210,6 +210,13 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   .flag("+fsanitize=address")
   .flag("-fexceptions")
   .flag("+fno-exceptions"));
+  // Use the relative vtables ABI.
+  Multilibs.push_back(Multilib("relative-vtables", {}, {}, 4)
+  .flag("+fexperimental-relative-c++-abi-vtables"));
+  Multilibs.push_back(Multilib("relative-vtables+noexcept", {}, {}, 5)
+  .flag("+fexperimental-relative-c++-abi-vtables")
+  .flag("-fexceptions")
+  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
@@ -222,6 +229,13 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple 
&Triple,
   Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, 
true),
   "fexceptions", Flags);
   addMultilibFlag(getSanitizerArgs().needsAsanRt(), "fsanitize=address", 
Flags);
+
+  addMultilibFlag(
+  Args.hasFlag(options::OPT_fexperimental_relative_cxx_abi_vtables,
+   options::OPT_fno_experi

[llvm-branch-commits] [clang] 155fca3 - [clang] Fix noderef for array member of deref expr

2020-12-07 Thread Leonard Chan via llvm-branch-commits

Author: Leonard Chan
Date: 2020-12-07T14:39:42-08:00
New Revision: 155fca3cae275562e626d3e4fbfac70b4b75d2e7

URL: 
https://github.com/llvm/llvm-project/commit/155fca3cae275562e626d3e4fbfac70b4b75d2e7
DIFF: 
https://github.com/llvm/llvm-project/commit/155fca3cae275562e626d3e4fbfac70b4b75d2e7.diff

LOG: [clang] Fix noderef for array member of deref expr

Committing on behalf of thejh (Jann Horn).

Given an attribute((noderef)) pointer "p" to the struct

struct s { int a[2]; };
ensure that the following expressions are treated the same way by the
noderef logic:

p->a
(*p).a
Until now, the first expression would be treated correctly (nothing is
added to PossibleDerefs because CheckMemberAccessOfNoDeref() bails out
on array members), but the second expression would incorrectly warn
because "*p" creates a PossibleDerefs entry.

Handle this case the same way as for the AddrOf operator.

Differential Revision: https://reviews.llvm.org/D92140

Added: 


Modified: 
clang/lib/Sema/SemaExprMember.cpp
clang/test/Frontend/noderef.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 23cfae81df46..3e9d2a056c5c 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1739,12 +1739,23 @@ void Sema::CheckMemberAccessOfNoDeref(const MemberExpr 
*E) {
 
   QualType ResultTy = E->getType();
 
-  // Do not warn on member accesses to arrays since this returns an array
-  // lvalue and does not actually dereference memory.
-  if (isa(ResultTy))
-return;
-
-  if (E->isArrow()) {
+  // Member accesses have four cases:
+  // 1: non-array member via "->": dereferences
+  // 2: non-array member via ".": nothing interesting happens
+  // 3: array member access via "->": nothing interesting happens
+  //(this returns an array lvalue and does not actually dereference memory)
+  // 4: array member access via ".": *adds* a layer of indirection
+  if (ResultTy->isArrayType()) {
+if (!E->isArrow()) {
+  // This might be something like:
+  // (*structPtr).arrayMember
+  // which behaves roughly like:
+  // &(*structPtr).pointerMember
+  // in that the apparent dereference in the base expression does not
+  // actually happen.
+  CheckAddressOfNoDeref(E->getBase());
+}
+  } else if (E->isArrow()) {
 if (const auto *Ptr = dyn_cast(
 E->getBase()->getType().getDesugaredType(Context))) {
   if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))

diff  --git a/clang/test/Frontend/noderef.c b/clang/test/Frontend/noderef.c
index 3388f2a39992..b548ffa13273 100644
--- a/clang/test/Frontend/noderef.c
+++ b/clang/test/Frontend/noderef.c
@@ -73,6 +73,7 @@ int test() {
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared 
here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
+  p = (*s2_noderef).a; // ok since result is an array in a struct
   p = s2_noderef->a2; // ok
   p = s2_noderef->b;  // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}
   p = s2_noderef->b2; // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 6dad7ec - [clang] Fix noderef for AddrOf on MemberExpr

2020-12-07 Thread Leonard Chan via llvm-branch-commits

Author: Jann Horn
Date: 2020-12-07T14:48:41-08:00
New Revision: 6dad7ec539cbcf6f59b63753a86b8015bd6ea66f

URL: 
https://github.com/llvm/llvm-project/commit/6dad7ec539cbcf6f59b63753a86b8015bd6ea66f
DIFF: 
https://github.com/llvm/llvm-project/commit/6dad7ec539cbcf6f59b63753a86b8015bd6ea66f.diff

LOG: [clang] Fix noderef for AddrOf on MemberExpr

Committing on behalf of thejh (Jann Horn).

As part of this change, one existing test case has to be adjusted
because it accidentally stripped the NoDeref attribute without
getting caught.

Depends on D92140

Differential Review: https://reviews.llvm.org/D92141

Added: 


Modified: 
clang/lib/Sema/SemaExprMember.cpp
clang/test/Frontend/noderef.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 3e9d2a056c5c..f5afcb76fc96 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1810,6 +1810,14 @@ Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool 
IsArrow,
 Qualifiers Combined = BaseQuals + MemberQuals;
 if (Combined != MemberQuals)
   MemberType = Context.getQualifiedType(MemberType, Combined);
+
+// Pick up NoDeref from the base in case we end up using AddrOf on the
+// result. E.g. the expression
+// &someNoDerefPtr->pointerMember
+// should be a noderef pointer again.
+if (BaseType->hasAttr(attr::NoDeref))
+  MemberType =
+  Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
   auto *CurMethod = dyn_cast(CurContext);

diff  --git a/clang/test/Frontend/noderef.c b/clang/test/Frontend/noderef.c
index b548ffa13273..d136ff0c7192 100644
--- a/clang/test/Frontend/noderef.c
+++ b/clang/test/Frontend/noderef.c
@@ -70,6 +70,12 @@ int test() {
   x = sizeof(s->a + (s->b)); // ok
   x = sizeof(int[++s->a]);   // expected-warning{{dereferencing s; was 
declared with a 'noderef' type}}
 
+  // Struct member access should carry NoDeref type information through to an
+  // enclosing AddrOf.
+  p2 = &s->a;   // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}
+  p2 = &(*s).a; // expected-warning{{casting to dereferenceable pointer 
removes 'noderef' attribute}}
+  x = *&s->a;   // expected-warning{{dereferencing expression marked as 
'noderef'}}
+
   // Nested struct access
   struct S2 NODEREF *s2_noderef;// expected-note 5 {{s2_noderef declared 
here}}
   p = s2_noderef->a;  // ok since result is an array in a struct
@@ -113,7 +119,7 @@ int test() {
 
   p = s2_arr[1]->a;
   p = s2_arr[1]->b; // expected-warning{{dereferencing expression marked as 
'noderef'}}
-  int **bptr = &s2_arr[1]->b;
+  int *NODEREF *bptr = &s2_arr[1]->b;
 
   x = s2->s2->a;// expected-warning{{dereferencing expression marked 
as 'noderef'}}
   x = s2_noderef->a[1]; // expected-warning{{dereferencing s2_noderef; was 
declared with a 'noderef' type}}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits