[PATCH] D50089: [DWARF v4] Suppressing the __debug_ranges section when there are no ranges

2018-07-31 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: aprantl, JDevlieghere, dblaikie.

One of the clang tests in debuginfo-tests (apple-accel.cpp) insists on checking 
for the existence of the __debug_ranges section (it requires darwin) even for 
trivial code which doesn't need any range lists. My recent patch to implement 
DWARF v5 rnglists suppressed the section for trivial cases and broke the test. 
To pacify the bots I disabled the suppression for DWARF 4, restoring the 
original behavior.

This patch (actually 2, debuginfo-tests is a separate repo) fixes the test and 
re-enables the suppression of unneeded DWARF 4 (and earlier) range lists.

@aprantl , @JDevlieghere Could you please make sure the test change makes 
sense. I am not that well-versed with Mach-O. I'm just trying to force the 
compiler to emit ranges.


https://reviews.llvm.org/D50089

Files:
  apple-accel.cpp
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp


Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2136,7 +2136,7 @@
 return;
   }
 
-  if (getDwarfVersion() >= 5 && NoRangesPresent())
+  if (NoRangesPresent())
 return;
 
   // Start the dwarf ranges section.
Index: apple-accel.cpp
===
--- apple-accel.cpp
+++ apple-accel.cpp
@@ -8,6 +8,7 @@
 // RUN: %clang %s %target_itanium_abi_host_triple -gdwarf-4 -O0 -c -g -o %t-ex
 // RUN: llvm-objdump -section-headers %t-ex | FileCheck %s
 
+__attribute__((section("1,__text_foo"))) void foo() {}
 int main (int argc, char const *argv[]) { return argc; }
 
 // CHECK: __debug_str


Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2136,7 +2136,7 @@
 return;
   }
 
-  if (getDwarfVersion() >= 5 && NoRangesPresent())
+  if (NoRangesPresent())
 return;
 
   // Start the dwarf ranges section.
Index: apple-accel.cpp
===
--- apple-accel.cpp
+++ apple-accel.cpp
@@ -8,6 +8,7 @@
 // RUN: %clang %s %target_itanium_abi_host_triple -gdwarf-4 -O0 -c -g -o %t-ex
 // RUN: llvm-objdump -section-headers %t-ex | FileCheck %s
 
+__attribute__((section("1,__text_foo"))) void foo() {}
 int main (int argc, char const *argv[]) { return argc; }
 
 // CHECK: __debug_str
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50089: [DWARF v4] Suppressing the __debug_ranges section when there are no ranges

2018-07-31 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338437: [DWARF] Do not create a .debug_ranges section when 
no ranges are needed. (authored by wolfgangp, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50089?vs=158328&id=158378#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50089

Files:
  llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp


Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2136,7 +2136,7 @@
 return;
   }
 
-  if (getDwarfVersion() >= 5 && NoRangesPresent())
+  if (NoRangesPresent())
 return;
 
   // Start the dwarf ranges section.


Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2136,7 +2136,7 @@
 return;
   }
 
-  if (getDwarfVersion() >= 5 && NoRangesPresent())
+  if (NoRangesPresent())
 return;
 
   // Start the dwarf ranges section.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41044: Implementation of -fextend-lifetimes and -fextend-this-ptr to aid with debugging of optimized code

2018-11-26 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp updated this revision to Diff 175307.
wolfgangp added a comment.

Rebased on r347577 with some test cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D41044/new/

https://reviews.llvm.org/D41044

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/EHScopeStack.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/fake-use-determinism.c
  test/CodeGen/fake-use-landingpad.c
  test/CodeGen/fake-use-noreturn.c
  test/CodeGen/fake-use-return-line.c
  test/CodeGen/fake-use-sanitizer.cpp
  test/CodeGen/fake-use-scalar.c
  test/CodeGen/fake-use-while.c
  test/CodeGen/fake-use.cpp
  test/CodeGen/no-fake-use-O0.cpp

Index: test/CodeGen/no-fake-use-O0.cpp
===
--- /dev/null
+++ test/CodeGen/no-fake-use-O0.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -O0 -emit-llvm -fextend-this-ptr -o -  | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -emit-llvm -fextend-lifetimes -o - | FileCheck %s
+// RUN: %clang_cc1 %s -O1 -emit-llvm -fextend-this-ptr -o -  | FileCheck -check-prefix=OPT %s
+// RUN: %clang_cc1 %s -O1 -emit-llvm -fextend-lifetimes -o - | FileCheck -check-prefix=OPT %s
+// RUN: %clang_cc1 %s -Os -emit-llvm -fextend-this-ptr -o -  | FileCheck -check-prefix=OPT %s
+// RUN: %clang_cc1 %s -Os -emit-llvm -fextend-lifetimes -o - | FileCheck -check-prefix=OPT %s
+// RUN: %clang_cc1 %s -Oz -emit-llvm -fextend-this-ptr -o -  | FileCheck -check-prefix=OPT %s
+// RUN: %clang_cc1 %s -Oz -emit-llvm -fextend-lifetimes -o - | FileCheck -check-prefix=OPT %s
+// Check that we do not generate a fake_use call when we are not optimizing. 
+
+extern void bar();
+
+class v
+{
+public:
+int x;
+int y;
+int z;
+int w;
+
+v(int a, int b, int c, int d) : x(a), y(b), z(c), w(d) {}
+};
+
+class w
+{
+public:
+v test(int, int, int, int, int, int, int, int, int, int);
+w(int in): a(in), b(1234) {}
+
+private:
+int a;
+int b;
+};
+
+v w::test(int q, int w, int e, int r, int t, int y, int u, int i, int o, int p)
+{
+// CHECK: define{{.*}}test
+int res = q*w + e - r*t + y*u*i*o*p;
+int res2 = (w + e + r + t + y + o)*(p*q);
+int res3 = res + res2;
+int res4 = q*e + t*y*i + p*e*w * 6 * 4 * 3;
+
+v V(res, res2, res3, res4);
+
+bar();
+// CHECK-NOT: call void (...) @llvm.fake.use
+// OPT:   call void (...) @llvm.fake.use
+return V;
+}
Index: test/CodeGen/fake-use.cpp
===
--- /dev/null
+++ test/CodeGen/fake-use.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -O2 -emit-llvm -fextend-this-ptr -o - | FileCheck %s
+// Check that we generate a fake_use call with the 'this' pointer as argument.
+// The call should appear after the call to bar().
+
+extern void bar();
+
+class v
+{
+public:
+int x;
+int y;
+int z;
+int w;
+
+v(int a, int b, int c, int d) : x(a), y(b), z(c), w(d) {}
+};
+
+class w
+{
+public:
+v test(int, int, int, int, int, int, int, int, int, int);
+w(int in): a(in), b(1234) {}
+
+private:
+int a;
+int b;
+};
+
+v w::test(int q, int w, int e, int r, int t, int y, int u, int i, int o, int p)
+{
+// CHECK: define{{.*}}test
+int res = q*w + e - r*t + y*u*i*o*p;
+int res2 = (w + e + r + t + y + o)*(p*q);
+int res3 = res + res2;
+int res4 = q*e + t*y*i + p*e*w * 6 * 4 * 3;
+
+v V(res, res2, res3, res4);
+
+bar();
+// CHECK: call{{.*}}bar
+// CHECK: call void (...) @llvm.fake.use(%class.w* %this)
+return V;
+// CHECK: ret
+}
Index: test/CodeGen/fake-use-while.c
===
--- /dev/null
+++ test/CodeGen/fake-use-while.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -fextend-lifetimes -o %t.ll
+//
+// Check we don't assert when there is no more code after a while statement
+// and the body of the while statement ends in a return, i.e. no insertion point
+// is available.
+
+// CHECK: define{{.*}}main
+// CHECK: call{{.*}}llvm.fake.use
+
+void foo() {
+  {
+while (1) {
+  int ret;
+  if (1)
+return;
+}
+  }
+}
Index: test/CodeGen/fake-use-scalar.c
===
--- /dev/null
+++ test/CodeGen/fake-use-scalar.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -O2 -emit-llvm -fextend-lifetimes -o - | FileCheck %s
+// Make sure we don't generate fake.use for non-scalar 
+// variables.
+
+struct A {
+  unsigned long t;
+  char c[1024];
+  unsigned char r[32];
+};
+
+
+int foo()
+{
+  struct A s;
+  struct A v[128];
+  char c[32];
+  return 0;
+}
+
+// CHECK-NOT:  fake.use
Index: test/CodeGen/fake-use-sanitizer.cpp
===
--- /dev/null
+++ test/CodeGen/fake-

[PATCH] D80293: [clangd] Run PreambleThread in async mode behind a flag

2020-06-01 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

Hi!

Shortly after this patch went in, we started to see intermittent failures with 
the unittest TUSchedulerTests.ManyUpdates. The build server (Windows) we're 
running it on is quite powerful and our own hand-run tests only take about 400 
ms, so we don't really understand what could be happening. Any help would be 
appreciated.

Here is an excerpt from the log:

Note: Google Test filter = TUSchedulerTests.ManyUpdates

[==] Running 1 test from 1 test case.

[--] Global test environment set-up.

[--] 1 test from TUSchedulerTests

[ RUN  ] TUSchedulerTests.ManyUpdates

C:\j\w\...\clang-tools-extra\clangd\unittests\TUSchedulerTests.cpp(508): error: 
Value of: S.blockUntilIdle(timeoutSeconds(10))

  Actual: false

Expected: true

[  FAILED  ] TUSchedulerTests.ManyUpdates (10576 ms)

[--] 1 test from TUSchedulerTests (10576 ms total)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80293/new/

https://reviews.llvm.org/D80293



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


[PATCH] D41044: Implementation of -fextend-lifetimes and -fextend-this-ptr to aid with debugging of optimized code

2017-12-08 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
Herald added a subscriber: JDevlieghere.

The patch implements the clang support for generating artificial uses of local 
variables and parameters to aid with debugging of optimized code. I presented 
this concept in my lightning talk "Debugging of optimized code: Extending the 
lifetime of local variables" at the October 2017 LLVM conference.

Since the concept is not universally supported, the purpose of this review is 
to make the patch available to interested parties and perhaps to restart the 
discussion.

This patch requires the patch posted in https://reviews.llvm.org/D41043 (the 
llvm portion).

The implementation generates calls to the llvm intrinsic fake.use in similar 
fashion as end of lifetime markers.


https://reviews.llvm.org/D41044

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/fake-use.cpp

Index: test/CodeGen/fake-use.cpp
===
--- test/CodeGen/fake-use.cpp
+++ test/CodeGen/fake-use.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -O2 -emit-llvm -fextend-lifetimes -o - | FileCheck %s
+// Check that we generate a fake_use call with the 'this' pointer as argument.
+// The call should appear after the call to bar().
+
+extern void bar();
+
+class v
+{
+public:
+int x;
+int y;
+int z;
+int w;
+
+v(int a, int b, int c, int d) : x(a), y(b), z(c), w(d) {}
+};
+
+class w
+{
+public:
+v test(int, int, int, int, int, int, int, int, int, int);
+w(int in): a(in), b(1234) {}
+
+private:
+int a;
+int b;
+};
+
+v w::test(int q, int w, int e, int r, int t, int y, int u, int i, int o, int p)
+{
+// CHECK: define{{.*}}test
+int res = q*w + e - r*t + y*u*i*o*p;
+int res2 = (w + e + r + t + y + o)*(p*q);
+int res3 = res + res2;
+int res4 = q*e + t*y*i + p*e*w * 6 * 4 * 3;
+
+v V(res, res2, res3, res4);
+
+bar();
+// CHECK: call{{.*}}bar
+// CHECK: call void (...) @llvm.fake.use(%class.w* %this)
+return V;
+// CHECK: ret
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -999,6 +999,11 @@
   Opts.CudaGpuBinaryFileNames =
   Args.getAllArgValues(OPT_fcuda_include_gpubinary);
 
+  Opts.ExtendThisPtr =
+  Opts.OptimizationLevel > 0 && Args.hasArg(OPT_fextend_this_ptr);
+  Opts.ExtendLifetimes =
+  Opts.OptimizationLevel > 0 && Args.hasArg(OPT_fextend_lifetimes);
+
   Opts.Backchain = Args.hasArg(OPT_mbackchain);
 
   Opts.EmitCheckPathComponentsToStrip = getLastArgIntValue(
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4434,6 +4434,11 @@
   if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
 CmdArgs.push_back("-fretain-comments-from-system-headers");
 
+  if (Args.hasArg(options::OPT_fextend_this_ptr))
+CmdArgs.push_back("-fextend-this-ptr");
+  if (Args.hasArg(options::OPT_fextend_lifetimes))
+CmdArgs.push_back("-fextend-lifetimes");
+
   // Forward -fcomment-block-commands to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
   // Forward -fparse-all-comments to -cc1.
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -484,6 +484,9 @@
   /// void @llvm.lifetime.end(i64 %size, i8* nocapture )
   llvm::Constant *LifetimeEndFn = nullptr;
 
+  /// void @llvm.fake.use(i8* nocapture )
+  llvm::Constant *FakeUseFn = nullptr;
+
   GlobalDecl initializedGlobalDecl;
 
   std::unique_ptr SanitizerMD;
@@ -970,6 +973,7 @@
 
   llvm::Constant *getLLVMLifetimeStartFn();
   llvm::Constant *getLLVMLifetimeEndFn();
+  llvm::Constant *getLLVMFakeUseFn();
 
   // Make sure that this type is translated.
   void UpdateCompletedType(const TagDecl *TD);
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -421,6 +421,20 @@
 }
   };
 
+  // We are using objects of this 'cleanup' class to emit fake.use calls
+  // for -fextend-lifetimes. They are placed at the end of a variable's
+  // scope analogous to lifetime markers.
+  class FakeUse final : public EHScopeStack::Cleanup {
+Address Addr;
+
+  public:
+FakeUse(Address addr) : Addr(addr) {}
+
+void Emit(CodeGenFunction &CGF, Flags flags) override {
+  CGF.EmitFakeUse(Addr);
+}
+  };
+
   /// Header for data within LifetimeExtendedCleanupStack.
   struct LifetimeExtendedCleanupHeader {
 /// The size of the following cl

[PATCH] D41044: Implementation of -fextend-lifetimes and -fextend-this-ptr to aid with debugging of optimized code

2017-12-08 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

A quick note on usage: Compile your source with "clang -O2 -g -c 
-fextend-lifetimes foo.cpp" to see the effects (or use -fextend-this-ptr if you 
just want to extend the lifetime of 'this').


https://reviews.llvm.org/D41044



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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

Hi, there seems to be a unit test failure, for example here 
.

/home/buildbot/as-worker-91/clang-with-lto-ubuntu/build/stage1/tools/clang/unittests/Driver/./ClangDriverTests
 --gtest_filter=DxcModeTest.TargetProfileValidation

/home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/unittests/Driver/ToolChainTest.cpp:484
Expected equality of these values:

  DiagConsumer->Errors.back().data()
Which is: "invalid profile : ps_6_x1"
  "invalid profile : ps_6_x"

/home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/unittests/Driver/ToolChainTest.cpp:502
Expected equality of these values:

  DiagConsumer->Errors.back().data()
Which is: "invalid profile : foo_6_1"
  "invalid profile : foo"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122865/new/

https://reviews.llvm.org/D122865

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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-16 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

Seems to be fine now. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122865/new/

https://reviews.llvm.org/D122865

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


[PATCH] D103495: [static initializers] Don't put ordered dynamic initializers of static variables into global_ctors

2021-06-01 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: rnk, jyu2.
wolfgangp requested review of this revision.

Commit c19f4f8069 

 caused some ordered dynamic initialization of static member variables to be 
treated like unordered initialization, i.e. put into global_ctors. This caused 
issues in some configurations, specifically when init_array is not used. This 
patch proposes to restrict this behaviour to the Microsoft ABI, where it is 
apparently necessary for correctness.

2 existing test cases are affected by this change.

This fixes PR50266.


https://reviews.llvm.org/D103495

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/static-init-order.cpp
  clang/test/Modules/initializers.cpp


Index: clang/test/Modules/initializers.cpp
===
--- clang/test/Modules/initializers.cpp
+++ clang/test/Modules/initializers.cpp
@@ -232,9 +232,9 @@
 // CHECK-IMPORT: load {{.*}} (i64* @_ZGV
 // CHECK-IMPORT: store {{.*}}, i32* @[[D]],
 
-
 // CHECK-IMPORT: define {{.*}} @[[TU_INIT]]()
 // CHECK-IMPORT: call void @[[A_INIT]]()
+// CHECK-IMPORT: call void @[[B_INIT]]()
 
 // CHECK-IMPORT: define {{.*}} @__tls_init()
 // CHECK-IMPORT: call void @[[C_INIT]]()
Index: clang/test/CodeGenCXX/static-init-order.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/static-init-order.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck %s
+// Make sure we generate a single initialization routine and put its address 
into the
+// global_ctors. Check that the initialization routine makes 2 calls to 
individual
+// initializer functions in the correct order.
+
+// CHECK: @llvm.global_ctors = 
{{.*}}@[[INIT:_GLOBAL__sub_I[A-Za-z0-9_\.]+]]
+// CHECK: define {{.*}} @[[VARINIT1:__cxx_global_var_init]]
+// CHECK-NOT: }
+// CHECK: call void @_ZN1AC1Ev
+// CHECK: define {{.*}} @[[VARINIT2:__cxx_global_var_init\.[0-9]+]]
+// CHECK-NOT: }
+// CHECK: call void @_ZN1BC1Ev
+// CHECK: define {{.*}} @[[INIT]]
+// CHECK-NOT: }
+// CHECK: call void @[[VARINIT1]]
+// CHECK: call void @[[VARINIT2]]
+
+class A {
+public:
+  A() {
+  }
+};
+
+class B {
+public:
+  B() {
+  }
+};
+
+class StaticsClass {
+private:
+  static inline A A_Var;
+  static inline B B_Var;
+};
Index: clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
===
--- clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
+++ clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
@@ -47,7 +47,7 @@
 // CHECK: @_ZGVN5test12t2E = linkonce_odr global i64 0, align 8
 // CHECK: @_ZGVN5test21AIvE8instanceE = weak_odr global i64 0, align 8
 // CHECK: @_ZGVN5test12t1IiEE = linkonce_odr global i64 0, align 8
-// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] 
[{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init.1, i8* 
null }, { i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init.2, 
i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* 
@__cxx_global_var_init.4, i8* null }, { i32, void ()*, i8* } { i32 65535, void 
()* @_GLOBAL__sub_I__, i8* null }]
+// CHECK: @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] 
[{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init.2, i8* 
null }, { i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init.4, 
i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* 
null }]
 // CHECK: @llvm.global_dtors = appending global [4 x { i32, void ()*, i8* }] 
[{ i32, void ()*, i8* } { i32 65535, void ()* @__finalize__ZN5test12t2E, i8* 
null }, { i32, void ()*, i8* } { i32 65535, void ()* 
@__finalize__ZN5test21AIvE8instanceE, i8* null }, { i32, void ()*, i8* } { i32 
65535, void ()* @__finalize__ZN5test12t1IiEE, i8* null }, { i32, void ()*, i8* 
} { i32 65535, void ()* @_GLOBAL__D_a, i8* null }]
 
 // CHECK: define internal void @__cxx_global_var_init() [[ATTR:#[0-9]+]] {
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -503,7 +503,8 @@
   PrioritizedCXXGlobalInits.size());
 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
   } else if (isTemplateInstantiation(D->getTemplateSpecializationKind()) ||
- getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR) {
+ (getTarget().getCXXABI().isMicrosoft() &&
+  getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR)) 
{
 // C++ [basic.start.init]p2:
 //   Definitions of explicitly

[PATCH] D103495: [static initializers] Don't put ordered dynamic initializers of static variables into global_ctors

2021-06-02 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D103495#2794329 , @rnk wrote:

> +@rsmith @hans @aeubanks
>
>> specifically when init_array is not used
>
> Can you elaborate on why that is? Here's what I remember, and what I guess is 
> happening. ELF has two initializer schemes: .init_array and .ctors. They are 
> essentially equivalent, they are both arrays of function pointers, but one is 
> called in reverse order and the other is called in forward order. The 
> compiler knows which scheme is in use and it is controlled by 
> -fuse-init-array.

For PS4, we use the .ctors scheme, and so the initialization order was suddenly 
reversed, which was not noticed for a while until the user had a  dependency on 
the previous initialization. And using init_array or not has currently no 
effect on the order of emission of global_ctors.

> The LLVM IR langref says that llvm.global_ctors are called in ascending 
> priority order, and the order between initializers is not defined. That's not 
> very helpful and often doesn't reflect reality. I wonder if we could do two 
> things, perhaps separately:
>
> 1. emit llvm.global_ctors so that they are called in order of appearance in 
> the IR array (is this not already true?)

AFAICT, this is already happening. After sorting by priority, the order remains 
intact at emission. So with -fno-use-init-array0we're going to emit 
global_ctors in reverse order, I suppose.

> 2. define the order of initialization in LangRef
>
> With the first change in place, we can be confident that so long as all 
> includers of the `StaticsClass` in the test emit both initializers in the 
> correct order, no matter which initializers prevail, they will be called in 
> the correct order. Of course, this could break users relying on the existing 
> ordering, nevermind that it is explicitly documented as undefined.
>
> The second change is only a documentation change, but I would like to find a 
> way to justify what LLVM does in GlobalOpt. GlobalOpt can effectively fold a 
> dynamic initializer to constant memory in certain cases. That can only ever 
> have the effect of making an initializer run earlier. As long as no 
> initializers depend on observing uninitialized globals, that should be safe. 
> The guarantee that we want to provide is that, for each initializer, all 
> initializers prior to it in the global_ctors array will have run when it 
> runs. Initializers that appear later may run earlier. Hopefully that covers 
> both the usual way that .init_array sections are linked together and the way 
> globalopt optimizes dynamic initialization.




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

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


[PATCH] D109981: [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing

2021-09-17 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added a reviewer: dexonsmith.
wolfgangp requested review of this revision.

Fixes PR 51837.

When a -W option is given on the command line, and the corresponding 
diangostic has the NoWarnOnError flag set, the flag is dropped when the 
severity is reevaluated, possibly as a result of a pragma or of command line 
processing.


https://reviews.llvm.org/D109981

Files:
  clang/lib/Basic/Diagnostic.cpp
  clang/test/Lexer/pragma-message.c


Index: clang/test/Lexer/pragma-message.c
===
--- clang/test/Lexer/pragma-message.c
+++ clang/test/Lexer/pragma-message.c
@@ -8,24 +8,25 @@
 // #pragma message messagestring
 //
 // RUN: %clang_cc1 -fsyntax-only -verify -Werror %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror -W#pragma-messages %s
 #define STRING2(x) #x
 #define STRING(x) STRING2(x)
-#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning 
{{:O I'm a message! 13}}
-#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning 
{{:O gcc accepts this! 14}}
+#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning 
{{:O I'm a message! 14}}
+#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning 
{{:O gcc accepts this! 15}}
 
 #pragma message(invalid) // expected-error {{expected string literal in pragma 
message}}
 
 // GCC supports a similar pragma, #pragma GCC warning (which generates a 
warning
 // message) and #pragma GCC error (which generates an error message).
 
-#pragma GCC warning(":O I'm a message! " STRING(__LINE__)) // expected-warning 
{{:O I'm a message! 21}}
-#pragma GCC warning ":O gcc accepts this! " STRING(__LINE__) // 
expected-warning {{:O gcc accepts this! 22}}
+#pragma GCC warning(":O I'm a message! " STRING(__LINE__)) // expected-warning 
{{:O I'm a message! 22}}
+#pragma GCC warning ":O gcc accepts this! " STRING(__LINE__) // 
expected-warning {{:O gcc accepts this! 23}}
 
-#pragma GCC error(":O I'm a message! " STRING(__LINE__)) // expected-error 
{{:O I'm a message! 24}}
-#pragma GCC error ":O gcc accepts this! " STRING(__LINE__) // expected-error 
{{:O gcc accepts this! 25}}
+#pragma GCC error(":O I'm a message! " STRING(__LINE__)) // expected-error 
{{:O I'm a message! 25}}
+#pragma GCC error ":O gcc accepts this! " STRING(__LINE__) // expected-error 
{{:O gcc accepts this! 26}}
 
 #define COMPILE_ERROR(x) _Pragma(STRING2(GCC error(x)))
-COMPILE_ERROR("Compile error at line " STRING(__LINE__) "!"); // 
expected-error {{Compile error at line 28!}}
+COMPILE_ERROR("Compile error at line " STRING(__LINE__) "!"); // 
expected-error {{Compile error at line 29!}}
 
 #pragma message // expected-error {{pragma message requires parenthesized 
string}}
 #pragma GCC warning("" // expected-error {{pragma warning requires 
parenthesized string}}
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -374,6 +374,12 @@
   DiagnosticMapping Mapping = makeUserMapping(Map, L);
   Mapping.setUpgradedFromWarning(WasUpgradedFromWarning);
 
+  // Make sure we propagate the NoWarningAsError flag from an existing
+  // mapping (which may be the default mapping).
+  DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
+  Mapping.setNoWarningAsError(Info.hasNoWarningAsError() ||
+  Mapping.hasNoWarningAsError());
+
   // Common case; setting all the diagnostics of a group in one place.
   if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
   DiagStatesByLoc.getCurDiagState()) {


Index: clang/test/Lexer/pragma-message.c
===
--- clang/test/Lexer/pragma-message.c
+++ clang/test/Lexer/pragma-message.c
@@ -8,24 +8,25 @@
 // #pragma message messagestring
 //
 // RUN: %clang_cc1 -fsyntax-only -verify -Werror %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror -W#pragma-messages %s
 #define STRING2(x) #x
 #define STRING(x) STRING2(x)
-#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}}
-#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 14}}
+#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 14}}
+#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 15}}
 
 #pragma message(invalid) // expected-error {{expected string literal in pragma message}}
 
 // GCC supports a similar pragma, #pragma GCC warning (which generates a warning
 // message) and #pragma GCC error (which generates an error message).
 
-#pragma GCC warning(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 21}}
-#pragma GCC warning ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this

[PATCH] D109981: [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing

2021-09-29 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

ping ...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109981/new/

https://reviews.llvm.org/D109981

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


[PATCH] D110783: [clang] Make crash reproducer work with clang-cl

2021-09-30 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D110783#3035158 , @dyung wrote:

> Hi, the test you modified Driver/crash-report.cpp is failing on the PS4 bot 
> after your change. Can you take a look?
>
> https://lab.llvm.org/buildbot/#/builders/139/builds/10939

Seems like adding -fexceptions to the response file fixes it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110783/new/

https://reviews.llvm.org/D110783

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


[PATCH] D67429: Improve code generation for thread_local variables:

2021-02-16 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

Ping. Just wondering if there are any new insights on the issue reported in 
PR48030 .


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67429/new/

https://reviews.llvm.org/D67429

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


[PATCH] D103495: [static initializers] Don't put ordered dynamic initializers of static variables into global_ctors

2021-06-07 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp updated this revision to Diff 350364.
wolfgangp added a comment.
Herald added subscribers: llvm-commits, jdoerfert, pengfei, jrtc27, 
fedor.sergeev, hiraditya, jyknight, dschuff.
Herald added a project: LLVM.

Following the suggestion to define an order of initialization for the entries 
in llvm.global_ctors and llvm.global_dtors this is mainly a documentation 
change, as well as a simple reversed emission of global_ctors/dtors entries 
when InitArray is not used. 
3 test cases are affected, 2 of them just by a reversed order of emission of 
priority-suffixed sections. I added a couple of entries to the third test case 
to verify in-order emission of entries with equal priority.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

Files:
  llvm/docs/LangRef.rst
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/SPARC/constructor.ll
  llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
  llvm/test/CodeGen/X86/constructor.ll

Index: llvm/test/CodeGen/X86/constructor.ll
===
--- llvm/test/CodeGen/X86/constructor.ll
+++ llvm/test/CodeGen/X86/constructor.ll
@@ -9,7 +9,7 @@
 ; RUN: llc -mtriple i586-intel-elfiamcu -use-ctors < %s | FileCheck %s --check-prefix=MCU-CTORS
 ; RUN: llc -mtriple i586-intel-elfiamcu < %s | FileCheck %s --check-prefix=MCU-INIT-ARRAY
 ; RUN: llc -mtriple x86_64-win32-gnu < %s | FileCheck --check-prefix=COFF-CTOR %s
-@llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 5, void ()* @h, i8* @v }]
+@llvm.global_ctors = appending global [5 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 5, void ()* @h, i8* @v }, { i32, void ()*, i8* } { i32 65535, void ()* @i, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @j, i8* null }]
 
 @v = weak_odr global i8 0
 
@@ -28,15 +28,27 @@
   ret void
 }
 
-; CTOR:		.section	.ctors.65520,"aGw",@progbits,v,comdat
+define void @i() {
+entry:
+  ret void
+}
+
+define void @j() {
+entry:
+  ret void
+}
+
+; CTOR:	.section	.ctors,"aw",@progbits
 ; CTOR-NEXT:	.p2align	3
-; CTOR-NEXT:	.quad	g
+; CTOR-NEXT:	.quad	j
+; CTOR-NEXT:	.quad	i
+; CTOR-NEXT:	.quad	f
 ; CTOR-NEXT:	.section	.ctors.09980,"aGw",@progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
 ; CTOR-NEXT:	.quad	h
-; CTOR-NEXT:	.section	.ctors,"aw",@progbits
+; CTOR-NEXT:	.section	.ctors.65520,"aGw",@progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
-; CTOR-NEXT:	.quad	f
+; CTOR-NEXT:	.quad	g
 
 ; INIT-ARRAY:		.section	.init_array.15,"aGw",@init_array,v,comdat
 ; INIT-ARRAY-NEXT:	.p2align	3
@@ -47,6 +59,8 @@
 ; INIT-ARRAY-NEXT:	.section	.init_array,"aw",@init_array
 ; INIT-ARRAY-NEXT:	.p2align	3
 ; INIT-ARRAY-NEXT:	.quad	f
+; INIT-ARRAY-NEXT:	.quad	i
+; INIT-ARRAY-NEXT:	.quad	j
 
 ; NACL:		.section	.init_array.15,"aGw",@init_array,v,comdat
 ; NACL-NEXT:	.p2align	2
@@ -57,6 +71,8 @@
 ; NACL-NEXT:	.section	.init_array,"aw",@init_array
 ; NACL-NEXT:	.p2align	2
 ; NACL-NEXT:	.long	f
+; NACL-NEXT:	.long	i
+; NACL-NEXT:	.long	j
 
 ; MCU-CTORS: .section.ctors,"aw",@progbits
 ; MCU-INIT-ARRAY:.section.init_array,"aw",@init_array
@@ -70,3 +86,5 @@
 ; COFF-CTOR-NEXT:	.section	.ctors,"dw"
 ; COFF-CTOR-NEXT:	.p2align	3
 ; COFF-CTOR-NEXT:	.quad	f
+; COFF-CTOR-NEXT:	.quad	i
+; COFF-CTOR-NEXT:	.quad	j
Index: llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
===
--- llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
+++ llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
@@ -3,24 +3,24 @@
 ; PR5329
 
 @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @construct_2, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @construct_3, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @construct_1, i8* null }]
-; CHECK-DEFAULT: .section.ctors.64535,"aw",@progbits
-; CHECK-DEFAULT: .long construct_1
-; CHECK-DEFAULT: .section.ctors.63535,"aw",@progbits
-; CHECK-DEFAULT: .long construct_2
 ; CHECK-DEFAULT: .section.ctors.62535,"aw",@progbits
 ; CHECK-DEFAULT: .long construct_3
+; CHECK-DEFAULT: .section.ctors.63535,"aw",@progbits
+; CHECK-DEFAULT: .long construct_2
+; CHECK-DEFAULT: .section.ctors.64535,"aw",@progbits
+; CHECK-DEFAULT: .long construct_1
 
 ; CHECK-DARWIN: .long _construct_1
 ; CHECK-DARWIN-NEXT: .long _construct_2
 ; CHECK-DARWIN-NEXT: .long _construct_3
 
 @llvm.global_dtors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @destruct_2, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @destruct_1, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @destruct_3,

[PATCH] D103495: [static initializers] Emit global_ctors and global_dtors in reverse order when init_array is not used.

2021-06-08 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp updated this revision to Diff 350644.
wolfgangp retitled this revision from "[static initializers] Don't put ordered 
dynamic initializers of static variables into global_ctors" to "[static 
initializers] Emit global_ctors and global_dtors in reverse order when 
init_array is not used.".
wolfgangp added a comment.

Given the assessment on GlobalOpt, removed the LangRef changes and updated the 
subject line.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/SPARC/constructor.ll
  llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
  llvm/test/CodeGen/X86/constructor.ll

Index: llvm/test/CodeGen/X86/constructor.ll
===
--- llvm/test/CodeGen/X86/constructor.ll
+++ llvm/test/CodeGen/X86/constructor.ll
@@ -9,7 +9,7 @@
 ; RUN: llc -mtriple i586-intel-elfiamcu -use-ctors < %s | FileCheck %s --check-prefix=MCU-CTORS
 ; RUN: llc -mtriple i586-intel-elfiamcu < %s | FileCheck %s --check-prefix=MCU-INIT-ARRAY
 ; RUN: llc -mtriple x86_64-win32-gnu < %s | FileCheck --check-prefix=COFF-CTOR %s
-@llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 5, void ()* @h, i8* @v }]
+@llvm.global_ctors = appending global [5 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 5, void ()* @h, i8* @v }, { i32, void ()*, i8* } { i32 65535, void ()* @i, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @j, i8* null }]
 
 @v = weak_odr global i8 0
 
@@ -28,15 +28,27 @@
   ret void
 }
 
-; CTOR:		.section	.ctors.65520,"aGw",@progbits,v,comdat
+define void @i() {
+entry:
+  ret void
+}
+
+define void @j() {
+entry:
+  ret void
+}
+
+; CTOR:	.section	.ctors,"aw",@progbits
 ; CTOR-NEXT:	.p2align	3
-; CTOR-NEXT:	.quad	g
+; CTOR-NEXT:	.quad	j
+; CTOR-NEXT:	.quad	i
+; CTOR-NEXT:	.quad	f
 ; CTOR-NEXT:	.section	.ctors.09980,"aGw",@progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
 ; CTOR-NEXT:	.quad	h
-; CTOR-NEXT:	.section	.ctors,"aw",@progbits
+; CTOR-NEXT:	.section	.ctors.65520,"aGw",@progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
-; CTOR-NEXT:	.quad	f
+; CTOR-NEXT:	.quad	g
 
 ; INIT-ARRAY:		.section	.init_array.15,"aGw",@init_array,v,comdat
 ; INIT-ARRAY-NEXT:	.p2align	3
@@ -47,6 +59,8 @@
 ; INIT-ARRAY-NEXT:	.section	.init_array,"aw",@init_array
 ; INIT-ARRAY-NEXT:	.p2align	3
 ; INIT-ARRAY-NEXT:	.quad	f
+; INIT-ARRAY-NEXT:	.quad	i
+; INIT-ARRAY-NEXT:	.quad	j
 
 ; NACL:		.section	.init_array.15,"aGw",@init_array,v,comdat
 ; NACL-NEXT:	.p2align	2
@@ -57,6 +71,8 @@
 ; NACL-NEXT:	.section	.init_array,"aw",@init_array
 ; NACL-NEXT:	.p2align	2
 ; NACL-NEXT:	.long	f
+; NACL-NEXT:	.long	i
+; NACL-NEXT:	.long	j
 
 ; MCU-CTORS: .section.ctors,"aw",@progbits
 ; MCU-INIT-ARRAY:.section.init_array,"aw",@init_array
@@ -70,3 +86,5 @@
 ; COFF-CTOR-NEXT:	.section	.ctors,"dw"
 ; COFF-CTOR-NEXT:	.p2align	3
 ; COFF-CTOR-NEXT:	.quad	f
+; COFF-CTOR-NEXT:	.quad	i
+; COFF-CTOR-NEXT:	.quad	j
Index: llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
===
--- llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
+++ llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
@@ -3,24 +3,24 @@
 ; PR5329
 
 @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @construct_2, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @construct_3, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @construct_1, i8* null }]
-; CHECK-DEFAULT: .section.ctors.64535,"aw",@progbits
-; CHECK-DEFAULT: .long construct_1
-; CHECK-DEFAULT: .section.ctors.63535,"aw",@progbits
-; CHECK-DEFAULT: .long construct_2
 ; CHECK-DEFAULT: .section.ctors.62535,"aw",@progbits
 ; CHECK-DEFAULT: .long construct_3
+; CHECK-DEFAULT: .section.ctors.63535,"aw",@progbits
+; CHECK-DEFAULT: .long construct_2
+; CHECK-DEFAULT: .section.ctors.64535,"aw",@progbits
+; CHECK-DEFAULT: .long construct_1
 
 ; CHECK-DARWIN: .long _construct_1
 ; CHECK-DARWIN-NEXT: .long _construct_2
 ; CHECK-DARWIN-NEXT: .long _construct_3
 
 @llvm.global_dtors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @destruct_2, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @destruct_1, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @destruct_3, i8* null }]
-; CHECK-DEFAULT: .section.dtors.64535,"aw",@progbits
-; CHECK-DEFAULT: .long destruct_1
-; CHECK-DEFAULT: .section.dtors.63535,"aw",@progbits
-; CHECK-DEFAULT: .long destruct_2
 ; CHECK-DEFAULT: .section.dtors.62535,"aw",@progbits
 ; CHECK-DEFAULT: .long destruct

[PATCH] D103495: [static initializers] Emit global_ctors and global_dtors in reverse order when init_array is not used.

2021-06-08 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D103495#2804685 , @MaskRay wrote:

> 



> Can you check whether clang/lib/CodeGen/CGDeclCXX.cpp:507 needs any comment 
> update?
> The subject "Don't put ordered dynamic initializers of static variables into 
> global_ctors" needs an update as well.

If we are not defining the initialization order, it seems the comment doesn't 
need any updating yet, although once we do, it definitely will.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

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


[PATCH] D103495: [static initializers] Emit global_ctors and global_dtors in reverse order when init_array is not used.

2021-06-09 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D103495#2808247 , @rnk wrote:

> So, a question for @wolfgangp and @probinson , do we need to make adjustments 
> to the LTO library, or is this OK as is?

We never guaranteed our licensees any particular initialization order (between 
modules), so after checking with my team members I think this is OK as is.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

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


[PATCH] D103495: [static initializers] Emit global_ctors and global_dtors in reverse order when init_array is not used.

2021-06-10 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

If nobody has any more objections, I'll commit this change, then. Please let me 
know if you think otherwise.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

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


[PATCH] D103495: [static initializers] Emit global_ctors and global_dtors in reverse order when .ctors/.dtors are used.

2021-06-10 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5a1589fc6d11: [static initializers] Emit global_ctors and 
global_dtors in reverse order when . (authored by wolfgangp).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/SPARC/constructor.ll
  llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
  llvm/test/CodeGen/X86/constructor.ll

Index: llvm/test/CodeGen/X86/constructor.ll
===
--- llvm/test/CodeGen/X86/constructor.ll
+++ llvm/test/CodeGen/X86/constructor.ll
@@ -9,7 +9,7 @@
 ; RUN: llc -mtriple i586-intel-elfiamcu -use-ctors < %s | FileCheck %s --check-prefix=MCU-CTORS
 ; RUN: llc -mtriple i586-intel-elfiamcu < %s | FileCheck %s --check-prefix=MCU-INIT-ARRAY
 ; RUN: llc -mtriple x86_64-win32-gnu < %s | FileCheck --check-prefix=COFF-CTOR %s
-@llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 5, void ()* @h, i8* @v }]
+@llvm.global_ctors = appending global [5 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null}, { i32, void ()*, i8* } { i32 15, void ()* @g, i8* @v }, { i32, void ()*, i8* } { i32 5, void ()* @h, i8* @v }, { i32, void ()*, i8* } { i32 65535, void ()* @i, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @j, i8* null }]
 
 @v = weak_odr global i8 0
 
@@ -28,15 +28,27 @@
   ret void
 }
 
-; CTOR:		.section	.ctors.65520,"aGw",@progbits,v,comdat
+define void @i() {
+entry:
+  ret void
+}
+
+define void @j() {
+entry:
+  ret void
+}
+
+; CTOR:	.section	.ctors,"aw",@progbits
 ; CTOR-NEXT:	.p2align	3
-; CTOR-NEXT:	.quad	g
+; CTOR-NEXT:	.quad	j
+; CTOR-NEXT:	.quad	i
+; CTOR-NEXT:	.quad	f
 ; CTOR-NEXT:	.section	.ctors.09980,"aGw",@progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
 ; CTOR-NEXT:	.quad	h
-; CTOR-NEXT:	.section	.ctors,"aw",@progbits
+; CTOR-NEXT:	.section	.ctors.65520,"aGw",@progbits,v,comdat
 ; CTOR-NEXT:	.p2align	3
-; CTOR-NEXT:	.quad	f
+; CTOR-NEXT:	.quad	g
 
 ; INIT-ARRAY:		.section	.init_array.15,"aGw",@init_array,v,comdat
 ; INIT-ARRAY-NEXT:	.p2align	3
@@ -47,6 +59,8 @@
 ; INIT-ARRAY-NEXT:	.section	.init_array,"aw",@init_array
 ; INIT-ARRAY-NEXT:	.p2align	3
 ; INIT-ARRAY-NEXT:	.quad	f
+; INIT-ARRAY-NEXT:	.quad	i
+; INIT-ARRAY-NEXT:	.quad	j
 
 ; NACL:		.section	.init_array.15,"aGw",@init_array,v,comdat
 ; NACL-NEXT:	.p2align	2
@@ -57,6 +71,8 @@
 ; NACL-NEXT:	.section	.init_array,"aw",@init_array
 ; NACL-NEXT:	.p2align	2
 ; NACL-NEXT:	.long	f
+; NACL-NEXT:	.long	i
+; NACL-NEXT:	.long	j
 
 ; MCU-CTORS: .section.ctors,"aw",@progbits
 ; MCU-INIT-ARRAY:.section.init_array,"aw",@init_array
@@ -70,3 +86,5 @@
 ; COFF-CTOR-NEXT:	.section	.ctors,"dw"
 ; COFF-CTOR-NEXT:	.p2align	3
 ; COFF-CTOR-NEXT:	.quad	f
+; COFF-CTOR-NEXT:	.quad	i
+; COFF-CTOR-NEXT:	.quad	j
Index: llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
===
--- llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
+++ llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
@@ -3,24 +3,24 @@
 ; PR5329
 
 @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @construct_2, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @construct_3, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @construct_1, i8* null }]
-; CHECK-DEFAULT: .section.ctors.64535,"aw",@progbits
-; CHECK-DEFAULT: .long construct_1
-; CHECK-DEFAULT: .section.ctors.63535,"aw",@progbits
-; CHECK-DEFAULT: .long construct_2
 ; CHECK-DEFAULT: .section.ctors.62535,"aw",@progbits
 ; CHECK-DEFAULT: .long construct_3
+; CHECK-DEFAULT: .section.ctors.63535,"aw",@progbits
+; CHECK-DEFAULT: .long construct_2
+; CHECK-DEFAULT: .section.ctors.64535,"aw",@progbits
+; CHECK-DEFAULT: .long construct_1
 
 ; CHECK-DARWIN: .long _construct_1
 ; CHECK-DARWIN-NEXT: .long _construct_2
 ; CHECK-DARWIN-NEXT: .long _construct_3
 
 @llvm.global_dtors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @destruct_2, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @destruct_1, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @destruct_3, i8* null }]
-; CHECK-DEFAULT: .section.dtors.64535,"aw",@progbits
-; CHECK-DEFAULT: .long destruct_1
-; CHECK-DEFAULT: .section.dtors.63535,"aw",@progbits
-; CHECK-DEFAULT: .long destruct_2
 ; CHECK-DEFAULT: .section.dtors.62535,"aw",@progbits
 ; CHECK-DEFAULT: .long destruct_3
+; CHECK-DEFAULT: .section.dtors.63535,"aw",@progbits
+; CHECK-DEFAULT: .long destruct_2
+; CHECK-DEFA

[PATCH] D98300: [TLS] Initialization functions of dynamic TLS variables cannot be in a comdat (fix for PR48030)

2021-03-09 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: cfe-commits, rsmith.
wolfgangp requested review of this revision.

This is an attempt to fix PR48030.

The initialization function of dynamic TLS variables are currently placed into 
comdats (on ELF at least). The wrapper functions that are used to access these 
variables call the initializers via an alias, but in TUs where the variables 
are not used, no wrapper function (and no alias) is generated. At link time it 
is possible that an initializer function from a TU without a wrapper function 
is selected, while the wrapper is selected from a different TU. In that case, 
the alias is undefined.

A possible fix is to not place the initializer function into a comdat. This 
will lead to some duplication in the final executable, but this can be 
mitigated by the linker via --gc-sections or the like.

The fix is based on a suggestion by Andrew Ng.


https://reviews.llvm.org/D98300

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp


Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -176,8 +176,7 @@
 
 // LINUX: define internal void @[[VF_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[VF_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1VIfE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIfE1mE to i8*)
 // CHECK: %[[VF_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[VF_M_INITIALIZED]],
@@ -189,8 +188,7 @@
 
 // LINUX: define internal void @[[XF_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[XF_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1XIfE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIfE1mE to i8*)
 // CHECK: %[[XF_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[XF_M_INITIALIZED]],
@@ -277,8 +275,7 @@
 
 // LINUX: define internal void @[[V_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[V_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1VIiE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIiE1mE to i8*)
 // CHECK: %[[V_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[V_M_INITIALIZED]],
@@ -290,8 +287,7 @@
 
 // LINUX: define internal void @[[X_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[X_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1XIiE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIiE1mE to i8*)
 // CHECK: %[[X_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[X_M_INITIALIZED]],
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2385,7 +2385,10 @@
   // An inline variable's guard function is run from the per-TU
   // initialization function, not via a dedicated global ctor function, so
   // we can't put it in a comdat.
-  if (!NonTemplateInline)
+  // TLS access wrappers call the initialization function via an alias.
+  // In order to guarantee that the alias is defined, the initialization
+  // function must not be in a comdat.
+  if (!NonTemplateInline && D.getTLSKind() != VarDecl::TLS_Dynamic)
 CGF.CurFn->setComdat(C);
 } else if (CGM.supportsCOMDAT() && guard->isWeakForLinker()) {
   guard->setComdat(CGM.getModule().getOrInsertComdat(guard->getName()));


Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -176,8 +176,7 @@
 
 // LINUX: define internal void @[[VF_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[VF_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1VIfE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIfE1mE to i8*)
 // CHECK: %[[VF_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[VF_M_INITIALIZED]],
@@ -189,8 +188,7 @@
 
 // LINUX: define internal void @[[XF_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[XF_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1XIfE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIfE1mE to i8*)
 // CHECK: %[[XF_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[XF_M_INITIALIZED]],
@@ -277,8 +275,7 @@
 
 // LINUX: define internal void @[[V_M_INIT]]()
 // DARWIN: define internal cxx_fast_tlscc void @[[V_M_INIT]]()
-// LINUX-SAME: comdat($_ZN1VIiE1mE)
-// DARWIN-NOT: comdat
+// CHECK-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIiE1mE to i8*)
 // CHECK: %[[V_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[V_M_INITI

[PATCH] D131986: [inlining] Add a clang option to control inlining of functions based on stack size

2022-08-16 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: mtrofin, aeubanks.
Herald added a project: All.
wolfgangp requested review of this revision.
Herald added a subscriber: MaskRay.

Adding -finline-max-stacksize= to clang. This generates the function 
attribute` inline-max-stacksize` (introduced in D129904 
, suppressing inlining of functions with 
stack sizes exceeding a specified limit.


https://reviews.llvm.org/D131986

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/inline-stacksize.c


Index: clang/test/CodeGen/inline-stacksize.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-stacksize.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | 
FileCheck %s
+
+void foo() {}
+
+// CHECK: define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
+// CHECK: attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6592,6 +6592,8 @@
 InlineArg->render(Args, CmdArgs);
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
+
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or just assume that all languages do.
   bool HaveModules =
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2372,6 +2372,9 @@
   if (getLangOpts().OpenMP && FD->hasAttr())
 getOpenMPRuntime().emitDeclareSimdFunction(FD, F);
 
+  if (CodeGenOpts.InlineMaxStackSize != UINT_MAX)
+F->addFnAttr("inline-max-stacksize", 
llvm::utostr(CodeGenOpts.InlineMaxStackSize));
+
   if (const auto *CB = FD->getAttr()) {
 // Annotate the callback behavior as metadata:
 //  - The callback callee (as argument number).
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1985,6 +1985,11 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+def finline_max_stacksize_EQ
+: Joined<["-"], "finline-max-stacksize=">,
+  Group, Flags<[CoreOption, CC1Option]>,
+  HelpText<"Suppress inlining of functions whose stack size exceeds the 
given value">,
+  MarshallingInfoInt, "UINT_MAX">;
 defm jmc : BoolFOption<"jmc",
   CodeGenOpts<"JMCInstrument">, DefaultFalse,
   PosFlag,
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -399,6 +399,9 @@
 /// The kind of inlining to perform.
 ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)
 
+/// The maximum stack size a function can have to be considered for inlining.
+VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX)
+
 // Vector functions library to use.
 ENUM_CODEGENOPT(VecLib, VectorLibrary, 3, NoLibrary)
 
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -945,6 +945,10 @@
 
 Inline functions which are (explicitly or implicitly) marked inline
 
+.. option:: -finline-max-stacksize=
+
+Suppress inlining of functions with a stacksize larger than  bytes.
+
 .. option:: -fno-legacy-pass-manager, -fexperimental-new-pass-manager
 
 .. option:: -fno-sanitize-ignorelist, -fno-sanitize-blacklist


Index: clang/test/CodeGen/inline-stacksize.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-stacksize.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | FileCheck %s
+
+void foo() {}
+
+// CHECK: define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
+// CHECK: attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6592,6 +6592,8 @@
 InlineArg->render(Args, CmdArgs);
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
+
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or just

[PATCH] D131986: [inlining] Add a clang option to control inlining of functions based on stack size

2022-08-18 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8564e2fea559: [Inlining] Add a clang option to limit 
inlining of functions (authored by wolfgangp).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D131986?vs=453079&id=453748#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131986/new/

https://reviews.llvm.org/D131986

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/inline-stacksize.c


Index: clang/test/CodeGen/inline-stacksize.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-stacksize.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | FileCheck %s --check-prefixes NOOPT
+// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | 
FileCheck %s --check-prefix OPT
+
+void foo() {}
+
+// NOOPT-NOT: inline-max-stacksize
+// OPT:   define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
+// OPT:   attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6592,6 +6592,8 @@
 InlineArg->render(Args, CmdArgs);
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
+
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or just assume that all languages do.
   bool HaveModules =
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2372,6 +2372,9 @@
   if (getLangOpts().OpenMP && FD->hasAttr())
 getOpenMPRuntime().emitDeclareSimdFunction(FD, F);
 
+  if (CodeGenOpts.InlineMaxStackSize != UINT_MAX)
+F->addFnAttr("inline-max-stacksize", 
llvm::utostr(CodeGenOpts.InlineMaxStackSize));
+
   if (const auto *CB = FD->getAttr()) {
 // Annotate the callback behavior as metadata:
 //  - The callback callee (as argument number).
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1985,6 +1985,11 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+def finline_max_stacksize_EQ
+: Joined<["-"], "finline-max-stacksize=">,
+  Group, Flags<[CoreOption, CC1Option]>,
+  HelpText<"Suppress inlining of functions whose stack size exceeds the 
given value">,
+  MarshallingInfoInt, "UINT_MAX">;
 defm jmc : BoolFOption<"jmc",
   CodeGenOpts<"JMCInstrument">, DefaultFalse,
   PosFlag,
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -399,6 +399,9 @@
 /// The kind of inlining to perform.
 ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)
 
+/// The maximum stack size a function can have to be considered for inlining.
+VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX)
+
 // Vector functions library to use.
 ENUM_CODEGENOPT(VecLib, VectorLibrary, 3, NoLibrary)
 
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -945,6 +945,10 @@
 
 Inline functions which are (explicitly or implicitly) marked inline
 
+.. option:: -finline-max-stacksize=
+
+Suppress inlining of functions with a stacksize larger than  bytes.
+
 .. option:: -fno-legacy-pass-manager, -fexperimental-new-pass-manager
 
 .. option:: -fno-sanitize-ignorelist, -fno-sanitize-blacklist


Index: clang/test/CodeGen/inline-stacksize.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-stacksize.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | FileCheck %s --check-prefixes NOOPT
+// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | FileCheck %s --check-prefix OPT
+
+void foo() {}
+
+// NOOPT-NOT: inline-max-stacksize
+// OPT:   define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
+// OPT:   attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- cla

[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-30 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

covered.cpp and uar.cpp seem to fail on ubuntu bots here 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136078/new/

https://reviews.llvm.org/D136078

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


[PATCH] D39396: Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.

2017-10-27 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.

The problem in PRR33930  comes 
about because clang is cloning a function (to generate varargs thunks) before 
all the Metadata nodes are resolved. The value mapper, which is used by the 
cloner to deal with Medatdata nodes, asserts when it encounters temporary 
otherwise unresolved nodes.

Ideally we would improve varargs thunk generation to not use cloning, but in 
the meantime the fix I'm proposing here is to clone the function's DISubprogram 
node explicitly (the verifier insists on ever function having its own). The 
cloned node is then entered into the value map that is supplied to the cloner 
(which feeds it to the value mapper). This has the effect that the value mapper 
does not look any further when it's trying to map all the rest of the MD nodes 
and therefore does not run into any temporary MD nodes that still exist at than 
point (in the form of forward references to struct declarations).

Furthermore, there are unresolved DILocalVariable nodes referenced by dbg.value 
intrinsics, which causes the value mapper to assert when it is remapping the 
function's instructions' MDNodes. These nodes are normally resolved at the 
catch-all at the end of the module, but they can be safely resolved here, since 
they won't change any more. The value mapper will safely clone them (if 
necessary) and remap their operand nodes during the cloning process.

The only drawback is that the cloned function's (the thunk's) 
DILocalVariableNodes will not appear in the newly cloned DISubprogram's node 
variable list. Instead, the new node points to the original function's variable 
list. However, since the only difference between the original function and the 
thunk is the this-ptr adjustment, the resulting debug information is correct, 
at least in the test cases I have looked at.

Unfortunately this isn't the cleanest solution in the world. A different 
approach, deferring the creation of varargs thunks until the end of the module, 
is more invasive. The approach proposed here  
duplicates Metadata. If anybody has any better ideas, please let me know.

Note that there are two patches here. One is an llvm patch that is NFC (making 
resolve() public) while the main one is a clang patch.


https://reviews.llvm.org/D39396

Files:
  include/llvm/IR/Metadata.h
  lib/CodeGen/CGVTables.cpp
  test/CodeGenCXX/tmp-md-nodes1.cpp
  test/CodeGenCXX/tmp-md-nodes2.cpp

Index: test/CodeGenCXX/tmp-md-nodes2.cpp
===
--- test/CodeGenCXX/tmp-md-nodes2.cpp
+++ test/CodeGenCXX/tmp-md-nodes2.cpp
@@ -0,0 +1,33 @@
+// REQUIRES: asserts
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s
+
+// This test simply checks that the varargs thunk is created. The failing test
+// case asserts.
+
+typedef signed char __int8_t;
+typedef int BOOL;
+class CMsgAgent;
+
+class CFs {
+public:
+  typedef enum {} CACHE_HINT;
+  virtual BOOL ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) ;
+};
+
+typedef struct {} _Lldiv_t;
+
+class CBdVfs {
+public:
+  virtual ~CBdVfs( ) {}
+};
+
+class CBdVfsImpl : public CBdVfs, public CFs {
+  BOOL ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... );
+};
+
+BOOL CBdVfsImpl::ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) {
+  return true;
+}
+
+// CHECK: define {{.*}} @_ZThn8_N10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz(
Index: test/CodeGenCXX/tmp-md-nodes1.cpp
===
--- test/CodeGenCXX/tmp-md-nodes1.cpp
+++ test/CodeGenCXX/tmp-md-nodes1.cpp
@@ -0,0 +1,18 @@
+// REQUIRES: asserts
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s
+
+// This test simply checks that the varargs thunk is created. The failing test
+// case asserts.
+
+struct Alpha {
+  virtual void bravo(...);
+};
+struct Charlie {
+  virtual ~Charlie() {}
+};
+struct CharlieImpl : Charlie, Alpha {
+  void bravo(...) {}
+} delta;
+
+// CHECK: define {{.*}} void @_ZThn8_N11CharlieImpl5bravoEz(
Index: lib/CodeGen/CGVTables.cpp
===
--- lib/CodeGen/CGVTables.cpp
+++ lib/CodeGen/CGVTables.cpp
@@ -14,11 +14,12 @@
 #include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
-#include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/CodeGenOptions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include 
@@ -122,6 +123,35 @@
   return RValue::get(ReturnValue);
 }
 
+// This function clones a function's DISubprogram node and enters i

[PATCH] D39396: Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.

2017-10-30 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp updated this revision to Diff 120876.
wolfgangp added a comment.

Incorporated review comments.


https://reviews.llvm.org/D39396

Files:
  include/llvm/IR/Metadata.h
  lib/CodeGen/CGVTables.cpp
  test/CodeGenCXX/tmp-md-nodes1.cpp
  test/CodeGenCXX/tmp-md-nodes2.cpp

Index: test/CodeGenCXX/tmp-md-nodes2.cpp
===
--- test/CodeGenCXX/tmp-md-nodes2.cpp
+++ test/CodeGenCXX/tmp-md-nodes2.cpp
@@ -0,0 +1,33 @@
+// REQUIRES: asserts
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s
+
+// This test simply checks that the varargs thunk is created. The failing test
+// case asserts.
+
+typedef signed char __int8_t;
+typedef int BOOL;
+class CMsgAgent;
+
+class CFs {
+public:
+  typedef enum {} CACHE_HINT;
+  virtual BOOL ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) ;
+};
+
+typedef struct {} _Lldiv_t;
+
+class CBdVfs {
+public:
+  virtual ~CBdVfs( ) {}
+};
+
+class CBdVfsImpl : public CBdVfs, public CFs {
+  BOOL ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... );
+};
+
+BOOL CBdVfsImpl::ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) {
+  return true;
+}
+
+// CHECK: define {{.*}} @_ZThn8_N10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz(
Index: test/CodeGenCXX/tmp-md-nodes1.cpp
===
--- test/CodeGenCXX/tmp-md-nodes1.cpp
+++ test/CodeGenCXX/tmp-md-nodes1.cpp
@@ -0,0 +1,18 @@
+// REQUIRES: asserts
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s
+
+// This test simply checks that the varargs thunk is created. The failing test
+// case asserts.
+
+struct Alpha {
+  virtual void bravo(...);
+};
+struct Charlie {
+  virtual ~Charlie() {}
+};
+struct CharlieImpl : Charlie, Alpha {
+  void bravo(...) {}
+} delta;
+
+// CHECK: define {{.*}} void @_ZThn8_N11CharlieImpl5bravoEz(
Index: lib/CodeGen/CGVTables.cpp
===
--- lib/CodeGen/CGVTables.cpp
+++ lib/CodeGen/CGVTables.cpp
@@ -14,11 +14,12 @@
 #include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
-#include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/CodeGenOptions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include 
@@ -122,6 +123,33 @@
   return RValue::get(ReturnValue);
 }
 
+/// This function clones a function's DISubprogram node and enters it into 
+/// a value map with the intent that the map can be utilized by the cloner
+/// to short-circuit Metadata node mapping.
+/// Furthermore, the function resolves any DILocalVariable nodes referenced
+/// by dbg.value intrinsics so they can be properly mapped during cloning.
+static void resolveTopLevelMetadata(llvm::Function *Fn,
+llvm::ValueToValueMapTy &VMap) {
+  // Clone the DISubprogram node and put it into the Value map.
+  auto *DIS = Fn->getSubprogram();
+  if (!DIS)
+return;
+  auto *NewDIS = DIS->replaceWithDistinct(DIS->clone());
+  VMap.MD()[DIS].reset(NewDIS);
+
+  // Find all llvm.dbg.declare intrinsics and resolve the DILocalVariable nodes
+  // they are referencing.
+  for (auto &BB : Fn->getBasicBlockList()) {
+for (auto &I : BB) {
+  if (auto *DII = dyn_cast(&I)) {
+auto *DILocal = DII->getVariable();
+if (!DILocal->isResolved())
+  DILocal->resolve();
+  }
+}
+  }
+}
+
 // This function does roughly the same thing as GenerateThunk, but in a
 // very different way, so that va_start and va_end work correctly.
 // FIXME: This function assumes "this" is the first non-sret LLVM argument of
@@ -154,6 +182,10 @@
 
   // Clone to thunk.
   llvm::ValueToValueMapTy VMap;
+
+  // We are cloning a function while some Metadata nodes are still unresolved.
+  // Ensure that the value mapper does not encounter any of them.
+  resolveTopLevelMetadata(BaseFn, VMap);
   llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap);
   Fn->replaceAllUsesWith(NewFn);
   NewFn->takeName(Fn);
Index: include/llvm/IR/Metadata.h
===
--- include/llvm/IR/Metadata.h
+++ include/llvm/IR/Metadata.h
@@ -958,6 +958,9 @@
   /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
   void resolveCycles();
 
+  /// Resolve a unique, unresolved node.
+  void resolve();
+
   /// \brief Replace a temporary node with a permanent one.
   ///
   /// Try to create a uniqued version of \c N -- in place, if possible -- and
@@ -1009,9 +1012,6 @@
 private:
   void handleChangedOperand(void *Ref, Metadata *New);
 
-  /// Resolve a unique, unresolve

[PATCH] D39396: Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.

2017-10-30 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp marked 5 inline comments as done.
wolfgangp added inline comments.



Comment at: lib/CodeGen/CGVTables.cpp:143
+  for (llvm::Function::iterator BB = Fn->begin(), E = Fn->end(); BB != E;
+   ++BB) {
+for (llvm::Instruction &I : *BB) {

aprantl wrote:
> does this work?
> `for (auto &BB : Fn->getBasicBlockList())`
Yep, thanks. I wasn't aware of this.


https://reviews.llvm.org/D39396



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


[PATCH] D39396: Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.

2017-10-30 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp marked an inline comment as done.
wolfgangp added a comment.

In https://reviews.llvm.org/D39396#911306, @aprantl wrote:

> This works for me, but as I said previously, perhaps we can get by with just 
> not having any variables described in the thunk to further simplify the code.


I remember, but this "thunk" isn't really a thunk in the sense that it makes 
some adjustments and then branches to (or calls) the real function. It 
effectively becomes the real function (hence the cloning), so if you drop the 
variables you lose the ability to debug it.


https://reviews.llvm.org/D39396



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


[PATCH] D39396: Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.

2017-10-31 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL317047: Fix for PR33930. Short-circuit metadata mapping when 
cloning a varargs thunk. (authored by wolfgangp).

Changed prior to commit:
  https://reviews.llvm.org/D39396?vs=120876&id=121078#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39396

Files:
  cfe/trunk/lib/CodeGen/CGVTables.cpp
  cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
  cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp

Index: cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp
===
--- cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp
+++ cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp
@@ -0,0 +1,33 @@
+// REQUIRES: asserts
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s
+
+// This test simply checks that the varargs thunk is created. The failing test
+// case asserts.
+
+typedef signed char __int8_t;
+typedef int BOOL;
+class CMsgAgent;
+
+class CFs {
+public:
+  typedef enum {} CACHE_HINT;
+  virtual BOOL ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) ;
+};
+
+typedef struct {} _Lldiv_t;
+
+class CBdVfs {
+public:
+  virtual ~CBdVfs( ) {}
+};
+
+class CBdVfsImpl : public CBdVfs, public CFs {
+  BOOL ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... );
+};
+
+BOOL CBdVfsImpl::ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) {
+  return true;
+}
+
+// CHECK: define {{.*}} @_ZThn8_N10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz(
Index: cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
===
--- cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
+++ cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
@@ -0,0 +1,18 @@
+// REQUIRES: asserts
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s
+
+// This test simply checks that the varargs thunk is created. The failing test
+// case asserts.
+
+struct Alpha {
+  virtual void bravo(...);
+};
+struct Charlie {
+  virtual ~Charlie() {}
+};
+struct CharlieImpl : Charlie, Alpha {
+  void bravo(...) {}
+} delta;
+
+// CHECK: define {{.*}} void @_ZThn8_N11CharlieImpl5bravoEz(
Index: cfe/trunk/lib/CodeGen/CGVTables.cpp
===
--- cfe/trunk/lib/CodeGen/CGVTables.cpp
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp
@@ -14,11 +14,12 @@
 #include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
-#include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/CodeGenOptions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include 
@@ -122,6 +123,33 @@
   return RValue::get(ReturnValue);
 }
 
+/// This function clones a function's DISubprogram node and enters it into 
+/// a value map with the intent that the map can be utilized by the cloner
+/// to short-circuit Metadata node mapping.
+/// Furthermore, the function resolves any DILocalVariable nodes referenced
+/// by dbg.value intrinsics so they can be properly mapped during cloning.
+static void resolveTopLevelMetadata(llvm::Function *Fn,
+llvm::ValueToValueMapTy &VMap) {
+  // Clone the DISubprogram node and put it into the Value map.
+  auto *DIS = Fn->getSubprogram();
+  if (!DIS)
+return;
+  auto *NewDIS = DIS->replaceWithDistinct(DIS->clone());
+  VMap.MD()[DIS].reset(NewDIS);
+
+  // Find all llvm.dbg.declare intrinsics and resolve the DILocalVariable nodes
+  // they are referencing.
+  for (auto &BB : Fn->getBasicBlockList()) {
+for (auto &I : BB) {
+  if (auto *DII = dyn_cast(&I)) {
+auto *DILocal = DII->getVariable();
+if (!DILocal->isResolved())
+  DILocal->resolve();
+  }
+}
+  }
+}
+
 // This function does roughly the same thing as GenerateThunk, but in a
 // very different way, so that va_start and va_end work correctly.
 // FIXME: This function assumes "this" is the first non-sret LLVM argument of
@@ -154,6 +182,10 @@
 
   // Clone to thunk.
   llvm::ValueToValueMapTy VMap;
+
+  // We are cloning a function while some Metadata nodes are still unresolved.
+  // Ensure that the value mapper does not encounter any of them.
+  resolveTopLevelMetadata(BaseFn, VMap);
   llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap);
   Fn->replaceAllUsesWith(NewFn);
   NewFn->takeName(Fn);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145970: [MSVC][PS][dllexport/dllimport] Propagate a dllexport/dllimport attribute to template baseclasses

2023-03-14 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D145970#4192679 , @hans wrote:

> LGTM
>
> I've always found this to be an interesting behavior, and I'm guessing you 
> found some code where it does matter :)

Well, one of our customers did, anyway. The code in the description is the 
distilled version of it.

Thank you for the review!




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2612
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+  Context.getTargetInfo().getTriple().isPS()) {
 if (Attr *ClassAttr = getDLLAttr(Class)) {

hans wrote:
> Would using `getTargetInfo().shouldDLLImportComdatSymbols()` be appropriate 
> here now?
Perhaps. It would affect the Windows/Itanium platform in addition to what's 
here, and I wasn't sure if that was desirable.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145970/new/

https://reviews.llvm.org/D145970

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


[PATCH] D145970: [MSVC][PS][dllexport/dllimport] Propagate a dllexport/dllimport attribute to template baseclasses

2023-03-15 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG634430d5857e: [MSVC][dllexport/dllimport] Propagate a 
dllexport/dllimport attribute to… (authored by wolfgangp).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145970/new/

https://reviews.llvm.org/D145970

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -1557,7 +1557,7 @@
 class __declspec(dllexport) DerivedFromTemplateB2 : public ClassTemplate {};
 
 template  struct ExplicitlySpecializedTemplate { void func() {} };
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-note@+2{{class template 'ExplicitlySpecializedTemplate' was explicitly specialized here}}
 #endif
 template <> struct ExplicitlySpecializedTemplate { void func() {} };
@@ -1567,7 +1567,7 @@
 template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate { void func() {} };
 
 template  struct ExplicitlyInstantiatedTemplate { void func() {} };
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-note@+2{{class template 'ExplicitlyInstantiatedTemplate' was instantiated here}}
 #endif
 template struct ExplicitlyInstantiatedTemplate;
@@ -1576,7 +1576,7 @@
 template  struct ExplicitlyImportInstantiatedTemplate { void func() {} };
 template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate;
 
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-warning@+3{{propagating dll attribute to explicitly specialized base class template without dll attribute is not supported}}
 // expected-note@+2{{attribute is here}}
 #endif
@@ -1588,7 +1588,7 @@
 // Base class already specialized with import attribute.
 struct __declspec(dllimport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate {};
 
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-warning@+3{{propagating dll attribute to already instantiated base class template without dll attribute is not supported}}
 // expected-note@+2{{attribute is here}}
 #endif
Index: clang/test/SemaCXX/dllexport.cpp
===
--- clang/test/SemaCXX/dllexport.cpp
+++ clang/test/SemaCXX/dllexport.cpp
@@ -4,8 +4,8 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI  %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI  %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI  %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI  %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -

[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

2023-03-17 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: hans, probinson, mstorsjo.
Herald added a project: All.
wolfgangp requested review of this revision.

This replaces D145271 .

Rather than coercing classes with UniqueExternalLInkage to ExternalLinkage as 
proposed in D145271 , this patch suggests to 
simply allow the dllexport/dllimport attributes for classes that exhibit 
UniqueExternalLinkage, which includes instantiations of template classes where 
the template parameters are local classes or classes in anonymous namespaces:

  template 
  class __declspec(dllimport) A {};
  
  void func()
  {
class B : public A {};
  }
  
  namespace {
class C : public A {};
  }

In D145271  it was suggested that we drop the 
attribute in such contexts, and this is effectively what happens. The compiler 
does not produce any exported definitions (or import any symbols) for such 
classes. The patch is simply to suppress the diagnostic for MSVC mode and 
Playstation.

I have not changed the behavior of the Windows/Itanium triple since I wasn't 
sure if this was desirable.


https://reviews.llvm.org/D146338

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -60,7 +60,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -71,7 +71,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -82,7 +82,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -93,7 +93,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -184,7 +184,7 @@
 #endif
 

[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

2023-03-22 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D146338#4206222 , @hans wrote:

>> In D145271  it was suggested that we drop 
>> the attribute in such contexts, and this is effectively what happens. The 
>> compiler does not produce any exported definitions (or import any symbols) 
>> for such classes. The patch is simply to suppress the diagnostic for MSVC 
>> mode and Playstation.



> With the current patch, we still end up with the attribute on the base class 
> in the AST. Also, does this make the compiler accept dllexport of classes in 
> anonymous namespaces? I'm not sure we want that.
> Is it not possible to check the linkage and bail out in 
> `Sema::propagateDLLAttrToBaseClassTemplate` instead?

Actually, the compiler would (still) not accept explicit dll* attributes on the 
class in either function scopes or anon namespaces. This case is about classes 
with internal linkage deriving from exported/imported template classes that 
have been instantiated with a class with internal linkage. In the description, 
the classes B and C are such classes. They both derive from A, which is 
imported and instantiated with B and C as template parameters.

However, I think I have found a way to drop the attribute. I think it's 
equivalent to just suppressing the error message, but it's probably cleaner.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146338/new/

https://reviews.llvm.org/D146338

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


[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

2023-03-22 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp updated this revision to Diff 507428.
wolfgangp added a comment.

Instead of suppressing the error message we drop the dllimport/dllexport 
attribute when we see that a class has UniqueExternal linkage. This will 
suppress exporting or importing any members, which could not be accessed 
outside the TU anyway.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146338/new/

https://reviews.llvm.org/D146338

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -60,7 +60,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -71,7 +71,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -82,7 +82,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -93,7 +93,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -184,7 +184,7 @@
 #endif
 template 
 __declspec(dllimport) extern int ExternVarTmplDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+5{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+3{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -197,7 +197,7 @@
 #endif
 template 
 __declspec(dllimport) int VarTmplDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+5{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+3{{'Va

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-24 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D145803#4219894 , @probinson wrote:

> This is pretty different from the "always desugar to the canonical type" 
> habit that has always been in place. Sony has done some downstream things to 
> try to work around that in the past. @wolfgangp will remember it better than 
> I do, but I think we make some effort to preserve the type-as-written. This 
> goes in completely the other direction.

The Sony solution does not rely on a user-specified attribute, but uniformly 
preserves all typedefs, though only in template argument types. Similar to this 
solution, it adds a second type to keep track of the preferred type, though it 
does so in the TemplateArgument structure as a separate QualType. A client can 
then either print the preferred type or the canonical type, depending on a 
printing policy, which is controlled by an option. This leads to a similar 
result in the resulting DWARF, i.e. the DW_AT_type node gets the preferred type 
string. The preferred type can also be used for diagnostic messages.




Comment at: clang/lib/CodeGen/CGDebugInfo.h:289
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,

This comment seems a bit garbled. Also, this is just a helper function, no?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145803/new/

https://reviews.llvm.org/D145803

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


[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

2023-03-27 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp updated this revision to Diff 508747.
wolfgangp marked an inline comment as done.
wolfgangp added a comment.

Added 2 test cases that check that dll{ex,im}ported classes that are 
instantiated with classes with internal linkage as template arguments are not 
exported or imported.

Had to place them into separate files, since they are negative tests and did 
not fit well into dllexport.cpp and dllimport.cpp


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146338/new/

https://reviews.llvm.org/D146338

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/dllexport-unique-external.cpp
  clang/test/CodeGenCXX/dllimport-unique-external.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -60,7 +60,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -71,7 +71,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -82,7 +82,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -93,7 +93,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -184,7 +184,7 @@
 #endif
 template 
 __declspec(dllimport) extern int ExternVarTmplDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+5{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+3{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -197,7 +197,7 @@
 #endif
 template 
 __declspec(dllimport) int VarTmplDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || de

[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

2023-03-27 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added inline comments.



Comment at: clang/test/SemaCXX/dllexport.cpp:437
 
+class Base {};
+class __declspec(dllexport) ExportedClass {};

hans wrote:
> Is this one used somewhere?
It's not. Thanks for finding it.



Comment at: clang/test/SemaCXX/dllexport.cpp:439
+class __declspec(dllexport) ExportedClass {};
+class __declspec(dllimport) ImportedClass {};
+

hans wrote:
> Just to double check: this case (non-template base class) worked before this 
> patch too, right?
Right. I just added the case for good measure. Our case is about allowing a 
dll{ex,im}ported class that is called into existence, so to speak (i.e. 
instantiated), with template arguments that cause it to have non-external 
linkage. There is no question about the linkage of the non-template base 
classes. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146338/new/

https://reviews.llvm.org/D146338

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


[PATCH] D145271: [MSVC compatibility][DLLEXPORT/DLLIMPORT] Allow dllexport/dllimport for local classes

2023-03-06 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D145271#4171267 , @hans wrote:

> Interesting! Do you have an example where this (local dllexport/import 
> classes) comes up in practice?

A customer complained about the following code (I'm obscuring the class names) 
compiling with MSVC but
rejected by clang:

  template 
  class __declspec(dllimport) A
  {
  };
  
  void func()
  {
// local class with internal linkage
class B: public A
{
};
  }

The code derives from various instantiations of A in several contexts and it's 
causing extra work for the customer to do something different in a local 
context.
While I do agree that clang has it right I think this is more a case of 
bug-compatibility with MSVC.

> MSVC will also allow the following:
>
>   namespace {
>   struct __declspec(dllexport) T {
>   void foo();
>   };
>   }
>
> whereas Clang will not, and I think Clang is making the right call there.

Again, I do think clang makes the right call in all of these cases, but it's 
about MSVC compatibility, for better or worse.
I did also look at the anonymous namespace case above, but that's a bit more 
complicated, so I didn't address it this time.




Comment at: clang/lib/AST/Decl.cpp:492
+  // classes with dllexport/dllimport attributes.
+  if (spec->getASTContext().getTargetInfo().shouldDLLImportComdatSymbols())
+if (spec->hasAttr() || spec->hasAttr())

hans wrote:
> We usually check ASTContext's `getTargetInfo().getCXXABI().isMicrosoft()`
That would not work for Playstation, since it's not following the Microsoft 
ABI. The call to shouldDLLImport...(), checks the triple (it includes Windows 
Itanium, Windows MSVC and PS).
Perhaps we need a less obscure predicate to indicate source compatibility with 
MSVC as opposed to MS ABI compatibility.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145271/new/

https://reviews.llvm.org/D145271

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


[PATCH] D145271: [MSVC compatibility][DLLEXPORT/DLLIMPORT] Allow dllexport/dllimport for local classes

2023-03-08 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

> It still seems like the export/import there is an accident since 
> `Base` can't really be referenced from outside the file anyway.
>
> Perhaps rather than giving `Base` external linkage to allow it to 
> be imported/exported, the better fix would be to drop its dllimport/export 
> attribute when instantiated with a local type?

I like it. However, we would then not match MSVC's behavior in generating 
external definitions for the class (useless as they are). I suppose that's OK.

But on another note, would we then abandon matching MSVC on the following?

  void func() {
class __declspec(dllexport) A {
};
  }

This is currently accepted by MSVC, though arguably much less defensible than 
the above example.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145271/new/

https://reviews.llvm.org/D145271

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


[PATCH] D145970: [MSVC][PS][dllexport/dllimport] Propagate a dllexport/dllimport attribute to template baseclasses

2023-03-13 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: probinson, bd1976llvm, hans, mstorsjo.
Herald added a project: All.
wolfgangp requested review of this revision.

For the Playstation platform, mimic MSVC in propagating dllexport/dllimport 
attributes
to an instantiated template base class.

This is particularly relevant in cases where the base class has static members 
that need to be shared between all instantiations:

  template 
  class Base
  {
  public:
static unsigned int& foo()
{
  static unsigned int S = 0x;
  return S;
}
  };
  
  class __declspec(dllexport) A : public Base
  {
  };

BTW, this is unrelated to D145271 


https://reviews.llvm.org/D145970

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -1557,7 +1557,7 @@
 class __declspec(dllexport) DerivedFromTemplateB2 : public ClassTemplate {};
 
 template  struct ExplicitlySpecializedTemplate { void func() {} };
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-note@+2{{class template 'ExplicitlySpecializedTemplate' was explicitly specialized here}}
 #endif
 template <> struct ExplicitlySpecializedTemplate { void func() {} };
@@ -1567,7 +1567,7 @@
 template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate { void func() {} };
 
 template  struct ExplicitlyInstantiatedTemplate { void func() {} };
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-note@+2{{class template 'ExplicitlyInstantiatedTemplate' was instantiated here}}
 #endif
 template struct ExplicitlyInstantiatedTemplate;
@@ -1576,7 +1576,7 @@
 template  struct ExplicitlyImportInstantiatedTemplate { void func() {} };
 template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate;
 
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-warning@+3{{propagating dll attribute to explicitly specialized base class template without dll attribute is not supported}}
 // expected-note@+2{{attribute is here}}
 #endif
@@ -1588,7 +1588,7 @@
 // Base class already specialized with import attribute.
 struct __declspec(dllimport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate {};
 
-#ifdef MS
+#if defined(MS) || defined(PS)
 // expected-warning@+3{{propagating dll attribute to already instantiated base class template without dll attribute is not supported}}
 // expected-note@+2{{attribute is here}}
 #endif
Index: clang/test/SemaCXX/dllexport.cpp
===
--- clang/test/SemaCXX/dllexport.cpp
+++ clang/test/SemaCXX/dllexport.cpp
@@ -4,8 +4,8 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI  %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI  %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI  %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps

[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

2023-03-29 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG477f9cea77e6: [MSCV][dllexport/dllimport][PS] Allow 
UniqueExternal linkage classes with… (authored by wolfgangp).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146338/new/

https://reviews.llvm.org/D146338

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/dllexport-unique-external.cpp
  clang/test/CodeGenCXX/dllimport-unique-external.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,9 +5,9 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -60,7 +60,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -71,7 +71,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -82,7 +82,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -93,7 +93,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -184,7 +184,7 @@
 #endif
 template 
 __declspec(dllimport) extern int ExternVarTmplDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+5{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+3{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -197,7 +197,7 @@
 #endif
 template 
 __declspec(dllimport) int VarTmplDeclInit; // expected-note{{previous declaration is here}}
-#if defined(MS) || defined(WI)
+#if defined(MS) || defined(WI) || defined(PS)
 // expected-warning@+5{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: '

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-04 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

> @probinson Sounds like Sony's solution also changes the `DW_AT_type` to a 
> non-canonical form. Do you still have concerns with the direction of this 
> patch? Would it cause any problems for you downstream?

Sorry for the late reply. Looking at the patch I don't think it will cause us 
any trouble. The 2 solutions should be able to live happily side by side.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145803/new/

https://reviews.llvm.org/D145803

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


[PATCH] D140123: [TLS] Clamp the alignment of TLS global variables if required by the target

2023-02-08 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d07e0448e38: [TLS]: Clamp the alignment of TLS global 
variables if required by the target (authored by wolfgangp).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140123/new/

https://reviews.llvm.org/D140123

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/tls-maxalign-modflag.c
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Module.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/CodeGen/X86/tls-align.ll

Index: llvm/test/CodeGen/X86/tls-align.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/tls-align.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86-registered-target
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+
+%class.Arr = type <{ [160 x %class.Derived], i32, [4 x i8] }>
+%class.Derived = type { %class.Base, ptr }
+%class.Base = type { ptr }
+
+@array = hidden thread_local global %class.Arr zeroinitializer, align 32
+; CHECK: @array{{.*}}align 32
+
+@_ZTV7Derived = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr null, ptr null] }, align 8
+
+define internal fastcc void @foo() unnamed_addr {
+entry:
+  store <8 x ptr> , ptr @array, align 32
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"MaxTLSAlign", i32 256}
Index: llvm/lib/Transforms/Utils/Local.cpp
===
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -1423,6 +1423,12 @@
 if (!GO->canIncreaseAlignment())
   return CurrentAlign;
 
+if (GO->isThreadLocal()) {
+  unsigned MaxTLSAlign = GO->getParent()->getMaxTLSAlignment() / CHAR_BIT;
+  if (MaxTLSAlign && PrefAlign > Align(MaxTLSAlign))
+PrefAlign = Align(MaxTLSAlign);
+}
+
 GO->setAlignment(PrefAlign);
 return PrefAlign;
   }
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -746,6 +746,13 @@
   return 0;
 }
 
+unsigned Module::getMaxTLSAlignment() const {
+  Metadata *MD = getModuleFlag("MaxTLSAlign");
+  if (auto *CI = mdconst::dyn_extract_or_null(MD))
+return CI->getZExtValue();
+  return 0;
+}
+
 void Module::setOverrideStackAlignment(unsigned Align) {
   addModuleFlag(ModFlagBehavior::Error, "override-stack-alignment", Align);
 }
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -923,6 +923,8 @@
   unsigned getOverrideStackAlignment() const;
   void setOverrideStackAlignment(unsigned Align);
 
+  unsigned getMaxTLSAlignment() const;
+
   /// @name Utility functions for querying and setting the build SDK version
   /// @{
 
Index: clang/test/CodeGen/tls-maxalign-modflag.c
===
--- /dev/null
+++ clang/test/CodeGen/tls-maxalign-modflag.c
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+
+// Test that we get the module flag TLSMaxAlign on the PS platforms.
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps5 -S -emit-llvm -o - %s | FileCheck %s
+
+int main(void) {
+  return 0;
+}
+
+// CHECK-DAG: ![[MDID:[0-9]+]] = !{i32 1, !"MaxTLSAlign", i32 256}
+// CHECK-DAG: llvm.module.flags = {{.*}}![[MDID]]
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -947,6 +947,10 @@
   if (getCodeGenOpts().SkipRaxSetup)
 getModule().addModuleFlag(llvm::Module::Override, "SkipRaxSetup", 1);
 
+  if (getContext().getTargetInfo().getMaxTLSAlign())
+getModule().addModuleFlag(llvm::Module::Error, "MaxTLSAlign",
+  getContext().getTargetInfo().getMaxTLSAlign());
+
   getTargetCodeGenInfo().emitTargetMetadata(*this, MangledDeclNames);
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140123: [TLS] Clamp the alignment of TLS global variables if required by the target

2023-02-13 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D140123#4123625 , @efriedma wrote:

> In D140123#4113536 , @efriedma 
> wrote:
>
>> Missing LangRef change?
>
> Ping?

Added a LangRef entry with 776b7499ea813c06b 
. There 
seems to be no separate section for module flags, so I added it to the entry on 
global variables.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140123/new/

https://reviews.llvm.org/D140123

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


[PATCH] D140123: [TLS] Clamp the alignment of TLS global variables if required by the target

2023-02-13 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

In D140123#4124512 , @efriedma wrote:

>> no separate section for module flags
>
> https://llvm.org/docs/LangRef.html#module-flags-metadata ?

That seems to be the description of the metadata for module flags, not the 
documentation of the flags themselves.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140123/new/

https://reviews.llvm.org/D140123

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


[PATCH] D98300: [TLS] Initialization functions of dynamic TLS variables cannot be in a comdat (fix for PR48030)

2021-04-29 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

ping...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98300/new/

https://reviews.llvm.org/D98300

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


[PATCH] D109981: [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing

2022-01-10 Thread Wolfgang Pieb via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd789ea713372: [Diagnostics] Don't drop a statically set 
NoWarningAsError flag during option… (authored by wolfgangp).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D109981?vs=373255&id=398778#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109981/new/

https://reviews.llvm.org/D109981

Files:
  clang/lib/Basic/Diagnostic.cpp
  clang/test/Lexer/pragma-message.c


Index: clang/test/Lexer/pragma-message.c
===
--- clang/test/Lexer/pragma-message.c
+++ clang/test/Lexer/pragma-message.c
@@ -1,6 +1,5 @@
 /* Test pragma message directive from
http://msdn.microsoft.com/en-us/library/x7dkzch2.aspx */
-
 // message: Sends a string literal to the standard output without terminating
 // the compilation.
 // #pragma message(messagestring)
@@ -8,6 +7,7 @@
 // #pragma message messagestring
 //
 // RUN: %clang_cc1 -fsyntax-only -verify -Werror %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror -W#pragma-messages %s
 #define STRING2(x) #x
 #define STRING(x) STRING2(x)
 #pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning 
{{:O I'm a message! 13}}
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -374,6 +374,12 @@
   DiagnosticMapping Mapping = makeUserMapping(Map, L);
   Mapping.setUpgradedFromWarning(WasUpgradedFromWarning);
 
+  // Make sure we propagate the NoWarningAsError flag from an existing
+  // mapping (which may be the default mapping).
+  DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
+  Mapping.setNoWarningAsError(Info.hasNoWarningAsError() ||
+  Mapping.hasNoWarningAsError());
+
   // Common case; setting all the diagnostics of a group in one place.
   if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
   DiagStatesByLoc.getCurDiagState()) {


Index: clang/test/Lexer/pragma-message.c
===
--- clang/test/Lexer/pragma-message.c
+++ clang/test/Lexer/pragma-message.c
@@ -1,6 +1,5 @@
 /* Test pragma message directive from
http://msdn.microsoft.com/en-us/library/x7dkzch2.aspx */
-
 // message: Sends a string literal to the standard output without terminating
 // the compilation.
 // #pragma message(messagestring)
@@ -8,6 +7,7 @@
 // #pragma message messagestring
 //
 // RUN: %clang_cc1 -fsyntax-only -verify -Werror %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror -W#pragma-messages %s
 #define STRING2(x) #x
 #define STRING(x) STRING2(x)
 #pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}}
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -374,6 +374,12 @@
   DiagnosticMapping Mapping = makeUserMapping(Map, L);
   Mapping.setUpgradedFromWarning(WasUpgradedFromWarning);
 
+  // Make sure we propagate the NoWarningAsError flag from an existing
+  // mapping (which may be the default mapping).
+  DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
+  Mapping.setNoWarningAsError(Info.hasNoWarningAsError() ||
+  Mapping.hasNoWarningAsError());
+
   // Common case; setting all the diagnostics of a group in one place.
   if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
   DiagStatesByLoc.getCurDiagState()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109981: [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing

2021-12-13 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

ping ...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109981/new/

https://reviews.llvm.org/D109981

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


[PATCH] D98300: [TLS] Initialization functions of dynamic TLS variables cannot be in a comdat (fix for PR48030)

2021-03-25 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

ping ...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98300/new/

https://reviews.llvm.org/D98300

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


[PATCH] D109981: [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing

2021-10-12 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

ping ...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109981/new/

https://reviews.llvm.org/D109981

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