[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-12-06 Thread dong jianqiang via cfe-commits


@@ -2400,7 +2400,8 @@ void tools::addMachineOutlinerArgs(const Driver &D,
   // Otherwise, add the proper mllvm flags.
   if (!(Triple.isARM() || Triple.isThumb() ||
 Triple.getArch() == llvm::Triple::aarch64 ||

dongjianqiang2 wrote:

Updated, thanks.

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


[clang] [clang][AMDGPU] Update amdgpu_waves_per_eu attr docs (PR #74587)

2023-12-06 Thread Pierre van Houtryve via cfe-commits


@@ -2659,8 +2659,9 @@ An error will be given if:
   - Specified values violate subtarget specifications;
   - Specified values are not compatible with values provided through other
 attributes;
-  - The AMDGPU target backend is unable to create machine code that can meet 
the
-request.
+
+The AMDGPU target backend will emit a warning whenever it is unable to

Pierre-vh wrote:

Do you want me to format it like this instead to mimic the previous formatting?
```
A warning will be given if:
  - ...
```

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


[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-12-06 Thread dong jianqiang via cfe-commits

https://github.com/dongjianqiang2 updated 
https://github.com/llvm/llvm-project/pull/73223

>From 438da675d853e0b1bc38670c18361d7d3615f860 Mon Sep 17 00:00:00 2001
From: dong jianqiang 
Date: Thu, 23 Nov 2023 16:58:11 +0800
Subject: [PATCH] [Driver][MachineOutliner] Support outlining option with LTO
 for aarch64_be

This patch propagates the -moutline option when target is aarch64_be,
fix warning: 'aarch64_be' does not support '-moutline'; flag ignored 
[-Woption-ignored]
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 4 +---
 clang/test/Driver/aarch64-outliner.c   | 2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206e..4dc471ddc098f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2398,9 +2398,7 @@ void tools::addMachineOutlinerArgs(const Driver &D,
   // We only support -moutline in AArch64 and ARM targets right now. If
   // we're not compiling for these, emit a warning and ignore the flag.
   // Otherwise, add the proper mllvm flags.
-  if (!(Triple.isARM() || Triple.isThumb() ||
-Triple.getArch() == llvm::Triple::aarch64 ||
-Triple.getArch() == llvm::Triple::aarch64_32)) {
+  if (!(Triple.isARM() || Triple.isThumb() || Triple.isAArch64())) {
 D.Diag(diag::warn_drv_moutline_unsupported_opt) << 
Triple.getArchName();
   } else {
 addArg(Twine("-enable-machine-outliner"));
diff --git a/clang/test/Driver/aarch64-outliner.c 
b/clang/test/Driver/aarch64-outliner.c
index 42e43b433e282..06e5de11ec49e 100644
--- a/clang/test/Driver/aarch64-outliner.c
+++ b/clang/test/Driver/aarch64-outliner.c
@@ -1,7 +1,9 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang --target=aarch64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
+// RUN: %clang --target=aarch64_be -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
 // ON: "-mllvm" "-enable-machine-outliner"
 // RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF
+// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF
 // OFF: "-mllvm" "-enable-machine-outliner=never"
 // RUN: %clang --target=x86_64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=WARN
 // WARN: warning: 'x86_64' does not support '-moutline'; flag ignored 
[-Woption-ignored]

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-06 Thread via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-llvm -triple loongarch64 %s -o - | FileCheck %s
+
+// CHECK: @normal ={{.*}} global i32 0, code_model "small"
+int normal __attribute__((model("normal")));
+
+// CHECK: @medium ={{.*}} global i32 0, code_model "medium"
+int medium __attribute__((model("medium")));
+
+// CHECK: @extreme ={{.*}} global i32 0, code_model "large"
+int extreme __attribute__((model("extreme")));

heiher wrote:

Thank you. Done.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-06 Thread via cfe-commits


@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple aarch64 -verify=expected,aarch64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple loongarch64 -verify=expected,loongarch64 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple mips64 -verify=expected,mips64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64 -verify=expected,powerpc64 -fsyntax-only 
%s
+// RUN: %clang_cc1 -triple riscv64 -verify=expected,riscv64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64 -verify=expected,x86_64 -fsyntax-only %s
+
+#if !__has_attribute(model)
+#error "Should support model attribute"
+#endif
+
+int a __attribute((model("tiny")));// expected-error {{code_model 'tiny' 
is not yet supported on this target}}
+int b __attribute((model("small")));   // expected-error {{code_model 'small' 
is not yet supported on this target}}
+int c __attribute((model("normal")));  // aarch64-error {{code_model 'normal' 
is not yet supported on this target}} \
+   // loongarch-no-warning \

heiher wrote:

Done.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-06 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/72078

>From e3863873ab817dacf8680763bb42d91f005fe5ea Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Fri, 10 Nov 2023 21:07:48 -0600
Subject: [PATCH 1/5] [clang] Add per-global code model attribute

This patch adds a per-global code model attribute, which can override
the target's code model to access global variables.

Currently, the code model attribute is only supported on LoongArch.
This patch also maps GCC's code model names to LLVM's, which allows
for better compatibility between the two compilers.

Suggested-by: Arthur Eubanks 
Signed-off-by: WANG Rui 
Link: 
https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
---
 clang/include/clang/Basic/Attr.td |  8 +
 clang/include/clang/Basic/AttrDocs.td |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 13 
 clang/lib/Sema/SemaDeclAttr.cpp   | 30 +++
 clang/test/CodeGen/LoongArch/attributes.c | 10 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Sema/loongarch-attr-model.c| 13 
 8 files changed, 86 insertions(+)
 create mode 100644 clang/test/CodeGen/LoongArch/attributes.c
 create mode 100644 clang/test/Sema/loongarch-attr-model.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1800f584c7e10..d5b5717f3d77c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2718,6 +2718,14 @@ def PragmaClangTextSection : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
+def CodeModel : InheritableAttr {
+  let Spellings = [GCC<"model">];
+  let Args = [StringArgument<"Model">];
+  let Subjects =
+  SubjectList<[ GlobalVar ], ErrorDiag>;
+  let Documentation = [CodeModelDocs];
+}
+
 def Sentinel : InheritableAttr {
   let Spellings = [GCC<"sentinel">];
   let Args = [DefaultIntArgument<"Sentinel", 0>,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b45ec6bbb8d37..1d37c2da6bec0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -57,6 +57,15 @@ global variable or function should be in after translation.
   let Heading = "section, __declspec(allocate)";
 }
 
+def CodeModelDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``model`` attribute allows you to specify a specific code model a
+global variable should be in after translation.
+  }];
+  let Heading = "model";
+}
+
 def UsedDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203..d438fdde9ac7e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;
+
 def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dea58a7ff4146..1f49721e79ddc 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4841,6 +4841,19 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
   GV->setSection(".cp.rodata");
 
+// Handle code model attribute
+if (D->hasAttr()) {
+  if (const CodeModelAttr *CMA = D->getAttr()) {
+auto CM = llvm::StringSwitch(CMA->getModel())
+  .Case("tiny", llvm::CodeModel::Tiny)
+  .Case("kernel", llvm::CodeModel::Kernel)
+  .Case("medium", llvm::CodeModel::Medium)
+  .Case("large", llvm::CodeModel::Large)
+  .Default(llvm::CodeModel::Small);
+GV->setCodeModel(CM);
+  }
+}
+
 // Check if we a have a const declaration with an initializer, we may be
 // able to emit it as available_externally to expose it's value to the
 // optimizer.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 87c78d742d0ff..64aa242dbb04f 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3369,6 +3369,33 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 }
 
+static void handleCodeModelAttr(

[clang] [llvm] [RISCV] Remove experimental from Vector Crypto extensions (PR #74213)

2023-12-06 Thread Yueh-Ting Chen via cfe-commits

eopXD wrote:

The intrinsics for vector crypto is not a formalized version yet. To be safe, I 
think we should have an experimental tag to guard the intrinsics, while the 
extension is ratified and do indeed don't need the experimental.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits

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


[clang-tools-extra] 04ce9a3 - [clang-tidy] performance-unnecessary-copy-init: Add a hook... (#73921)

2023-12-06 Thread via cfe-commits

Author: Clement Courbet
Date: 2023-12-07T08:31:16+01:00
New Revision: 04ce9a34ea82647a61b4e2a2a3cc5c93cc2f0d7d

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

LOG: [clang-tidy] performance-unnecessary-copy-init: Add a hook... (#73921)

... so that derived checks can can observe for which
variables a warning has been emitted. Does nothing by default, which
makes this an NFC.

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 990e20400fbfc..dfe12c5b6007d 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include 
+#include 
 
 namespace clang::tidy::performance {
 namespace {
@@ -263,19 +264,25 @@ void 
UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
 
 void UnnecessaryCopyInitialization::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *NewVar = Result.Nodes.getNodeAs("newVarDecl");
+  const auto &NewVar = *Result.Nodes.getNodeAs("newVarDecl");
+  const auto &BlockStmt = *Result.Nodes.getNodeAs("blockStmt");
+  const auto &VarDeclStmt = *Result.Nodes.getNodeAs("declStmt");
+  // Do not propose fixes if the DeclStmt has multiple VarDecls or in
+  // macros since we cannot place them correctly.
+  const bool IssueFix =
+  VarDeclStmt.isSingleDecl() && !NewVar.getLocation().isMacroID();
+  const bool IsVarUnused = isVariableUnused(NewVar, BlockStmt, 
*Result.Context);
+  const bool IsVarOnlyUsedAsConst =
+  isOnlyUsedAsConst(NewVar, BlockStmt, *Result.Context);
+  const CheckContext Context{
+  NewVar,   BlockStmt,   VarDeclStmt, *Result.Context,
+  IssueFix, IsVarUnused, IsVarOnlyUsedAsConst};
   const auto *OldVar = Result.Nodes.getNodeAs(OldVarDeclId);
   const auto *ObjectArg = Result.Nodes.getNodeAs(ObjectArgId);
-  const auto *BlockStmt = Result.Nodes.getNodeAs("blockStmt");
   const auto *CtorCall = Result.Nodes.getNodeAs("ctorCall");
-  const auto *Stmt = Result.Nodes.getNodeAs("declStmt");
 
   TraversalKindScope RAII(*Result.Context, TK_AsIs);
 
-  // Do not propose fixes if the DeclStmt has multiple VarDecls or in macros
-  // since we cannot place them correctly.
-  bool IssueFix = Stmt->isSingleDecl() && !NewVar->getLocation().isMacroID();
-
   // A constructor that looks like T(const T& t, bool arg = false) counts as a
   // copy only when it is called with default arguments for the arguments after
   // the first.
@@ -289,74 +296,71 @@ void UnnecessaryCopyInitialization::check(
   // instantiations where the types 
diff er and rely on implicit conversion would
   // no longer compile if we switched to a reference.
   if (
diff erentReplacedTemplateParams(
-  NewVar->getType(), constructorArgumentType(OldVar, Result.Nodes),
+  Context.Var.getType(), constructorArgumentType(OldVar, Result.Nodes),
   *Result.Context))
 return;
 
   if (OldVar == nullptr) {
-handleCopyFromMethodReturn(*NewVar, *BlockStmt, *Stmt, IssueFix, ObjectArg,
-   *Result.Context);
+// `auto NewVar = functionCall();`
+handleCopyFromMethodReturn(Context, ObjectArg);
   } else {
-handleCopyFromLocalVar(*NewVar, *OldVar, *BlockStmt, *Stmt, IssueFix,
-   *Result.Context);
+// `auto NewVar = OldVar;`
+handleCopyFromLocalVar(Context, *OldVar);
   }
 }
 
 void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
-const VarDecl &Var, const Stmt &BlockStmt, const DeclStmt &Stmt,
-bool IssueFix, const VarDecl *ObjectArg, ASTContext &Context) {
-  bool IsConstQualified = Var.getType().isConstQualified();
-  if (!IsConstQualified && !isOnlyUsedAsConst(Var, BlockStmt, Context))
+const CheckContext &Ctx, const VarDecl *ObjectArg) {
+  bool IsConstQualified = Ctx.Var.getType().isConstQualified();
+  if (!IsConstQualified && !Ctx.IsVarOnlyUsedAsConst)
 return;
   if (ObjectArg != nullptr &&
-  !isInitializingVariableImmutable(*ObjectArg, BlockStmt, Context,
+  !isInitializingVariableImmutable(*ObjectArg, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
-  if (isVariableUnused(Var, BlockStmt, Context)) {
-auto Diagnostic =
-diag(Var.getLocation(),
- "the %select{|const qualified }0variable %1 is copy-constructed "
- "fro

[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits

legrosbuffle wrote:

Thanks

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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-06 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

I have started to implement defining the -Wformat-signedness option config in 
clang/include/clang/Basic/DiagnosticSemaKinds.td as suggested originally by 
@hazohelet and I agree that the implementation is a lot cleaner that way.
However before finishing implementing that I think we need to conclude what 
level of gcc compatibility that we aim for in clang.

Below I list the characteristics of -Wformat-signedness that I have seen by 
testing it out in gcc and reading the gcc documentation (I have not inspected 
the gcc source code):

1. The option -Wformat-signedness is default off.
2. The -Wformat-signedness warnings are not enabled alone by the -Wformat 
option.
3. The -Wformat-signedness warnings are not enabled alone by the 
-Wformat-signedness option.
4. The -Wformat-signedness warnings are enabled by the option -Wformat together 
with the option -Wformat-signedness.
5. Parts of the -Wformat-signedness warnings (regarding scanf) are enabled by 
the options -Wformat together with the option -pedantic.
6. Warnings produced by -Wformat-signedness is reported as a -Wformat warnings 
(e.g "warning: format ‘%u’ expects argument of type ‘unsigned int’, but 
argument 2 has type ‘int’ [-Wformat=]"
7. Warnings produced by -Wformat-signedness can be suppressed by "#pragma GCC 
diagnostic ignored -Wformat"

Which of the above points are important for us to follow in clang to get a 
reasonable gcc compatibility?
To me I think point 1, 2 and maybe 7 is the most important to follow.

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


[mlir] [lldb] [clang-tools-extra] [llvm] [flang] [libcxx] [openmp] [libc] [compiler-rt] [clang] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-12-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Personally I think that check for move out of std::unique_ptr, and check for 
overall heavy moves could be implemented as an separate one, not related to 
unique_ptr. Easiest way to detect heavy moves is to check size of object, and 
above some threshold mark them as heavy. But thats a separate problem. Maybe 
this PR should be abandoned.

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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -145,9 +160,78 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// ._tls_get_mod node is being tuned here. It is better to put the

amy-kwan wrote:

```suggestion
// .__tls_get_mod node is being tuned here. It is better to put the
```

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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -2385,6 +2385,13 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
   SmallString<128> Name;
   getNameWithPrefix(Name, GO, TM);
 
+  // AIX TLS local-dynamic requires the setting for the specific symbol name.

amy-kwan wrote:

Maybe we can clarify a bit on what we're setting here rather than just saying 
"the setting". It looks like `XMC_TC` here.

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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -2058,6 +2089,10 @@ void PPCAIXAsmPrinter::emitLinkage(const GlobalValue *GV,
 }
   }
 
+  // Do not emit the _$TLSML symbol.
+  if (GVSym->getName() == "_Renamed..5f24__TLSML[TC]")

amy-kwan wrote:

Maybe a silly question, but will this always contain the `5f24`?

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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -145,9 +160,78 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// ._tls_get_mod node is being tuned here. It is better to put the
+// LoadOffset@toc node after the call, since the LoadOffset@toc 
node
+// can use clobbers r4/r5. Search for the pattern of two Load@toc
+// nodes, and then move the LoadOffset@toc node right before the
+// node that uses the OutReg of the ._tls_get_mod node.
+unsigned LDTocOp =
+Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+: (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+if (!RegInfo.use_empty(OutReg)) {
+  std::set Uses;
+  // Collect all instructions that use the OutReg.
+  for (MachineOperand &MO : RegInfo.use_operands(OutReg))
+Uses.insert(MO.getParent());
+  // Find the first user (e.g.: lwax/stfdx) within the current BB.
+  MachineBasicBlock::iterator UseIter = MBB.begin();
+  for (MachineBasicBlock::iterator IE = MBB.end(); UseIter != IE;
+   ++UseIter)
+if (Uses.count(&*UseIter))
+  break;
+
+  if (UseIter != MBB.end()) {
+// Collect associated Load@toc nodes.
+std::set LoadFromTocs;
+for (MachineOperand &MO : UseIter->operands())
+  if (MO.isReg() && MO.isUse()) {
+if (RegInfo.hasOneDef(MO.getReg())) {
+  MachineInstr *Temp =
+  RegInfo.getOneDef(MO.getReg())->getParent();
+  if (Temp == &MI && RegInfo.hasOneDef(InReg))
+Temp = RegInfo.getOneDef(InReg)->getParent();
+  if (Temp->getOpcode() == LDTocOp)
+LoadFromTocs.insert(Temp);
+} else {
+  // FIXME: analyze this scenario if there is one.
+  LoadFromTocs.clear();
+  break;
+}
+  }
+
+// Check the two Load@toc: one should be _$TLSML, and the other
+// will be moved before the node that uses the OutReg of the
+// ._tls_get_mod node.
+if (LoadFromTocs.size() == 2) {
+  MachineBasicBlock::iterator TLSMLIter = MBB.end();
+  MachineBasicBlock::iterator OffsetIter = MBB.end();
+  for (MachineBasicBlock::iterator I = MBB.begin(),
+   IE = MBB.end();
+   I != IE; ++I)
+if (LoadFromTocs.count(&*I)) {
+  if (I->getOperand(1).isGlobal() &&

amy-kwan wrote:

Pull out `I->getOperand(1)` maybe?

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -145,9 +160,78 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// ._tls_get_mod node is being tuned here. It is better to put the
+// LoadOffset@toc node after the call, since the LoadOffset@toc 
node
+// can use clobbers r4/r5. Search for the pattern of two Load@toc
+// nodes, and then move the LoadOffset@toc node right before the
+// node that uses the OutReg of the ._tls_get_mod node.

amy-kwan wrote:

```suggestion
// node that uses the OutReg of the .__tls_get_mod node.
```

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -231,12 +231,19 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
   MCSymbolXCOFF *TCSym =
   cast(Streamer.getCurrentSectionOnly())
   ->getQualNameSymbol();
-  // On AIX, we have a region handle (symbol@m) and the variable offset
-  // (symbol@{gd|ie|le}) for TLS variables, depending on the TLS model.
+  // On AIX, we have TLS variable offsets (symbol@({gd|ie|le|ld}) depending
+  // on the TLS access method (or model). For the general-dynamic access
+  // method, we also have region handle (symbol@m) for each variable. For
+  // local-dynamic, there is a module handle (__TLSML[TC]@ml) for all

amy-kwan wrote:

```suggestion
  // local-dynamic, there is a module handle (_TLSML[TC]@ml) for all
```
Single `_` I think?

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -1356,6 +1382,11 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
.addExpr(SymGotTlsGD));
 return;
   }
+  case PPC::GETtlsMOD32AIX:
+  case PPC::GETtlsMOD64AIX:
+// Transform: %r3 = GETtlsMODNNAIX %r3 (for NN == 32/64).
+// Into: BLA .__tls_get_mod()
+// Input parameter is a module handle (__TLSML[TC]@ml) for all variables.

amy-kwan wrote:

```suggestion
// Input parameter is a module handle (_TLSML[TC]@ml) for all variables.
```
Single `_`?

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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan commented:

I imagine this will be updated after 4b932d84f48e0f3f42c769a5ca7ce6623ab62f2e 
so I plan to review again after.

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits


@@ -145,9 +160,78 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// ._tls_get_mod node is being tuned here. It is better to put the
+// LoadOffset@toc node after the call, since the LoadOffset@toc 
node
+// can use clobbers r4/r5. Search for the pattern of two Load@toc
+// nodes, and then move the LoadOffset@toc node right before the
+// node that uses the OutReg of the ._tls_get_mod node.
+unsigned LDTocOp =
+Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+: (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+if (!RegInfo.use_empty(OutReg)) {
+  std::set Uses;
+  // Collect all instructions that use the OutReg.
+  for (MachineOperand &MO : RegInfo.use_operands(OutReg))
+Uses.insert(MO.getParent());
+  // Find the first user (e.g.: lwax/stfdx) within the current BB.
+  MachineBasicBlock::iterator UseIter = MBB.begin();
+  for (MachineBasicBlock::iterator IE = MBB.end(); UseIter != IE;
+   ++UseIter)
+if (Uses.count(&*UseIter))
+  break;
+
+  if (UseIter != MBB.end()) {
+// Collect associated Load@toc nodes.
+std::set LoadFromTocs;
+for (MachineOperand &MO : UseIter->operands())
+  if (MO.isReg() && MO.isUse()) {
+if (RegInfo.hasOneDef(MO.getReg())) {
+  MachineInstr *Temp =
+  RegInfo.getOneDef(MO.getReg())->getParent();
+  if (Temp == &MI && RegInfo.hasOneDef(InReg))
+Temp = RegInfo.getOneDef(InReg)->getParent();
+  if (Temp->getOpcode() == LDTocOp)
+LoadFromTocs.insert(Temp);
+} else {
+  // FIXME: analyze this scenario if there is one.
+  LoadFromTocs.clear();
+  break;
+}
+  }
+
+// Check the two Load@toc: one should be _$TLSML, and the other
+// will be moved before the node that uses the OutReg of the
+// ._tls_get_mod node.

amy-kwan wrote:

```suggestion
// .__tls_get_mod node.
```

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Amy Kwan via cfe-commits

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


[clang] [clang-tools-extra] [llvm] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

Loooks, good, minor nit in release notes.

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


[llvm] [clang] [clang-tools-extra] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-06 Thread Piotr Zegar via cfe-commits


@@ -318,7 +318,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-using
   ` check to fix function pointer and
-  forward declared ``typedef`` correctly.
+  forward declared ``typedef`` correctly. Ignore ``typedef`` declaration in

PiotrZSL wrote:

Actually release notes should say that new option IgnoreExternC were added to 
control whatever typedefs in extern C should be ignored.

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


[clang-tools-extra] [clang] [llvm] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-06 Thread Piotr Zegar via cfe-commits

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,129 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This funciton will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't has atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {

topperc wrote:

I updated `select` to use SmallVectorImpl&.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Bj=C3=B6rn?= Svensson ,
=?utf-8?q?Bj=C3=B6rn?= Svensson ,
=?utf-8?q?Bj=C3=B6rn?= Svensson 
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,21 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to ``std::erase``.
+

PiotrZSL wrote:

Add info that this check is a subset of bugprone-unused-return-value, and if 
that's enabled then this doesn't have to be.

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


[clang] 6c39ab9 - [Driver] Use SmallVectorImpl reference instead of SmallVector reference in MultilibSet. NFC

2023-12-06 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-12-06T22:25:33-08:00
New Revision: 6c39ab90524ee791b0c6adaf8a305bf68ed4cd7f

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

LOG: [Driver] Use SmallVectorImpl reference instead of SmallVector reference in 
MultilibSet. NFC

We prefer to pass SmallVectorImpl reference so that no specific
inline size is required.

Added: 


Modified: 
clang/include/clang/Driver/Multilib.h
clang/lib/Driver/Multilib.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 6a9533e6dd831..9a2cc9bb1ba13 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -130,7 +130,7 @@ class MultilibSet {
 
   /// Select compatible variants, \returns false if none are compatible
   bool select(const Multilib::flags_list &Flags,
-  llvm::SmallVector &) const;
+  llvm::SmallVectorImpl &) const;
 
   unsigned size() const { return Multilibs.size(); }
 

diff  --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 7681c1a3ce675..9c091bbfdabab 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -95,7 +95,7 @@ MultilibSet &MultilibSet::FilterOut(FilterCallback F) {
 void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); }
 
 bool MultilibSet::select(const Multilib::flags_list &Flags,
- llvm::SmallVector &Selected) const {
+ llvm::SmallVectorImpl &Selected) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
 



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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits

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


[clang] [llvm] [RISCV] Always emit relocations for resolved symbols and relax (PR #73793)

2023-12-06 Thread Fangrui Song via cfe-commits

MaskRay wrote:

For the driver BareMetal.cpp change, claiming `-mno-relax` should not be done 
for non-RISCV targets (e.g. AArch32).

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


[clang] [llvm] [compiler-rt] [flang] [clang-tools-extra] [PowerPC][CodeGen] Exploit STMW and LMW in 32-bit big-endian mode. (PR #74415)

2023-12-06 Thread via cfe-commits

https://github.com/EsmeYi updated 
https://github.com/llvm/llvm-project/pull/74415

>From f6d0ef8357540c61a9c20774e3b170a8db5b72ca Mon Sep 17 00:00:00 2001
From: esmeyi 
Date: Tue, 5 Dec 2023 00:44:04 -0500
Subject: [PATCH 1/4] Exploit STMW and LMW in 32-bit big-endian mode.

---
 llvm/lib/Target/PowerPC/PPCFrameLowering.cpp |  76 -
 llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp  |   4 +
 llvm/test/CodeGen/PowerPC/stm-lm-merge.ll| 110 +++
 3 files changed, 188 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/stm-lm-merge.ll

diff --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
index eb3bf3b2690b2..4d4ef6251a999 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -40,6 +40,12 @@ EnablePEVectorSpills("ppc-enable-pe-vector-spills",
  cl::desc("Enable spills in prologue to vector 
registers."),
  cl::init(false), cl::Hidden);
 
+static cl::opt
+EnableLoadStoreMultiple("ppc-enable-load-store-multiple",
+cl::desc("Enable load/store multiple (only "
+ "support in 32-bit big-endian mode)."),
+cl::init(false), cl::Hidden);
+
 static unsigned computeReturnSaveOffset(const PPCSubtarget &STI) {
   if (STI.isAIXABI())
 return STI.isPPC64() ? 16 : 8;
@@ -2407,6 +2413,30 @@ bool PPCFrameLowering::assignCalleeSavedSpillSlots(
   return AllSpilledToReg;
 }
 
+static void findContinuousLoadStore(ArrayRef CSI,
+Register &MergeFrom) {
+  CalleeSavedInfo BeginI = CSI[0];
+  unsigned I = 1, E = CSI.size();
+  for (; I < E; ++I) {
+// Find continuous store/load.
+unsigned RegDiff = CSI[I].getReg() - CSI[I - 1].getReg();
+unsigned FrameIdxDiff = CSI[I - 1].getFrameIdx() - CSI[I].getFrameIdx();
+Register BeginReg = BeginI.getReg();
+if (BeginReg < PPC::R0 || BeginReg > PPC::R31 || BeginI.isSpilledToReg() ||
+RegDiff != 1 || FrameIdxDiff != 1)
+  BeginI = CSI[I];
+if (CSI[I].getReg() == PPC::R31)
+  break;
+  }
+
+  if (I == E || BeginI.getReg() == PPC::R31)
+return;
+
+  // Record the first reg that STMW/LMW are going to merge since STMW/LMW save
+  // from rN to r31.
+  MergeFrom = BeginI.getReg();
+}
+
 bool PPCFrameLowering::spillCalleeSavedRegisters(
 MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
 ArrayRef CSI, const TargetRegisterInfo *TRI) const {
@@ -2437,6 +2467,11 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
 }
   }
 
+  Register MergeFrom = PPC::R31;
+  if (EnableLoadStoreMultiple && !Subtarget.isLittleEndian() &&
+  !Subtarget.isPPC64())
+findContinuousLoadStore(CSI, MergeFrom);
+
   for (const CalleeSavedInfo &I : CSI) {
 Register Reg = I.getReg();
 
@@ -2521,7 +2556,23 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
 !MF->getFunction().hasFnAttribute(Attribute::NoUnwind))
   TII.storeRegToStackSlotNoUpd(MBB, MI, Reg, !IsLiveIn,
I.getFrameIdx(), RC, TRI);
-else
+else if (MergeFrom < PPC::R31 && Reg == MergeFrom) {
+  // Build an STMW instruction.
+  int FrameIdx = I.getFrameIdx();
+  MachineInstrBuilder MIB =
+  BuildMI(MBB, MBB.begin(), DL, TII.get(PPC::STMW));
+  MIB.addReg(Reg, getKillRegState(!IsLiveIn));
+  // Add frame reference.
+  MIB.addImm(0).addFrameIndex(FrameIdx);
+  const MachineFrameInfo &MFI = MF->getFrameInfo();
+  MachineMemOperand *MMO = MF->getMachineMemOperand(
+  MachinePointerInfo::getFixedStack(*MF, FrameIdx),
+  MachineMemOperand::MOStore, MFI.getObjectSize(FrameIdx),
+  MFI.getObjectAlign(FrameIdx));
+  MIB.addMemOperand(MMO);
+} else if (Reg > MergeFrom && Reg <= PPC::R31)
+  continue;
+   else
   TII.storeRegToStackSlot(MBB, MI, Reg, !IsLiveIn, I.getFrameIdx(), RC,
   TRI, Register());
   }
@@ -2615,6 +2666,11 @@ bool PPCFrameLowering::restoreCalleeSavedRegisters(
   unsigned CSIIndex = 0;
   BitVector Restored(TRI->getNumRegs());
 
+  Register MergeFrom = PPC::R31;
+  if (EnableLoadStoreMultiple && !Subtarget.isLittleEndian() &&
+  !Subtarget.isPPC64())
+findContinuousLoadStore(CSI, MergeFrom);
+
   // Initialize insertion-point logic; we will be restoring in reverse
   // order of spill.
   MachineBasicBlock::iterator I = MI, BeforeI = I;
@@ -2694,7 +2750,23 @@ bool PPCFrameLowering::restoreCalleeSavedRegisters(
 !MF->getFunction().hasFnAttribute(Attribute::NoUnwind))
   TII.loadRegFromStackSlotNoUpd(MBB, I, Reg, CSI[i].getFrameIdx(), RC,
 TRI);
-else
+else if (MergeFrom < PPC::R31 && Reg == MergeFrom) {
+  // Buil

[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -2400,7 +2400,8 @@ void tools::addMachineOutlinerArgs(const Driver &D,
   // Otherwise, add the proper mllvm flags.
   if (!(Triple.isARM() || Triple.isThumb() ||
 Triple.getArch() == llvm::Triple::aarch64 ||

MaskRay wrote:

This can be simplified as `isAArch64()`

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


[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-12-06 Thread Fangrui Song via cfe-commits

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


[clang] [Driver][MachineOutliner] Support -moutline option for aarch64_be (PR #73223)

2023-12-06 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


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


[llvm] [clang-tools-extra] [clang] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [XCOFF][obj2yaml] support parsing auxiliary symbols for XCOFF (PR #70642)

2023-12-06 Thread via cfe-commits


@@ -282,45 +282,57 @@ static void auxSymMapping(IO &IO, 
XCOFFYAML::SectAuxEntForStat &AuxSym) {
 
 void MappingTraits>::mapping(
 IO &IO, std::unique_ptr &AuxSym) {
-  assert(!IO.outputting() && "We don't dump aux symbols currently.");
+
+  auto ResetAuxSym = [&](auto *AuxEnt) {
+if (!IO.outputting())
+  AuxSym.reset(AuxEnt);

EsmeYi wrote:

Thanks, this seems cause a sanitizer error in 
https://lab.llvm.org/buildbot/#/builders/5/builds/39023
I gonna fix it.

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


[llvm] [clang-tools-extra] [clang] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -230,3 +230,15 @@ defm add_symbol
 defm update_section
 : Eq<"update-section", "Replace the contents of section  with 
contents from a file ">,
   MetaVarName<"name=file">;
+
+defm gap_fill
+: Eq<"gap-fill", "Fill the gaps between sections with  instead of 
zero. "
+ " must be an unsigned 8-bit integer. "
+ "This option is only supported for ELF inputs and binary 
outputs.">,
+  MetaVarName<"value">;
+
+defm pad_to
+: Eq<"pad-to", "Pad the output to the load address , using a 
value "
+   "of zero or the value specified by :option:`--gap-fill`"
+   "This option is only supported for ELF inputs and binary 
outputs.">,

MaskRay wrote:

Help message typically omit the trailing period

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


[clang] [clang-tools-extra] [llvm] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


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


[clang-tools-extra] [clang] [llvm] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -230,3 +230,15 @@ defm add_symbol
 defm update_section
 : Eq<"update-section", "Replace the contents of section  with 
contents from a file ">,
   MetaVarName<"name=file">;
+
+defm gap_fill
+: Eq<"gap-fill", "Fill the gaps between sections with  instead of 
zero. "
+ " must be an unsigned 8-bit integer. "
+ "This option is only supported for ELF inputs and binary 
outputs.">,
+  MetaVarName<"value">;
+
+defm pad_to
+: Eq<"pad-to", "Pad the output to the load address , using a 
value "
+   "of zero or the value specified by :option:`--gap-fill`"
+   "This option is only supported for ELF inputs and binary 
outputs.">,

MaskRay wrote:

Missing `.` before `This option ...`?

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


[clang-tools-extra] [clang] [llvm] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -230,3 +230,15 @@ defm add_symbol
 defm update_section
 : Eq<"update-section", "Replace the contents of section  with 
contents from a file ">,
   MetaVarName<"name=file">;
+
+defm gap_fill
+: Eq<"gap-fill", "Fill the gaps between sections with  instead of 
zero. "
+ " must be an unsigned 8-bit integer. "
+ "This option is only supported for ELF inputs and binary 
outputs.">,

MaskRay wrote:

Help message typically omit the trailing period. I think you can use the 
singular form `... binary output">`

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


[llvm] [clang] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.
+  if (!Flag.startswith("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  llvm::Expected> MLConfigParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Flag.drop_front(7), /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might get parsing error if rv32e in the list, we could just skip
+// that and process the rest of multi-lib configs.
+Skip = true;
+continue;
+  }
+  auto &MLConfigISAInfo = *MLConfigParseResult;
+
+  const llvm::RISCVISAInfo::OrderedExtensionMap &MLConfigArchExts =
+  MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if (!AllArchExts.contains(ExtName)) {
+  AllArchExts.insert(ExtName);
+  addMultilibFlag(ISAInfo->hasExtension(ExtName),
+  Twine("-", ExtName).str(), NewFlags);
+}
+  }
+
+  // Check the XLEN explicitly.
+  if (MLConfigISAInfo->getXLen() == 32) {
+NewMultilib.flag("-m32");
+NewMultilib.flag("!m64");
+  } else {
+NewMultilib.flag("!m32");
+NewMultilib.flag("-m64");
+  }
+
+  // Atomic extension must be explicitly checked, soft and hard atomic
+  // operation never co-work correctly.
+  if (!MLConfigISAInfo->hasExtension("a"))
+NewMultilib.flag("!a");
+}
+
+if (Skip)
+  continue;
+
+NewMultilibs.emplace_back(NewMultilib);
+  }
+
+  // Build an internal used only multi-lib list, used for checking any
+  // compatible multi-lib.
+  MultilibSet NewRISCVMultilibs =
+  MultilibSetBuilder().Either(NewMultilibs).makeMultilibSet();
+
+  if (NewRISCVMultilibs.select(NewFlags, SelectedMultilibs))
+for (const Multilib &NewSelectedM : SelectedMultilibs)
+  for (auto M : RISCVMultilibSet)

topperc wrote:

auto &M

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.
+  if (!Flag.startswith("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  llvm::Expected> MLConfigParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Flag.drop_front(7), /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might get parsing error if rv32e in the list, we could just skip
+// that and process the rest of multi-lib configs.
+Skip = true;
+continue;
+  }
+  auto &MLConfigISAInfo = *MLConfigParseResult;
+
+  const llvm::RISCVISAInfo::OrderedExtensionMap &MLConfigArchExts =
+  MLConfigISAInfo->getExtensions();
+  for (auto MLConfigArchExt : MLConfigArchExts) {
+auto ExtName = MLConfigArchExt.first;
+NewMultilib.flag(Twine("-", ExtName).str());
+
+if (!AllArchExts.contains(ExtName)) {

topperc wrote:

```
if (AllArchExts.insert(ExtName).second) {
  addMultilibFlag(ISAInfo->hasExtension(ExtName),
  Twine("-", ExtName).str(), NewFlags);
}
```

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {

topperc wrote:

`auto &M`?

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.
+  if (!Flag.startswith("-march=")) {

topperc wrote:

Use `!Flag.consume_front("-march=")` and remove the `.drop_front(7)` in the 
`parseArchString` call

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.
+  if (!Flag.startswith("-march=")) {
+NewMultilib.flag(Flag);
+continue;
+  }
+
+  // Break down -march into individual extension.
+  llvm::Expected> MLConfigParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Flag.drop_front(7), /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!MLConfigParseResult) {
+// Ignore any error here, we assume it will handled in another place.
+llvm::consumeError(MLConfigParseResult.takeError());
+
+// We might get parsing error if rv32e in the list, we could just skip

topperc wrote:

"get parsing" -> "get a parsing"

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,
+const Multilib::flags_list &Flags,
+llvm::SmallVector &SelectedMultilibs) {
+  // Try to find the perfect matching multi-lib first.
+  if (RISCVMultilibSet.select(Flags, SelectedMultilibs))
+return true;
+
+  Multilib::flags_list NewFlags;
+  std::vector NewMultilibs;
+
+  llvm::Expected> ParseResult =
+  llvm::RISCVISAInfo::parseArchString(
+  Arch, /*EnableExperimentalExtension=*/true,
+  /*ExperimentalExtensionVersionCheck=*/false);
+  if (!ParseResult) {
+// Ignore any error here, we assume it will be handled in another place.
+consumeError(ParseResult.takeError());
+return false;
+  }
+
+  auto &ISAInfo = *ParseResult;
+
+  addMultilibFlag(ISAInfo->getXLen() == 32, "-m32", NewFlags);
+  addMultilibFlag(ISAInfo->getXLen() == 64, "-m64", NewFlags);
+
+  // Collect all flags except march=*
+  for (StringRef Flag : Flags) {
+if (Flag.startswith("!march=") || Flag.startswith("-march="))
+  continue;
+
+NewFlags.push_back(Flag.str());
+  }
+
+  llvm::StringSet<> AllArchExts;
+  // Reconstruct multi-lib list, and break march option into separated
+  // extension. e.g. march=rv32im -> +i +m
+  for (auto M : RISCVMultilibSet) {
+bool Skip = false;
+
+MultilibBuilder NewMultilib =
+MultilibBuilder(M.gccSuffix(), M.osSuffix(), M.includeSuffix());
+for (StringRef Flag : M.flags()) {
+  // Add back the all option except -march.

topperc wrote:

`Add back all flags except -march.`

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


[clang] [llvm] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay commented:

Sorry for the delay..

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


[clang] [llvm] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,198 @@
+# RUN: yaml2obj --docnum=1 %s -o %t
+
+# RUN: not llvm-objcopy --gap-fill 1 %t 2>&1 | FileCheck %s 
--check-prefix=NOT-BINARY
+# NOT-BINARY: error: '--gap-fill' is only supported for binary output
+
+# RUN: not llvm-objcopy -O binary --gap-fill= %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-FORMAT
+# BAD-FORMAT: error: --gap-fill: bad number:
+
+# RUN: not llvm-objcopy -O binary --gap-fill=x %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-INPUT
+# BAD-INPUT: error: --gap-fill: bad number: x
+
+# RUN: not llvm-objcopy -O binary --gap-fill=0x %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-INPUT2
+# BAD-INPUT2: error: --gap-fill: bad number: 0x
+
+# RUN: not llvm-objcopy -O binary --gap-fill=0x1G %t %t.bin 2>&1 | FileCheck 
%s --check-prefix=BAD-INPUT3
+# BAD-INPUT3: error: --gap-fill: bad number: 0x1G
+
+# RUN: not llvm-objcopy -O binary --gap-fill=ff %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-INPUT4
+# BAD-INPUT4: error: --gap-fill: bad number: ff
+
+# RUN: llvm-objcopy -O binary --gap-fill=0x1122 %t %t-val16 2>&1 | FileCheck 
%s --check-prefix=TRUNCATED-ERR
+# TRUNCATED-ERR: warning: truncating gap-fill from 0x1122 to 0x22
+
+# RUN: od -v -Ax -t x1 %t-val16 | FileCheck %s --check-prefix=TRUNCATED 
--match-full-lines
+# TRUNCATED:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 22 a1 b2
+# TRUNCATED-NEXT: 10 c3 d4 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 20 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 30 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 40 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 50 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 60 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 70 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 80 22 22 89 ab cd ef
+# TRUNCATED-NEXT: 86
+
+## Test no gap fill with all allocatable output sections.
+# RUN: llvm-objcopy -O binary %t %t-default
+# RUN: od -v -Ax -t x1 %t-default | FileCheck %s --check-prefix=DEFAULT 
--match-full-lines
+# DEFAULT:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 00 a1 b2
+# DEFAULT-NEXT: 10 c3 d4 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 80 00 00 89 ab cd ef
+# DEFAULT-NEXT: 86
+
+## Test gap fill with all allocatable output sections.
+# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t %t-filled
+# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=FULL 
--match-full-lines
+# FULL:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2
+# FULL-NEXT: 10 c3 d4 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 20 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 30 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 40 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 50 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 60 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 70 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 80 e9 e9 89 ab cd ef
+# FULL-NEXT: 86
+
+## Test gap fill with a decimal value.
+# RUN: llvm-objcopy -O binary --gap-fill=99 %t %t-filled-decimal
+# RUN: od -v -Ax -t x1 %t-filled-decimal | FileCheck %s --check-prefix=DEC 
--match-full-lines
+# DEC:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 63 a1 b2
+# DEC-NEXT: 10 c3 d4 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 20 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 30 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 40 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 50 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 60 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 70 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 80 63 63 89 ab cd ef
+# DEC-NEXT: 86
+
+## Test gap fill with the last section removed, should be truncated.
+# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.foo %t 
%t-filled
+# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s 
--check-prefix=REMOVE-LAST-SECTION --match-full-lines
+# REMOVE-LAST-SECTION: 00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2
+# REMOVE-LAST-SECTION-NEXT: 10 c3 d4
+# REMOVE-LAST-SECTION-NEXT: 12
+
+## Test gap fill with the middle section removed, should be filled.
+# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.gap2 %t 
%t-filled
+# RUN: od 

[llvm] [clang] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits

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


[llvm] [clang] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,198 @@
+# RUN: yaml2obj --docnum=1 %s -o %t
+
+# RUN: not llvm-objcopy --gap-fill 1 %t 2>&1 | FileCheck %s 
--check-prefix=NOT-BINARY
+# NOT-BINARY: error: '--gap-fill' is only supported for binary output
+
+# RUN: not llvm-objcopy -O binary --gap-fill= %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-FORMAT
+# BAD-FORMAT: error: --gap-fill: bad number:
+
+# RUN: not llvm-objcopy -O binary --gap-fill=x %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-INPUT
+# BAD-INPUT: error: --gap-fill: bad number: x
+
+# RUN: not llvm-objcopy -O binary --gap-fill=0x %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-INPUT2
+# BAD-INPUT2: error: --gap-fill: bad number: 0x
+
+# RUN: not llvm-objcopy -O binary --gap-fill=0x1G %t %t.bin 2>&1 | FileCheck 
%s --check-prefix=BAD-INPUT3
+# BAD-INPUT3: error: --gap-fill: bad number: 0x1G
+
+# RUN: not llvm-objcopy -O binary --gap-fill=ff %t %t.bin 2>&1 | FileCheck %s 
--check-prefix=BAD-INPUT4
+# BAD-INPUT4: error: --gap-fill: bad number: ff
+
+# RUN: llvm-objcopy -O binary --gap-fill=0x1122 %t %t-val16 2>&1 | FileCheck 
%s --check-prefix=TRUNCATED-ERR
+# TRUNCATED-ERR: warning: truncating gap-fill from 0x1122 to 0x22
+
+# RUN: od -v -Ax -t x1 %t-val16 | FileCheck %s --check-prefix=TRUNCATED 
--match-full-lines
+# TRUNCATED:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 22 a1 b2
+# TRUNCATED-NEXT: 10 c3 d4 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 20 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 30 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 40 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 50 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 60 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 70 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
+# TRUNCATED-NEXT: 80 22 22 89 ab cd ef
+# TRUNCATED-NEXT: 86
+
+## Test no gap fill with all allocatable output sections.
+# RUN: llvm-objcopy -O binary %t %t-default
+# RUN: od -v -Ax -t x1 %t-default | FileCheck %s --check-prefix=DEFAULT 
--match-full-lines
+# DEFAULT:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 00 a1 b2
+# DEFAULT-NEXT: 10 c3 d4 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# DEFAULT-NEXT: 80 00 00 89 ab cd ef
+# DEFAULT-NEXT: 86
+
+## Test gap fill with all allocatable output sections.
+# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t %t-filled
+# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=FULL 
--match-full-lines
+# FULL:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2
+# FULL-NEXT: 10 c3 d4 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 20 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 30 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 40 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 50 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 60 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 70 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
+# FULL-NEXT: 80 e9 e9 89 ab cd ef
+# FULL-NEXT: 86
+
+## Test gap fill with a decimal value.
+# RUN: llvm-objcopy -O binary --gap-fill=99 %t %t-filled-decimal
+# RUN: od -v -Ax -t x1 %t-filled-decimal | FileCheck %s --check-prefix=DEC 
--match-full-lines
+# DEC:  00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 63 a1 b2
+# DEC-NEXT: 10 c3 d4 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 20 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 30 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 40 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 50 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 60 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 70 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
+# DEC-NEXT: 80 63 63 89 ab cd ef
+# DEC-NEXT: 86
+
+## Test gap fill with the last section removed, should be truncated.
+# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.foo %t 
%t-filled
+# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s 
--check-prefix=REMOVE-LAST-SECTION --match-full-lines
+# REMOVE-LAST-SECTION: 00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2
+# REMOVE-LAST-SECTION-NEXT: 10 c3 d4
+# REMOVE-LAST-SECTION-NEXT: 12
+
+## Test gap fill with the middle section removed, should be filled.
+# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.gap2 %t 
%t-filled
+# RUN: od 

[clang] [llvm] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -738,6 +739,36 @@ objcopy::parseObjcopyOptions(ArrayRef 
RawArgsArr,
   if (auto Arg = InputArgs.getLastArg(OBJCOPY_extract_partition))
 Config.ExtractPartition = Arg->getValue();
 
+  if (const auto *A = InputArgs.getLastArg(OBJCOPY_gap_fill)) {
+if (Config.OutputFormat != FileFormat::Binary)
+  return createStringError(
+  errc::invalid_argument,
+  "'--gap-fill' is only supported for binary output");
+ErrorOr Val = getAsInteger(A->getValue());
+if (!Val)
+  return createStringError(Val.getError(), "--gap-fill: bad number: %s",
+   A->getValue());
+uint8_t ByteVal = Val.get();
+if (ByteVal != Val.get())
+  if (Error E = reportWarning(llvm::createStringError(

MaskRay wrote:

I see that objcopy uses a warning, but an error seems more appropriate and the 
difference between warning/error should not matter for the user.

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


[clang] [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute (PR #71300)

2023-12-06 Thread Tobias Hieta via cfe-commits

tru wrote:

@rnk @amykhuang might be interested in reviewing as well. 

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


[clang] [RISCV] Implement multi-lib reuse rule for RISC-V bare-metal toolchain (PR #73765)

2023-12-06 Thread Craig Topper via cfe-commits


@@ -1715,6 +1716,130 @@ static void findCSKYMultilibs(const Driver &D, const 
llvm::Triple &TargetTriple,
 Result.Multilibs = CSKYMultilibs;
 }
 
+/// Extend the multi-lib re-use selection mechanism for RISC-V.
+/// This function will try to re-use multi-lib if they are compatible.
+/// Definition of compatible:
+///   - ABI must be the same.
+///   - multi-lib is a subset of current arch, e.g. multi-lib=march=rv32im
+/// is a subset of march=rv32imc.
+///   - march that contains atomic extension can't reuse multi-lib that
+/// doesn't have atomic, vice versa. e.g. multi-lib=march=rv32im and
+/// march=rv32ima are not compatible, because software and hardware
+/// atomic operation can't work together correctly.
+static bool
+RISCVMultilibSelect(const MultilibSet &RISCVMultilibSet, StringRef Arch,

topperc wrote:

function names should start with a verb (an action word) and a lower case 
letter. Maybe `selectRISCVMultilib`?

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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-06 Thread Chen Zheng via cfe-commits


@@ -3412,13 +3416,23 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate two TOC entries, one for
+// the variable offset, the other for the module handle. The module handle
+// is encapsulated inside the TLSLD_AIX pseudo node, and will be expanded 
by
+// PPCTLSDynamicCall.
+SDValue VariableOffsetTGA =
+DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, PPCII::MO_TLSLD_FLAG);
+SDValue VariableOffset = getTOCEntry(DAG, dl, VariableOffsetTGA);

chenzheng1030 wrote:

4b932d84f48e0f3f42c769a5ca7ce6623ab62f2e is committed to redesign the target 
flags of machine operand on PPC. Now we should be able to add new flags.

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


[llvm] [clang-tools-extra] [clang] [XCOFF][obj2yaml] support parsing auxiliary symbols for XCOFF (PR #70642)

2023-12-06 Thread Kai Luo via cfe-commits


@@ -282,45 +282,57 @@ static void auxSymMapping(IO &IO, 
XCOFFYAML::SectAuxEntForStat &AuxSym) {
 
 void MappingTraits>::mapping(
 IO &IO, std::unique_ptr &AuxSym) {
-  assert(!IO.outputting() && "We don't dump aux symbols currently.");
+
+  auto ResetAuxSym = [&](auto *AuxEnt) {
+if (!IO.outputting())
+  AuxSym.reset(AuxEnt);

bzEq wrote:

Might use a templated helper function to replace this lambda.
```c++
template
static void ResetAuxSym(IO &IO, std::unique_ptr 
&AuxSym) {
  if (!IO.outputting()) AuxSym.reset(new AuxEntT);
}
```

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


[clang] [Clang] Mark WG14 N2939 (Identifier Syntax Fixes) as available in Clang 15 (PR #74666)

2023-12-06 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM

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


[clang] [clang] Crash when referencing capture in static lambda (PR #74661)

2023-12-06 Thread via cfe-commits

cor3ntin wrote:

Can you add a release note? Otherwise it looks good to me

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


[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)

2023-12-06 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/74553

>From 9be87da42e48895cf23d90a3ed735b7a36b1ccb3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 6 Dec 2023 04:51:45 +0100
Subject: [PATCH 1/4] [clang] Add separate C++23 extension flag for attrs on
 lambda

---
 clang/include/clang/Basic/DiagnosticGroups.td   |  4 +++-
 clang/include/clang/Basic/DiagnosticParseKinds.td   |  2 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp   | 10 ++
 clang/test/SemaCXX/coro-return-type-and-wrapper.cpp |  9 ++---
 4 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ff028bbbf7426..81443fb16a1f3 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1126,6 +1126,8 @@ def FutureAttrs : 
DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
 CXX20Attrs]>;
 
+def CXX23AttrsOnLambda : DiagGroup<"c++23-attrs-on-lambda">;
+
 // A warning group for warnings about using C++11 features as extensions in
 // earlier C++ versions.
 def CXX11 : DiagGroup<"c++11-extensions", [CXX11ExtraSemi, 
CXX11InlineNamespace,
@@ -1145,7 +1147,7 @@ def CXX20 : DiagGroup<"c++20-extensions", 
[CXX20Designator, CXX20Attrs]>;
 
 // A warning group for warnings about using C++23 features as extensions in
 // earlier C++ versions.
-def CXX23 : DiagGroup<"c++23-extensions">;
+def CXX23 : DiagGroup<"c++23-extensions", [CXX23AttrsOnLambda]>;
 
 // A warning group for warnings about using C++26 features as extensions in
 // earlier C++ versions.
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 21fe6066d5876..bc7bd7589ef14 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1035,7 +1035,7 @@ def err_capture_default_first : Error<
   "capture default must be first">;
 def ext_decl_attrs_on_lambda : ExtWarn<
   "%select{an attribute specifier sequence|%0}1 in this position "
-  "is a C++23 extension">, InGroup;
+  "is a C++23 extension">, InGroup;
 def ext_lambda_missing_parens : ExtWarn<
   "lambda without a parameter clause is a C++23 extension">,
   InGroup;
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
index d3e2d673ebb3c..ec8997036feb4 100644
--- a/clang/test/SemaCXX/coro-lifetimebound.cpp
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused 
-Wno-c++23-attrs-on-lambda
 
 #include "Inputs/std-coroutine.h"
 
@@ -64,14 +64,8 @@ Co bar_coro(const int &b, int c) {
   : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
 }
 
-#define CORO_WRAPPER \
-  _Pragma("clang diagnostic push") \
-  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
-  [[clang::coro_wrapper]] \
-  _Pragma("clang diagnostic pop")
-
 void lambdas() {
-  auto unsafe_lambda = [] CORO_WRAPPER (int b) {
+  auto unsafe_lambda = [] [[clang::coro_wrapper]] (int b) {
 return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
   };
   auto coro_lambda = [] (const int&) -> Co {
diff --git a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp 
b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
index 5f8076f1c782a..d52d1e4cea399 100644
--- a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
+++ b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-c++23-attrs-on-lambda
 #include "Inputs/std-coroutine.h"
 
 using std::suspend_always;
@@ -45,11 +45,6 @@ Co non_marked_wrapper(int b) { return foo_coro(b); }
 } // namespace using_decl
 
 namespace lambdas {
-#define CORO_WRAPPER \
-  _Pragma("clang diagnostic push") \
-  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
-  [[clang::coro_wrapper]] \
-  _Pragma("clang diagnostic pop")
 
 void foo() {
   auto coro_lambda = []() -> Gen {
@@ -59,7 +54,7 @@ void foo() {
   auto not_allowed_wrapper = []() -> Gen {
 return foo_coro(1);
   };
-  auto allowed_wrapper = [] CORO_WRAPPER() -> Gen {
+  auto allowed_wrapper = [] [[clang::coro_wrapper]] () -> Gen {
 return foo_coro(1);
   };
 }

>From 14532988c00fc0ce6530a05a899abbc3976bd374 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 6 Dec 202

[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple aarch64 -verify=expected,aarch64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple loongarch64 -verify=expected,loongarch64 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple mips64 -verify=expected,mips64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64 -verify=expected,powerpc64 -fsyntax-only 
%s
+// RUN: %clang_cc1 -triple riscv64 -verify=expected,riscv64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64 -verify=expected,x86_64 -fsyntax-only %s
+
+#if !__has_attribute(model)
+#error "Should support model attribute"
+#endif
+
+int a __attribute((model("tiny")));// expected-error {{code_model 'tiny' 
is not yet supported on this target}}
+int b __attribute((model("small")));   // expected-error {{code_model 'small' 
is not yet supported on this target}}
+int c __attribute((model("normal")));  // aarch64-error {{code_model 'normal' 
is not yet supported on this target}} \
+   // loongarch-no-warning \

MaskRay wrote:

`loongarch-no-warning` can be omitted. If there is a diagnostic, `-verify` will 
complain.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-06 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-llvm -triple loongarch64 %s -o - | FileCheck %s
+
+// CHECK: @normal ={{.*}} global i32 0, code_model "small"
+int normal __attribute__((model("normal")));
+
+// CHECK: @medium ={{.*}} global i32 0, code_model "medium"
+int medium __attribute__((model("medium")));
+
+// CHECK: @extreme ={{.*}} global i32 0, code_model "large"
+int extreme __attribute__((model("extreme")));

MaskRay wrote:

You can add `static` to one of the variables to add some variance, and add a 
`void use() { ... }` to use the variable.

Consider testing a C++ variable template, a TLS variable, a function, and a 
struct.

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


[clang-tools-extra] [llvm] [clang] [XCOFF][obj2yaml] support parsing auxiliary symbols for XCOFF (PR #70642)

2023-12-06 Thread Kai Luo via cfe-commits


@@ -282,45 +282,57 @@ static void auxSymMapping(IO &IO, 
XCOFFYAML::SectAuxEntForStat &AuxSym) {
 
 void MappingTraits>::mapping(
 IO &IO, std::unique_ptr &AuxSym) {
-  assert(!IO.outputting() && "We don't dump aux symbols currently.");
+
+  auto ResetAuxSym = [&](auto *AuxEnt) {
+if (!IO.outputting())
+  AuxSym.reset(AuxEnt);

bzEq wrote:

What if `IO.outputting()` is `true`, will `AuxEnt` be deleted?

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


[clang] [clang][AMDGPU] Update amdgpu_waves_per_eu attr docs (PR #74587)

2023-12-06 Thread Matt Arsenault via cfe-commits


@@ -2659,8 +2659,9 @@ An error will be given if:
   - Specified values violate subtarget specifications;
   - Specified values are not compatible with values provided through other
 attributes;
-  - The AMDGPU target backend is unable to create machine code that can meet 
the
-request.
+
+The AMDGPU target backend will emit a warning whenever it is unable to

arsenm wrote:

This looks indented differently, without the list - as the previous comment did 

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


[openmp] [clang] [OpenMP] Fix runtime problem due wrong map size. (PR #74692)

2023-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (jyu2-git)


Changes

Currently we are missing set up-boundary address for FinalArraySection as 
highests elements in partial struct data.

Currently for:
\#pragma omp target map(D.a) map(D.b[:2])
The size is:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %2 = getelementptr float, ptr %arrayidx, i32 1
  %3 = ptrtoint ptr %2 to i64
  %4 = ptrtoint ptr %a to i64
  %5 = sub i64 %3, %4
  %6 = sdiv exact i64 %5, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to 
i64)

Where %arrayidx is wrong for (D.b[:2]) should be:
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 1

The fix is to emit the pointer to the last element of array section and use 
this pointer as the highest element in partial struct data.

After change IR:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %b1 = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx2 = getelementptr inbounds [2 x float], ptr %b1, i64 0, i64 1
  %1 = getelementptr float, ptr %arrayidx2, i32 1
  %2 = ptrtoint ptr %1 to i64
  %3 = ptrtoint ptr %a to i64
  %4 = sub i64 %2, %3
  %5 = sdiv exact i64 %4, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to 
i64)

---
Full diff: https://github.com/llvm/llvm-project/pull/74692.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+8-1) 
- (modified) clang/test/OpenMP/target_data_use_device_addr_codegen.cpp (+7-1) 
- (added) openmp/libomptarget/test/offloading/target_map_for_member_data.cpp 
(+23) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 55648963df36a..7f7e6f5306664 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7389,7 +7389,14 @@ class MappableExprsHandler {
   } else if (FieldIndex < PartialStruct.LowestElem.first) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
-PartialStruct.HighestElem = {FieldIndex, LowestElem};
+if (IsFinalArraySection) {
+  Address HB =
+  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+  .getAddress(CGF);
+  PartialStruct.HighestElem = {FieldIndex, HB};
+} else {
+  PartialStruct.HighestElem = {FieldIndex, LowestElem};
+}
   }
 }
 
diff --git a/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp 
b/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
index 7e70cdf74ad37..ae0653d0585d4 100644
--- a/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
+++ b/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
@@ -144,7 +144,13 @@ int main() {
 // CHECK: [[ARR_IDX6:%.+]] = getelementptr inbounds [4 x i32], ptr 
[[ARR_ADDR]], i64 0, i64 0
 // CHECK: [[A_ADDR2:%.+]] = getelementptr inbounds %struct.S, ptr [[THIS]], 
i32 0, i32 0
 // CHECK: [[P4:%.+]] = mul nuw i64 [[CONV:%.+]], 4
-// CHECK: [[ARR_END:%.+]] = getelementptr i32, ptr [[ARR_IDX6]], i32 1
+// CHECK: [[A_ADDR3:%.+]] = getelementptr inbounds %struct.S, ptr [[THIS]], 
i32 0, i32 0
+// CHECK: [[L5:%.+]] = load i32, ptr [[A_ADDR3]]
+// CHECK: [[L6:%.+]] = sext i32 [[L5]] to i64
+// CHECK: [[LB_ADD_LEN:%lb_add_len]] = add nsw i64 -1, [[L6]]
+// CHECK: [[ARR_ADDR9:%.+]] = getelementptr inbounds %struct.S, ptr [[THIS]], 
i32 0, i32 3
+// CHECK: [[ARR_IDX10:%arrayidx.+]] = getelementptr inbounds [4 x i32], ptr 
[[ARR_ADDR9]], i64 0, i64 %lb_add_len
+// CHECK: [[ARR_END:%.+]] = getelementptr i32, ptr [[ARR_IDX10]], i32 1
 // CHECK: [[E:%.+]] = ptrtoint ptr [[ARR_END]] to i64
 // CHECK: [[B:%.+]] = ptrtoint ptr [[A_ADDR]] to i64
 // CHECK: [[DIFF:%.+]] = sub i64 [[E]], [[B]]
diff --git a/openmp/libomptarget/test/offloading/target_map_for_member_data.cpp 
b/openmp/libomptarget/test/offloading/target_map_for_member_data.cpp
new file mode 100644
index 0..8c8b4668c32e6
--- /dev/null
+++ b/openmp/libomptarget/test/offloading/target_map_for_member_data.cpp
@@ -0,0 +1,23 @@
+// clang-format off
+// RUN: %libomptarget-compilexx-generic && env LIBOMPTARGET_DEBUG=1 
%libomptarget-run-generic 2>&1 | %fcheck-generic
+// clang-format on
+
+struct DataTy {
+  float a;
+  float b[2];
+};
+
+int main(int argc, char **argv) {
+  DataTy D;
+#pragma omp target map(D.a) map(D.b[ : 2])
+  {
+D.a = 0;
+D.b[0] = 1;
+  }
+  return 0;
+}
+// clang-format off
+// CHECK: omptarget --> Entry  0: Base=[[DAT_HST_PTR_BASE:0x.*]], 
Begin=[[DAT_HST_PTR_BASE]], Size=12
+// CHECK: omptarget --> Entry  1: Base=[[DAT_HST_PTR_BASE]], 
Begin=[[

[openmp] [clang] [OpenMP] Fix runtime problem due wrong map size. (PR #74692)

2023-12-06 Thread via cfe-commits

https://github.com/jyu2-git created 
https://github.com/llvm/llvm-project/pull/74692

Currently we are missing set up-boundary address for FinalArraySection as 
highests elements in partial struct data.

Currently for:
\#pragma omp target map(D.a) map(D.b[:2])
The size is:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %2 = getelementptr float, ptr %arrayidx, i32 1
  %3 = ptrtoint ptr %2 to i64
  %4 = ptrtoint ptr %a to i64
  %5 = sub i64 %3, %4
  %6 = sdiv exact i64 %5, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to 
i64)

Where %arrayidx is wrong for (D.b[:2]) should be:
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 1

The fix is to emit the pointer to the last element of array section and use 
this pointer as the highest element in partial struct data.

After change IR:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %b1 = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx2 = getelementptr inbounds [2 x float], ptr %b1, i64 0, i64 1
  %1 = getelementptr float, ptr %arrayidx2, i32 1
  %2 = ptrtoint ptr %1 to i64
  %3 = ptrtoint ptr %a to i64
  %4 = sub i64 %2, %3
  %5 = sdiv exact i64 %4, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to 
i64)

>From 50c6009e4f4184ed7710a7ee3d8ee0983306edc1 Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Wed, 6 Dec 2023 13:53:16 -0800
Subject: [PATCH] [OpenMP] Fix runtime problem due wrong map size.

Currently we are missing set up-boundary address for FinalArraySection
as highests elements in partial struct data.

Currently for:
\#pragma omp target map(D.a) map(D.b[:2])
The size is:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %2 = getelementptr float, ptr %arrayidx, i32 1
  %3 = ptrtoint ptr %2 to i64
  %4 = ptrtoint ptr %a to i64
  %5 = sub i64 %3, %4
  %6 = sdiv exact i64 %5, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to 
i64)

Where %arrayidx is wrong for (D.b[:2]) should be:
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 1

The fix is to emit the pointer to the last element of array section and
use this pointer as the highest element in partial struct data.

After change IR:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %b1 = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx2 = getelementptr inbounds [2 x float], ptr %b1, i64 0, i64 1
  %1 = getelementptr float, ptr %arrayidx2, i32 1
  %2 = ptrtoint ptr %1 to i64
  %3 = ptrtoint ptr %a to i64
  %4 = sub i64 %2, %3
  %5 = sdiv exact i64 %4, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to 
i64)
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp |  9 +++-
 .../target_data_use_device_addr_codegen.cpp   |  8 ++-
 .../offloading/target_map_for_member_data.cpp | 23 +++
 3 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 
openmp/libomptarget/test/offloading/target_map_for_member_data.cpp

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 55648963df36a..7f7e6f5306664 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7389,7 +7389,14 @@ class MappableExprsHandler {
   } else if (FieldIndex < PartialStruct.LowestElem.first) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
-PartialStruct.HighestElem = {FieldIndex, LowestElem};
+if (IsFinalArraySection) {
+  Address HB =
+  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+  .getAddress(CGF);
+  PartialStruct.HighestElem = {FieldIndex, HB};
+} else {
+  PartialStruct.HighestElem = {FieldIndex, LowestElem};
+}
   }
 }
 
diff --git a/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp 
b/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
index 7e70cdf74ad37..ae0653d0585d4 100644
--- a/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
+++ b/clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
@@ -144,7 +144,13 @@ int main() {
 // CHECK: [[ARR_IDX6:%.+]] = getelementptr inbounds [4 x i32], ptr 
[[ARR_ADDR]], i64 0, i64 0
 // CHECK: [[A_ADDR2:%.+]] = getelementptr inbounds %struct.S, ptr [[THIS]], 
i32 0, i32 0
 // CHECK: [[P4:%.+]] = mul nuw i

[flang] [clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-12-06 Thread Fangcao Wang via cfe-commits

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


[flang] [clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-12-06 Thread Fangcao Wang via cfe-commits


@@ -5077,6 +5077,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[NoXarchOption]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption, 
FlangOption]>,

LittleMeepo wrote:

I made a mistake then and these options were not actually confirmed. Sorry, I 
will close the PR.

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


[clang-tools-extra] [clang] [llvm] [XCOFF][obj2yaml] support parsing auxiliary symbols for XCOFF (PR #70642)

2023-12-06 Thread via cfe-commits

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


[clang] [clang] Crash when referencing capture in static lambda (PR #74661)

2023-12-06 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I think this makes sense but @cor3ntin should look at it.

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


[llvm] [clang] [clang][RISCV] Change default abi with f extension but without d extension (PR #73489)

2023-12-06 Thread Jianjian Guan via cfe-commits


@@ -1,4 +1,4 @@
-// Check target CPUs are correctly passed.
+·// Check target CPUs are correctly passed.

jacquesguan wrote:

Fixed

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


[llvm] [clang] [clang][RISCV] Change default abi with f extension but without d extension (PR #73489)

2023-12-06 Thread Jianjian Guan via cfe-commits

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


[llvm] [clang] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-12-06 Thread Jianjian Guan via cfe-commits

https://github.com/jacquesguan updated 
https://github.com/llvm/llvm-project/pull/73489

>From ce22351f42b0a641000d1aa4db86f090f9b4e6c8 Mon Sep 17 00:00:00 2001
From: Jianjian GUAN 
Date: Mon, 27 Nov 2023 16:14:04 +0800
Subject: [PATCH] [clang][RISCV] Change default abi with f extension but
 without d extension

Now we have default abi lp64 for rv64if and ilp32 for rv32if, which is 
different with riscv-gnu-toolchain.
In 
https://github.com/riscv-collab/riscv-gnu-toolchain/blob/8e9fb09a0c4b1e566492ee6f42e8c1fa5ef7e0c2/configure#L3385
 when have f but not, it prefers lp64f/ilp32f but no soft float. This patch 
tries to make their behaviors consistent.
---
 clang/test/Driver/riscv-abi.c  | 14 +-
 clang/test/Driver/riscv-cpus.c |  6 +++---
 llvm/lib/Support/RISCVISAInfo.cpp  |  4 
 llvm/test/CodeGen/RISCV/callee-saved-fpr32s.ll |  4 ++--
 llvm/test/CodeGen/RISCV/calling-conv-half.ll   |  4 ++--
 .../CodeGen/RISCV/calling-conv-rv32f-ilp32.ll  |  2 +-
 .../CodeGen/RISCV/calling-conv-vector-float.ll |  2 +-
 .../RISCV/float-bitmanip-dagcombines.ll|  8 
 llvm/test/CodeGen/RISCV/float-frem.ll  |  7 +--
 llvm/test/CodeGen/RISCV/float-select-verify.ll |  2 +-
 .../CodeGen/RISCV/half-bitmanip-dagcombines.ll | 18 +-
 llvm/test/CodeGen/RISCV/half-fcmp.ll   |  8 
 12 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/clang/test/Driver/riscv-abi.c b/clang/test/Driver/riscv-abi.c
index e67f790e0de0e..16568271564c7 100644
--- a/clang/test/Driver/riscv-abi.c
+++ b/clang/test/Driver/riscv-abi.c
@@ -4,8 +4,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
-// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32 %s
 // RUN: %clang --target=riscv32-unknown-elf -x assembler %s -### \
@@ -24,6 +22,10 @@
 
 // RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if -mabi=ilp32f 
2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -mabi=ilp32f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
+// RUN: %clang --target=riscv32-unknown-elf %s -### -march=rv32if 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ILP32F %s
 
 // CHECK-ILP32F: "-target-abi" "ilp32f"
 
@@ -51,8 +53,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imc 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
-// RUN: %clang --target=riscv64-unknown-elf %s -### -march=rv64imf 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-LP64 %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64  %s
 // RUN: %clang --target=riscv64-unknown-elf -x assembler %s -### \
@@ -60,7 +60,11 @@
 
 // CHECK-LP64: "-target-abi" "lp64"
 
-// RUN:  not %clang --target=riscv64-unknown-elf %s -### -march=rv64f 
-mabi=lp64f 2>&1 \
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if -mabi=lp64f 
2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -mabi=lp64f 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
+// RUN:  %clang --target=riscv64-unknown-elf %s -### -march=rv64if 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LP64F %s
 
 // CHECK-LP64F: "-target-abi" "lp64f"
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 6c31282d0c8d4..d7fa7c9854a48 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -113,7 +113,7 @@
 // MCPU-SIFIVE-E24: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f"
 // MCPU-SIFIVE-E24: "-target-feature" "+c"
 // MCPU-SIFIVE-E24: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
-// MCPU-SIFIVE-E24: "-target-abi" "ilp32"
+// MCPU-SIFIVE-E24: "-target-abi" "ilp32f"
 
 // mcpu with default march
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=sifive-e34 | FileCheck 
-check-prefix=MCPU-SIFIVE-E34 %s
@@ -121,7 +121,7 @@
 // MCPU-SIFIVE-E34: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f"
 // MCPU-SIFIVE-E34: "-target-feature" "+c"
 // MCPU-SIFIVE-E34: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
-// MCPU-SIFIVE-E34: "-target-abi" "ilp32"
+// MCPU-SIFIVE-E34: "-target-abi" "ilp32f"
 
 // mcpu with mabi option
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=sifive-s21 -mabi=lp64 | 
FileCheck -check-prefix=MCPU-ABI-SIFIVE-S21 %s
@@ -178,7 +178,7 @@
 // MCPU-SIFIVE-E76: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f"
 // MCPU-SIFIVE-E76: "-target-feature" "+c"
 // MCP

[clang] b683709 - [clang-format] Fix a possible crash in `AlignAfterOpenBracket: BlockIndent`

2023-12-06 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-12-06T17:40:41-08:00
New Revision: b683709ea6eec7d0a388bd50c571774c9b9ffdb7

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

LOG: [clang-format] Fix a possible crash in `AlignAfterOpenBracket: BlockIndent`

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index cb7dc5f3dd9ba..9e4e939503dfe 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1259,7 +1259,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
-   (Current.is(tok::r_brace) &&
+   (Current.is(tok::r_brace) && Current.MatchingParen &&
 Current.MatchingParen->is(BK_BracedInit))) &&
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].LastSpace;



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


[clang] [clang-tools-extra] [compiler-rt] [flang] [llvm] [libc] [clang] Exclude non-template classes when checking if constraint refers to containing template arguments (PR #74265)

2023-12-06 Thread via cfe-commits

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


[clang] fed4e3a - [clang] Exclude non-template classes when checking if constraint refers to containing template arguments (#74265)

2023-12-06 Thread via cfe-commits

Author: antangelo
Date: 2023-12-06T20:17:59-05:00
New Revision: fed4e3a6eb5d04856169951347892d983695f86a

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

LOG: [clang] Exclude non-template classes when checking if constraint refers to 
containing template arguments (#74265)

When checking if the constraint uses any enclosing template parameters
for [temp.friend]p9, if a containing record is used as argument, we
assume that the constraint depends on enclosing template parameters
without checking if the record is templated. The reproducer from the bug
is included as a test case.

Fixes #71595

Added: 
clang/test/SemaTemplate/GH71595.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 43a322030baae..1fbd332f74057 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -653,6 +653,9 @@ Bug Fixes in This Version
 - Fixed false positive error emitted by clang when performing qualified name
   lookup and the current class instantiation has dependent bases.
   Fixes (`#13826 `_)
+- Fix a ``clang-17`` regression where a templated friend with constraints is 
not
+  properly applied when its parameters reference an enclosing non-template 
class.
+  Fixes (`#71595 `_)
 - Fix the name of the ifunc symbol emitted for multiversion functions declared 
with the
   ``target_clones`` attribute. This addresses a linker error that would 
otherwise occur
   when these functions are referenced from other TUs.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 603ad2b79cecb..f10abeaba0d45 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1712,6 +1712,8 @@ class ConstraintRefersToContainingTemplateChecker
   // Friend, likely because it was referred to without its template arguments.
   void CheckIfContainingRecord(const CXXRecordDecl *CheckingRD) {
 CheckingRD = CheckingRD->getMostRecentDecl();
+if (!CheckingRD->isTemplated())
+  return;
 
 for (const DeclContext *DC = Friend->getLexicalDeclContext();
  DC && !DC->isFileContext(); DC = DC->getParent())

diff  --git a/clang/test/SemaTemplate/GH71595.cpp 
b/clang/test/SemaTemplate/GH71595.cpp
new file mode 100644
index 0..7d34d1bf054e4
--- /dev/null
+++ b/clang/test/SemaTemplate/GH71595.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template
+concept C = true;
+
+class non_temp {
+template T>
+friend void f();
+
+non_temp();
+};
+
+template T>
+void f() {
+auto v = non_temp();
+}
+
+template
+class temp {
+template T>
+friend void g();
+
+temp(); // expected-note {{implicitly declared private here}}
+};
+
+template> T>
+void g() {
+auto v = temp(); // expected-error {{calling a private constructor of 
class 'temp'}}
+}
+
+void h() {
+f();
+g(); // expected-note {{in instantiation of function template 
specialization 'g' requested here}}
+}



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


[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-06 Thread via cfe-commits

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


[clang] c281782 - [clang][Sema] Add -Wswitch-default warning option (#73077)

2023-12-06 Thread via cfe-commits

Author: dong jianqiang
Date: 2023-12-07T09:03:15+08:00
New Revision: c28178298513f99dc869daa301fc25257df81688

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

LOG: [clang][Sema] Add -Wswitch-default warning option (#73077)

Adds a warning, issued by the clang semantic analysis. The patch warns
on switch which don't have the default branch.

This is a counterpart of gcc's Wswitch-default.

Added: 
clang/test/Sema/switch-default.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89ea2f0930ceca..43a322030baae8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -353,6 +353,8 @@ Improvements to Clang's diagnostics
   of a base class is not called in the constructor of its derived class.
 - Clang no longer emits ``-Wmissing-variable-declarations`` for variables 
declared
   with the ``register`` storage class.
+- Clang's ``-Wswitch-default`` flag now diagnoses whenever a ``switch`` 
statement
+  does not have a ``default`` label.
 - Clang's ``-Wtautological-negation-compare`` flag now diagnoses logical
   tautologies like ``x && !x`` and ``!x || x`` in expressions. This also
   makes ``-Winfinite-recursion`` diagnose more cases.

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ff028bbbf74261..12b11527b30571 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -632,7 +632,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, 
ShadowFieldInConstructor,
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
 def : DiagGroup<"sign-promo">;
 def SignCompare : DiagGroup<"sign-compare">;
-def : DiagGroup<"switch-default">;
+def SwitchDefault  : DiagGroup<"switch-default">;
 def : DiagGroup<"synth">;
 def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">;
 def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e0ac3af7b98e36..ea08fa84d022cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10064,6 +10064,8 @@ def warn_missing_case : Warning<"%plural{"
   "3:enumeration values %1, %2, and %3 not handled in switch|"
   ":%0 enumeration values not handled in switch: %1, %2, %3...}0">,
   InGroup;
+def warn_switch_default : Warning<"'switch' missing 'default' label">,
+  InGroup, DefaultIgnore;
 
 def warn_unannotated_fallthrough : Warning<
   "unannotated fall-through between switch labels">,

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 2b45aa5dff7be7..63348d27a8c94a 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -1327,6 +1327,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 
Stmt *Switch,
 }
   }
 
+  if (!TheDefaultStmt)
+Diag(SwitchLoc, diag::warn_switch_default);
+
   if (!HasDependentValue) {
 // If we don't have a default statement, check whether the
 // condition is constant.

diff  --git a/clang/test/Sema/switch-default.c 
b/clang/test/Sema/switch-default.c
new file mode 100644
index 00..854b561b37c48e
--- /dev/null
+++ b/clang/test/Sema/switch-default.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s
+
+int f1(int a) {
+  switch (a) {// expected-warning {{'switch' missing 'default' 
label}}
+case 1: a++; break;
+case 2: a += 2; break;
+  }
+  return a;
+}
+
+int f2(int a) {
+  switch (a) {// no-warning
+default:
+  ;
+  }
+  return a;
+}



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


[clang] [clang-format] Handle merging functions containing only a block comment (PR #74651)

2023-12-06 Thread Owen Pan via cfe-commits

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


[clang] e1a4b00 - [clang-format] Handle merging functions containing only a block comment (#74651)

2023-12-06 Thread via cfe-commits

Author: Owen Pan
Date: 2023-12-06T16:56:22-08:00
New Revision: e1a4b0032f89355da94a5505bf308ab12668b1b0

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

LOG: [clang-format] Handle merging functions containing only a block comment 
(#74651)

Fixed #41854.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index b4930c2e4621d..56077499c39d5 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -411,9 +411,16 @@ class LineJoiner {
   }
 }
 
+const auto *LastNonComment = TheLine->getLastNonComment();
+assert(LastNonComment);
+// FIXME: There are probably cases where we should use LastNonComment
+// instead of TheLine->Last.
+
 // Try to merge a function block with left brace unwrapped.
-if (TheLine->Last->is(TT_FunctionLBrace) && TheLine->First != 
TheLine->Last)
+if (LastNonComment->is(TT_FunctionLBrace) &&
+TheLine->First != LastNonComment) {
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
+}
 // Try to merge a control statement block with left brace unwrapped.
 if (TheLine->Last->is(tok::l_brace) && FirstNonComment != TheLine->Last &&
 FirstNonComment->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for,
@@ -789,7 +796,8 @@ class LineJoiner {
   }
 }
 
-if (Line.Last->is(tok::l_brace)) {
+if (const auto *LastNonComment = Line.getLastNonComment();
+LastNonComment && LastNonComment->is(tok::l_brace)) {
   if (IsSplitBlock && Line.First == Line.Last &&
   I > AnnotatedLines.begin() &&
   (I[-1]->endsWith(tok::kw_else) || IsCtrlStmt(*I[-1]))) {
@@ -805,7 +813,8 @@ class LineJoiner {
 
   if (ShouldMerge()) {
 // We merge empty blocks even if the line exceeds the column limit.
-Tok->SpacesRequiredBefore = Style.SpaceInEmptyBlock ? 1 : 0;
+Tok->SpacesRequiredBefore =
+(Style.SpaceInEmptyBlock || Line.Last->is(tok::comment)) ? 1 : 0;
 Tok->CanBreakBefore = true;
 return 1;
   } else if (Limit != 0 && !Line.startsWithNamespace() &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8782cb7c49cad..24b2fd599dc39 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13950,6 +13950,19 @@ TEST_F(FormatTest, 
PullTrivialFunctionDefinitionsIntoSingleLine) {
"  void f() { int i; } \\\n"
"  int j;",
getLLVMStyleWithColumns(23));
+
+  verifyFormat(
+  "void (\n"
+  "aa,\n"
+  "aa) {}");
+
+  constexpr StringRef Code{"void foo() { /* Empty */ }"};
+  verifyFormat(Code);
+  verifyFormat(Code, "void foo() { /* Empty */\n"
+ "}");
+  verifyFormat(Code, "void foo() {\n"
+ "/* Empty */\n"
+ "}");
 }
 
 TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLine) {

diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 9770d5090703c..c249f4d9333fd 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -386,15 +386,16 @@ TEST_F(FormatTestComments, UnderstandsBlockComments) {
   "  /* Leading comment for bb... */ b);",
   format("f(a,   \n"
  "/* Leading comment for bb... */   b);"));
-  EXPECT_EQ(
+
+  verifyFormat(
   "void (\n"
   "aa,\n"
-  "aa) { /*aaa*/\n"
-  "}",
-  format("void  (\n"
- "  aa  ,\n"
- "aa) {   
/*aaa*/\n"
- "}"));
+  "aa) { /*aaa*/ }",
+  "void  (\n"
+  "  aa  ,\n"
+  "aa) {   /*aaa*/\n"
+  "}");
+
   verifyFormat("f(/* aa = */\n"
"  );");
 



___
cfe-commits mailing list
cfe-commits@

[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits


@@ -133,6 +133,11 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
 "::boost::system::error_code"))),
   AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
 
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,

bjosv wrote:

Added a constructor that initialized the (missing) CheckedReturnTypes and 
AllowCastToVoid, which is delegated to from the constructor that is used by the 
new checker.
Is this in line with your thoughts?

An alternative is to only have the constructor which sets all members, but I 
thought that looked a bit weird to set AllowCastToVoid twice when constructing 
IgnoredRemoveResultCheck, once when initializing the baseclass and secondly in 
the body to be able to use Options.get (which can't be called in the 
initialization list there).


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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits


@@ -0,0 +1,17 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to ``std::erase``.
+
+Suppressing issues by casting to ``void`` is enabled by default and can be
+disabled by setting `AllowCastToVoid` option to ``false``.

bjosv wrote:

Options part copied from unused-return-value.rst

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


[clang-tools-extra] [clang] [llvm] [compiler-rt] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

2023-12-06 Thread David Li via cfe-commits

david-xl wrote:

> > > > David says the itanium remapper file was only used once during gcc to 
> > > > llvm transition, so not relevant here.
> > > 
> > > 
> > > I believe it was actually for the libstdc++ to libc++ transition (see 
> > > https://reviews.llvm.org/D51247 and https://reviews.llvm.org/D51240).
> > > If it is broken we'll at least want to add a FIXME there.
> > 
> > 
> > Yes, I meant libstdc++ to libc++ transition. Why source line is this 
> > comment addressing? I take take a look the changes/comments there.
> 
> Sorry for the misinformation, and thanks for the Phab links.
> 
> I think the itanium remapper needs a `:` -> `;` update (going to update this 
> PR and related tests), since (for local-linkage functions) the function name 
> used to look up profiles should use `;` delimiter.



> > > > David says the itanium remapper file was only used once during gcc to 
> > > > llvm transition, so not relevant here.
> > > 
> > > 
> > > I believe it was actually for the libstdc++ to libc++ transition (see 
> > > https://reviews.llvm.org/D51247 and https://reviews.llvm.org/D51240).
> > > If it is broken we'll at least want to add a FIXME there.
> > 
> > 
> > Yes, I meant libstdc++ to libc++ transition. Why source line is this 
> > comment addressing? I take take a look the changes/comments there.
> 
> Sorry for the misinformation, and thanks for the Phab links.
> 
> I think the itanium remapper needs a `:` -> `;` update (going to update this 
> PR and related tests), since (for local-linkage functions) the function name 
> used to look up profiles should use `;` delimiter.

The remapper is not aware of any internal symbol mangling scheme, so those 
entires won't be tracked by it. In other words, there is no need to change 
anything there, I think.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits


@@ -0,0 +1,28 @@
+//===--- IgnoredRemoveResultCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IgnoredRemoveResultCheck.h"
+
+namespace clang::tidy::hicpp {
+
+IgnoredRemoveResultCheck::IgnoredRemoveResultCheck(llvm::StringRef Name,
+   ClangTidyContext *Context)
+: UnusedReturnValueCheck(Name, Context,
+ "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;") {

bjosv wrote:

Removed

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Björn Svensson via cfe-commits

https://github.com/bjosv updated https://github.com/llvm/llvm-project/pull/73119

From 91cf412abcfd231ab399c3e44c6a9bc14109537c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= 
Date: Tue, 21 Nov 2023 23:30:07 +0100
Subject: [PATCH 1/4] [clang-tidy] Add check hicpp-ignored-remove-result

This check implements the rule 17.5.1 of the HICPP standard
which states:

- Do not ignore the result of std::remove, std::remove_if or std::unique

  The mutating algorithms std::remove, std::remove_if and both overloads of
  std::unique operate by swapping or moving elements of the range they are
  operating over. On completion, they return an iterator to the last valid 
element.
  In the majority of cases the correct behavior is to use this result as the
  first operand in a call to std::erase.

Suppressing issues by casting to `void` is enabled by default, but can be
disabled by setting `AllowCastToVoid` option to `false`.
---
 .../clang-tidy/hicpp/HICPPTidyModule.cpp  | 20 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../checks/hicpp/ignored-remove-result.rst| 20 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/hicpp/ignored-remove-result.cpp  | 47 +++
 5 files changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/hicpp/ignored-remove-result.cpp

diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp 
b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 3749796877120e..09d15ccab3f29c 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
 #include "../bugprone/UseAfterMoveCheck.h"
 #include "../cppcoreguidelines/AvoidGotoCheck.h"
 #include "../cppcoreguidelines/NoMallocCheck.h"
@@ -41,6 +42,15 @@
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
+namespace {
+
+// Checked functions for hicpp-ignored-remove-result.
+const llvm::StringRef CheckedFunctions = "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;";
+
+} // namespace
+
 namespace clang::tidy {
 namespace hicpp {
 
@@ -64,6 +74,8 @@ class HICPPModule : public ClangTidyModule {
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(
 "hicpp-function-size");
+CheckFactories.registerCheck(
+"hicpp-ignored-remove-result");
 CheckFactories.registerCheck(
 "hicpp-named-parameter");
 CheckFactories.registerCheck(
@@ -107,6 +119,14 @@ class HICPPModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "hicpp-vararg");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+Opts["hicpp-ignored-remove-result.CheckedFunctions"] = CheckedFunctions;
+Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+return Options;
+  }
 };
 
 // Register the HICPPModule using this statically initialized variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d5f49dc062545..c940025df1c63c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -205,6 +205,10 @@ New check aliases
   ` to 
:doc:`modernize-macro-to-enum
   ` was added.
 
+- New alias :doc:`hicpp-ignored-remove-result
+  ` to 
:doc:`bugprone-unused-return-value
+  ` was added.
+
 Changes in existing checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
new file mode 100644
index 00..4b6188b886db12
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to std::erase.
+
+This check is an alias of check :doc:`bugprone-unused-return-value 
<../bugprone/u

[llvm] [clang] [compiler-rt] [HIP] support 128 bit int division (PR #71978)

2023-12-06 Thread Yaxun Liu via cfe-commits


@@ -596,6 +596,7 @@ static bool mustPreserveGV(const GlobalValue &GV) {
   if (const Function *F = dyn_cast(&GV))
 return F->isDeclaration() || F->getName().startswith("__asan_") ||
F->getName().startswith("__sanitizer_") ||
+   F->getName() == "__divti3" ||

yxsamliu wrote:

will add a function attribute for that

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


[clang] Fix tests clang-offload-bundler-zlib/zstd.c (PR #74504)

2023-12-06 Thread Yaxun Liu via cfe-commits

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


[clang] 36e4cb7 - Fix tests clang-offload-bundler-zlib/zstd.c (#74504)

2023-12-06 Thread via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-12-06T18:38:21-05:00
New Revision: 36e4cb7986da455342dfd535b659640ab0692340

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

LOG: Fix tests clang-offload-bundler-zlib/zstd.c (#74504)

The test fails intermittently due to non-unique file name %T.

Use %t based file names instead.

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

Added: 


Modified: 
clang/test/Driver/clang-offload-bundler-zlib.c
clang/test/Driver/clang-offload-bundler-zstd.c

Removed: 




diff  --git a/clang/test/Driver/clang-offload-bundler-zlib.c 
b/clang/test/Driver/clang-offload-bundler-zlib.c
index c46c32a4a0537b..a57ee6da9a86a6 100644
--- a/clang/test/Driver/clang-offload-bundler-zlib.c
+++ b/clang/test/Driver/clang-offload-bundler-zlib.c
@@ -55,14 +55,15 @@
 // Check unbundling archive.
 //
 // RUN: clang-offload-bundler -type=bc 
-targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
-// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%T/hip_bundle1.bc -compress
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip_bundle1.bc -compress
 // RUN: clang-offload-bundler -type=bc 
-targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
-// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%T/hip_bundle2.bc -compress
-// RUN: llvm-ar cr %T/hip_archive.a %T/hip_bundle1.bc %T/hip_bundle2.bc
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip_bundle2.bc -compress
+// RUN: rm -f %t.hip_archive.a
+// RUN: llvm-ar cr %t.hip_archive.a %t.hip_bundle1.bc %t.hip_bundle2.bc
 // RUN: clang-offload-bundler -unbundle -type=a 
-targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
-// RUN:   -output=%T/hip_900.a -output=%T/hip_906.a -input=%T/hip_archive.a
-// RUN: llvm-ar t %T/hip_900.a | FileCheck -check-prefix=HIP-AR-900 %s
-// RUN: llvm-ar t %T/hip_906.a | FileCheck -check-prefix=HIP-AR-906 %s
+// RUN:   -output=%t.hip_900.a -output=%t.hip_906.a -input=%t.hip_archive.a
+// RUN: llvm-ar t %t.hip_900.a | FileCheck -check-prefix=HIP-AR-900 %s
+// RUN: llvm-ar t %t.hip_906.a | FileCheck -check-prefix=HIP-AR-906 %s
 // HIP-AR-900-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx900
 // HIP-AR-900-DAG: hip_bundle2-hip-amdgcn-amd-amdhsa--gfx900
 // HIP-AR-906-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx906

diff  --git a/clang/test/Driver/clang-offload-bundler-zstd.c 
b/clang/test/Driver/clang-offload-bundler-zstd.c
index b2b588b72d4d6f..3b577d4d166a3f 100644
--- a/clang/test/Driver/clang-offload-bundler-zstd.c
+++ b/clang/test/Driver/clang-offload-bundler-zstd.c
@@ -48,18 +48,18 @@
 // RUN: 
diff  %t.tgt1 %t.res.tgt1
 // RUN: 
diff  %t.tgt2 %t.res.tgt2
 
-//
 // Check unbundling archive.
 //
 // RUN: clang-offload-bundler -type=bc 
-targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
-// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%T/hip_bundle1.bc -compress
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip_bundle1.bc -compress
 // RUN: clang-offload-bundler -type=bc 
-targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
-// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%T/hip_bundle2.bc -compress
-// RUN: llvm-ar cr %T/hip_archive.a %T/hip_bundle1.bc %T/hip_bundle2.bc
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip_bundle2.bc -compress
+// RUN: rm -f %t.hip_archive.a
+// RUN: llvm-ar cr %t.hip_archive.a %t.hip_bundle1.bc %t.hip_bundle2.bc
 // RUN: clang-offload-bundler -unbundle -type=a 
-targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
-// RUN:   -output=%T/hip_900.a -output=%T/hip_906.a -input=%T/hip_archive.a
-// RUN: llvm-ar t %T/hip_900.a | FileCheck -check-prefix=HIP-AR-900 %s
-// RUN: llvm-ar t %T/hip_906.a | FileCheck -check-prefix=HIP-AR-906 %s
+// RUN:   -output=%t.hip_900.a -output=%t.hip_906.a -input=%t.hip_archive.a
+// RUN: llvm-ar t %t.hip_900.a | FileCheck -check-prefix=HIP-AR-900 %s
+// RUN: llvm-ar t %t.hip_906.a | FileCheck -check-prefix=HIP-AR-906 %s
 // HIP-AR-900-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx900
 // HIP-AR-900-DAG: hip_bundle2-hip-amdgcn-amd-amdhsa--gfx900
 // HIP-AR-906-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx906



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


[clang] [NFC] Remove unneeded nullptr checks after cast<> (PR #74674)

2023-12-06 Thread Mike Rice via cfe-commits


@@ -6454,8 +6454,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   !EvalResult.hasSideEffects())
 Value = &EvalResult.Val;
 
-  LangAS AddrSpace =
-  VD ? GetGlobalVarAddressSpace(VD) : MaterializedType.getAddressSpace();

mikerice1969 wrote:

@yxsamliu, you may have added this back in cbf647cc3a712. Do you know when/if 
the AddrSpace should be set from MaterializedType since it seems VD is always 
non-null here.

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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-06 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder approved this pull request.


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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-06 Thread Ian Anderson via cfe-commits


@@ -0,0 +1,131 @@
+// RUN: %clang -### --target=arm64-apple-darwin %s 2>&1 | FileCheck %s 
--check-prefix=DEFAULT-OPTION
+
+// RUN: %clang -dM -E --target=arm64-apple-macos %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=1 \
+// RUN:-DIPHONE=0  \
+// RUN:-DIOS=0 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=0
+
+// RUN: %clang -dM -E --target=arm64-apple-ios %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=1 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=1\
+// RUN:-DSIMULATOR=0
+
+// RUN: %clang -dM -E --target=arm64-apple-ios-macabi %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=1 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=1 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=0
+
+// RUN: %clang -dM -E --target=arm64-apple-ios-simulator %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=1 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=1
+
+// RUN: %clang -dM -E --target=arm64-apple-tvos %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=0 \
+// RUN:-DTV=1  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=1\
+// RUN:-DSIMULATOR=0
+
+// RUN: %clang -dM -E --target=arm64-apple-tvos-simulator %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=0 \
+// RUN:-DTV=1  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=1
+
+// RUN: %clang -dM -E --target=arm64-apple-watchos %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=0 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=1   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=1\
+// RUN:-DSIMULATOR=0
+
+// RUN: %clang -dM -E --target=arm64-apple-watchos-simulator %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=1  \
+// RUN:-DIOS=0 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=1   \
+// RUN:-DDRIVERKIT=0   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=1
+
+// RUN: %clang -dM -E --target=arm64-apple-driverkit %s 2>&1 \
+// RUN: | FileCheck %s -DMAC=1 \
+// RUN:-DOSX=0 \
+// RUN:-DIPHONE=0  \
+// RUN:-DIOS=0 \
+// RUN:-DTV=0  \
+// RUN:-DWATCH=0   \
+// RUN:-DDRIVERKIT=1   \
+// RUN:-DMACCATALYST=0 \
+// RUN:-DEMBEDDED=0\
+// RUN:-DSIMULATOR=0
+
+// DEFAULT-OPTION: "-fdefine-target-os-macros"
+
+// CHECK-DAG: #define TARGET_OS_MAC [[MAC]]
+// CHECK-DAG: #define TARGET_OS_OSX [[OSX]]
+// CHECK-DAG: #define TARGET_OS_IPHONE [[IPHONE]]
+// CHECK-DAG: #define TARGET_OS_IOS [[IOS]]
+// CHECK-DAG: #define TARGET_OS_TV [[TV]]
+// CHECK-DAG: #define TARGET_OS_WATCH [[WATCH]]
+// CHECK-DAG: #define TARGET_OS_DRIVERKIT [[DRIVERKIT]]
+// CHECK-DAG: #define TARGET_OS_MACCATALYST [[MACCATALYST]]
+// CHECK-DAG: #define TARGET_OS_SIMULATOR [[SIMULATOR]]
+// Deprecated
+

[openmp] [lld] [clang-tools-extra] [llvm] [flang] [clang] [mlir] [HLSL] RWBuffer should not have a default parameter (PR #71265)

2023-12-06 Thread Justin Bogner via cfe-commits

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


[mlir] [flang] [clang] [lld] [openmp] [llvm] [clang-tools-extra] [HLSL] RWBuffer should not have a default parameter (PR #71265)

2023-12-06 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/71265

>From 1779fd08dad4f03ae5e9f1803b8ea3d7dc77c093 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 3 Nov 2023 19:03:00 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5

[skip ci]
---
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaInit.cpp   |   3 +-
 clang/lib/Sema/SemaLambda.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 123 --
 clang/lib/Sema/SemaType.cpp   |   3 +-
 .../test/SemaHLSL/BuiltIns/vector-errors.hlsl |   5 -
 7 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9..a86c428c9121a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e4531..de5cc07f5d428 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f..0952b065d56b5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac..603b7465323e2 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee35486221280..1a6eaa196db09 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Temp

[flang] [clang] [mlir] [llvm] [lld] [clang-tools-extra] [openmp] [HLSL] RWBuffer should not have a default parameter (PR #71265)

2023-12-06 Thread Justin Bogner via cfe-commits

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


[clang] 61329bd - [HLSL] RWBuffer should not have a default parameter

2023-12-06 Thread via cfe-commits

Author: Justin Bogner
Date: 2023-12-06T15:27:27-08:00
New Revision: 61329b9cb155b4902fd7fa4a2367e796d51a

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

LOG: [HLSL] RWBuffer should not have a default parameter

RWBuffer doesn't have a default type in dxc's implementation, so it
shouldn't have one in clang either.

Reviewers: llvm-beanz, python3kgae

Reviewed By: python3kgae, llvm-beanz

Pull Request: https://github.com/llvm/llvm-project/pull/71265

Added: 


Modified: 
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/RWBuffer-AST.hlsl
clang/test/AST/HLSL/pch.hlsl
clang/test/AST/HLSL/pch_with_buf.hlsl
clang/test/AST/HLSL/resource_binding_attr.hlsl
clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl

Removed: 




diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 8de144486c91d..5057bc6629f04 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -471,7 +471,7 @@ void HLSLExternalSemaSource::forwardDeclareHLSLTypes() {
   CXXRecordDecl *Decl;
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
  .addTemplateArgumentList()
- .addTypeParameter("element_type", 
SemaPtr->getASTContext().FloatTy)
+ .addTypeParameter("element_type")
  .finalizeTemplateArgs()
  .Record;
   if (!Decl->isCompleteDefinition())

diff  --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
index 9dd9244b73eed..c1613520a146c 100644
--- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -13,8 +13,6 @@
 
 // EMPTY: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit RWBuffer
 // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
-// EMPTY-NEXT: TemplateArgument type 'float'
-// EMPTY-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'float'
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class RWBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
@@ -33,8 +31,6 @@ RWBuffer Buffer;
 
 // CHECK: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit RWBuffer
 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
-// CHECK-NEXT: TemplateArgument type 'float'
-// CHECK-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'float'
 // CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class RWBuffer definition
 
 // CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final

diff  --git a/clang/test/AST/HLSL/pch.hlsl b/clang/test/AST/HLSL/pch.hlsl
index 74254fedf27cb..27fae8f499daa 100644
--- a/clang/test/AST/HLSL/pch.hlsl
+++ b/clang/test/AST/HLSL/pch.hlsl
@@ -6,7 +6,7 @@
 
 // Make sure PCH works by using function declared in PCH header and declare a 
RWBuffer in current file.
 // CHECK:FunctionDecl 0x[[FOO:[0-9a-f]+]] <{{.*}}:2:1, line:4:1> line:2:8 
imported used foo 'float2 (float2, float2)'
-// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:10:1, col:23> col:23 Buffer 
'hlsl::RWBuffer':'hlsl::RWBuffer<>'
+// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:10:1, col:23> col:23 Buffer 
'hlsl::RWBuffer'
 hlsl::RWBuffer Buffer;
 
 float2 bar(float2 a, float2 b) {

diff  --git a/clang/test/AST/HLSL/pch_with_buf.hlsl 
b/clang/test/AST/HLSL/pch_with_buf.hlsl
index 4e657606cbcb1..e8eae533af629 100644
--- a/clang/test/AST/HLSL/pch_with_buf.hlsl
+++ b/clang/test/AST/HLSL/pch_with_buf.hlsl
@@ -5,9 +5,9 @@
 // Make sure PCH works by using function declared in PCH header.
 // CHECK:FunctionDecl 0x[[FOO:[0-9a-f]+]] <{{.*}}:2:1, line:4:1> line:2:8 
imported used foo 'float2 (float2, float2)'
 // Make sure buffer defined in PCH works.
-// CHECK:VarDecl 0x{{[0-9a-f]+}}  col:17 imported Buf 
'RWBuffer':'hlsl::RWBuffer<>'
+// CHECK:VarDecl 0x{{[0-9a-f]+}}  col:17 imported Buf 
'RWBuffer'
 // Make sure declare a RWBuffer in current file works.
-// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:11:1, col:23> col:23 Buf2 
'hlsl::RWBuffer':'hlsl::RWBuffer<>'
+// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:11:1, col:23> col:23 Buf2 
'hlsl::RWBuffer'
 hlsl::RWBuffer Buf2;
 
 float2 bar(float2 a, float2 b) {

diff  --git a/clang/test/AST/HLSL/resource_binding_attr.hlsl 
b/clang/test/AST/HLSL/resource_binding_attr.hlsl
index 683607197..71900f2dbda55 100644
--- a/clang/test/AST/HLSL/resource_binding_attr.hlsl
+++ b/clang/test/AST/HLSL/resource_binding_attr.hlsl
@@ -23,15 +23,15 @@ float foo() {
   return a + b;
 }
 
-// CHECK: VarDecl 0x{{[0-9a-f]+}} <{{.*}}> col:17 UAV 
'RWBuffer':'hlsl::RWBuffer<>' callinit
-// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  
'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK: VarDecl 0x{{[0-9a-f]+}} <{{.*}}> col:17 UAV 
'RWBuffer':'hlsl::RWBuffer' callinit
+// CHECK-NEXT:-

[clang] [clang-format] Handle merging functions containing only a block comment (PR #74651)

2023-12-06 Thread via cfe-commits

https://github.com/mydeveloperday approved this pull request.

Lgtm

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


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-06 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w updated 
https://github.com/llvm/llvm-project/pull/74676

>From cdc7cf721a7d4a6bf318181ea3f37adf7c571ed1 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Thu, 14 Sep 2023 17:06:24 -0700
Subject: [PATCH] [clang][PP] Add extension to predefine target OS macros

Add an extension feature `define-target-os-macros` that enables clang
to provide definitions of common TARGET_OS_* conditional macros.
The extension is enabled in the Darwin toolchain driver.
---
 clang/include/clang/Basic/Features.def|   2 +
 clang/include/clang/Basic/TargetOSMacros.def  |  55 
 clang/include/clang/Driver/Options.td |   3 +
 clang/include/clang/Lex/PreprocessorOptions.h |   3 +
 clang/lib/Driver/ToolChains/Darwin.cpp|   4 +
 clang/lib/Frontend/CompilerInvocation.cpp |   7 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   9 ++
 .../Driver/darwin-fdefine-target-os-macros.c  | 131 ++
 8 files changed, 214 insertions(+)
 create mode 100644 clang/include/clang/Basic/TargetOSMacros.def
 create mode 100644 clang/test/Driver/darwin-fdefine-target-os-macros.c

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index adaf2e413f2f6d..df1eff8cbcc9f0 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -89,6 +89,8 @@ FEATURE(blocks, LangOpts.Blocks)
 FEATURE(c_thread_safety_attributes, true)
 FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
 FEATURE(cxx_rtti, LangOpts.RTTI &&LangOpts.RTTIData)
+EXTENSION(define_target_os_macros,
+  PP.getPreprocessorOpts().DefineTargetOSMacros)
 FEATURE(enumerator_attributes, true)
 FEATURE(nullability, true)
 FEATURE(nullability_on_arrays, true)
diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
new file mode 100644
index 00..dfc2e033f6fd0d
--- /dev/null
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -0,0 +1,55 @@
+//===--- TargetOSMacros.def - Target OS macros --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file specifies the predefined TARGET_OS_* conditional macros.
+// A target macro `Name` should be defined if `Predicate` evaluates to true.
+// The macro expects `const llvm::Triple &Triple` and the class `llvm::Triple`
+// to be available for the predicate.
+//
+//===--===//
+
+#ifndef TARGET_OS
+#define TARGET_OS(Name, Predicate)
+#endif
+
+// Windows targets.
+TARGET_OS(TARGET_OS_WIN32, Triple.isOSWindows())
+TARGET_OS(TARGET_OS_WINDOWS, Triple.isOSWindows())
+
+// Linux target.
+TARGET_OS(TARGET_OS_LINUX, Triple.isOSLinux())
+
+// Unix target.
+TARGET_OS(TARGET_OS_UNIX, Triple.isOSNetBSD() ||
+  Triple.isOSFreeBSD() ||
+  Triple.isOSOpenBSD() ||
+  Triple.isOSSolaris())
+
+// Apple (Mac) targets.
+TARGET_OS(TARGET_OS_MAC, Triple.isOSDarwin())
+TARGET_OS(TARGET_OS_OSX, Triple.isMacOSX())
+TARGET_OS(TARGET_OS_IPHONE, Triple.isiOS() || Triple.isTvOS() ||
+Triple.isWatchOS())
+// Triple::isiOS() also includes tvOS
+TARGET_OS(TARGET_OS_IOS, Triple.getOS() == llvm::Triple::IOS)
+TARGET_OS(TARGET_OS_TV, Triple.isTvOS())
+TARGET_OS(TARGET_OS_WATCH, Triple.isWatchOS())
+TARGET_OS(TARGET_OS_DRIVERKIT, Triple.isDriverKit())
+TARGET_OS(TARGET_OS_MACCATALYST, Triple.isMacCatalystEnvironment())
+TARGET_OS(TARGET_OS_SIMULATOR, Triple.isSimulatorEnvironment())
+
+// Deprecated Apple target conditionals.
+TARGET_OS(TARGET_OS_EMBEDDED, (Triple.isiOS() || Triple.isTvOS() \
+   || Triple.isWatchOS()) \
+   && !Triple.isMacCatalystEnvironment() \
+   && !Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
+TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
+
+#undef TARGET_OS
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0eec2b35263762..b959fd20fe413d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1818,6 +1818,9 @@ def fcomment_block_commands : CommaJoined<["-"], 
"fcomment-block-commands=">, Gr
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">, 
MarshallingInfoStringVector>;
+defm define_target_os_macros : OptInCC1FFlag<"define-target-os-macros",
+  "Enable", "Disable", " predefined target OS macros",
+  [ClangOption, CC

[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-06 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

Thanks

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


  1   2   3   4   5   >