[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-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"



_

[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;
-  // getUSRsForDeclaration will find other related symbols, e.g. virtual and 
its
-  // overriddens, primary template and all explicit specializations.
-  // FIXME: get rid of the remaining tooling APIs.
-  std::vector RenameUSRs = tooling::getUSRsForDeclaration(
-  

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) DerivedFromExplicitlySpecializedTemplate : public 
ExplicitlySpecializedTemplate 

[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 - %s | 
FileCheck --check-prefix=PS %s
+
+template  struct __declspec(dllimp

[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> , ptr @array, align 32
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"MaxTLSAlign", i32 256}



_

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