[llvm-branch-commits] [llvm] c76d57b - add regression test

2022-05-17 Thread Ben Dunbobbin via llvm-branch-commits

Author: Ben Dunbobbin
Date: 2022-05-17T11:39:33+01:00
New Revision: c76d57b63163a0c6b84bc79895c8ad7079cbc439

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

LOG: add regression test

Added: 


Modified: 
llvm/test/tools/llvm-ar/regular-to-thin-archive.test

Removed: 




diff  --git a/llvm/test/tools/llvm-ar/regular-to-thin-archive.test 
b/llvm/test/tools/llvm-ar/regular-to-thin-archive.test
index f216e47b2c6d..d94a2c9f1b0c 100644
--- a/llvm/test/tools/llvm-ar/regular-to-thin-archive.test
+++ b/llvm/test/tools/llvm-ar/regular-to-thin-archive.test
@@ -5,6 +5,9 @@
 # RUN: llvm-ar qc %t/archive.a %S/Inputs/a.txt
 # RUN: not llvm-ar q --thin %t/archive.a %s 2>&1 | FileCheck %s
 # RUN: not llvm-ar r --thin %t/archive.a %s 2>&1 | FileCheck %s
+## Special case of replacing the same file, see: 
+##   https://github.com/llvm/llvm-project/issues/55527
+# RUN: not llvm-ar r --thin %t/archive.a %S/Inputs/a.txt 2>&1 | FileCheck %s
 
 # CHECK: error: cannot convert a regular archive to a thin one
 



___
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] e42021d - [Clang][-fvisibility-from-dllstorageclass] Set DSO Locality from final visibility

2020-11-24 Thread Ben Dunbobbin via llvm-branch-commits

Author: Ben Dunbobbin
Date: 2020-11-24T00:32:14Z
New Revision: e42021d5cc25a8dc7e3efac1e7007cc0c1a7b2bd

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

LOG: [Clang][-fvisibility-from-dllstorageclass] Set DSO Locality from final 
visibility

Ensure that the DSO Locality of the globals in the IR is derived from
their final visibility when using -fvisibility-from-dllstorageclass.

To accomplish this we reset the DSO locality of globals (before
setting their visibility from their dllstorageclass) at the end of
IRGen in Clang. This removes any effects that visibility options or
annotations may have had on the DSO locality.

The resulting DSO locality of the globals will be pessimistic
w.r.t. to the normal compiler IRGen.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/visibility-dllstorageclass.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f56b7374082f..6d0228e9e2e9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -420,6 +420,13 @@ static void setVisibilityFromDLLStorageClass(const 
clang::LangOptions &LO,
 if (GV.hasAppendingLinkage() || GV.hasLocalLinkage())
   continue;
 
+// Reset DSO locality before setting the visibility. This removes
+// any effects that visibility options and annotations may have
+// had on the DSO locality. Setting the visibility will implicitly set
+// appropriate globals to DSO Local; however, this will be pessimistic
+// w.r.t. to the normal compiler IRGen.
+GV.setDSOLocal(false);
+
 if (GV.isDeclarationForLinker()) {
   GV.setVisibility(GV.getDLLStorageClass() ==
llvm::GlobalValue::DLLImportStorageClass

diff  --git a/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp 
b/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
index 9003909f3ee0..c4dddcec2eb0 100644
--- a/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
+++ b/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
@@ -5,12 +5,14 @@
 
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
 // RUN: -fvisibility hidden \
+// RUN: -fapply-global-visibility-to-externs \
 // RUN: -fvisibility-from-dllstorageclass \
 // RUN: -x c++ %s -S -emit-llvm -o - | \
-// RUN:   FileCheck %s --check-prefixes=DEFAULT
+// RUN:   FileCheck %s --check-prefixes=DEFAULTS
 
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
 // RUN: -fvisibility hidden \
+// RUN: -fapply-global-visibility-to-externs \
 // RUN: -fvisibility-from-dllstorageclass \
 // RUN: -fvisibility-dllexport=hidden \
 // RUN: -fvisibility-nodllstorageclass=protected \
@@ -19,45 +21,78 @@
 // RUN: -x c++  %s -S -emit-llvm -o - | \
 // RUN:   FileCheck %s --check-prefixes=EXPLICIT
 
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -fvisibility hidden \
+// RUN: -fapply-global-visibility-to-externs \
+// RUN: -fvisibility-from-dllstorageclass \
+// RUN: -fvisibility-dllexport=default \
+// RUN: -fvisibility-nodllstorageclass=default \
+// RUN: -fvisibility-externs-dllimport=default \
+// RUN: -fvisibility-externs-nodllstorageclass=default \
+// RUN: -x c++  %s -S -emit-llvm -o - | \
+// RUN:   FileCheck %s --check-prefixes=ALL_DEFAULT
+
 // Local
 static void l() {}
 void use_locals(){l();}
-// DEFAULT-DAG: define internal void @_ZL1lv()
+// DEFAULTS-DAG: define internal void @_ZL1lv()
 // EXPLICIT-DAG: define internal void @_ZL1lv()
+// ALL_DEFAULT-DAG: define internal void @_ZL1lv()
 
 // Function
 void f() {}
 void __declspec(dllexport) exported_f() {}
-// DEFAULT-DAG: define hidden void @_Z1fv()
-// DEFAULT-DAG: define dso_local void @_Z10exported_fv()
+// DEFAULTS-DAG: define hidden void @_Z1fv()
+// DEFAULTS-DAG: define void @_Z10exported_fv()
 // EXPLICIT-DAG: define protected void @_Z1fv()
 // EXPLICIT-DAG: define hidden void @_Z10exported_fv()
+// ALL_DEFAULT-DAG: define void @_Z1fv()
+// ALL_DEFAULT-DAG: define void @_Z10exported_fv()
 
 // Variable
 int d = 123;
 __declspec(dllexport) int exported_d = 123;
-// DEFAULT-DAG: @d = hidden global
-// DEFAULT-DAG: @exported_d = dso_local global
+// DEFAULTS-DAG: @d = hidden global
+// DEFAULTS-DAG: @exported_d = global
 // EXPLICIT-DAG: @d = protected global
 // EXPLICIT-DAG: @exported_d = hidden global
+// ALL_DEFAULT-DAG: @d = global
+// ALL_DEFAULT-DAG: @exported_d = global
 
 // Alias
 extern "C" void aliased() {}
 void a() __attribute__((alias("aliased")));
 void __declspec(dllexport) a_exported() __attribute__((alias("aliased")));
-// DEFAULT-DAG: @_Z1av = hidden alias
-//

[llvm-branch-commits] [clang] d5aaf60 - [windows-itanium] handle dllimport/export code paths separately and share with PS4

2020-11-30 Thread Ben Dunbobbin via llvm-branch-commits

Author: Ben Dunbobbin
Date: 2020-11-30T14:36:39Z
New Revision: d5aaf6021476243de73f8eb8a7479a2288582225

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

LOG: [windows-itanium] handle dllimport/export code paths separately and share 
with PS4

Similar to Windows Itanium, PS4 is also an Itanium C++ ABI variant
which shares the goal of semantic compatibility with Microsoft C++
code that uses dllimport/export.

This change introduces a new function to determine from the triple
if an environment aims for compatibility with MS C++ code w.r.t to
these attributes and guards the relevant code paths using that
function.

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

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CodeGenCXX/dllexport-vtable-thunks.cpp
clang/test/CodeGenCXX/windows-implicit-dllexport-template-specialization.cpp
clang/test/CodeGenCXX/windows-itanium-dllexport.cpp
clang/test/Sema/dllimport.c
clang/test/SemaCXX/dllexport.cpp
clang/test/SemaCXX/dllimport.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 698964b94ee2..de91ca2ee82e 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1098,6 +1098,13 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
   /// either; the entire thing is pretty badly mangled.
   virtual bool hasProtectedVisibility() const { return true; }
 
+  /// Does this target aim for semantic compatibility with
+  /// Microsoft C++ code using dllimport/export attributes?
+  virtual bool shouldDLLImportComdatSymbols() const {
+return getTriple().isWindowsMSVCEnvironment() ||
+   getTriple().isWindowsItaniumEnvironment() || getTriple().isPS4CPU();
+  }
+
   /// An optional hook that targets can implement to perform semantic
   /// checking on attribute((section("foo"))) specifiers.
   ///

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ce7475b0d5da..9c282a73e0ed 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6510,9 +6510,7 @@ static void checkDLLAttributeRedeclaration(Sema &S, 
NamedDecl *OldDecl,
   // special MSVC extension: in the last case, the declaration is treated as if
   // it were marked dllexport.
   bool IsInline = false, IsStaticDataMember = false, IsQualifiedFriend = false;
-  bool IsMicrosoft =
-  S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
-  S.Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment();
+  bool IsMicrosoftABI  = 
S.Context.getTargetInfo().shouldDLLImportComdatSymbols();
   if (const auto *VD = dyn_cast(NewDecl)) {
 // Ignore static data because out-of-line definitions are diagnosed
 // separately.
@@ -6526,9 +6524,9 @@ static void checkDLLAttributeRedeclaration(Sema &S, 
NamedDecl *OldDecl,
   }
 
   if (OldImportAttr && !HasNewAttr &&
-  (!IsInline || (IsMicrosoft && IsTemplate)) && !IsStaticDataMember &&
+  (!IsInline || (IsMicrosoftABI && IsTemplate)) && !IsStaticDataMember &&
   !NewDecl->isLocalExternDecl() && !IsQualifiedFriend) {
-if (IsMicrosoft && IsDefinition) {
+if (IsMicrosoftABI && IsDefinition) {
   S.Diag(NewDecl->getLocation(),
  diag::warn_redeclaration_without_import_attribute)
   << NewDecl;
@@ -6545,7 +6543,7 @@ static void checkDLLAttributeRedeclaration(Sema &S, 
NamedDecl *OldDecl,
   OldDecl->dropAttr();
   NewDecl->dropAttr();
 }
-  } else if (IsInline && OldImportAttr && !IsMicrosoft) {
+  } else if (IsInline && OldImportAttr && !IsMicrosoftABI) {
 // In MinGW, seeing a function declared inline drops the dllimport
 // attribute.
 OldDecl->dropAttr();

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index a14c16229419..d31d18eac474 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6791,16 +6791,14 @@ DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D,
 
 static void handleDLLAttr(Sema &S, Decl *D, const ParsedAttr &A) {
   if (isa(D) &&
-  (S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
-   S.Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) {
+  (S.Context.getTargetInfo().shouldDLLImportComdatSymbols())) {
 S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) << A;
 return;
   }
 
   if (const auto *FD = dyn_cast(D)) {
 if (FD->isInlined() && A.getKind() == ParsedAttr::AT_DLLImport &&
-!(S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
-  
S.Context.getTargetInfo().g