Re: [PATCH] D11360: Proposed patch to prevent the creation of empty (forwarding) blocks resulting from nested ifs.

2015-08-05 Thread Wolfgang Pieb
wolfgangp added a comment.

Ping...


http://reviews.llvm.org/D11360



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


[clang] [llvm] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-10-31 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 closed 
https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-10-31 Thread Wolfgang Pieb via cfe-commits

wolfy1961 wrote:

Superseded by PR [70014](https://github.com/llvm/llvm-project/pull/70014).

https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-10-23 Thread Wolfgang Pieb via cfe-commits

wolfy1961 wrote:

Ping...
Any takers?

https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8564e2f - [Inlining] Add a clang option to limit inlining of functions

2022-08-18 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2022-08-18T11:56:24-07:00
New Revision: 8564e2fea559c58fecab3c7c01acf498bbe7820a

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

LOG: [Inlining] Add a clang option to limit inlining of functions

Add the clang option -finline-max-stacksize= to suppress inlining
of functions whose stack size exceeds the given value.

Reviewed By: aeubanks

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

Added: 
clang/test/CodeGen/inline-stacksize.c

Modified: 
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

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index da95d66a66e7d..265a6d7beb6e9 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -945,6 +945,10 @@ Inline suitable functions
 
 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

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 1d322814f6ee3..0f35420f43133 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -399,6 +399,9 @@ CODEGENOPT(CodeViewGHash, 1, 0)
 /// 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)
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8c9901d086eee..7c91b91eeddf4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1985,6 +1985,11 @@ def finline_functions : Flag<["-"], 
"finline-functions">, Group,
 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,

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0921008e254c3..639285540c0a6 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2372,6 +2372,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, 
llvm::Function *F,
   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).

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 69e6e63839093..57cbdffbe838a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6592,6 +6592,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 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 =

diff  --git a/clang/test/CodeGen/inline-stacksize.c 
b/clang/test/CodeGen/inline-stacksize.c
new file mode 100644
index 0..6aab158987d76
--- /dev/null
+++ b/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-

[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-19 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 updated 
https://github.com/llvm/llvm-project/pull/65512

>From 2e5abcec65c189fbb7f789816373969ee81ecfa5 Mon Sep 17 00:00:00 2001
From: wpieb 
Date: Tue, 5 Sep 2023 10:43:23 -0700
Subject: [PATCH 1/2] [LTO] A static relocation model can override the PIC
 level wrt treating external address as directly accessible.

Fixes https://github.com/llvm/llvm-project/issues/64999
---
 clang/lib/CodeGen/CodeGenModule.cpp | 5 +++--
 llvm/include/llvm/IR/Module.h   | 2 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp | 3 ++-
 llvm/lib/IR/Module.cpp  | 4 ++--
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp | 3 ++-
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8b0c9340775cbe9..c8756d0b5f56a57 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1127,7 +1127,8 @@ void CodeGenModule::Release() {
   if (LangOpts.HLSL)
 getHLSLRuntime().finishCodeGen();
 
-  if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
+  uint32_t PLevel = Context.getLangOpts().PICLevel;
+  if (PLevel) {
 assert(PLevel < 3 && "Invalid PIC Level");
 getModule().setPICLevel(static_cast(PLevel));
 if (Context.getLangOpts().PIE)
@@ -1152,7 +1153,7 @@ void CodeGenModule::Release() {
 getModule().setRtLibUseGOT();
   if (getTriple().isOSBinFormatELF() &&
   CodeGenOpts.DirectAccessExternalData !=
-  getModule().getDirectAccessExternalData()) {
+  getModule().getDirectAccessExternalData(PLevel == 0)) {
 getModule().setDirectAccessExternalData(
 CodeGenOpts.DirectAccessExternalData);
   }
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 70bec1c1615..cade1fccd4c5c17 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -958,7 +958,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 
   /// Get/set whether referencing global variables can use direct access
   /// relocations on ELF targets.
-  bool getDirectAccessExternalData() const;
+  bool getDirectAccessExternalData(bool IsStaticRelocModel) const;
   void setDirectAccessExternalData(bool Value);
 
   /// Get/set whether synthesized functions should get the uwtable attribute.
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp 
b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 3e4bff5ddce1264..e1f439fd32dad1a 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2016,7 +2016,8 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) 
const {
   "__stack_chk_guard");
 
 // FreeBSD has "__stack_chk_guard" defined externally on libc.so
-if (M.getDirectAccessExternalData() &&
+if (M.getDirectAccessExternalData(TM.getRelocationModel() ==
+  Reloc::Static) &&
 !TM.getTargetTriple().isWindowsGNUEnvironment() &&
 !TM.getTargetTriple().isOSFreeBSD() &&
 !TM.getTargetTriple().isOSDarwin())
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index dba660bbe5bafd3..db90bc0c9cae44b 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -687,12 +687,12 @@ void Module::setRtLibUseGOT() {
   addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
 }
 
-bool Module::getDirectAccessExternalData() const {
+bool Module::getDirectAccessExternalData(bool IsStaticRelocModel) const {
   auto *Val = cast_or_null(
   getModuleFlag("direct-access-external-data"));
   if (Val)
 return cast(Val->getValue())->getZExtValue() > 0;
-  return getPICLevel() == PICLevel::NotPIC;
+  return getPICLevel() == PICLevel::NotPIC || IsStaticRelocModel;
 }
 
 void Module::setDirectAccessExternalData(bool Value) {
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp 
b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index 754d2042105e57d..9eeb9bf682b1f41 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -606,7 +606,8 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilderBase 
&IRB) const {
 nullptr, GuardSymb, nullptr,
 GlobalValue::NotThreadLocal, AddressSpace);
 if (!Subtarget.isTargetDarwin())
-  GV->setDSOLocal(M->getDirectAccessExternalData());
+  GV->setDSOLocal(M->getDirectAccessExternalData(
+  getTargetMachine().getRelocationModel() == Reloc::Static));
   }
   return GV;
 }

>From 2ddd45b0c9c11bb38fcf88a55cf22269a6d16946 Mon Sep 17 00:00:00 2001
From: wpieb 
Date: Tue, 19 Sep 2023 17:07:41 -0700
Subject: [PATCH 2/2] Adjust the test

---
 llvm/test/LTO/ARM/ssp-static-reloc.ll | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/llvm/test/LTO/ARM/ssp-static-reloc.ll 
b/llvm/test/LTO/ARM/ssp-static-reloc.ll
index c8825c2aae0fbb6..bee3639e19d8222 100644
--- a/l

[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-10-02 Thread Wolfgang Pieb via cfe-commits

wolfy1961 wrote:

Ping ...

https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-10-10 Thread Wolfgang Pieb via cfe-commits

wolfy1961 wrote:

Ping ...

https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-11 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 review_requested 
https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-06 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 created 
https://github.com/llvm/llvm-project/pull/65512:

As described in issue 
[#64999](https://github.com/llvm/llvm-project/issues/64999), commit 
[e018cbf7208](https://github.com/llvm/llvm-project/commit/e018cbf7208b3d34f18997ddee84c66cee32fb1b)
 caused the symbol __stack_chk_guard to not become dso_local when PIC is 
enabled in a module. However, during LTO we can force a static relocation 
model, which overrides the PIC level. In this case __stack_chk_guard should 
become dso_local.
For this purpose we're adding a boolean to the interface of 
getDirectAccessExternalData() to indicate the relocation model.

Fixes https://github.com/llvm/llvm-project/issues/64999

>From 6a176368c90183fc1744b73632746636fe46da42 Mon Sep 17 00:00:00 2001
From: wpieb 
Date: Tue, 5 Sep 2023 10:43:23 -0700
Subject: [PATCH] [LTO] A static relocation model can override the PIC level
 wrt treating external address as directly accessible.

Fixes https://github.com/llvm/llvm-project/issues/64999
---
 clang/lib/CodeGen/CodeGenModule.cpp |  5 +--
 llvm/include/llvm/IR/Module.h   |  2 +-
 llvm/lib/CodeGen/TargetLoweringBase.cpp |  3 +-
 llvm/lib/IR/Module.cpp  |  4 +--
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp |  3 +-
 llvm/test/LTO/ARM/ssp-static-reloc.ll   | 38 +
 6 files changed, 48 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/LTO/ARM/ssp-static-reloc.ll

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 95f185f5824d8c..f0a10f5d294270 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1127,7 +1127,8 @@ void CodeGenModule::Release() {
   if (LangOpts.HLSL)
 getHLSLRuntime().finishCodeGen();
 
-  if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
+  uint32_t PLevel = Context.getLangOpts().PICLevel;
+  if (PLevel) {
 assert(PLevel < 3 && "Invalid PIC Level");
 getModule().setPICLevel(static_cast(PLevel));
 if (Context.getLangOpts().PIE)
@@ -1152,7 +1153,7 @@ void CodeGenModule::Release() {
 getModule().setRtLibUseGOT();
   if (getTriple().isOSBinFormatELF() &&
   CodeGenOpts.DirectAccessExternalData !=
-  getModule().getDirectAccessExternalData()) {
+  getModule().getDirectAccessExternalData(PLevel == 0)) {
 getModule().setDirectAccessExternalData(
 CodeGenOpts.DirectAccessExternalData);
   }
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 670a40b28eabbe..bf2c41bb9c3e44 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -947,7 +947,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 
   /// Get/set whether referencing global variables can use direct access
   /// relocations on ELF targets.
-  bool getDirectAccessExternalData() const;
+  bool getDirectAccessExternalData(bool IsStaticRelocModel) const;
   void setDirectAccessExternalData(bool Value);
 
   /// Get/set whether synthesized functions should get the uwtable attribute.
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp 
b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 3e4bff5ddce126..e1f439fd32dad1 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2016,7 +2016,8 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) 
const {
   "__stack_chk_guard");
 
 // FreeBSD has "__stack_chk_guard" defined externally on libc.so
-if (M.getDirectAccessExternalData() &&
+if (M.getDirectAccessExternalData(TM.getRelocationModel() ==
+  Reloc::Static) &&
 !TM.getTargetTriple().isWindowsGNUEnvironment() &&
 !TM.getTargetTriple().isOSFreeBSD() &&
 !TM.getTargetTriple().isOSDarwin())
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 73354a8f36d215..8186f256007c48 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -672,12 +672,12 @@ void Module::setRtLibUseGOT() {
   addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
 }
 
-bool Module::getDirectAccessExternalData() const {
+bool Module::getDirectAccessExternalData(bool IsStaticRelocModel) const {
   auto *Val = cast_or_null(
   getModuleFlag("direct-access-external-data"));
   if (Val)
 return cast(Val->getValue())->getZExtValue() > 0;
-  return getPICLevel() == PICLevel::NotPIC;
+  return getPICLevel() == PICLevel::NotPIC || IsStaticRelocModel;
 }
 
 void Module::setDirectAccessExternalData(bool Value) {
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp 
b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index 754d2042105e57..9eeb9bf682b1f4 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -606,7 +606,8 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilderBase 
&IRB) const {
 nullptr, GuardSymb, nullptr,
  

[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-06 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 review_requested 
https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-06 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 review_requested 
https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-06 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 review_requested 
https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] A static relocation model can override the PIC level wrt treating external address as directly accessible (PR #65512)

2023-09-06 Thread Wolfgang Pieb via cfe-commits

https://github.com/wolfy1961 review_requested 
https://github.com/llvm/llvm-project/pull/65512
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f805c60 - Revert "[clangd] Implement rename by using SelectionTree and findExplicitReferences."

2019-11-18 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2019-11-18T15:39:05-08:00
New Revision: f805c60a093325c16ce4200d2615ef48555d9cb8

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

LOG: Revert "[clangd] Implement rename by using SelectionTree and 
findExplicitReferences."

This reverts commit 4f80fc2491cc35730a9a84b86975278b7daa8522.

Caused buildbot failure at
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/58251

Added: 


Modified: 
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index fb83083384f9..3969f3e2e4e2 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -8,16 +8,14 @@
 
 #include "refactor/Rename.h"
 #include "AST.h"
-#include "FindTarget.h"
 #include "Logger.h"
 #include "ParsedAST.h"
-#include "Selection.h"
 #include "SourceCode.h"
 #include "index/SymbolCollector.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclTemplate.h"
-#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
+#include "clang/Tooling/Refactoring/Rename/USRFinder.h"
 #include "clang/Tooling/Refactoring/Rename/USRFindingAction.h"
+#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h"
 
 namespace clang {
 namespace clangd {
@@ -36,17 +34,6 @@ llvm::Optional filePath(const SymbolLocation 
&Loc,
   return *Path;
 }
 
-// Returns true if the given location is expanded from any macro body.
-bool isInMacroBody(const SourceManager &SM, SourceLocation Loc) {
-  while (Loc.isMacroID()) {
-if (SM.isMacroBodyExpansion(Loc))
-  return true;
-Loc = SM.getImmediateMacroCallerLoc(Loc);
-  }
-
-  return false;
-}
-
 // Query the index to find some other files where the Decl is referenced.
 llvm::Optional getOtherRefFile(const Decl &D, StringRef MainFile,
 const SymbolIndex &Index) {
@@ -69,41 +56,12 @@ llvm::Optional getOtherRefFile(const Decl &D, 
StringRef MainFile,
   return OtherFile;
 }
 
-llvm::DenseSet locateDeclAt(ParsedAST &AST,
-  SourceLocation TokenStartLoc) {
-  unsigned Offset =
-  AST.getSourceManager().getDecomposedSpellingLoc(TokenStartLoc).second;
-
-  SelectionTree Selection(AST.getASTContext(), AST.getTokens(), Offset);
-  const SelectionTree::Node *SelectedNode = Selection.commonAncestor();
-  if (!SelectedNode)
-return {};
-
-  // If the location points to a Decl, we check it is actually on the name
-  // range of the Decl. This would avoid allowing rename on unrelated tokens.
-  //   ^class Foo {} // SelectionTree returns CXXRecordDecl,
-  // // we don't attempt to trigger rename on this position.
-  // FIXME: make this work on destructors, e.g. "~F^oo()".
-  if (const auto *D = SelectedNode->ASTNode.get()) {
-if (D->getLocation() != TokenStartLoc)
-  return {};
-  }
-
-  llvm::DenseSet Result;
-  for (const auto *D :
-   targetDecl(SelectedNode->ASTNode,
-  DeclRelation::Alias | DeclRelation::TemplatePattern))
-Result.insert(D);
-  return Result;
-}
-
 enum ReasonToReject {
   NoSymbolFound,
   NoIndexProvided,
   NonIndexable,
   UsedOutsideFile,
   UnsupportedSymbol,
-  AmbiguousSymbol,
 };
 
 // Check the symbol Decl is renameable (per the index) within the file.
@@ -167,8 +125,6 @@ llvm::Error makeError(ReasonToReject Reason) {
   return "symbol may be used in other files (not eligible for indexing)";
 case UnsupportedSymbol:
   return "symbol is not a supported kind (e.g. namespace, macro)";
-case AmbiguousSymbol:
-  return "there are multiple symbols at the given location";
 }
 llvm_unreachable("unhandled reason kind");
   };
@@ -178,38 +134,22 @@ llvm::Error makeError(ReasonToReject Reason) {
 }
 
 // Return all rename occurrences in the main file.
-std::vector findOccurrencesWithinFile(ParsedAST &AST,
-  const NamedDecl &ND) {
-  // In theory, locateDeclAt should return the primary template. However, if 
the
-  // cursor is under the underlying CXXRecordDecl of the ClassTemplateDecl, ND
-  // will be the CXXRecordDecl, for this case, we need to get the primary
-  // template maunally.
-  const auto &RenameDecl =
-  ND.getDescribedTemplate() ? *ND.getDescribedTemplate() : ND;
-  

r317047 - Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.

2017-10-31 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Tue Oct 31 15:49:48 2017
New Revision: 317047

URL: http://llvm.org/viewvc/llvm-project?rev=317047&view=rev
Log:
Fix for PR33930. Short-circuit metadata mapping when cloning a varargs thunk.
The cloning happens before all metadata nodes are resolved. Prevent the value
mapper from running into unresolved or temporary MD nodes.

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

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

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=317047&r1=317046&r2=317047&view=diff
==
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Oct 31 15:49:48 2017
@@ -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 @@ static RValue PerformReturnAdjustment(Co
   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 @@ CodeGenFunction::GenerateVarArgsThunk(ll
 
   // 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);

Added: cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp?rev=317047&view=auto
==
--- cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp Tue Oct 31 15:49:48 2017
@@ -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(

Added: cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp?rev=317047&view=auto
==
--- cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp Tue Oct 31 15:49:48 2017
@@ -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( ) {}
+

r317053 - Making a couple of tests a bit more flexible wrt thunk mangling. Fixes checkin for r317047.

2017-10-31 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Tue Oct 31 17:01:20 2017
New Revision: 317053

URL: http://llvm.org/viewvc/llvm-project?rev=317053&view=rev
Log:
Making a couple of tests a bit more flexible wrt thunk mangling. Fixes checkin 
for r317047.

Modified:
cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp

Modified: cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp?rev=317053&r1=317052&r2=317053&view=diff
==
--- cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/tmp-md-nodes1.cpp Tue Oct 31 17:01:20 2017
@@ -15,4 +15,4 @@ struct CharlieImpl : Charlie, Alpha {
   void bravo(...) {}
 } delta;
 
-// CHECK: define {{.*}} void @_ZThn8_N11CharlieImpl5bravoEz(
+// CHECK: define {{.*}} void @_ZThn{{[48]}}_N11CharlieImpl5bravoEz(

Modified: cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp?rev=317053&r1=317052&r2=317053&view=diff
==
--- cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/tmp-md-nodes2.cpp Tue Oct 31 17:01:20 2017
@@ -30,4 +30,4 @@ BOOL CBdVfsImpl::ReqCacheHint( CMsgAgent
   return true;
 }
 
-// CHECK: define {{.*}} 
@_ZThn8_N10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz(
+// CHECK: define {{.*}} 
@_ZThn{{[48]}}_N10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz(


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


[clang] 634430d - [MSVC][dllexport/dllimport] Propagate a dllexport/dllimport attribute to template baseclass

2023-03-15 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2023-03-15T11:47:54-07:00
New Revision: 634430d5857e395cff62534b11c460f51c6c846a

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

LOG: [MSVC][dllexport/dllimport] Propagate a dllexport/dllimport attribute to 
template baseclass

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

Reviewed By: hans

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

Added: 


Modified: 
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

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 21c02b7ba4aa1..41c76e5c13715 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2608,7 +2608,8 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class,
   }
 
   // For the MS ABI, propagate DLL attributes to base class templates.
-  if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+  Context.getTargetInfo().getTriple().isPS()) {
 if (Attr *ClassAttr = getDLLAttr(Class)) {
   if (auto *BaseTemplate = 
dyn_cast_or_null(
   BaseType->getAsCXXRecordDecl())) {

diff  --git a/clang/test/CodeGenCXX/dllexport.cpp 
b/clang/test/CodeGenCXX/dllexport.cpp
index b4e42ed7abab2..c8ac526f4cbe3 100644
--- a/clang/test/CodeGenCXX/dllexport.cpp
+++ b/clang/test/CodeGenCXX/dllexport.cpp
@@ -6,6 +6,8 @@
 
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-gnu
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | 
FileCheck -allow-deprecated-dag-overlap --check-prefix=GNU --check-prefix=G32 %s
 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-windows-gnu  
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | 
FileCheck -allow-deprecated-dag-overlap --check-prefix=GNU %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-scei-ps4  
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | 
FileCheck -allow-deprecated-dag-overlap --check-prefix=PS %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-sie-ps5  
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | 
FileCheck -allow-deprecated-dag-overlap --check-prefix=PS %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Exported {};
@@ -980,18 +982,21 @@ struct __declspec(dllexport) DerivedFromTemplate : public 
ClassTemplate {};
 USEMEMFUNC(DerivedFromTemplate, func)
 // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void 
@"?func@?$ClassTemplate@H@@QAEXXZ"
 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void 
@_ZN13ClassTemplateIiE4funcEv
+// PS-DAG:  define weak_odr dllexport void @_ZN13ClassTemplateIiE4funcEv
 
 // ExportedTemplate is explicitly exported.
 struct __declspec(dllexport) DerivedFromExportedTemplate : public 
ExportedClassTemplate {};
 USEMEMFUNC(DerivedFromExportedTemplate, func)
 // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void 
@"?func@?$ExportedClassTemplate@H@@QAEXXZ"
 // G32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void 
@_ZN21ExportedClassTemplateIiE4funcEv
+// PS-DAG:  define weak_odr dllexport void 
@_ZN21ExportedClassTemplateIiE4funcEv
 
 // ImportedClassTemplate is explicitly imported.
 struct __declspec(dllexport) DerivedFromImportedTemplate : public 
ImportedClassTemplate {};
 USEMEMFUNC(DerivedFromImportedTemplate, func)
 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc 
void @"?func@?$ImportedClassTemplate@H@@QAEXXZ"
 // G32-DAG: declare dllimport x86_thiscallcc void 
@_ZN21ImportedClassTemplateIiE4funcEv
+// PS-DAG:  declare dllimport void @_ZN21ImportedClassTemplateIiE4funcEv
 
 // Base class already implicitly instantiated without dll attribute.
 struct DerivedFromTemplateD : public ClassTemplate {};
@@ -999,6 +1004,7 @@ struct __declspec(dllexport) DerivedFromTemplateD2 : 
public ClassTemplate 
{};
@@ -1006,42 +1012,49 @@ struct __declspec(dllexport) DerivedFromTemplateB2 : 
public ClassTemplate
 USEMEMFUNC(DerivedFromTemplateB2, func)
 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc 
void @"?func@?$ClassTemplate@_N@@QAEXXZ"
 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void 
@_ZN13ClassTemplateIbE4funcEv
+// PS-DAG:  declare dllimport void @_ZN13ClassTemplateIbE4funcEv
 
 // Base class already specialized without dll attribute.
 struct __declspec(dllexport) DerivedFromExplicitlySpecializedTempl

[clang] 477f9ce - [MSCV][dllexport/dllimport][PS] Allow UniqueExternal linkage classes with dllexport/dllimport

2023-03-29 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2023-03-29T18:15:04Z
New Revision: 477f9cea77e6d55ecddaafbedccd418750c40dbd

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

LOG: [MSCV][dllexport/dllimport][PS] Allow UniqueExternal linkage classes with 
dllexport/dllimport

MSVC allows instantiations of exported or imported template classes with 
template
parameters that have internal linkage. Clang now allows it in Microsoft mode 
and for
the Playstation platform. This partially addresses issue 56068.

Note that MSVC also allows explicit dllexport/dllimport attributes on classes
with internal linkage (e.g. local classes or classes declared in anonymous name 
spaces).
Clang continues to reject such declarations.

Reviewed By: hans

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

Added: 
clang/test/CodeGenCXX/dllexport-unique-external.cpp
clang/test/CodeGenCXX/dllimport-unique-external.cpp

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

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3dcc08f797811..e28c44f97f1fe 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -6351,6 +6351,18 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
*Class) {
   if (!ClassAttr)
 return;
 
+  // MSVC allows imported or exported template classes that have UniqueExternal
+  // linkage. This occurs when the template class has been instantiated with
+  // a template parameter which itself has internal linkage.
+  // We drop the attribute to avoid exporting or importing any members.
+  if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+   Context.getTargetInfo().getTriple().isPS()) &&
+  (!Class->isExternallyVisible() && Class->hasExternalFormalLinkage())) {
+Class->dropAttr();
+Class->dropAttr();
+return;
+  }
+
   if (!Class->isExternallyVisible()) {
 Diag(Class->getLocation(), diag::err_attribute_dll_not_extern)
 << Class << ClassAttr;

diff  --git a/clang/test/CodeGenCXX/dllexport-unique-external.cpp 
b/clang/test/CodeGenCXX/dllexport-unique-external.cpp
new file mode 100644
index 0..192438c6bfeba
--- /dev/null
+++ b/clang/test/CodeGenCXX/dllexport-unique-external.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc 
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 
-disable-llvm-passes -o - %s | FileCheck --check-prefix=MSC %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-scei-ps4 
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s | 
FileCheck --check-prefix=PS %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-sie-ps5 
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s | 
FileCheck --check-prefix=PS %s
+
+template  struct __declspec(dllexport) ExportedClassTemplate { 
void func(); };
+
+// Make sure that we do not export classes with unique external linkage.
+// Note that MSVC does indeed export the symbols in the MSC check string.
+void func1() {
+  class LocalCRTP : public ExportedClassTemplate {};
+  LocalCRTP lc;
+  lc.func();
+}
+
+namespace {
+  class AnonNSCRTP : public ExportedClassTemplate {};
+  AnonNSCRTP ac;
+}
+
+void func2() {
+  ac.func();
+}
+
+// MSC-NOT: declare {{.*}}dllexport
+// MSC: call 
{{.*}}@"?func@?$ExportedClassTemplate@VLocalCRTP@?1??func1@@{{.*}}"
+// MSC-NOT: declare {{.*}}dllexport
+// MSC: call {{.*}}@"?func@?$ExportedClassTemplate@VAnonNSCRTP@?{{.*}}"
+// MSC-NOT: declare {{.*}}dllexport
+
+// PS-NOT:  declare {{.*}}dllexport
+// PS:  call {{.*}}@_ZN21ExportedClassTemplateIZ5func1vE9LocalCRTPE4funcEv
+// PS-NOT:  declare {{.*}}dllexport
+// PS:  call 
{{.*}}@_ZN21ExportedClassTemplateIN12_GLOBAL__N_110AnonNSCRTPEE4funcEv
+// PS-NOT:  declare {{.*}}dllexport

diff  --git a/clang/test/CodeGenCXX/dllimport-unique-external.cpp 
b/clang/test/CodeGenCXX/dllimport-unique-external.cpp
new file mode 100644
index 0..8c0d5d37dfe8f
--- /dev/null
+++ b/clang/test/CodeGenCXX/dllimport-unique-external.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc 
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 
-disable-llvm-passes -o - %s | FileCheck --check-prefix=MSC %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-scei-ps4 
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s | 
FileCheck --check-prefix=PS %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-sie-ps5 
-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %

[clang] 5d07e04 - [TLS]: Clamp the alignment of TLS global variables if required by the target

2023-02-08 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2023-02-08T10:34:56-08:00
New Revision: 5d07e0448e38d4be0cc7b1079d72b5e3644e941c

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

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

Adding a module flag 'MaxTLSAlign' describing the maximum alignment a global TLS
variable can have. Optimizers are prevented from increasing the alignment of 
such
variables beyond this threshold.

Reviewed By: probinson

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

Added: 
clang/test/CodeGen/tls-maxalign-modflag.c
llvm/test/CodeGen/X86/tls-align.ll

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
llvm/include/llvm/IR/Module.h
llvm/lib/IR/Module.cpp
llvm/lib/Transforms/Utils/Local.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 57c9e589be3ba..0f93c33194353 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -947,6 +947,10 @@ void CodeGenModule::Release() {
   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());

diff  --git a/clang/test/CodeGen/tls-maxalign-modflag.c 
b/clang/test/CodeGen/tls-maxalign-modflag.c
new file mode 100644
index 0..d2936b66eda6d
--- /dev/null
+++ b/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]]

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index cd71a848addbb..e86880406b7ea 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -923,6 +923,8 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   unsigned getOverrideStackAlignment() const;
   void setOverrideStackAlignment(unsigned Align);
 
+  unsigned getMaxTLSAlignment() const;
+
   /// @name Utility functions for querying and setting the build SDK version
   /// @{
 

diff  --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 49fadc9ed7e63..3df1e7b23625a 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -746,6 +746,13 @@ unsigned Module::getOverrideStackAlignment() const {
   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);
 }

diff  --git a/llvm/lib/Transforms/Utils/Local.cpp 
b/llvm/lib/Transforms/Utils/Local.cpp
index 624907a691de1..ddef654ca73cc 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1423,6 +1423,12 @@ static Align tryEnforceAlignment(Value *V, Align 
PrefAlign,
 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;
   }

diff  --git a/llvm/test/CodeGen/X86/tls-align.ll 
b/llvm/test/CodeGen/X86/tls-align.ll
new file mode 100644
index 0..3c8ee6b3f8ab2
--- /dev/null
+++ b/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> , 

r276361 - Reverting r275115 which caused PR28634.

2016-07-21 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Thu Jul 21 18:28:18 2016
New Revision: 276361

URL: http://llvm.org/viewvc/llvm-project?rev=276361&view=rev
Log:
Reverting r275115 which caused PR28634.
When empty (forwarding) basic blocks that are referenced by user labels
are removed, incorrect code may be generated.


Removed:
cfe/trunk/test/CodeGen/forwarding-blocks-if.c
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=276361&r1=276360&r2=276361&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Jul 21 18:28:18 2016
@@ -623,14 +623,7 @@ void CodeGenFunction::EmitIfStmt(const I
 RunCleanupsScope ThenScope(*this);
 EmitStmt(S.getThen());
   }
-  {
-auto CurBlock = Builder.GetInsertBlock();
-EmitBranch(ContBlock);
-// Eliminate any empty blocks that may have been created by nested
-// control flow statements in the 'then' clause.
-if (CurBlock)
-  SimplifyForwardingBlocks(CurBlock); 
-  }
+  EmitBranch(ContBlock);
 
   // Emit the 'else' code if present.
   if (const Stmt *Else = S.getElse()) {
@@ -646,12 +639,7 @@ void CodeGenFunction::EmitIfStmt(const I
 {
   // There is no need to emit line number for an unconditional branch.
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
-  auto CurBlock = Builder.GetInsertBlock();
   EmitBranch(ContBlock);
-  // Eliminate any empty blocks that may have been created by nested
-  // control flow statements emitted in the 'else' clause.
-  if (CurBlock)
-SimplifyForwardingBlocks(CurBlock); 
 }
   }
 

Removed: cfe/trunk/test/CodeGen/forwarding-blocks-if.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/forwarding-blocks-if.c?rev=276360&view=auto
==
--- cfe/trunk/test/CodeGen/forwarding-blocks-if.c (original)
+++ cfe/trunk/test/CodeGen/forwarding-blocks-if.c (removed)
@@ -1,36 +0,0 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
-// Check that no empty blocks are generated for nested ifs.
-
-extern void func();
-
-int f0(int val) {
-  if (val == 0) {
-func();
-  } else if (val == 1) {
-func();
-  }
-  return 0;
-}
-
-// CHECK-LABEL: define {{.*}}i32 @f0
-// CHECK: call void {{.*}} @func
-// CHECK: call void {{.*}} @func
-// CHECK: br label %[[RETBLOCK1:[^ ]*]]
-// CHECK: [[RETBLOCK1]]:
-// CHECK-NOT: br label
-// CHECK: ret i32
-
-int f1(int val, int g) {
-  if (val == 0)
-if (g == 1) {
-  func();
-}
-  return 0;
-}
-
-// CHECK-LABEL: define {{.*}}i32 @f1
-// CHECK: call void {{.*}} @func
-// CHECK: br label %[[RETBLOCK2:[^ ]*]]
-// CHECK: [[RETBLOCK2]]:
-// CHECK-NOT: br label
-// CHECK: ret i32


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


r277094 - Change a test to be less prone to random failures due to

2016-07-28 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Thu Jul 28 19:54:13 2016
New Revision: 277094

URL: http://llvm.org/viewvc/llvm-project?rev=277094&view=rev
Log:
Change a test to be less prone to random failures due to
unintended matches of label numbers to debug metadata
handles in release builds.

Modified:
cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp

Modified: cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp?rev=277094&r1=277093&r2=277094&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp Thu Jul 28 19:54:13 2016
@@ -30,12 +30,12 @@ void simple(float *a, float *b, float *c
 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
 // CHECK: [[CMP:%.+]] = icmp sgt i32 [[UB_VAL]], 5
 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
-// CHECK: [[TRUE]]
+// CHECK: [[TRUE]]:
 // CHECK: br label %[[SWITCH:[^,]+]]
-// CHECK: [[FALSE]]
+// CHECK: [[FALSE]]:
 // CHECK: [[UB_VAL:%.+]] = load i32, i32* [[UB]],
 // CHECK: br label %[[SWITCH]]
-// CHECK: [[SWITCH]]
+// CHECK: [[SWITCH]]:
 // CHECK: [[UP:%.+]] = phi i32 [ 5, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
 // CHECK: store i32 [[UP]], i32* [[UB]],
 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
@@ -46,7 +46,7 @@ void simple(float *a, float *b, float *c
 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB_VAL]]
 // CHECK-NEXT: br i1 [[CMP]], label %[[SIMPLE_LOOP1_BODY:.+]], label 
%[[SIMPLE_LOOP1_END:[^,]+]]
   for (int i = 3; i < 32; i += 5) {
-// CHECK: [[SIMPLE_LOOP1_BODY]]
+// CHECK: [[SIMPLE_LOOP1_BODY]]:
 // Start of body: calculate i from IV:
 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]
 // CHECK: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 5
@@ -61,7 +61,7 @@ void simple(float *a, float *b, float *c
 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
 // br label %{{.+}}, !llvm.loop !{{.+}}
   }
-// CHECK: [[SIMPLE_LOOP1_END]]
+// CHECK: [[SIMPLE_LOOP1_END]]:
 // CHECK: call void @__kmpc_for_static_fini(%ident_t* {{.+}}, i32 %{{.+}})
 
   long long k = get_val();
@@ -74,7 +74,7 @@ void simple(float *a, float *b, float *c
 // CHECK: [[NEXT:%.+]] = call i32 @__kmpc_dispatch_next_4(%ident_t* {{.+}}, 
i32 %{{.+}}, i32* %{{.+}}, i32* [[LB:%.+]], i32* [[UB:%.+]], i32* %{{.+}})
 // CHECK: [[COND:%.+]] = icmp ne i32 [[NEXT]], 0
 // CHECK: br i1 [[COND]], label %[[CONT:.+]], label %[[END:.+]]
-// CHECK: [[CONT]]
+// CHECK: [[CONT]]:
 // CHECK: [[LB_VAL:%.+]] = load i32, i32* [[LB]],
 // CHECK: store i32 [[LB_VAL]], i32* [[OMP_IV2:%[^,]+]],
 
@@ -83,7 +83,7 @@ void simple(float *a, float *b, float *c
 // CHECK-NEXT: [[CMP2:%.+]] = icmp sle i32 [[IV2]], [[UB_VAL]]
 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP2_BODY:.+]], label 
%[[SIMPLE_LOOP2_END:[^,]+]]
   for (int i = 10; i > 1; i--) {
-// CHECK: [[SIMPLE_LOOP2_BODY]]
+// CHECK: [[SIMPLE_LOOP2_BODY]]:
 // Start of body: calculate i from IV:
 // CHECK: [[IV2_0:%.+]] = load i32, i32* 
[[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
@@ -105,7 +105,7 @@ void simple(float *a, float *b, float *c
 // CHECK-NEXT: store i32 [[ADD2_2]], i32* 
[[OMP_IV2]]{{.*}}!llvm.mem.parallel_loop_access ![[SIMPLE_LOOP2_ID]]
 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP2_ID]]
   }
-// CHECK: [[SIMPLE_LOOP2_END]]
+// CHECK: [[SIMPLE_LOOP2_END]]:
 //
 // Update linear vars after loop, as the loop was operating on a private 
version.
 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
@@ -130,12 +130,12 @@ void simple(float *a, float *b, float *c
 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
 // CHECK: [[CMP:%.+]] = icmp ugt i64 [[UB_VAL]], 3
 // CHECK: br i1 [[CMP]], label %[[TRUE:.+]], label %[[FALSE:[^,]+]]
-// CHECK: [[TRUE]]
+// CHECK: [[TRUE]]:
 // CHECK: br label %[[SWITCH:[^,]+]]
-// CHECK: [[FALSE]]
+// CHECK: [[FALSE]]:
 // CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],
 // CHECK: br label %[[SWITCH]]
-// CHECK: [[SWITCH]]
+// CHECK: [[SWITCH]]:
 // CHECK: [[UP:%.+]] = phi i64 [ 3, %[[TRUE]] ], [ [[UB_VAL]], %[[FALSE]] ]
 // CHECK: store i64 [[UP]], i64* [[UB]],
 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
@@ -146,7 +146,7 @@ void simple(float *a, float *b, float *c
 // CHECK-NEXT: [[CMP3:%.+]] = icmp ule i64 [[IV3]], [[UB_VAL]]
 // CHECK-NEXT: br i1 [[CMP3]], label %[[SIMPLE_LOOP3_BODY:.+]], label 
%[[SIMPLE_LOOP3_END:[^,]+]]
   for (unsigned long long it = 2000; it >= 600; it-=400) {
-// CHECK: [[SIMPLE_LOOP3_BODY]]
+// CHECK: [[SIMPLE_LOOP3_BODY]]:
 // Start of body: calculate it from IV:
 // CHECK: [[IV3_0:%.+]] = load i64, i64* [[OMP_IV3]]
 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul i64 [[IV3_0]], 400
@@ -172,7 +172,7 @@ void simple(float *a, float *b, float *c
 // CHECK-NEXT: [[ADD3_2:%.+]] = add i64 [[IV3_2]], 1
 // CHECK-NEXT: store i64 [[AD

Re: [PATCH] D11360: Proposed patch to prevent the creation of empty (forwarding) blocks resulting from nested ifs.

2016-06-27 Thread Wolfgang Pieb via cfe-commits
wolfgangp updated this revision to Diff 61987.
wolfgangp added a comment.
Herald added a subscriber: mehdi_amini.

Updating this patch against a recent revision.


http://reviews.llvm.org/D11360

Files:
  lib/CodeGen/CGStmt.cpp
  test/CodeGen/forwarding-blocks-if.c

Index: test/CodeGen/forwarding-blocks-if.c
===
--- test/CodeGen/forwarding-blocks-if.c
+++ test/CodeGen/forwarding-blocks-if.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// Check that no empty blocks are generated for nested ifs.
+
+extern void func();
+
+int f0(int val)
+{
+if (val == 0)
+{
+func();
+}
+else if (val == 1)
+{
+func();
+}
+return 0;
+}
+
+// CHECK-LABEL: define i32 @f0
+// CHECK: call void {{.*}} @func
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK1:[^ ]*]]
+// CHECK: [[RETBLOCK1]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
+
+
+int f1(int val, int g)
+{
+if (val == 0)
+if (g == 1)
+{
+func();
+}
+return 0;
+}
+
+// CHECK-LABEL: define i32 @f1
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK2:[^ ]*]]
+// CHECK: [[RETBLOCK2]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -606,7 +606,12 @@
 RunCleanupsScope ThenScope(*this);
 EmitStmt(S.getThen());
   }
-  EmitBranch(ContBlock);
+  {
+auto CurBlock = Builder.GetInsertBlock();
+EmitBranch(ContBlock);
+if (CurBlock)
+  SimplifyForwardingBlocks(CurBlock); 
+  }
 
   // Emit the 'else' code if present.
   if (const Stmt *Else = S.getElse()) {
@@ -622,7 +627,10 @@
 {
   // There is no need to emit line number for an unconditional branch.
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
+  auto CurBlock = Builder.GetInsertBlock();
   EmitBranch(ContBlock);
+  if (CurBlock)
+SimplifyForwardingBlocks(CurBlock); 
 }
   }
 


Index: test/CodeGen/forwarding-blocks-if.c
===
--- test/CodeGen/forwarding-blocks-if.c
+++ test/CodeGen/forwarding-blocks-if.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// Check that no empty blocks are generated for nested ifs.
+
+extern void func();
+
+int f0(int val)
+{
+if (val == 0)
+{
+func();
+}
+else if (val == 1)
+{
+func();
+}
+return 0;
+}
+
+// CHECK-LABEL: define i32 @f0
+// CHECK: call void {{.*}} @func
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK1:[^ ]*]]
+// CHECK: [[RETBLOCK1]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
+
+
+int f1(int val, int g)
+{
+if (val == 0)
+if (g == 1)
+{
+func();
+}
+return 0;
+}
+
+// CHECK-LABEL: define i32 @f1
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK2:[^ ]*]]
+// CHECK: [[RETBLOCK2]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -606,7 +606,12 @@
 RunCleanupsScope ThenScope(*this);
 EmitStmt(S.getThen());
   }
-  EmitBranch(ContBlock);
+  {
+auto CurBlock = Builder.GetInsertBlock();
+EmitBranch(ContBlock);
+if (CurBlock)
+  SimplifyForwardingBlocks(CurBlock); 
+  }
 
   // Emit the 'else' code if present.
   if (const Stmt *Else = S.getElse()) {
@@ -622,7 +627,10 @@
 {
   // There is no need to emit line number for an unconditional branch.
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
+  auto CurBlock = Builder.GetInsertBlock();
   EmitBranch(ContBlock);
+  if (CurBlock)
+SimplifyForwardingBlocks(CurBlock); 
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11360: Proposed patch to prevent the creation of empty (forwarding) blocks resulting from nested ifs.

2016-07-05 Thread Wolfgang Pieb via cfe-commits
wolfgangp added a comment.

Ping...


http://reviews.llvm.org/D11360



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


Re: [PATCH] D11360: Proposed patch to prevent the creation of empty (forwarding) blocks resulting from nested ifs.

2016-07-06 Thread Wolfgang Pieb via cfe-commits
wolfgangp updated this revision to Diff 62916.
wolfgangp added a comment.

Addressed review comments: documented changes and clang-formatted the test case.


http://reviews.llvm.org/D11360

Files:
  lib/CodeGen/CGStmt.cpp
  test/CodeGen/forwarding-blocks-if.c

Index: test/CodeGen/forwarding-blocks-if.c
===
--- test/CodeGen/forwarding-blocks-if.c
+++ test/CodeGen/forwarding-blocks-if.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// Check that no empty blocks are generated for nested ifs.
+
+extern void func();
+
+int f0(int val) {
+  if (val == 0) {
+func();
+  } else if (val == 1) {
+func();
+  }
+  return 0;
+}
+
+// CHECK-LABEL: define i32 @f0
+// CHECK: call void {{.*}} @func
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK1:[^ ]*]]
+// CHECK: [[RETBLOCK1]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
+
+int f1(int val, int g) {
+  if (val == 0)
+if (g == 1) {
+  func();
+}
+  return 0;
+}
+
+// CHECK-LABEL: define i32 @f1
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK2:[^ ]*]]
+// CHECK: [[RETBLOCK2]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -610,7 +610,14 @@
 RunCleanupsScope ThenScope(*this);
 EmitStmt(S.getThen());
   }
-  EmitBranch(ContBlock);
+  {
+auto CurBlock = Builder.GetInsertBlock();
+EmitBranch(ContBlock);
+// Eliminate any empty blocks that may have been created by nested
+// control flow statements in the 'then' clause.
+if (CurBlock)
+  SimplifyForwardingBlocks(CurBlock); 
+  }
 
   // Emit the 'else' code if present.
   if (const Stmt *Else = S.getElse()) {
@@ -626,7 +633,12 @@
 {
   // There is no need to emit line number for an unconditional branch.
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
+  auto CurBlock = Builder.GetInsertBlock();
   EmitBranch(ContBlock);
+  // Eliminate any empty blocks that may have been created by nested
+  // control flow statements emitted in the 'else' clause.
+  if (CurBlock)
+SimplifyForwardingBlocks(CurBlock); 
 }
   }
 


Index: test/CodeGen/forwarding-blocks-if.c
===
--- test/CodeGen/forwarding-blocks-if.c
+++ test/CodeGen/forwarding-blocks-if.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// Check that no empty blocks are generated for nested ifs.
+
+extern void func();
+
+int f0(int val) {
+  if (val == 0) {
+func();
+  } else if (val == 1) {
+func();
+  }
+  return 0;
+}
+
+// CHECK-LABEL: define i32 @f0
+// CHECK: call void {{.*}} @func
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK1:[^ ]*]]
+// CHECK: [[RETBLOCK1]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
+
+int f1(int val, int g) {
+  if (val == 0)
+if (g == 1) {
+  func();
+}
+  return 0;
+}
+
+// CHECK-LABEL: define i32 @f1
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK2:[^ ]*]]
+// CHECK: [[RETBLOCK2]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -610,7 +610,14 @@
 RunCleanupsScope ThenScope(*this);
 EmitStmt(S.getThen());
   }
-  EmitBranch(ContBlock);
+  {
+auto CurBlock = Builder.GetInsertBlock();
+EmitBranch(ContBlock);
+// Eliminate any empty blocks that may have been created by nested
+// control flow statements in the 'then' clause.
+if (CurBlock)
+  SimplifyForwardingBlocks(CurBlock); 
+  }
 
   // Emit the 'else' code if present.
   if (const Stmt *Else = S.getElse()) {
@@ -626,7 +633,12 @@
 {
   // There is no need to emit line number for an unconditional branch.
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
+  auto CurBlock = Builder.GetInsertBlock();
   EmitBranch(ContBlock);
+  // Eliminate any empty blocks that may have been created by nested
+  // control flow statements emitted in the 'else' clause.
+  if (CurBlock)
+SimplifyForwardingBlocks(CurBlock); 
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11360: Proposed patch to prevent the creation of empty (forwarding) blocks resulting from nested ifs.

2016-07-06 Thread Wolfgang Pieb via cfe-commits
wolfgangp added inline comments.


Comment at: test/CodeGen/forwarding-blocks-if.c:17
@@ +16,3 @@
+return 0;
+}
+

mehdi_amini wrote:
> Any reason to not stick with LLVM coding convention here?
No reason, thanks for pointing this out.


http://reviews.llvm.org/D11360



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


r275115 - Prevent the creation of empty (forwarding) blocks resulting from nested ifs.

2016-07-11 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Mon Jul 11 17:22:23 2016
New Revision: 275115

URL: http://llvm.org/viewvc/llvm-project?rev=275115&view=rev
Log:
Prevent the creation of empty (forwarding) blocks resulting from nested ifs.

Summary:
Nested if statements can generate empty BBs whose terminator branches 
unconditionally to its successor. These branches are not eliminated
to help generate better line number information in some cases, but there
is no reason to keep the empty blocks that result from nested ifs.

Reviewers: mehdi_amini, dblaikie, echristo

Subscribers: mehdi_amini, cfe-commits

Differential review: http://reviews.llvm.org/D11360
 

Added:
cfe/trunk/test/CodeGen/forwarding-blocks-if.c
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=275115&r1=275114&r2=275115&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Mon Jul 11 17:22:23 2016
@@ -613,7 +613,14 @@ void CodeGenFunction::EmitIfStmt(const I
 RunCleanupsScope ThenScope(*this);
 EmitStmt(S.getThen());
   }
-  EmitBranch(ContBlock);
+  {
+auto CurBlock = Builder.GetInsertBlock();
+EmitBranch(ContBlock);
+// Eliminate any empty blocks that may have been created by nested
+// control flow statements in the 'then' clause.
+if (CurBlock)
+  SimplifyForwardingBlocks(CurBlock); 
+  }
 
   // Emit the 'else' code if present.
   if (const Stmt *Else = S.getElse()) {
@@ -629,7 +636,12 @@ void CodeGenFunction::EmitIfStmt(const I
 {
   // There is no need to emit line number for an unconditional branch.
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
+  auto CurBlock = Builder.GetInsertBlock();
   EmitBranch(ContBlock);
+  // Eliminate any empty blocks that may have been created by nested
+  // control flow statements emitted in the 'else' clause.
+  if (CurBlock)
+SimplifyForwardingBlocks(CurBlock); 
 }
   }
 

Added: cfe/trunk/test/CodeGen/forwarding-blocks-if.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/forwarding-blocks-if.c?rev=275115&view=auto
==
--- cfe/trunk/test/CodeGen/forwarding-blocks-if.c (added)
+++ cfe/trunk/test/CodeGen/forwarding-blocks-if.c Mon Jul 11 17:22:23 2016
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// Check that no empty blocks are generated for nested ifs.
+
+extern void func();
+
+int f0(int val) {
+  if (val == 0) {
+func();
+  } else if (val == 1) {
+func();
+  }
+  return 0;
+}
+
+// CHECK-LABEL: define i32 @f0
+// CHECK: call void {{.*}} @func
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK1:[^ ]*]]
+// CHECK: [[RETBLOCK1]]:
+// CHECK-NOT: br label
+// CHECK: ret i32
+
+int f1(int val, int g) {
+  if (val == 0)
+if (g == 1) {
+  func();
+}
+  return 0;
+}
+
+// CHECK-LABEL: define i32 @f1
+// CHECK: call void {{.*}} @func
+// CHECK: br label %[[RETBLOCK2:[^ ]*]]
+// CHECK: [[RETBLOCK2]]:
+// CHECK-NOT: br label
+// CHECK: ret i32


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


r275127 - Fix test submitted with r275115 (failed on ppc64 buildbots).

2016-07-11 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Mon Jul 11 18:20:28 2016
New Revision: 275127

URL: http://llvm.org/viewvc/llvm-project?rev=275127&view=rev
Log:
Fix test submitted with r275115 (failed on ppc64 buildbots).

Modified:
cfe/trunk/test/CodeGen/forwarding-blocks-if.c

Modified: cfe/trunk/test/CodeGen/forwarding-blocks-if.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/forwarding-blocks-if.c?rev=275127&r1=275126&r2=275127&view=diff
==
--- cfe/trunk/test/CodeGen/forwarding-blocks-if.c (original)
+++ cfe/trunk/test/CodeGen/forwarding-blocks-if.c Mon Jul 11 18:20:28 2016
@@ -12,7 +12,7 @@ int f0(int val) {
   return 0;
 }
 
-// CHECK-LABEL: define i32 @f0
+// CHECK-LABEL: define {{.*}} i32 @f0
 // CHECK: call void {{.*}} @func
 // CHECK: call void {{.*}} @func
 // CHECK: br label %[[RETBLOCK1:[^ ]*]]
@@ -28,7 +28,7 @@ int f1(int val, int g) {
   return 0;
 }
 
-// CHECK-LABEL: define i32 @f1
+// CHECK-LABEL: define {{.*}} i32 @f1
 // CHECK: call void {{.*}} @func
 // CHECK: br label %[[RETBLOCK2:[^ ]*]]
 // CHECK: [[RETBLOCK2]]:


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


r275128 - Correcting the previous fix for test submitted with r275115.

2016-07-11 Thread Wolfgang Pieb via cfe-commits
Author: wolfgangp
Date: Mon Jul 11 18:27:19 2016
New Revision: 275128

URL: http://llvm.org/viewvc/llvm-project?rev=275128&view=rev
Log:
Correcting the previous fix for test submitted with r275115.

Modified:
cfe/trunk/test/CodeGen/forwarding-blocks-if.c

Modified: cfe/trunk/test/CodeGen/forwarding-blocks-if.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/forwarding-blocks-if.c?rev=275128&r1=275127&r2=275128&view=diff
==
--- cfe/trunk/test/CodeGen/forwarding-blocks-if.c (original)
+++ cfe/trunk/test/CodeGen/forwarding-blocks-if.c Mon Jul 11 18:27:19 2016
@@ -12,7 +12,7 @@ int f0(int val) {
   return 0;
 }
 
-// CHECK-LABEL: define {{.*}} i32 @f0
+// CHECK-LABEL: define {{.*}}i32 @f0
 // CHECK: call void {{.*}} @func
 // CHECK: call void {{.*}} @func
 // CHECK: br label %[[RETBLOCK1:[^ ]*]]
@@ -28,7 +28,7 @@ int f1(int val, int g) {
   return 0;
 }
 
-// CHECK-LABEL: define {{.*}} i32 @f1
+// CHECK-LABEL: define {{.*}}i32 @f1
 // CHECK: call void {{.*}} @func
 // CHECK: br label %[[RETBLOCK2:[^ ]*]]
 // CHECK: [[RETBLOCK2]]:


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


Re: [PATCH] D8822: Proposed fix for PR23076 (conditional branch debug line info)

2016-01-28 Thread Wolfgang Pieb via cfe-commits
wolfgangp added a comment.



> Clang (with patch)

>  3, 5, 4, 5, 7

>  9, 11, 10, 11, 14

> 

> So that's somewhat problematic - we shouldn't visit 11 at all. (but we are 
> today, as is GCC... so maybe NBD?)


Well, if op&& is overloaded, wouldn't we lose the short-circuit property? If so 
it makes sense to visit 11.

> I think using the end of the condition is problematic/confusing. I'm not sure 
> why this doesn't show up in the primitive value version, but it seems like it 
> should (& we should end up stepping to the end of the condition (which would 
> be the close paren of the function call, not the close paren of the 'if ()'))


There is short-circuit in the primitive value version, so we wouldn't stop 
there.

> Perhaps we should use the close paren of the 'if ()' but tehre's no source 
> location for that readily available - I guess the way to get there is to 
> navigate to the next token from the end of the condition expression... ?


I agree, The close paren of the if() would be better.


http://reviews.llvm.org/D8822



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


[clang] d789ea7 - [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing

2022-01-10 Thread Wolfgang Pieb via cfe-commits

Author: Wolfgang Pieb
Date: 2022-01-10T16:38:01-08:00
New Revision: d789ea713372d44e50ff52a85a198ac6bbedaef9

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

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

When a -W option is given on the command line, and the corresponding 
diagnostic has
the NoWarnOnError flag set, prevent the flag from being dropped when the 
severity is reevaluated.
This fixes PR51837.

Reviewed By: dexonsmith

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 9b7ad96b949f1..ac4b9d2cd5a2b 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -374,6 +374,12 @@ void DiagnosticsEngine::setSeverity(diag::kind Diag, 
diag::Severity Map,
   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()) {

diff  --git a/clang/test/Lexer/pragma-message.c 
b/clang/test/Lexer/pragma-message.c
index d0bbe9ea3a628..aca9f14fa2f6d 100644
--- a/clang/test/Lexer/pragma-message.c
+++ b/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}}



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


[clang] [Clang][CodeGen] Emit fake uses before musttail calls (PR #136867)

2025-04-23 Thread Wolfgang Pieb via cfe-commits

wolfy1961 wrote:

LGTM

https://github.com/llvm/llvm-project/pull/136867
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://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
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