[llvm] [clang] [llvm][AArch64] Do not inline a function with different signing scheme. (PR #80642)

2024-02-05 Thread via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/80642

If the signing scheme is different that maybe the functions assumes different 
behaviours and dangerous to inline them without analysing them. This should be 
a rare case.

>From 2215b0400daecb3eb10040efb07a9669ef6f97ca Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 31 Jan 2024 17:54:24 +0100
Subject: [PATCH 1/3] [Clang] Replace Arch with Triplet.

---
 clang/lib/CodeGen/CodeGenModule.cpp | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c63e4ecc3dcba..36b63d78b06f8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1044,17 +1044,14 @@ void CodeGenModule::Release() {
   llvm::MDString::get(VMContext, "ascii"));
   }
 
-  llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
-  if (   Arch == llvm::Triple::arm
-  || Arch == llvm::Triple::armeb
-  || Arch == llvm::Triple::thumb
-  || Arch == llvm::Triple::thumbeb) {
+  llvm::Triple T = Context.getTargetInfo().getTriple();
+  if (T.isARM() || T.isThumb()) {
 // The minimum width of an enum in bytes
 uint64_t EnumWidth = Context.getLangOpts().ShortEnums ? 1 : 4;
 getModule().addModuleFlag(llvm::Module::Error, "min_enum_size", EnumWidth);
   }
 
-  if (Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64) {
+  if (T.isRISCV()) {
 StringRef ABIStr = Target.getABI();
 llvm::LLVMContext &Ctx = TheModule.getContext();
 getModule().addModuleFlag(llvm::Module::Error, "target-abi",
@@ -1127,10 +1124,7 @@ void CodeGenModule::Release() {
 getModule().addModuleFlag(llvm::Module::Override,
   "tag-stack-memory-buildattr", 1);
 
-  if (Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb ||
-  Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb ||
-  Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_32 ||
-  Arch == llvm::Triple::aarch64_be) {
+  if (T.isARM() || T.isThumb() || T.isAArch64()) {
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
 1);

>From 3f4eb61edf02475c4d9a91f8e918b848add000f7 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 29 Jan 2024 16:27:50 +0100
Subject: [PATCH 2/3] [llvm][AArch64] Autoupgrade function attributes from
 Module attributes.

sign-return-address and similar module attributes should be propagated to
the function level before got merged because module flags may contradict and
this information is not recoverable.
Generated code will match with the normal linking flow.
---
 llvm/include/llvm/IR/AutoUpgrade.h|  3 +-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |  2 +-
 llvm/lib/IR/AutoUpgrade.cpp   | 69 ++-
 llvm/lib/Linker/IRMover.cpp   |  4 ++
 .../test/Bitcode/upgrade-arc-runtime-calls.ll |  4 +-
 .../AArch64/link-branch-target-enforcement.ll |  1 +
 .../LTO/AArch64/link-sign-return-address.ll   | 43 
 llvm/test/Linker/link-arm-and-thumb.ll|  7 +-
 8 files changed, 125 insertions(+), 8 deletions(-)
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll

diff --git a/llvm/include/llvm/IR/AutoUpgrade.h 
b/llvm/include/llvm/IR/AutoUpgrade.h
index 152f781ffa9b3..c0d96efc54752 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -67,7 +67,8 @@ namespace llvm {
   void UpgradeSectionAttributes(Module &M);
 
   /// Correct any IR that is relying on old function attribute behavior.
-  void UpgradeFunctionAttributes(Function &F);
+  void UpgradeFunctionAttributes(Function &F,
+ bool ModuleMetadataIsMaterialized = false);
 
   /// If the given TBAA tag uses the scalar TBAA format, create a new node
   /// corresponding to the upgrade to the struct-path aware TBAA format.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 5b233fb365fe2..6b335dd9f1f89 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -6708,7 +6708,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
   }
 
   // Look for functions that rely on old function attribute behavior.
-  UpgradeFunctionAttributes(*F);
+  UpgradeFunctionAttributes(*F, true);
 
   // If we've materialized a function set up in "new" debug-info mode, the
   // contents just loaded will still be in dbg.value mode. Switch to the new
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 19d80eb9aec0b..e25ac46450cec 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5155,7 +5155,39 @@ struct StrictFPUpgradeVisitor : public 
InstVisitor {
 };
 } // namespace

[llvm] [clang] [llvm][AArch64] Do not inline a function with different signing scheme. (PR #80642)

2024-02-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-lto

Author: Dani (DanielKristofKiss)


Changes

If the signing scheme is different that maybe the functions assumes different 
behaviours and dangerous to inline them without analysing them. This should be 
a rare case.

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


11 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4-10) 
- (modified) llvm/include/llvm/IR/AutoUpgrade.h (+2-1) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+1-1) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+68-1) 
- (modified) llvm/lib/Linker/IRMover.cpp (+4) 
- (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+15) 
- (modified) llvm/test/Bitcode/upgrade-arc-runtime-calls.ll (+2-2) 
- (modified) llvm/test/LTO/AArch64/link-branch-target-enforcement.ll (+1) 
- (added) llvm/test/LTO/AArch64/link-sign-return-address.ll (+43) 
- (modified) llvm/test/Linker/link-arm-and-thumb.ll (+4-3) 
- (added) llvm/test/Transforms/Inline/inline-sign-return-address.ll (+126) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c63e4ecc3dcba..36b63d78b06f8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1044,17 +1044,14 @@ void CodeGenModule::Release() {
   llvm::MDString::get(VMContext, "ascii"));
   }
 
-  llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
-  if (   Arch == llvm::Triple::arm
-  || Arch == llvm::Triple::armeb
-  || Arch == llvm::Triple::thumb
-  || Arch == llvm::Triple::thumbeb) {
+  llvm::Triple T = Context.getTargetInfo().getTriple();
+  if (T.isARM() || T.isThumb()) {
 // The minimum width of an enum in bytes
 uint64_t EnumWidth = Context.getLangOpts().ShortEnums ? 1 : 4;
 getModule().addModuleFlag(llvm::Module::Error, "min_enum_size", EnumWidth);
   }
 
-  if (Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64) {
+  if (T.isRISCV()) {
 StringRef ABIStr = Target.getABI();
 llvm::LLVMContext &Ctx = TheModule.getContext();
 getModule().addModuleFlag(llvm::Module::Error, "target-abi",
@@ -1127,10 +1124,7 @@ void CodeGenModule::Release() {
 getModule().addModuleFlag(llvm::Module::Override,
   "tag-stack-memory-buildattr", 1);
 
-  if (Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb ||
-  Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb ||
-  Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_32 ||
-  Arch == llvm::Triple::aarch64_be) {
+  if (T.isARM() || T.isThumb() || T.isAArch64()) {
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
 1);
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h 
b/llvm/include/llvm/IR/AutoUpgrade.h
index 152f781ffa9b3..c0d96efc54752 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -67,7 +67,8 @@ namespace llvm {
   void UpgradeSectionAttributes(Module &M);
 
   /// Correct any IR that is relying on old function attribute behavior.
-  void UpgradeFunctionAttributes(Function &F);
+  void UpgradeFunctionAttributes(Function &F,
+ bool ModuleMetadataIsMaterialized = false);
 
   /// If the given TBAA tag uses the scalar TBAA format, create a new node
   /// corresponding to the upgrade to the struct-path aware TBAA format.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 5b233fb365fe2..6b335dd9f1f89 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -6708,7 +6708,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
   }
 
   // Look for functions that rely on old function attribute behavior.
-  UpgradeFunctionAttributes(*F);
+  UpgradeFunctionAttributes(*F, true);
 
   // If we've materialized a function set up in "new" debug-info mode, the
   // contents just loaded will still be in dbg.value mode. Switch to the new
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 19d80eb9aec0b..e25ac46450cec 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5155,7 +5155,39 @@ struct StrictFPUpgradeVisitor : public 
InstVisitor {
 };
 } // namespace
 
-void llvm::UpgradeFunctionAttributes(Function &F) {
+static void
+CopyModuleAttributeToFunction(Function &F, StringRef FnAttrName,
+  StringRef ModAttrName,
+  std::pair Values) {
+  Module *M = F.getParent();
+  if (!M)
+return;
+  if (F.hasFnAttribute(FnAttrName))
+return;
+  if (const auto *MAttr = mdconst::extract_or_null(
+  M->getModuleFlag(ModAttrName))) {
+if (MAttr->getZExtValue()) {
+  F.addFnAttr(FnAttrName, Values.first);
+  return;
+}
+

[clang-tools-extra] [clangd] Handle IndirectFieldDecl in kindForDecl (PR #80588)

2024-02-05 Thread Haojian Wu via cfe-commits

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


[clang-tools-extra] [clangd] Handle IndirectFieldDecl in kindForDecl (PR #80588)

2024-02-05 Thread Haojian Wu via cfe-commits

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


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


[clang-tools-extra] [clangd] Handle IndirectFieldDecl in kindForDecl (PR #80588)

2024-02-05 Thread Haojian Wu via cfe-commits


@@ -1076,6 +1076,21 @@ sizeof...($TemplateParameter[[Elements]]);
 using 
$Class[[Y]]$Bracket[[<]]0$Bracket[[>]]::$Unknown_dependentName[[xxx]];
   };
 };
+)cpp",
+  R"cpp(
+template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+struct $Class_def[[Base]] {
+  struct {
+int $Field_decl[[waldo]];
+  };
+};
+template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+struct $Class_def[[Derived]] : 
$Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]] {
+  using 
$Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]]::$Field_dependentName[[waldo]];
+  void $Method_def[[foo]]() {
+$Field_dependentName[[waldo]];

hokein wrote:

nit: This has a lot of boilerplate code that are required for this case , it is 
better to have a comment clarifying the test purpose.

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


[clang-tools-extra] [clangd] Handle IndirectFieldDecl in kindForDecl (PR #80588)

2024-02-05 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/80588

>From a2f622aa59d0bd2d2220ae08a6c3e26dd794e2e0 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 4 Feb 2024 02:22:38 -0500
Subject: [PATCH] [clangd] Handle IndirectFieldDecl in kindForDecl

https://github.com/clangd/clangd/issues/1925
---
 .../clangd/SemanticHighlighting.cpp  |  2 +-
 .../unittests/SemanticHighlightingTests.cpp  | 16 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 37939d36425a9..078b40c9db148 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -136,7 +136,7 @@ std::optional kindForDecl(const NamedDecl 
*D,
   if (auto *OMD = dyn_cast(D))
 return OMD->isClassMethod() ? HighlightingKind::StaticMethod
 : HighlightingKind::Method;
-  if (isa(D))
+  if (isa(D))
 return HighlightingKind::Field;
   if (isa(D))
 return HighlightingKind::Enum;
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index da12accc7898b..4156921d83edf 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1076,6 +1076,22 @@ sizeof...($TemplateParameter[[Elements]]);
 using 
$Class[[Y]]$Bracket[[<]]0$Bracket[[>]]::$Unknown_dependentName[[xxx]];
   };
 };
+)cpp",
+  // Heuristically resolved IndirectFieldDecl
+  R"cpp(
+template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+struct $Class_def[[Base]] {
+  struct {
+int $Field_decl[[waldo]];
+  };
+};
+template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+struct $Class_def[[Derived]] : 
$Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]] {
+  using 
$Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]]::$Field_dependentName[[waldo]];
+  void $Method_def[[foo]]() {
+$Field_dependentName[[waldo]];
+  }
+};
 )cpp"};
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.

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


[clang-tools-extra] 0a888fa - [clangd] Handle IndirectFieldDecl in kindForDecl (#80588)

2024-02-05 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-02-05T03:22:17-05:00
New Revision: 0a888fade2600dce737bc356a158e44c8f59b616

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

LOG: [clangd] Handle IndirectFieldDecl in kindForDecl (#80588)

Fixes https://github.com/clangd/clangd/issues/1925

Added: 


Modified: 
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index ee3772e3d380c..08f99e11ac9be 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -136,7 +136,7 @@ std::optional kindForDecl(const NamedDecl 
*D,
   if (auto *OMD = dyn_cast(D))
 return OMD->isClassMethod() ? HighlightingKind::StaticMethod
 : HighlightingKind::Method;
-  if (isa(D))
+  if (isa(D))
 return HighlightingKind::Field;
   if (isa(D))
 return HighlightingKind::Enum;

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index da12accc7898b..4156921d83edf 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1076,6 +1076,22 @@ sizeof...($TemplateParameter[[Elements]]);
 using 
$Class[[Y]]$Bracket[[<]]0$Bracket[[>]]::$Unknown_dependentName[[xxx]];
   };
 };
+)cpp",
+  // Heuristically resolved IndirectFieldDecl
+  R"cpp(
+template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+struct $Class_def[[Base]] {
+  struct {
+int $Field_decl[[waldo]];
+  };
+};
+template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+struct $Class_def[[Derived]] : 
$Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]] {
+  using 
$Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]]::$Field_dependentName[[waldo]];
+  void $Method_def[[foo]]() {
+$Field_dependentName[[waldo]];
+  }
+};
 )cpp"};
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.



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


[clang-tools-extra] [clangd] Handle IndirectFieldDecl in kindForDecl (PR #80588)

2024-02-05 Thread Nathan Ridge via cfe-commits

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


[clang] [clang-format] Fix a regression in dumping the config (PR #80628)

2024-02-05 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/80628

>From d49f94ca7de184fb7859a2d6d3f85e9b9adcc041 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 4 Feb 2024 18:29:42 -0800
Subject: [PATCH 1/2] [clang-format] Fix a regression in dumping the config

Commit d813af73f70f addressed a regression introduced by commit 3791b3fca6ea
but caused `clang-format -dump-config` to "hang".

This patch reverts changes to ClangFormat.cpp by both 3791b3fca6ea and
d813af73f70f and reworks the cleanup.

Fixes #80621.
---
 clang/tools/clang-format/ClangFormat.cpp | 49 
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 5ee6092bb9bb7..a854a97a2d189 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -399,7 +399,8 @@ class ClangFormatDiagConsumer : public DiagnosticConsumer {
 };
 
 // Returns true on error.
-static bool format(StringRef FileName, bool IsSTDIN) {
+static bool format(StringRef FileName) {
+  const bool IsSTDIN = FileName == "-";
   if (!OutputXML && Inplace && IsSTDIN) {
 errs() << "error: cannot use -i when reading from stdin.\n";
 return false;
@@ -545,24 +546,25 @@ static void PrintVersion(raw_ostream &OS) {
 }
 
 // Dump the configuration.
-static int dumpConfig(bool IsSTDIN) {
+static int dumpConfig() {
   std::unique_ptr Code;
-
-  // `FileNames` must have at least "-" in it even if no file was specified.
-  assert(!FileNames.empty());
-
-  // Read in the code in case the filename alone isn't enough to detect the
-  // language.
-  ErrorOr> CodeOrErr =
-  MemoryBuffer::getFileOrSTDIN(FileNames[0]);
-  if (std::error_code EC = CodeOrErr.getError()) {
-llvm::errs() << EC.message() << "\n";
-return 1;
+  // We can't read the code to detect the language if there's no file name.
+  if (!FileNames.empty()) {
+// Read in the code in case the filename alone isn't enough to detect the
+// language.
+ErrorOr> CodeOrErr =
+MemoryBuffer::getFileOrSTDIN(FileNames[0]);
+if (std::error_code EC = CodeOrErr.getError()) {
+  llvm::errs() << EC.message() << "\n";
+  return 1;
+}
+Code = std::move(CodeOrErr.get());
   }
-  Code = std::move(CodeOrErr.get());
-
   llvm::Expected FormatStyle =
-  clang::format::getStyle(Style, IsSTDIN ? AssumeFileName : FileNames[0],
+  clang::format::getStyle(Style,
+  FileNames.empty() || FileNames[0] == "-"
+  ? AssumeFileName
+  : FileNames[0],
   FallbackStyle, Code ? Code->getBuffer() : "");
   if (!FormatStyle) {
 llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
@@ -682,11 +684,8 @@ int main(int argc, const char **argv) {
 return 0;
   }
 
-  if (FileNames.empty())
-FileNames.push_back("-");
-
   if (DumpConfig)
-return dumpConfig(FileNames[0] == "-");
+return dumpConfig();
 
   if (!Files.empty()) {
 std::ifstream ExternalFileOfFiles{std::string(Files)};
@@ -699,7 +698,10 @@ int main(int argc, const char **argv) {
 errs() << "Clang-formating " << LineNo << " files\n";
   }
 
-  if (FileNames.size() != 1 &&
+  if (FileNames.empty())
+return clang::format::format("-");
+
+  if (FileNames.size() > 1 &&
   (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
 errs() << "error: -offset, -length and -lines can only be used for "
   "single file.\n";
@@ -709,14 +711,13 @@ int main(int argc, const char **argv) {
   unsigned FileNo = 1;
   bool Error = false;
   for (const auto &FileName : FileNames) {
-const bool IsSTDIN = FileName == "-";
-if (!IsSTDIN && isIgnored(FileName))
+if (FileName != "-" && isIgnored(FileName))
   continue;
 if (Verbose) {
   errs() << "Formatting [" << FileNo++ << "/" << FileNames.size() << "] "
  << FileName << "\n";
 }
-Error |= clang::format::format(FileName, IsSTDIN);
+Error |= clang::format::format(FileName);
   }
   return Error ? 1 : 0;
 }

>From 272442889a7e78eb1bd64f78136eb8edd86a6573 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 5 Feb 2024 00:52:44 -0800
Subject: [PATCH 2/2] Add a lit test.

---
 clang/test/Format/dump-config.cpp | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 clang/test/Format/dump-config.cpp

diff --git a/clang/test/Format/dump-config.cpp 
b/clang/test/Format/dump-config.cpp
new file mode 100644
index 0..fad517c44642f
--- /dev/null
+++ b/clang/test/Format/dump-config.cpp
@@ -0,0 +1,3 @@
+// RUN: clang-format -dump-config 2>&1 | FileCheck %s
+
+// CHECK: Language: Cpp

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


[clang] [Clang] Fix crash when recovering from an invalid pack indexing type. (PR #80652)

2024-02-05 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/80652

If the pattern of a pack indexing type did not contain a pack, we would still 
construct a pack indexing type (to improve error messages) but we would fail to 
make the type as dependent, leading to infinite recursion when trying to 
extract a canonical type.

>From 15e7279b71764342de5073da88854356e0d8dea2 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 5 Feb 2024 10:30:06 +0100
Subject: [PATCH] [Clang] Fix crash when recovering from an invalid pack
 indexing type.

If the pattern of a pack indexing type did not contain a pack,
we would still construct a pack indexing type (to improve error messages)
but we would fail to make the type as dependent, leading to infinite
recursion when trying to extract a canonical type.
---
 clang/lib/AST/Type.cpp |  6 ++
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 15 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 11ca02be13ab4..c68254a459ccc 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3854,6 +3854,12 @@ PackIndexingType::computeDependence(QualType Pattern, 
Expr *IndexExpr,
 
   if (!(IndexD & TypeDependence::UnexpandedPack))
 TD &= ~TypeDependence::UnexpandedPack;
+
+  // If the pattern does not contain an unexpended pack,
+  // the type is still dependent, and invalid
+  if (!Pattern->containsUnexpandedParameterPack())
+TD |= TypeDependence::Error | TypeDependence::DependentInstantiation;
+
   return TD;
 }
 
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp 
b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index bd75c1180a1c1..625a56031598b 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -11,6 +11,21 @@ void not_pack() {
 Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a 
parameter pack}}
 }
 
+template  typename Tp>
+void not_pack_arrays() {
+NotAPack...[0] a[1]; // expected-error{{'NotAPack' does not refer to the 
name of a parameter pack}}
+T...[0] b[1];   // expected-error{{'T' does not refer to the name of a 
parameter pack}}
+Tp...[0] c[1]; // expected-error{{'Tp' does not refer to the name of a 
parameter pack}}
+}
+
+template 
+struct TTP;
+
+void test_errors() {
+not_pack();
+not_pack_arrays();
+}
+
 namespace invalid_indexes {
 
 int non_constant_index(); // expected-note 2{{declared here}}

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


[clang] [Clang] Fix crash when recovering from an invalid pack indexing type. (PR #80652)

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

If the pattern of a pack indexing type did not contain a pack, we would still 
construct a pack indexing type (to improve error messages) but we would fail to 
make the type as dependent, leading to infinite recursion when trying to 
extract a canonical type.

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


2 Files Affected:

- (modified) clang/lib/AST/Type.cpp (+6) 
- (modified) clang/test/SemaCXX/cxx2c-pack-indexing.cpp (+15) 


``diff
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 11ca02be13ab4..c68254a459ccc 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3854,6 +3854,12 @@ PackIndexingType::computeDependence(QualType Pattern, 
Expr *IndexExpr,
 
   if (!(IndexD & TypeDependence::UnexpandedPack))
 TD &= ~TypeDependence::UnexpandedPack;
+
+  // If the pattern does not contain an unexpended pack,
+  // the type is still dependent, and invalid
+  if (!Pattern->containsUnexpandedParameterPack())
+TD |= TypeDependence::Error | TypeDependence::DependentInstantiation;
+
   return TD;
 }
 
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp 
b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index bd75c1180a1c1..625a56031598b 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -11,6 +11,21 @@ void not_pack() {
 Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a 
parameter pack}}
 }
 
+template  typename Tp>
+void not_pack_arrays() {
+NotAPack...[0] a[1]; // expected-error{{'NotAPack' does not refer to the 
name of a parameter pack}}
+T...[0] b[1];   // expected-error{{'T' does not refer to the name of a 
parameter pack}}
+Tp...[0] c[1]; // expected-error{{'Tp' does not refer to the name of a 
parameter pack}}
+}
+
+template 
+struct TTP;
+
+void test_errors() {
+not_pack();
+not_pack_arrays();
+}
+
 namespace invalid_indexes {
 
 int non_constant_index(); // expected-note 2{{declared here}}

``




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


[clang] [Clang] Fix a crash when dumping a pack indexing type. (PR #80439)

2024-02-05 Thread via cfe-commits

cor3ntin wrote:

@bjope I appreciate the investigation, thanks! Here is a fix 
https://github.com/llvm/llvm-project/pull/80652

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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-05 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,21 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -disable-llvm-optzns 
-mprintf-kind=hostcall -fno-builtin-printf -fcuda-is-device \
+// RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -disable-llvm-optzns 
-mprintf-kind=buffered -fno-builtin-printf -fcuda-is-device \
+// RUN:   -o - %s | FileCheck %s
+
+#define __device__ __attribute__((device))
+
+extern "C" __device__ int printf(const char *format, ...);
+
+// CHECK-LABEL: @_Z4foo1v()
+__device__ int foo1() {
+  // CHECK-NOT: call i32 (ptr, ...) @printf

arsenm wrote:

should add some positive checks 

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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-05 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> > It looks reasonable to me, although I'm not really an AMDGPU person. /me 
> > summons @arsenm ?
> 
> AMDGPU backend relies on LLVM passes to translate printf at IR level.

For the OpenCL case only, not for HIP/OpenMP

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


[clang] [llvm] [clang-tools-extra] Apply format only if --format is specified (PR #79466)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

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


[clang] [Clang][Parser] GH78524 (PR #80656)

2024-02-05 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/80656

Poking the CI.

>From 3ceeae611848b58f8d49c58295a625bdb052ac97 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 5 Feb 2024 18:01:34 +0800
Subject: [PATCH] GH78524

---
 clang/lib/Parse/ParseExprCXX.cpp  |  6 -
 .../Parser/cxx-concepts-requires-clause.cpp   | 27 +++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661..5c374d2eb452d 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  // We increase the template depth before recursing into a 
requires-clause.
+  // The abbreviated generic lambdas thereof could have different template
+  // depths, avoiding substituting into wrong template parameters during 
the
+  // satisfaction check.
+  ++CurTemplateDepthTracker;
   ExprResult RequiresClause;
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
@@ -1396,7 +1401,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 
   Actions.ActOnLambdaExplicitTemplateParameterList(
   Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
-  ++CurTemplateDepthTracker;
 }
   }
 
diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp 
b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 1ec1eefa12865..f268092728fdf 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // 
expected-error {{expected bo
 #if __cplusplus <= 202002L
 // expected-warning@-2{{lambda without a parameter clause is a C++23 
extension}}
 #endif
+
+namespace GH78524 {
+
+template  T Foo;
+
+template  auto C(Foo);
+
+template  struct D {
+  decltype(T()(C)) Type;
+};
+
+template  D G(T, U) { return {}; }
+
+struct E {};
+
+void F() {
+  G([]
+// ~~ T: 0,0
+  requires requires { [](auto...) {}; }(T)
+//    auto: 1,0
+{ return T(); },
+E{});
+}
+
+int a = [] requires requires { [](auto){}; } { return 0; }();
+
+} // namespace GH78524

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


[clang] [Clang] Fix crash when recovering from an invalid pack indexing type. (PR #80652)

2024-02-05 Thread Björn Pettersson via cfe-commits

bjope wrote:

@cor3ntin : I've verified that this would solve the problem that I noticed 
downstream. Thanks!

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


[clang] [analyzer] Teach analzer about ms __analyzer_assume(bool) and friends (PR #80456)

2024-02-05 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/80456

>From 3a11db7ce1e91daacb86e183e7137db7a6101c9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Joly?= 
Date: Tue, 9 Aug 2022 23:21:18 +0200
Subject: [PATCH] [analyzer] Model Microsoft "__assume" in the same way as
 clang "__builtin_assume"

---
 .../Checkers/BuiltinFunctionChecker.cpp|  3 ++-
 clang/test/Analysis/builtin-functions.cpp  | 18 ++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 61521c259ca90..01e46fa8591c0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -44,7 +44,8 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
   default:
 return false;
 
-  case Builtin::BI__builtin_assume: {
+  case Builtin::BI__builtin_assume:
+  case Builtin::BI__assume: {
 assert (Call.getNumArgs() > 0);
 SVal Arg = Call.getArgSVal(0);
 if (Arg.isUndef())
diff --git a/clang/test/Analysis/builtin-functions.cpp 
b/clang/test/Analysis/builtin-functions.cpp
index 37e522049b174..8719193e405c4 100644
--- a/clang/test/Analysis/builtin-functions.cpp
+++ b/clang/test/Analysis/builtin-functions.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
+// RUN: %clang_analyze_cc1 -triple x86_64-pc-windows-msvc19.11.0 
-fms-extensions -analyzer-checker=core,debug.ExprInspection %s -std=c++11 
-verify
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
@@ -65,6 +66,23 @@ void g(int i) {
   }
 }
 
+#ifdef _WIN32
+namespace ms {
+void f(int i) {
+  __assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}
+
+void g(int i) {
+  if (i > 5) {
+__assume(i < 5);
+clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
+// We give up the analysis on this path.
+  }
+}
+} // namespace ms
+#endif
+
 void test_constant_p(void *ptr) {
   int i = 1;
   const int j = 2;

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


[clang] [analyzer] Model Microsoft "__assume" in the same way as clang "__builtin_assume" (PR #80456)

2024-02-05 Thread Balazs Benics via cfe-commits

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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-05 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> I wonder if, instead, we should just have `-ffast-math` always downgrade 
> `-fdenormal-fp-math=ieee` to `-fdenormal-fp-math=preserve-sign`, under the 
> rationale of "you asked for fast math, and preserve-sign mode might let the 
> compiler generate faster code"?

This could also use denormal-fp-math=dynamic. It is not always safe to run 
preserve-sign code under IEEE settings 

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


[clang] [analyzer] Model Microsoft "__assume" in the same way as clang "__builtin_assume" (PR #80456)

2024-02-05 Thread Balazs Benics via cfe-commits

steakhal wrote:

It turns out we already had a downstream patch, so I'll drop this one in favor 
of what we already had.
Sorry about the confusion.
This version is already in production for many years now.

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


[clang] [analyzer] Model Microsoft "__assume" in the same way as clang "__builtin_assume" (PR #80456)

2024-02-05 Thread via cfe-commits

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

LGTM. It's good to see that this is also represented in the `Builtin::` enum, 
so there's no need for a different kind of logic.

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


[clang] [polly] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-02-05 Thread via cfe-commits

rmarker wrote:

Nice.
Thanks, @owenca, and @HazardyKnusperkeks.

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


[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-05 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/80662

First, we need to register local constant variables in C, so we get the same 
diagnostic behavior as the current interpeter.

Second, when returning an LValue (as a Pointer), which we eventually convert to 
an RValue, we need to do the conversion immediately when saving the Pointer in 
the EvaluationResult. Otherwise, we will possibly deallocate the data before 
doing the conversion (which will look at the Block*).

>From 9d2a6fc4c8b563657a7be7ccbeecb615597f598e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 5 Feb 2024 10:29:45 +0100
Subject: [PATCH] [clang][Interp] Do r-to-l conversion immediately when
 returning

First, we need to register local constant variables in C, so we get
the same diagnostic behavior as the current interpeter.

Second, when returning an LValue (as a Pointer), which we eventually
convert to an RValue, we need to do the conversion immediately when
saving the Pointer in the EvaluationResult. Otherwise, we will
possibly deallocate the data before doing the conversion (which will
look at the Block*).
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  3 +--
 clang/lib/AST/Interp/Context.cpp | 16 
 clang/lib/AST/Interp/EvalEmitter.cpp | 20 ++--
 clang/lib/AST/Interp/EvalEmitter.h   |  5 -
 clang/lib/AST/Interp/EvaluationResult.h  |  2 +-
 clang/test/AST/Interp/c.c| 13 +
 clang/test/Sema/warn-char-subscripts.c   |  1 +
 7 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3ca4f56903fda..3248a3b9471a6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3002,8 +3002,7 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // This happens in C.
   if (!Ctx.getLangOpts().CPlusPlus) {
 if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() && VD->getAnyInitializer() &&
-VD->getType().isConstQualified()) {
+VD && VD->getAnyInitializer() && VD->getType().isConstQualified()) {
   if (!this->visitVarDecl(VD))
 return false;
   // Retry.
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 5f5a6622f10f3..061f4e1f35779 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -44,7 +44,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, 
APValue &Result) {
   assert(Stk.empty());
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
 
-  auto Res = C.interpretExpr(E);
+  auto Res = C.interpretExpr(E, /*ConvertResultToRValue=*/E->isGLValue());
 
   if (Res.isInvalid()) {
 Stk.clear();
@@ -58,16 +58,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, 
APValue &Result) {
   Stk.clear();
 #endif
 
-  // Implicit lvalue-to-rvalue conversion.
-  if (E->isGLValue()) {
-std::optional RValueResult = Res.toRValue();
-if (!RValueResult) {
-  return false;
-}
-Result = *RValueResult;
-  } else {
-Result = Res.toAPValue();
-  }
+  Result = Res.toAPValue();
 
   return true;
 }
@@ -120,7 +111,8 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
 !Res.checkFullyInitialized(C.getState()))
   return false;
 
-// lvalue-to-rvalue conversion.
+// lvalue-to-rvalue conversion. We do this manually here so we can
+// examine the result above before converting and returning it.
 std::optional RValueResult = Res.toRValue();
 if (!RValueResult)
   return false;
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index a60f893de8bda..5a36b46b74543 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -33,7 +33,9 @@ EvalEmitter::~EvalEmitter() {
   }
 }
 
-EvaluationResult EvalEmitter::interpretExpr(const Expr *E) {
+EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
+bool ConvertResultToRValue) {
+  this->ConvertResultToRValue = ConvertResultToRValue;
   EvalResult.setSource(E);
 
   if (!this->visitExpr(E))
@@ -119,12 +121,26 @@ template  bool 
EvalEmitter::emitRet(const SourceInfo &Info) {
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
-  EvalResult.setPointer(S.Stk.pop());
+
+  const Pointer &Ptr = S.Stk.pop();
+  // Implicitly convert lvalue to rvalue, if requested.
+  if (ConvertResultToRValue) {
+if (std::optional V = Ptr.toRValue(Ctx)) {
+  EvalResult.setValue(*V);
+} else {
+  return false;
+}
+  } else {
+EvalResult.setPointer(Ptr);
+  }
+
   return true;
 }
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
+  // Function pointers are always lvalues to us and cannot be conv

[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

First, we need to register local constant variables in C, so we get the same 
diagnostic behavior as the current interpeter.

Second, when returning an LValue (as a Pointer), which we eventually convert to 
an RValue, we need to do the conversion immediately when saving the Pointer in 
the EvaluationResult. Otherwise, we will possibly deallocate the data before 
doing the conversion (which will look at the Block*).

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


7 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+1-2) 
- (modified) clang/lib/AST/Interp/Context.cpp (+4-12) 
- (modified) clang/lib/AST/Interp/EvalEmitter.cpp (+18-2) 
- (modified) clang/lib/AST/Interp/EvalEmitter.h (+4-1) 
- (modified) clang/lib/AST/Interp/EvaluationResult.h (+1-1) 
- (modified) clang/test/AST/Interp/c.c (+13) 
- (modified) clang/test/Sema/warn-char-subscripts.c (+1) 


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3ca4f56903fda..3248a3b9471a6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3002,8 +3002,7 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // This happens in C.
   if (!Ctx.getLangOpts().CPlusPlus) {
 if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() && VD->getAnyInitializer() &&
-VD->getType().isConstQualified()) {
+VD && VD->getAnyInitializer() && VD->getType().isConstQualified()) {
   if (!this->visitVarDecl(VD))
 return false;
   // Retry.
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 5f5a6622f10f3..061f4e1f35779 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -44,7 +44,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, 
APValue &Result) {
   assert(Stk.empty());
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
 
-  auto Res = C.interpretExpr(E);
+  auto Res = C.interpretExpr(E, /*ConvertResultToRValue=*/E->isGLValue());
 
   if (Res.isInvalid()) {
 Stk.clear();
@@ -58,16 +58,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, 
APValue &Result) {
   Stk.clear();
 #endif
 
-  // Implicit lvalue-to-rvalue conversion.
-  if (E->isGLValue()) {
-std::optional RValueResult = Res.toRValue();
-if (!RValueResult) {
-  return false;
-}
-Result = *RValueResult;
-  } else {
-Result = Res.toAPValue();
-  }
+  Result = Res.toAPValue();
 
   return true;
 }
@@ -120,7 +111,8 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
 !Res.checkFullyInitialized(C.getState()))
   return false;
 
-// lvalue-to-rvalue conversion.
+// lvalue-to-rvalue conversion. We do this manually here so we can
+// examine the result above before converting and returning it.
 std::optional RValueResult = Res.toRValue();
 if (!RValueResult)
   return false;
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index a60f893de8bda..5a36b46b74543 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -33,7 +33,9 @@ EvalEmitter::~EvalEmitter() {
   }
 }
 
-EvaluationResult EvalEmitter::interpretExpr(const Expr *E) {
+EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
+bool ConvertResultToRValue) {
+  this->ConvertResultToRValue = ConvertResultToRValue;
   EvalResult.setSource(E);
 
   if (!this->visitExpr(E))
@@ -119,12 +121,26 @@ template  bool 
EvalEmitter::emitRet(const SourceInfo &Info) {
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
-  EvalResult.setPointer(S.Stk.pop());
+
+  const Pointer &Ptr = S.Stk.pop();
+  // Implicitly convert lvalue to rvalue, if requested.
+  if (ConvertResultToRValue) {
+if (std::optional V = Ptr.toRValue(Ctx)) {
+  EvalResult.setValue(*V);
+} else {
+  return false;
+}
+  } else {
+EvalResult.setPointer(Ptr);
+  }
+
   return true;
 }
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
+  // Function pointers are always lvalues to us and cannot be converted
+  // to rvalues, so don't do any conversion here.
   EvalResult.setFunctionPointer(S.Stk.pop());
   return true;
 }
diff --git a/clang/lib/AST/Interp/EvalEmitter.h 
b/clang/lib/AST/Interp/EvalEmitter.h
index deb2ebc4e61fa..8159e489f168e 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -34,7 +34,8 @@ class EvalEmitter : public SourceMapper {
   using AddrTy = uintptr_t;
   using Local = Scope::Local;
 
-  EvaluationResult interpretExpr(const Expr *E);
+  EvaluationResult interpretExpr(const Expr *E,
+ boo

[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-05 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Asking for review here since I'm not sure if the reasoning makes sense for 
other people.

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


[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-05 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-05 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

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


[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-05 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80656

>From 48211eb7778db8fb8af144d59adb2e0941957c4c Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 5 Feb 2024 18:01:34 +0800
Subject: [PATCH] GH78524

---
 clang/docs/ReleaseNotes.rst   |  4 +++
 clang/lib/Parse/ParseExprCXX.cpp  |  6 -
 .../Parser/cxx-concepts-requires-clause.cpp   | 27 +++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..4234851232695 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -193,6 +193,10 @@ Bug Fixes to C++ Support
 - Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
   function calls while substituting into constraints.
   (`#58548 `_)
+- Fixed an issue where template parameters of the nested abbreviated generic 
lambda within
+  a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
+  in turn, results in the wrong template argument substitution during the 
constraint checking.
+  (`#78524 `_) 
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661..5c374d2eb452d 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  // We increase the template depth before recursing into a 
requires-clause.
+  // The abbreviated generic lambdas thereof could have different template
+  // depths, avoiding substituting into wrong template parameters during 
the
+  // satisfaction check.
+  ++CurTemplateDepthTracker;
   ExprResult RequiresClause;
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
@@ -1396,7 +1401,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 
   Actions.ActOnLambdaExplicitTemplateParameterList(
   Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
-  ++CurTemplateDepthTracker;
 }
   }
 
diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp 
b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 1ec1eefa12865..f268092728fdf 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // 
expected-error {{expected bo
 #if __cplusplus <= 202002L
 // expected-warning@-2{{lambda without a parameter clause is a C++23 
extension}}
 #endif
+
+namespace GH78524 {
+
+template  T Foo;
+
+template  auto C(Foo);
+
+template  struct D {
+  decltype(T()(C)) Type;
+};
+
+template  D G(T, U) { return {}; }
+
+struct E {};
+
+void F() {
+  G([]
+// ~~ T: 0,0
+  requires requires { [](auto...) {}; }(T)
+//    auto: 1,0
+{ return T(); },
+E{});
+}
+
+int a = [] requires requires { [](auto){}; } { return 0; }();
+
+} // namespace GH78524

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


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

Pushed as https://github.com/llvm/llvm-project/pull/79466

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


[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-05 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

A one-line fix, again : )

This fixes https://github.com/llvm/llvm-project/issues/78524 and the similar 
example at 
https://github.com/llvm/llvm-project/issues/78524#issuecomment-1899886951.

We previously increased the template depth by one after parsing the attaching 
requires-clause on a lambda expression. This led to a problem where the 'auto' 
parameters of nested abbreviated generic lambdas, inside of a 
requires-expression, had the same depth as the template parameters of the 
surrounding lambda. Consequently, during the concept-checking stage, we ended 
up substituting these parameters with the wrong template arguments because they 
were at different levels.


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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+5-1) 
- (modified) clang/test/Parser/cxx-concepts-requires-clause.cpp (+27) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..4234851232695 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -193,6 +193,10 @@ Bug Fixes to C++ Support
 - Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
   function calls while substituting into constraints.
   (`#58548 `_)
+- Fixed an issue where template parameters of the nested abbreviated generic 
lambda within
+  a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
+  in turn, results in the wrong template argument substitution during the 
constraint checking.
+  (`#78524 `_) 
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661..5c374d2eb452d 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  // We increase the template depth before recursing into a 
requires-clause.
+  // The abbreviated generic lambdas thereof could have different template
+  // depths, avoiding substituting into wrong template parameters during 
the
+  // satisfaction check.
+  ++CurTemplateDepthTracker;
   ExprResult RequiresClause;
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
@@ -1396,7 +1401,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 
   Actions.ActOnLambdaExplicitTemplateParameterList(
   Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
-  ++CurTemplateDepthTracker;
 }
   }
 
diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp 
b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 1ec1eefa12865..f268092728fdf 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // 
expected-error {{expected bo
 #if __cplusplus <= 202002L
 // expected-warning@-2{{lambda without a parameter clause is a C++23 
extension}}
 #endif
+
+namespace GH78524 {
+
+template  T Foo;
+
+template  auto C(Foo);
+
+template  struct D {
+  decltype(T()(C)) Type;
+};
+
+template  D G(T, U) { return {}; }
+
+struct E {};
+
+void F() {
+  G([]
+// ~~ T: 0,0
+  requires requires { [](auto...) {}; }(T)
+//    auto: 1,0
+{ return T(); },
+E{});
+}
+
+int a = [] requires requires { [](auto){}; } { return 0; }();
+
+} // namespace GH78524

``




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


[lld] [libc] [lldb] [flang] [clang] [libcxx] [llvm] [clang-tools-extra] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread David Stuttard via cfe-commits

https://github.com/dstutt updated 
https://github.com/llvm/llvm-project/pull/67104

>From 259138920126f09149b488fc54e8d2a7da969ca4 Mon Sep 17 00:00:00 2001
From: David Stuttard 
Date: Thu, 24 Aug 2023 16:45:50 +0100
Subject: [PATCH 1/4] [AMDGPU] Add pal metadata 3.0 support to callable pal
 funcs

---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |  28 +-
 .../AMDGPU/pal-metadata-3.0-callable.ll   | 290 ++
 2 files changed, 314 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index b2360ce30fd6e..22ecd3656d00a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1098,10 +1098,30 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   StringRef FnName = MF.getFunction().getName();
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+MD->setHwStage(CallingConv::AMDGPU_CS, ".ieee_mode",
+   (bool)CurrentProgramInfo.IEEEMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".wgp_mode",
+   (bool)CurrentProgramInfo.WgpMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".mem_ordered",
+   (bool)CurrentProgramInfo.MemOrdered);
+
+MD->setHwStage(CallingConv::AMDGPU_CS, ".trap_present",
+   (bool)CurrentProgramInfo.TrapHandlerEnable);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".excp_en",
+   CurrentProgramInfo.EXCPEnable);
+
+const unsigned LdsDwGranularity = 128;
+MD->setHwStage(CallingConv::AMDGPU_CS, ".lds_size",
+   (unsigned)(CurrentProgramInfo.LdsSize * LdsDwGranularity *
+  sizeof(uint32_t)));
+  }
 
   // Set optional info
   MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
diff --git a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll 
b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
new file mode 100644
index 0..d4a5f61aced61
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
@@ -0,0 +1,290 @@
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 -verify-machineinstrs < %s | 
FileCheck %s
+
+; CHECK:   .amdgpu_pal_metadata
+; CHECK-NEXT: ---
+; CHECK-NEXT: amdpal.pipelines:
+; CHECK-NEXT:  - .api:Vulkan
+; CHECK-NEXT:.compute_registers:
+; CHECK-NEXT:  .tg_size_en: true
+; CHECK-NEXT:  .tgid_x_en:  false
+; CHECK-NEXT:  .tgid_y_en:  false
+; CHECK-NEXT:  .tgid_z_en:  false
+; CHECK-NEXT:  .tidig_comp_cnt: 0x1
+; CHECK-NEXT:.hardware_stages:
+; CHECK-NEXT:  .cs:
+; CHECK-NEXT:.checksum_value: 0x9444d7d0
+; CHECK-NEXT:.debug_mode: 0
+; CHECK-NEXT:.excp_en:0
+; CHECK-NEXT:.float_mode: 0xc0
+; CHECK-NEXT:.ieee_mode:  true
+; CHECK-NEXT:.image_op:   false
+; CHECK-NEXT:.lds_size:   0x200
+; CHECK-NEXT:.mem_ordered:true
+; CHECK-NEXT:.sgpr_limit: 0x6a
+; CHECK-NEXT:.threadgroup_dimensions:
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:  - 0x400
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:.trap_present:   false
+; CHECK-NEXT:.user_data_reg_map:
+; CHECK-NEXT:  - 0x1000
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT

[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Sergio Afonso via cfe-commits

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


[openmp] [llvm] [clang] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Sergio Afonso via cfe-commits

https://github.com/skatrak commented:

I noticed a small breakage of the OpenMP MLIR dialect from one of these 
changes. It should be trivial to address.

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


[llvm] [clang] [openmp] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Sergio Afonso via cfe-commits


@@ -6872,35 +6883,6 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef 
HostFilePath) {
   loadOffloadInfoMetadata(*M.get());
 }
 
-Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) {

skatrak wrote:

Removing this function breaks the compilation of the OpenMP MLIR dialect, as 
it's used there 
(mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp: 
`convertRequiresAttr()`).

My understanding is that creating this function would no longer be necessary, 
so the solution to that should be to remove `convertRequiresAttr()` and replace 
the call to it in `OpenMPDialectLLVMIRTranslationInterface::amendOperation()` 
to `return success()` in the same file. Flang should already pick up your other 
changes, so REQUIRES information should still work in Fortran after this.

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


[llvm] [clang-tools-extra] [flang] [lldb] [clang] [libcxx] [libc] [lld] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread Matt Arsenault via cfe-commits


@@ -1127,10 +1131,16 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
   const GCNSubtarget &ST = MF.getSubtarget();
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS, ST));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS, ST));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+EmitPALMetadataCommon(MD, CurrentProgramInfo, CallingConv::AMDGPU_CS,
+  *getGlobalSTI());

arsenm wrote:

Never use getGlobalSTI. Use ST

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


[clang] [analyzer] Model Microsoft "__assume" in the same way as clang "__builtin_assume" (PR #80456)

2024-02-05 Thread Balazs Benics via cfe-commits

steakhal wrote:

Thanks Donát!

I'll wait for @Xazax-hun explicit approval to be sure everyone on board (who 
left remarks) are okay with the current content.

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


[lldb] [lld] [clang] [libcxx] [flang] [clang-tools-extra] [llvm] [libc] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread David Stuttard via cfe-commits

https://github.com/dstutt updated 
https://github.com/llvm/llvm-project/pull/67104

>From 259138920126f09149b488fc54e8d2a7da969ca4 Mon Sep 17 00:00:00 2001
From: David Stuttard 
Date: Thu, 24 Aug 2023 16:45:50 +0100
Subject: [PATCH 1/5] [AMDGPU] Add pal metadata 3.0 support to callable pal
 funcs

---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |  28 +-
 .../AMDGPU/pal-metadata-3.0-callable.ll   | 290 ++
 2 files changed, 314 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index b2360ce30fd6e..22ecd3656d00a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1098,10 +1098,30 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   StringRef FnName = MF.getFunction().getName();
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+MD->setHwStage(CallingConv::AMDGPU_CS, ".ieee_mode",
+   (bool)CurrentProgramInfo.IEEEMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".wgp_mode",
+   (bool)CurrentProgramInfo.WgpMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".mem_ordered",
+   (bool)CurrentProgramInfo.MemOrdered);
+
+MD->setHwStage(CallingConv::AMDGPU_CS, ".trap_present",
+   (bool)CurrentProgramInfo.TrapHandlerEnable);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".excp_en",
+   CurrentProgramInfo.EXCPEnable);
+
+const unsigned LdsDwGranularity = 128;
+MD->setHwStage(CallingConv::AMDGPU_CS, ".lds_size",
+   (unsigned)(CurrentProgramInfo.LdsSize * LdsDwGranularity *
+  sizeof(uint32_t)));
+  }
 
   // Set optional info
   MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
diff --git a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll 
b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
new file mode 100644
index 0..d4a5f61aced61
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
@@ -0,0 +1,290 @@
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 -verify-machineinstrs < %s | 
FileCheck %s
+
+; CHECK:   .amdgpu_pal_metadata
+; CHECK-NEXT: ---
+; CHECK-NEXT: amdpal.pipelines:
+; CHECK-NEXT:  - .api:Vulkan
+; CHECK-NEXT:.compute_registers:
+; CHECK-NEXT:  .tg_size_en: true
+; CHECK-NEXT:  .tgid_x_en:  false
+; CHECK-NEXT:  .tgid_y_en:  false
+; CHECK-NEXT:  .tgid_z_en:  false
+; CHECK-NEXT:  .tidig_comp_cnt: 0x1
+; CHECK-NEXT:.hardware_stages:
+; CHECK-NEXT:  .cs:
+; CHECK-NEXT:.checksum_value: 0x9444d7d0
+; CHECK-NEXT:.debug_mode: 0
+; CHECK-NEXT:.excp_en:0
+; CHECK-NEXT:.float_mode: 0xc0
+; CHECK-NEXT:.ieee_mode:  true
+; CHECK-NEXT:.image_op:   false
+; CHECK-NEXT:.lds_size:   0x200
+; CHECK-NEXT:.mem_ordered:true
+; CHECK-NEXT:.sgpr_limit: 0x6a
+; CHECK-NEXT:.threadgroup_dimensions:
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:  - 0x400
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:.trap_present:   false
+; CHECK-NEXT:.user_data_reg_map:
+; CHECK-NEXT:  - 0x1000
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT

[lld] [lldb] [libcxx] [clang] [libc] [clang-tools-extra] [flang] [llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread David Stuttard via cfe-commits


@@ -1127,10 +1131,16 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
   const GCNSubtarget &ST = MF.getSubtarget();
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS, ST));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS, ST));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+EmitPALMetadataCommon(MD, CurrentProgramInfo, CallingConv::AMDGPU_CS,
+  *getGlobalSTI());

dstutt wrote:

Thanks - done.

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


[clang] 60732c0 - [clang][Interp][NFC] Remove superfluous return statement

2024-02-05 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-05T13:05:52+01:00
New Revision: 60732c0fae56829c5475091de678ad46f0ce6287

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

LOG: [clang][Interp][NFC] Remove superfluous return statement

Added: 


Modified: 
clang/lib/AST/Interp/EvaluationResult.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/EvaluationResult.cpp 
b/clang/lib/AST/Interp/EvaluationResult.cpp
index 05105862a53a8..b44e8f84a1c42 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -151,8 +151,6 @@ bool EvaluationResult::checkFullyInitialized(InterpState 
&S) const {
   const auto *CAT =
   cast(Ptr.getType()->getAsArrayTypeUnsafe());
   return CheckArrayInitialized(S, InitLoc, Ptr, CAT);
-
-  return true;
 }
 
 void EvaluationResult::dump() const {



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


[clang] [llvm] [clang-tools-extra] [analyzer] Support interestingness in ArrayBoundV2 (PR #78315)

2024-02-05 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


NagyDonat wrote:

Gentle ping @steakhal

(I'm assuming that you're interested in following and concluding the review of 
this commit. I could also ask e.g. Endre Fülöp to perform the review if you'd 
prefer that.)  

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


[libc] [libcxx] [clang-tools-extra] [flang] [lld] [lldb] [llvm] [clang] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread Matt Arsenault via cfe-commits


@@ -1025,6 +1025,26 @@ void AMDGPUAsmPrinter::EmitProgramInfoSI(const 
MachineFunction &MF,
   OutStreamer->emitInt32(MFI->getNumSpilledVGPRs());
 }
 
+// Helper function to add common PAL Metadata 3.0+
+static void EmitPALMetadataCommon(AMDGPUPALMetadata *MD,
+  const SIProgramInfo &CurrentProgramInfo,
+  CallingConv::ID CC,
+  const MCSubtargetInfo &ST) {
+  MD->setHwStage(CC, ".ieee_mode", (bool)CurrentProgramInfo.IEEEMode);

arsenm wrote:

should this be skipped for gfx12? 

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


[clang] c391f28 - [clang][Interp][NFC] Add simple test case for atomic types

2024-02-05 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-05T13:36:03+01:00
New Revision: c391f285afdfd800a251b4ef6d0bbadbbe9069ff

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

LOG: [clang][Interp][NFC] Add simple test case for atomic types

Added: 
clang/test/AST/Interp/atomic.cpp

Modified: 


Removed: 




diff  --git a/clang/test/AST/Interp/atomic.cpp 
b/clang/test/AST/Interp/atomic.cpp
new file mode 100644
index 00..c0476c3ce13f98
--- /dev/null
+++ b/clang/test/AST/Interp/atomic.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected -std=c++11 %s
+// RUN: %clang_cc1 -verify=both,ref -std=c++11 %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected -std=c++98 %s
+// RUN: %clang_cc1 -verify=both,ref -std=c++98 %s
+
+
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+
+/// Rejected in c++98
+#if __cplusplus >= 201103L
+constexpr _Atomic(bool) B = true;
+static_assert(B, "");
+#endif
+



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


[lld] [lldb] [libcxx] [clang] [libc] [clang-tools-extra] [flang] [llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread Piotr Sobczak via cfe-commits


@@ -1025,6 +1025,26 @@ void AMDGPUAsmPrinter::EmitProgramInfoSI(const 
MachineFunction &MF,
   OutStreamer->emitInt32(MFI->getNumSpilledVGPRs());
 }
 
+// Helper function to add common PAL Metadata 3.0+
+static void EmitPALMetadataCommon(AMDGPUPALMetadata *MD,
+  const SIProgramInfo &CurrentProgramInfo,
+  CallingConv::ID CC,
+  const MCSubtargetInfo &ST) {
+  MD->setHwStage(CC, ".ieee_mode", (bool)CurrentProgramInfo.IEEEMode);

piotrAMD wrote:

Maybe, but I wasn't sure. Seems we generally do not bother to do gfxip checks 
for others (e.g., "MemOrdered" is only supported on gfx10 and gfx11).

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


[clang] [AMDGPU] Allow w64 ballot to be used on w32 targets (PR #80183)

2024-02-05 Thread Matt Arsenault via cfe-commits

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


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


[lld] [lldb] [libcxx] [clang] [libc] [clang-tools-extra] [flang] [llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread David Stuttard via cfe-commits


@@ -1025,6 +1025,26 @@ void AMDGPUAsmPrinter::EmitProgramInfoSI(const 
MachineFunction &MF,
   OutStreamer->emitInt32(MFI->getNumSpilledVGPRs());
 }
 
+// Helper function to add common PAL Metadata 3.0+
+static void EmitPALMetadataCommon(AMDGPUPALMetadata *MD,
+  const SIProgramInfo &CurrentProgramInfo,
+  CallingConv::ID CC,
+  const MCSubtargetInfo &ST) {
+  MD->setHwStage(CC, ".ieee_mode", (bool)CurrentProgramInfo.IEEEMode);

dstutt wrote:

I can easily add that though - and that does mirror the recent change to 
getPGMRsrc1.

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


[lld] [lldb] [libcxx] [clang] [libc] [clang-tools-extra] [flang] [llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread Piotr Sobczak via cfe-commits


@@ -1025,6 +1025,26 @@ void AMDGPUAsmPrinter::EmitProgramInfoSI(const 
MachineFunction &MF,
   OutStreamer->emitInt32(MFI->getNumSpilledVGPRs());
 }
 
+// Helper function to add common PAL Metadata 3.0+
+static void EmitPALMetadataCommon(AMDGPUPALMetadata *MD,
+  const SIProgramInfo &CurrentProgramInfo,
+  CallingConv::ID CC,
+  const MCSubtargetInfo &ST) {
+  MD->setHwStage(CC, ".ieee_mode", (bool)CurrentProgramInfo.IEEEMode);

piotrAMD wrote:

Sounds good.

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


[clang] [llvm] [AArch64] Add soft-float ABI (PR #74460)

2024-02-05 Thread via cfe-commits

ostannard wrote:

Ping

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


[openmp] [clang] [llvm] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Joseph Huber via cfe-commits


@@ -6872,35 +6883,6 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef 
HostFilePath) {
   loadOffloadInfoMetadata(*M.get());
 }
 
-Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) {

jhuber6 wrote:

Thanks for the heads up. Do you know if there will be any other changes 
required to make the requires information use the "new" format?

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


[lld] [lldb] [libcxx] [clang] [libc] [clang-tools-extra] [flang] [llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread David Stuttard via cfe-commits

https://github.com/dstutt updated 
https://github.com/llvm/llvm-project/pull/67104

>From 259138920126f09149b488fc54e8d2a7da969ca4 Mon Sep 17 00:00:00 2001
From: David Stuttard 
Date: Thu, 24 Aug 2023 16:45:50 +0100
Subject: [PATCH 1/6] [AMDGPU] Add pal metadata 3.0 support to callable pal
 funcs

---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |  28 +-
 .../AMDGPU/pal-metadata-3.0-callable.ll   | 290 ++
 2 files changed, 314 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index b2360ce30fd6e..22ecd3656d00a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1098,10 +1098,30 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   StringRef FnName = MF.getFunction().getName();
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+MD->setHwStage(CallingConv::AMDGPU_CS, ".ieee_mode",
+   (bool)CurrentProgramInfo.IEEEMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".wgp_mode",
+   (bool)CurrentProgramInfo.WgpMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".mem_ordered",
+   (bool)CurrentProgramInfo.MemOrdered);
+
+MD->setHwStage(CallingConv::AMDGPU_CS, ".trap_present",
+   (bool)CurrentProgramInfo.TrapHandlerEnable);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".excp_en",
+   CurrentProgramInfo.EXCPEnable);
+
+const unsigned LdsDwGranularity = 128;
+MD->setHwStage(CallingConv::AMDGPU_CS, ".lds_size",
+   (unsigned)(CurrentProgramInfo.LdsSize * LdsDwGranularity *
+  sizeof(uint32_t)));
+  }
 
   // Set optional info
   MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
diff --git a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll 
b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
new file mode 100644
index 0..d4a5f61aced61
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
@@ -0,0 +1,290 @@
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 -verify-machineinstrs < %s | 
FileCheck %s
+
+; CHECK:   .amdgpu_pal_metadata
+; CHECK-NEXT: ---
+; CHECK-NEXT: amdpal.pipelines:
+; CHECK-NEXT:  - .api:Vulkan
+; CHECK-NEXT:.compute_registers:
+; CHECK-NEXT:  .tg_size_en: true
+; CHECK-NEXT:  .tgid_x_en:  false
+; CHECK-NEXT:  .tgid_y_en:  false
+; CHECK-NEXT:  .tgid_z_en:  false
+; CHECK-NEXT:  .tidig_comp_cnt: 0x1
+; CHECK-NEXT:.hardware_stages:
+; CHECK-NEXT:  .cs:
+; CHECK-NEXT:.checksum_value: 0x9444d7d0
+; CHECK-NEXT:.debug_mode: 0
+; CHECK-NEXT:.excp_en:0
+; CHECK-NEXT:.float_mode: 0xc0
+; CHECK-NEXT:.ieee_mode:  true
+; CHECK-NEXT:.image_op:   false
+; CHECK-NEXT:.lds_size:   0x200
+; CHECK-NEXT:.mem_ordered:true
+; CHECK-NEXT:.sgpr_limit: 0x6a
+; CHECK-NEXT:.threadgroup_dimensions:
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:  - 0x400
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:.trap_present:   false
+; CHECK-NEXT:.user_data_reg_map:
+; CHECK-NEXT:  - 0x1000
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT

[llvm] [clang] [clang-tools-extra] [analyzer] Support interestingness in ArrayBoundV2 (PR #78315)

2024-02-05 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [llvm] [clang] [analyzer] Support interestingness in ArrayBoundV2 (PR #78315)

2024-02-05 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -318,17 +424,91 @@ static Messages getTaintMsgs(const SubRegion *Region, 
const char *OffsetName) {
   RegName, OffsetName)};
 }
 
-void ArrayBoundCheckerV2::performCheck(const Expr *E, CheckerContext &C) const 
{
-  // NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
-  // some new logic here that reasons directly about memory region extents.
-  // Once that logic is more mature, we can bring it back to assumeInBound()
-  // for all clients to use.
-  //
-  // The algorithm we are using here for bounds checking is to see if the
-  // memory access is within the extent of the base region.  Since we
-  // have some flexibility in defining the base region, we can achieve
-  // various levels of conservatism in our buffer overflow checking.
+const NoteTag *StateUpdateReporter::createNoteTag(CheckerContext &C) const {
+  // Don't create a note tag if we didn't assume anything:
+  if (!AssumedNonNegative && !AssumedUpperBound)
+return nullptr;
+
+  return C.getNoteTag([*this](PathSensitiveBugReport &BR) -> std::string {
+return getMessage(BR);
+  });
+}
+
+std::string StateUpdateReporter::getMessage(PathSensitiveBugReport &BR) const {
+  bool ShouldReportNonNegative = AssumedNonNegative;
+  if (!providesInformationAboutInteresting(ByteOffsetVal, BR)) {
+if (AssumedUpperBound &&
+providesInformationAboutInteresting(*AssumedUpperBound, BR)) {
+  // Even if the byte offset isn't interesting (e.g. it's a constant 
value),
+  // the assumption can still be interesting if it provides information
+  // about an interesting symbolic upper bound.
+  ShouldReportNonNegative = false;
+} else {
+  // We don't have anything interesting, don't report the assumption.
+  return "";
+}

steakhal wrote:

```suggestion
}
// We don't have anything interesting, don't report the assumption.
return "";
```
Return after else.

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


[clang-tools-extra] [clang] [llvm] [analyzer] Support interestingness in ArrayBoundV2 (PR #78315)

2024-02-05 Thread Balazs Benics via cfe-commits
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy 
Message-ID:
In-Reply-To: 


https://github.com/steakhal requested changes to this pull request.

I only found one logic bump. Other than that, it's approved.

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


[clang] [llvm] [clang-tools-extra] [analyzer] Support interestingness in ArrayBoundV2 (PR #78315)

2024-02-05 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -381,66 +574,105 @@ void ArrayBoundCheckerV2::performCheck(const Expr *E, 
CheckerContext &C) const {
 compareValueToThreshold(State, ByteOffset, *KnownSize, SVB);
 
 if (ExceedsUpperBound) {
+  // The offset may be invalid (>= Size)...
   if (!WithinUpperBound) {
-// We know that the index definitely exceeds the upper bound.
-if (isa(E) && isInAddressOf(E, C.getASTContext())) 
{
-  // ...but this is within an addressof expression, so we need to check
-  // for the exceptional case that `&array[size]` is valid.
-  auto [EqualsToThreshold, NotEqualToThreshold] =
-  compareValueToThreshold(ExceedsUpperBound, ByteOffset, 
*KnownSize,
-  SVB, /*CheckEquality=*/true);
-  if (EqualsToThreshold && !NotEqualToThreshold) {
-// We are definitely in the exceptional case, so return early
-// instead of reporting a bug.
-C.addTransition(EqualsToThreshold);
-return;
-  }
+// ...and it cannot be within bounds, so report an error, unless we can
+// definitely determine that this is an idiomatic `&array[size]`
+// expression that calculates the past-the-end pointer.
+if (isIdiomaticPastTheEndPtr(E, ExceedsUpperBound, ByteOffset,
+ *KnownSize, C)) {
+  C.addTransition(ExceedsUpperBound, SUR.createNoteTag(C));
+  return;
 }
+
 Messages Msgs = getExceedsMsgs(C.getASTContext(), Reg, ByteOffset,
*KnownSize, Location);
-reportOOB(C, ExceedsUpperBound, OOB_Exceeds, ByteOffset, Msgs);
+reportOOB(C, ExceedsUpperBound, Msgs, ByteOffset, KnownSize);
 return;
   }
+  // ...and it can be valid as well...
   if (isTainted(State, ByteOffset)) {
-// Both cases are possible, but the offset is tainted, so report.
-std::string RegName = getRegionName(Reg);
+// ...but it's tainted, so report an error.
 
-// Diagnostic detail: "tainted offset" is always correct, but the
-// common case is that 'idx' is tainted in 'arr[idx]' and then it's
+// Diagnostic detail: saying "tainted offset" is always correct, but
+// the common case is that 'idx' is tainted in 'arr[idx]' and then it's
 // nicer to say "tainted index".
 const char *OffsetName = "offset";
 if (const auto *ASE = dyn_cast(E))
   if (isTainted(State, ASE->getIdx(), C.getLocationContext()))
 OffsetName = "index";
 
 Messages Msgs = getTaintMsgs(Reg, OffsetName);
-reportOOB(C, ExceedsUpperBound, OOB_Taint, ByteOffset, Msgs);
+reportOOB(C, ExceedsUpperBound, Msgs, ByteOffset, KnownSize,
+  /*IsTaintBug=*/true);
 return;
   }
+  // ...and it isn't tainted, so the checker will (optimistically) assume
+  // that the offset is in bounds and mention this in the note tag.
+  SUR.recordUpperBoundAssumption(*KnownSize);
 }
 
+// Actually update the state. The "if" only fails in the extremely unlikely
+// case when compareValueToThreshold returns {nullptr, nullptr} becasue
+// evalBinOpNN fails to evaluate the less-than operator.
 if (WithinUpperBound)
   State = WithinUpperBound;
   }
 
-  C.addTransition(State);
+  // Add a transition, reporting the state updates that we accumulated.
+  C.addTransition(State, SUR.createNoteTag(C));
+}
+
+void ArrayBoundCheckerV2::markPartsInteresting(PathSensitiveBugReport &BR,
+   ProgramStateRef ErrorState,
+   NonLoc Val, bool MarkTaint) {
+  if (SymbolRef Sym = Val.getAsSymbol()) {
+// If the offset is a symbolic value, iterate over its "parts" with
+// `SymExpr::symbols()` and mark each of them as interesting.
+// For example, if the offset is `x*4 + y` then we put interestingness onto
+// the SymSymExpr `x*4 + y`, the SymIntExpr `x*4` and the two data symbols
+// `x` and `y`.
+for (SymbolRef PartSym : Sym->symbols())
+  BR.markInteresting(PartSym);
+  }
+
+  if (MarkTaint) {
+// If the issue that we're reporting depends on the taintedness of the
+// offset, then put interestingness onto symbols that could be the origin
+// of the taint.
+for (SymbolRef Sym : getTaintedSymbols(ErrorState, Val))
+  BR.markInteresting(Sym);
+  }

steakhal wrote:

This part seems redundant to me.
In the previous loo

[clang-tools-extra] [llvm] [clang] [analyzer] Support interestingness in ArrayBoundV2 (PR #78315)

2024-02-05 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -381,66 +574,105 @@ void ArrayBoundCheckerV2::performCheck(const Expr *E, 
CheckerContext &C) const {
 compareValueToThreshold(State, ByteOffset, *KnownSize, SVB);
 
 if (ExceedsUpperBound) {
+  // The offset may be invalid (>= Size)...
   if (!WithinUpperBound) {
-// We know that the index definitely exceeds the upper bound.
-if (isa(E) && isInAddressOf(E, C.getASTContext())) 
{
-  // ...but this is within an addressof expression, so we need to check
-  // for the exceptional case that `&array[size]` is valid.
-  auto [EqualsToThreshold, NotEqualToThreshold] =
-  compareValueToThreshold(ExceedsUpperBound, ByteOffset, 
*KnownSize,
-  SVB, /*CheckEquality=*/true);
-  if (EqualsToThreshold && !NotEqualToThreshold) {
-// We are definitely in the exceptional case, so return early
-// instead of reporting a bug.
-C.addTransition(EqualsToThreshold);
-return;
-  }
+// ...and it cannot be within bounds, so report an error, unless we can
+// definitely determine that this is an idiomatic `&array[size]`
+// expression that calculates the past-the-end pointer.
+if (isIdiomaticPastTheEndPtr(E, ExceedsUpperBound, ByteOffset,
+ *KnownSize, C)) {
+  C.addTransition(ExceedsUpperBound, SUR.createNoteTag(C));
+  return;
 }
+
 Messages Msgs = getExceedsMsgs(C.getASTContext(), Reg, ByteOffset,
*KnownSize, Location);
-reportOOB(C, ExceedsUpperBound, OOB_Exceeds, ByteOffset, Msgs);
+reportOOB(C, ExceedsUpperBound, Msgs, ByteOffset, KnownSize);
 return;
   }
+  // ...and it can be valid as well...
   if (isTainted(State, ByteOffset)) {
-// Both cases are possible, but the offset is tainted, so report.
-std::string RegName = getRegionName(Reg);
+// ...but it's tainted, so report an error.
 
-// Diagnostic detail: "tainted offset" is always correct, but the
-// common case is that 'idx' is tainted in 'arr[idx]' and then it's
+// Diagnostic detail: saying "tainted offset" is always correct, but
+// the common case is that 'idx' is tainted in 'arr[idx]' and then it's
 // nicer to say "tainted index".
 const char *OffsetName = "offset";
 if (const auto *ASE = dyn_cast(E))
   if (isTainted(State, ASE->getIdx(), C.getLocationContext()))
 OffsetName = "index";
 
 Messages Msgs = getTaintMsgs(Reg, OffsetName);
-reportOOB(C, ExceedsUpperBound, OOB_Taint, ByteOffset, Msgs);
+reportOOB(C, ExceedsUpperBound, Msgs, ByteOffset, KnownSize,
+  /*IsTaintBug=*/true);
 return;
   }
+  // ...and it isn't tainted, so the checker will (optimistically) assume
+  // that the offset is in bounds and mention this in the note tag.
+  SUR.recordUpperBoundAssumption(*KnownSize);
 }
 
+// Actually update the state. The "if" only fails in the extremely unlikely
+// case when compareValueToThreshold returns {nullptr, nullptr} becasue
+// evalBinOpNN fails to evaluate the less-than operator.
 if (WithinUpperBound)
   State = WithinUpperBound;
   }
 
-  C.addTransition(State);
+  // Add a transition, reporting the state updates that we accumulated.
+  C.addTransition(State, SUR.createNoteTag(C));
+}
+
+void ArrayBoundCheckerV2::markPartsInteresting(PathSensitiveBugReport &BR,
+   ProgramStateRef ErrorState,
+   NonLoc Val, bool MarkTaint) {
+  if (SymbolRef Sym = Val.getAsSymbol()) {
+// If the offset is a symbolic value, iterate over its "parts" with
+// `SymExpr::symbols()` and mark each of them as interesting.
+// For example, if the offset is `x*4 + y` then we put interestingness onto
+// the SymSymExpr `x*4 + y`, the SymIntExpr `x*4` and the two data symbols
+// `x` and `y`.
+for (SymbolRef PartSym : Sym->symbols())
+  BR.markInteresting(PartSym);
+  }
+
+  if (MarkTaint) {
+// If the issue that we're reporting depends on the taintedness of the
+// offset, then put interestingness onto symbols that could be the origin
+// of the taint.
+for (SymbolRef Sym : getTaintedSymbols(ErrorState, Val))
+  BR.markInteresting(Sym);
+  }
 }
 
 void ArrayBoundCheckerV2::reportOOB(CheckerContext &C,
-

[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-05 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80656

>From 48211eb7778db8fb8af144d59adb2e0941957c4c Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 5 Feb 2024 18:01:34 +0800
Subject: [PATCH 1/2] GH78524

---
 clang/docs/ReleaseNotes.rst   |  4 +++
 clang/lib/Parse/ParseExprCXX.cpp  |  6 -
 .../Parser/cxx-concepts-requires-clause.cpp   | 27 +++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9d..42348512326953 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -193,6 +193,10 @@ Bug Fixes to C++ Support
 - Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
   function calls while substituting into constraints.
   (`#58548 `_)
+- Fixed an issue where template parameters of the nested abbreviated generic 
lambda within
+  a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
+  in turn, results in the wrong template argument substitution during the 
constraint checking.
+  (`#78524 `_) 
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..5c374d2eb452dc 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  // We increase the template depth before recursing into a 
requires-clause.
+  // The abbreviated generic lambdas thereof could have different template
+  // depths, avoiding substituting into wrong template parameters during 
the
+  // satisfaction check.
+  ++CurTemplateDepthTracker;
   ExprResult RequiresClause;
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
@@ -1396,7 +1401,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 
   Actions.ActOnLambdaExplicitTemplateParameterList(
   Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
-  ++CurTemplateDepthTracker;
 }
   }
 
diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp 
b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 1ec1eefa128653..f268092728fdfe 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // 
expected-error {{expected bo
 #if __cplusplus <= 202002L
 // expected-warning@-2{{lambda without a parameter clause is a C++23 
extension}}
 #endif
+
+namespace GH78524 {
+
+template  T Foo;
+
+template  auto C(Foo);
+
+template  struct D {
+  decltype(T()(C)) Type;
+};
+
+template  D G(T, U) { return {}; }
+
+struct E {};
+
+void F() {
+  G([]
+// ~~ T: 0,0
+  requires requires { [](auto...) {}; }(T)
+//    auto: 1,0
+{ return T(); },
+E{});
+}
+
+int a = [] requires requires { [](auto){}; } { return 0; }();
+
+} // namespace GH78524

>From c550f3a5f519f11634e106cb40a3c53fa22b345e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 5 Feb 2024 21:00:40 +0800
Subject: [PATCH 2/2] Remove a trailing whitespace

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42348512326953..1c427618ce44bd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -196,7 +196,7 @@ Bug Fixes to C++ Support
 - Fixed an issue where template parameters of the nested abbreviated generic 
lambda within
   a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
   in turn, results in the wrong template argument substitution during the 
constraint checking.
-  (`#78524 `_) 
+  (`#78524 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.

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


[flang] [llvm] [libc] [clang-tools-extra] [libcxx] [clang] [lldb] [lld] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 84ea236af9f36d409d2c45c66f8a8b6eb027935d 
2f727b08b894bca7c0c8aec2fdaffe536f8348d6 -- 
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp 
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index f5495aa756..059df7879d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1028,8 +1028,7 @@ void AMDGPUAsmPrinter::EmitProgramInfoSI(const 
MachineFunction &MF,
 // Helper function to add common PAL Metadata 3.0+
 static void EmitPALMetadataCommon(AMDGPUPALMetadata *MD,
   const SIProgramInfo &CurrentProgramInfo,
-  CallingConv::ID CC,
-  const GCNSubtarget &ST) {
+  CallingConv::ID CC, const GCNSubtarget &ST) {
   if (ST.hasIEEEMode())
 MD->setHwStage(CC, ".ieee_mode", (bool)CurrentProgramInfo.IEEEMode);
 

``




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


[compiler-rt] [libcxx] [flang] [openmp] [llvm] [clang-tools-extra] [clang] [lldb] [lld] [libc] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-02-05 Thread Matt Arsenault via cfe-commits


@@ -862,14 +862,18 @@ static void instrumentOneFunc(
   auto Name = FuncInfo.FuncNameVar;
   auto CFGHash = ConstantInt::get(Type::getInt64Ty(M->getContext()),
   FuncInfo.FunctionHash);
+  // Make sure that pointer to global is passed in with zero addrspace
+  // This is relevant during GPU profiling
+  auto *NormalizedPtr = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+  Name, llvm::PointerType::getUnqual(M->getContext()));

arsenm wrote:

Avoid getUnqual, use an explicit 0 addrspace.

Also there should be no reason to emit pointer bitcast, simplify to just create 
addrspacecast 

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


[clang-tools-extra] [clang] [lld] [flang] [libc] [libcxx] [llvm] [lldb] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-05 Thread David Stuttard via cfe-commits

https://github.com/dstutt updated 
https://github.com/llvm/llvm-project/pull/67104

>From 259138920126f09149b488fc54e8d2a7da969ca4 Mon Sep 17 00:00:00 2001
From: David Stuttard 
Date: Thu, 24 Aug 2023 16:45:50 +0100
Subject: [PATCH 1/7] [AMDGPU] Add pal metadata 3.0 support to callable pal
 funcs

---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |  28 +-
 .../AMDGPU/pal-metadata-3.0-callable.ll   | 290 ++
 2 files changed, 314 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index b2360ce30fd6e..22ecd3656d00a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1098,10 +1098,30 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   StringRef FnName = MF.getFunction().getName();
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+MD->setHwStage(CallingConv::AMDGPU_CS, ".ieee_mode",
+   (bool)CurrentProgramInfo.IEEEMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".wgp_mode",
+   (bool)CurrentProgramInfo.WgpMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".mem_ordered",
+   (bool)CurrentProgramInfo.MemOrdered);
+
+MD->setHwStage(CallingConv::AMDGPU_CS, ".trap_present",
+   (bool)CurrentProgramInfo.TrapHandlerEnable);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".excp_en",
+   CurrentProgramInfo.EXCPEnable);
+
+const unsigned LdsDwGranularity = 128;
+MD->setHwStage(CallingConv::AMDGPU_CS, ".lds_size",
+   (unsigned)(CurrentProgramInfo.LdsSize * LdsDwGranularity *
+  sizeof(uint32_t)));
+  }
 
   // Set optional info
   MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
diff --git a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll 
b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
new file mode 100644
index 0..d4a5f61aced61
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
@@ -0,0 +1,290 @@
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 -verify-machineinstrs < %s | 
FileCheck %s
+
+; CHECK:   .amdgpu_pal_metadata
+; CHECK-NEXT: ---
+; CHECK-NEXT: amdpal.pipelines:
+; CHECK-NEXT:  - .api:Vulkan
+; CHECK-NEXT:.compute_registers:
+; CHECK-NEXT:  .tg_size_en: true
+; CHECK-NEXT:  .tgid_x_en:  false
+; CHECK-NEXT:  .tgid_y_en:  false
+; CHECK-NEXT:  .tgid_z_en:  false
+; CHECK-NEXT:  .tidig_comp_cnt: 0x1
+; CHECK-NEXT:.hardware_stages:
+; CHECK-NEXT:  .cs:
+; CHECK-NEXT:.checksum_value: 0x9444d7d0
+; CHECK-NEXT:.debug_mode: 0
+; CHECK-NEXT:.excp_en:0
+; CHECK-NEXT:.float_mode: 0xc0
+; CHECK-NEXT:.ieee_mode:  true
+; CHECK-NEXT:.image_op:   false
+; CHECK-NEXT:.lds_size:   0x200
+; CHECK-NEXT:.mem_ordered:true
+; CHECK-NEXT:.sgpr_limit: 0x6a
+; CHECK-NEXT:.threadgroup_dimensions:
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:  - 0x400
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:.trap_present:   false
+; CHECK-NEXT:.user_data_reg_map:
+; CHECK-NEXT:  - 0x1000
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT

[clang] [llvm] [openmp] [mlir] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Sergio Afonso via cfe-commits


@@ -6872,35 +6883,6 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef 
HostFilePath) {
   loadOffloadInfoMetadata(*M.get());
 }
 
-Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) {

skatrak wrote:

Flang already picks up your changes to `createOffloadEntriesAndInfoMetadata()` 
and it appears to be putting the corresponding flags into a structure, though 
I'm not sure it's the right one.

I ran `flang-new -fc1 -emit-llvm -fopenmp flang/test/Lower/OpenMP/requires.f90 
-o -` for a simple test with a single target region and I'm seeing two 
offloading entries being produced, which I'm not sure whether it's expected 
behavior. It looks like only one of them has the requires flags and the other 
one is the one that's properly linked with the kernel.

```llvmir
@.omp_offloading.entry_name = internal unnamed_addr constant [43 x i8] 
c"__omp_offloading_10307_d2a215c__QQmain_l12\00"
@.omp_offloading.entry.__omp_offloading_10307_d2a215c__QQmain_l12 = weak 
constant %struct.__tgt_offload_entry { ptr 
@.__omp_offloading_10307_d2a215c__QQmain_l12.region_id, ptr 
@.omp_offloading.entry_name, i64 0, i32 0, i32 0 }, section 
"omp_offloading_entries", align 1

@.omp_offloading.entry_name.1 = internal unnamed_addr constant [1 x i8] 
zeroinitializer
@.omp_offloading.entry. = weak constant %struct.__tgt_offload_entry { ptr null, 
ptr @.omp_offloading.entry_name.1, i64 0, i32 22, i32 10 }, section 
"omp_offloading_entries", align 1

...
%14 = call i32 @__tgt_target_kernel(ptr @1, i64 -1, i32 -1, i32 0, ptr 
@.__omp_offloading_10307_d2a215c__QQmain_l12.region_id, ptr %kernel_args)
```

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


[clang] [llvm] [clang-tools-extra] [AArch64] Implement -fno-plt for SelectionDAG/GlobalISel (PR #78890)

2024-02-05 Thread Matt Arsenault via cfe-commits


@@ -1293,8 +1293,19 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder 
&MIRBuilder,
!Subtarget.noBTIAtReturnTwice() &&
MF.getInfo()->branchTargetEnforcement())
 Opc = AArch64::BLR_BTI;
-  else
+  else {
+// For an intrinsic call (e.g. memset), use GOT if "RtLibUseGOT" (-fno-plt)
+// is set.
+if (Info.Callee.isSymbol() && F.getParent()->getRtLibUseGOT()) {
+  auto Reg =
+  MRI.createGenericVirtualRegister(getLLTForType(*F.getType(), DL));
+  auto MIB = MIRBuilder.buildInstr(TargetOpcode::G_GLOBAL_VALUE);
+  DstOp(Reg).addDefToMIB(MRI, MIB);

arsenm wrote:

Missing overload then, should try to avoid raw buildInstr calls when possible 

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


[clang] [llvm] [openmp] [mlir] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Joseph Huber via cfe-commits


@@ -6872,35 +6883,6 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef 
HostFilePath) {
   loadOffloadInfoMetadata(*M.get());
 }
 
-Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) {

jhuber6 wrote:

That looks a little weird, the `i32` value is `22` which I don't know what that 
corresponds to with the flags. The value is then `10` which would be two 
requires flags merged together maybe? `22` is 16, 4, and 2, so I don't know why 
all those flags would be set at the same time.

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


[llvm] [clang] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-02-05 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts created 
https://github.com/llvm/llvm-project/pull/80680

HLSL has wave operations and other kind of function which required the control 
flow to either be converged, or respect certain constraints as where and how to 
re-converge.

At the HLSL level, the convergence are mostly obvious: the control flow is 
expected to re-converge at the end of a scope.
Once translated to IR, HLSL scopes disapear. This means we need a way to 
communicate convergence restrictions down to the backend.

For this, the SPIR-V backend uses convergence intrinsics. So this commit adds 
some code to generate convergence intrinsics when required.

This commit is not to be submitted as-is (lacks testing), but should serve as a 
basis for an upcoming RFC.

From 8d653d1af6f624f341e88997682fc271195d8a45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Fri, 2 Feb 2024 16:38:46 +0100
Subject: [PATCH] [clang][HLSL][SPRI-V] Add convergence intrinsics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

HLSL has wave operations and other kind of function which required the
control flow to either be converged, or respect certain constraints as
where and how to re-converge.

At the HLSL level, the convergence are mostly obvious: the control flow
is expected to re-converge at the end of a scope.
Once translated to IR, HLSL scopes disapear. This means we need a way to
communicate convergence restrictions down to the backend.

For this, the SPIR-V backend uses convergence intrinsics. So this commit
adds some code to generate convergence intrinsics when required.

This commit is not to be submitted as-is (lacks testing), but
should serve as a basis for an upcoming RFC.

Signed-off-by: Nathan Gauër 
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 102 +++
 clang/lib/CodeGen/CGCall.cpp |   4 ++
 clang/lib/CodeGen/CGLoopInfo.h   |   8 ++-
 clang/lib/CodeGen/CodeGenFunction.h  |  19 +
 llvm/include/llvm/IR/IntrinsicInst.h |  13 
 5 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f17e4a83305bf..0de350dc65485 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1129,8 +1129,97 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullopt otherwise.
+std::optional getConvergenceToken(llvm::BasicBlock *BB) 
{
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return std::nullopt;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,
+   llvm::Value *ParentToken) {
+  llvm::Value *bundleArgs[] = {ParentToken};
+  llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
+  auto Output = llvm::CallBase::addOperandBundle(
+  Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
+  Input->replaceAllUsesWith(Output);
+  Input->eraseFromParent();
+  return Output;
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB,
+ llvm::Value *ParentToken) {
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto CB = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_loop, {}, {});
+  Builder.restoreIP(IP);
+
+  auto I = AddConvergenceControlAttr(CB, ParentToken);
+  // Controlled convergence is incompatible with uncontrolled convergence.
+  // Removing any old attributes.
+  I->setNotConvergent();
+
+  assert(isa(I));
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) {
+  auto *BB = &F->getEntryBlock();
+  auto token = getConvergenceToken(BB);
+  if (token.has_value())
+return token.value();
+
+  // Adding a convergence token requires the function to be marked as
+  // convergent.
+  F->setConvergent();
+
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto I = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_entry, {}, {});
+  assert(isa(I));
+  Builder.restoreIP(IP);
+
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceLoopToken(const LoopInfo *LI) {
+  assert(LI != nullptr);
+
+  auto token = getConvergenceToken(LI->getHeader());
+  if (token.has_value())
+return *token;
+
+  llvm::IntrinsicInst *PII =
+  LI->getParent()
+  ? EmitConvergenceLoop(LI->getHeader(),
+getOrEmitConvergenceLoopToken(LI->getParent()))
+  : getOrEmitConvergenceEntryToken(LI->getHeader()->getParent());
+
+  return EmitConvergenceLoop(LI->getHeader(), PII);
+}
+
+llvm::

[llvm] [openmp] [clang] [mlir] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Sergio Afonso via cfe-commits


@@ -6872,35 +6883,6 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef 
HostFilePath) {
   loadOffloadInfoMetadata(*M.get());
 }
 
-Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) {

skatrak wrote:

The test itself has "requires unified_shared_memory reverse_offload" (it 
originally just checks that the flags are passed to MLIR), so that's where the 
"10" is coming from. The "22" I don't know what it's supposed represent.

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


[llvm] [openmp] [clang] [mlir] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-05 Thread Joseph Huber via cfe-commits


@@ -6872,35 +6883,6 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(StringRef 
HostFilePath) {
   loadOffloadInfoMetadata(*M.get());
 }
 
-Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) {

jhuber6 wrote:

I encoded the fact that this is a "requires" entry into the global with `16`. 
Realistically it shouldn't make a difference in the runtime since as long as 
`16` is set and the address is null it will get counted as a requires entry. 
It's just a little weird that it wouldn't *just* be 16. I'll double check. 
Changing these entries is also on the list.

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


[clang] 992d852 - [flang]Add support for -moutline-atomics and -mno-outline-atomics (#78755)

2024-02-05 Thread via cfe-commits

Author: Mats Petersson
Date: 2024-02-05T13:54:12Z
New Revision: 992d8527585817af685bba0d82ed4e808bc613bb

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

LOG: [flang]Add support for -moutline-atomics and -mno-outline-atomics (#78755)

This adds the support to add the target-feature to outline atomic operations 
(calling the
runtime library instead).

Added: 
flang/test/Driver/aarch64-outline-atomics.f90
flang/test/Integration/aarch64-outline-atomics.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fb5f50ef452c2..4b232b8aab722 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4994,10 +4994,10 @@ def mno_fmv : Flag<["-"], "mno-fmv">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Disable function multiversioning">;
 def moutline_atomics : Flag<["-"], "moutline-atomics">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
   HelpText<"Generate local calls to out-of-line atomic operations">;
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, 
Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 46595852b1d80..13bf242115437 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7673,26 +7673,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   addMachineOutlinerArgs(D, Args, CmdArgs, Triple, /*IsLTO=*/false);
 
-  if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
-   options::OPT_mno_outline_atomics)) {
-// Option -moutline-atomics supported for AArch64 target only.
-if (!Triple.isAArch64()) {
-  D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
-  << Triple.getArchName() << A->getOption().getName();
-} else {
-  if (A->getOption().matches(options::OPT_moutline_atomics)) {
-CmdArgs.push_back("-target-feature");
-CmdArgs.push_back("+outline-atomics");
-  } else {
-CmdArgs.push_back("-target-feature");
-CmdArgs.push_back("-outline-atomics");
-  }
-}
-  } else if (Triple.isAArch64() &&
- getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
-CmdArgs.push_back("-target-feature");
-CmdArgs.push_back("+outline-atomics");
-  }
+  addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
 
   if (Triple.isAArch64() &&
   (Args.hasArg(options::OPT_mno_fmv) ||

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 5d570c90e5340..0fd7b8424eb4b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2796,3 +2796,28 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, 
Compilation &C,
 }
   }
 }
+
+void tools::addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
+  const llvm::opt::ArgList &Args,
+  llvm::opt::ArgStringList &CmdArgs,
+  const llvm::Triple &Triple) {
+  if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
+   options::OPT_mno_outline_atomics)) {
+// Option -moutline-atomics supported for AArch64 target only.
+if (!Triple.isAArch64()) {
+  D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
+  << Triple.getArchName() << A->getOption().getName();
+} else {
+  if (A->getOption().matches(options::OPT_moutline_atomics)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  } else {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-outline-atomics");
+  }
+}
+  } else if (Triple.isAArch64() && TC.IsAArch64OutlineAtomicsDefault(Args)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  }
+}

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 807867f13a5c3..2db

[clang] [flang] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)

2024-02-05 Thread Mats Petersson via cfe-commits

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


[clang] [Clang][AArch64] Fix some target guards and remove +sve from tests. (PR #80681)

2024-02-05 Thread Sander de Smalen via cfe-commits

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


[clang] [Clang][AArch64] Fix some target guards and remove +sve from tests. (PR #80681)

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sander de Smalen (sdesmalen-arm)


Changes

The TargetGuard fields for 'svldr[_vnum]_za' and 'svstr[_vnum]_za' were 
incorrectly set to `+sve` instead of `+sme`. This means that compiling code 
that uses these intrinsics requires compiling for both `+sve` as well as `+sme`.

This PR also fixes the target guards for the `svadd` and `svsub` builtins that 
are enabled under `+sme2,+sme-i16i64` and `+sme2,+sme-f64f64`, as it initially 
did the following:
```
  let TargetGuard = "+sme2" in {
let TargetGuard = "+sme-i16i64" in {
  // Builtins defined here will be predicated only by
  // '+sme-i16i64', and not '+sme2,+sme-i16i64'.
}
  }
```
This PR also removes `-target-feature +sve` from all the SME tests, to ensure 
that the SME features are sufficient to build the tests.

---

Patch is 113.68 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/80681.diff


49 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+16-12) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1_vnum.c 
(+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za32.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za32.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_read.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_st1.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_st1_vnum.c 
(+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_write.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_bmop.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
(+10-10) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvtn.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_frint.c 
(+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c (+3-3) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c (+3-3) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c (+3-3) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c (+3-3) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c (+3-3) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_maxnm.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_minnm.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mop.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_read.c (+3-3) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_reinterpret_svcount_svbool.c
 (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sub.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_unpkx2.c 
(+6-6) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_unpkx4.c 
(+6-6) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_add.c 
(+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_qrshr.c (+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_rshl.c 
(+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_selx2.c (+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_selx4.c (+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_uzpx2.c (+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_uzpx4.c (+5-5) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_zipx2.c (+5-5) 
- (modified) 
clang/test/CodeGen/aa

[clang] [clang][Interp] Support zero init for complex types (PR #79728)

2024-02-05 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


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

LGTM!

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


[clang] [clang][Interp] Fix MemberExpr initializing an existing value (PR #79973)

2024-02-05 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [llvm] [clang-tools-extra] [concepts] Extract function template pack arguments from the current instantiation if possible (PR #80594)

2024-02-05 Thread Erich Keane via cfe-commits

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


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


[clang] [Clang] Fix crash when recovering from an invalid pack indexing type. (PR #80652)

2024-02-05 Thread Erich Keane via cfe-commits

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

Seems reasonable.

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


[clang-tools-extra] [flang] [clang] [libcxx] [llvm] [mlir] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -7486,7 +7486,8 @@ static void createAndCollectMergePhiForReduction(
   auto *PhiR = cast(RedResult->getOperand(0));
   const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
 
-  TrackingVH ReductionStartValue = RdxDesc.getRecurrenceStartValue();
+  TrackingVH ReductionStartValue =

fhahn wrote:

Not needed any longer, removed, thanks!

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


[libcxx] [llvm] [flang] [mlir] [clang-tools-extra] [clang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -9110,6 +9111,41 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   continue;
 
 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
+// Adjust AnyOf reductions; replace the reduction phi for the selected 
value
+// with a boolean reduction phi node to check if the condition is true in
+// any iteration. The final value is selected by the final
+// ComputeReductionResult.
+if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
+RdxDesc.getRecurrenceKind())) {
+  auto *Select = cast(*find_if(PhiR->users(), [](VPUser *U) {
+return isa(U) ||
+   (isa(U) &&
+cast(U)->getUnderlyingInstr()->getOpcode() 
==
+Instruction::Select);
+  }));
+  VPValue *Cmp = Select->getOperand(0);
+  // If the compare is checking the reduction PHI node, adjust it to check
+  // the start value.
+  if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
+for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
+  if (CmpR->getOperand(I) == PhiR)
+CmpR->setOperand(I, PhiR->getStartValue());
+  }
+  VPBuilder::InsertPointGuard Guard(Builder);
+  Builder.setInsertPoint(Select);
+
+  // If the true value of the select is the reduction phi, the new value is
+  // selected if the negated condition is true in any iteration.
+  if (Select->getOperand(1) == PhiR)
+Cmp = Builder.createNot(Cmp);

fhahn wrote:

Yes, this could be handled like that, but I think then we would need to support 
both patterns here and also in codegen, so negating seems simpler (and the 
negation should be removable by instcombine). Left as is for now, but happy to 
adjust if needed. But then it should probably be modeled as AllOf directly in 
the reduction descriptor.

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


[libcxx] [flang] [mlir] [clang] [llvm] [clang-tools-extra] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -453,16 +453,17 @@ Value 
*VPInstruction::generateInstruction(VPTransformState &State,
 else if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) {
   TrackingVH ReductionStartValue =
   RdxDesc.getRecurrenceStartValue();
-  ReducedPartRdx = createAnyOfOp(Builder, ReductionStartValue, RK,
- ReducedPartRdx, RdxPart);
+  ReducedPartRdx = Builder.CreateOr(ReducedPartRdx, RdxPart);

fhahn wrote:

Adjusted, thanks!

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


[clang] [clang-tools-extra] [mlir] [flang] [libcxx] [llvm] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -452,16 +452,17 @@ Value 
*VPInstruction::generateInstruction(VPTransformState &State,
 else if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) {
   TrackingVH ReductionStartValue =
   RdxDesc.getRecurrenceStartValue();

fhahn wrote:

Folded into the CreateBinaryOp above, thanks!

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


[clang] [clang-tools-extra] [llvm] [mlir] [libcxx] [flang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -9110,6 +9111,41 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   continue;
 
 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
+// Adjust AnyOf reductions; replace the reduction phi for the selected 
value
+// with a boolean reduction phi node to check if the condition is true in
+// any iteration. The final value is selected by the final
+// ComputeReductionResult.
+if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
+RdxDesc.getRecurrenceKind())) {
+  auto *Select = cast(*find_if(PhiR->users(), [](VPUser *U) {
+return isa(U) ||
+   (isa(U) &&
+cast(U)->getUnderlyingInstr()->getOpcode() 
==
+Instruction::Select);
+  }));
+  VPValue *Cmp = Select->getOperand(0);
+  // If the compare is checking the reduction PHI node, adjust it to check
+  // the start value.

fhahn wrote:

At the moment, AnyOf reduction are also formed for code like 


```
define i32 @select_i32_from_icmp_same_inputs(i32 %a, i32 %b, i64 %n) {  
 
entry:
  br label %for.body

for.body:  ; preds = %entry, %for.body
  %0 = phi i64 [ 0, %entry ], [ %4, %for.body ]
  %1 = phi i32 [ %a, %entry ], [ %3, %for.body ]
  %2 = icmp eq i32 %1, 3
  %3 = select i1 %2, i32 %1, i32 %b
  %4 = add nuw nsw i64 %0, 1
  %5 = icmp eq i64 %4, %n
  br i1 %5, label %exit, label %for.body

exit: ; preds = %for.body
  ret i32 %3
}
```

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


[clang-tools-extra] [libcxx] [mlir] [clang] [llvm] [flang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -1079,16 +1070,13 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase 
&Builder, Value *Src,
 NewVal = SI->getTrueValue();
   }
 
-  // Create a splat vector with the new value and compare this to the vector
-  // we want to reduce.
-  ElementCount EC = cast(Src->getType())->getElementCount();
-  Value *Right = Builder.CreateVectorSplat(EC, InitVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Src, Right, "rdx.select.cmp");
-
   // If any predicate is true it means that we want to select the new value.
-  Cmp = Builder.CreateOrReduce(Cmp);
-  return Builder.CreateSelect(Cmp, NewVal, InitVal, "rdx.select");
+  Value *AnyOf =
+  Src->getType()->isVectorTy() ? Builder.CreateOrReduce(Src) : Src;
+  // The compares in the loop may yield poison, which propagates through the
+  // bitwise ORs. Freeze it here before the condition is used.
+  AnyOf = Builder.CreateFreeze(AnyOf);

fhahn wrote:

> Similar to a plain "result |= value[i]" OR reduction,

Freeze won't be needed in that case; if there's already a binary OR in the 
input, poison from the compare gets already propagated. It is only needed when 
converting from the `select` form (which doesn't propagate poison from the 
condition to its result)

Yes, but this will need a bit of additional refactoring, in particular how 
`createAndCollectMergePhiForReduction` looks up the reduction result value and 
when `ComputeReductionResult` VPInstructions are created.

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


[clang-tools-extra] [libcxx] [mlir] [llvm] [clang] [flang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -9110,6 +9111,41 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   continue;
 
 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
+// Adjust AnyOf reductions; replace the reduction phi for the selected 
value
+// with a boolean reduction phi node to check if the condition is true in
+// any iteration. The final value is selected by the final
+// ComputeReductionResult.
+if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
+RdxDesc.getRecurrenceKind())) {
+  auto *Select = cast(*find_if(PhiR->users(), [](VPUser *U) {
+return isa(U) ||
+   (isa(U) &&
+cast(U)->getUnderlyingInstr()->getOpcode() 
==
+Instruction::Select);
+  }));

fhahn wrote:

`cast` should already assert to check for non-null.

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


[clang] [libcxx] [flang] [mlir] [clang-tools-extra] [llvm] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -9142,7 +9178,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
 // then extend the loop exit value to enable InstCombine to evaluate the
 // entire expression in the smaller type.
 Type *PhiTy = PhiR->getStartValue()->getLiveInIRValue()->getType();
-if (MinVF.isVector() && PhiTy != RdxDesc.getRecurrenceType()) {
+if (MinVF.isVector() && PhiTy != RdxDesc.getRecurrenceType() &&
+!RecurrenceDescriptor::isAnyOfRecurrenceKind(
+RdxDesc.getRecurrenceKind())) {

fhahn wrote:

We only reach this path now because we adjust PhiR's start value to a bool. It 
requires more than plain truncates as below, so I think it's probably worth to 
keep it separate. I *think* it also needs handling before introducing selects 
for tail-folding; otherwise those selects would also need updating.

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


[llvm] [mlir] [clang-tools-extra] [clang] [libcxx] [flang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -9110,6 +9111,41 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
   continue;
 
 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
+// Adjust AnyOf reductions; replace the reduction phi for the selected 
value

fhahn wrote:

Agreed, probably best as followup?


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


[llvm] [mlir] [clang] [libcxx] [clang-tools-extra] [flang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-02-05 Thread Florian Hahn via cfe-commits


@@ -453,16 +453,17 @@ Value 
*VPInstruction::generateInstruction(VPTransformState &State,
 else if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) {
   TrackingVH ReductionStartValue =
   RdxDesc.getRecurrenceStartValue();
-  ReducedPartRdx = createAnyOfOp(Builder, ReductionStartValue, RK,
- ReducedPartRdx, RdxPart);
+  ReducedPartRdx = Builder.CreateOr(ReducedPartRdx, RdxPart);
 } else
   ReducedPartRdx = createMinMaxOp(Builder, RK, ReducedPartRdx, 
RdxPart);
   }
 }
 
 // Create the reduction after the loop. Note that inloop reductions create
 // the target reduction in the loop using a Reduction recipe.
-if (State.VF.isVector() && !PhiR->isInLoop()) {
+if ((State.VF.isVector() ||
+ RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) &&
+!PhiR->isInLoop()) {
   ReducedPartRdx =
   createTargetReduction(Builder, RdxDesc, ReducedPartRdx, OrigPhi);

fhahn wrote:

Yes, but this will need a bit of additional refactoring, in particular how 
createAndCollectMergePhiForReduction looks up the reduction result value and 
when ComputeReductionResult VPInstructions are created.



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


[clang] [docs] [C++20] [Modules] Ideas for transforming to modules (PR #80687)

2024-02-05 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/80687

This patch tries to provide some ideas to transform an existing libraries to 
modules. I feel this is helpful for users who is interested in modules from my 
observation.  While the syntax of modules look easy to understand, the practice 
gets harder if the users want to make compatible work with headers. Especially 
the `std` module can be installed in clang18, I think such document may be 
helpful.

I tried to not be too wordy in this document and I don't want the users to have 
impressions that they have to follow this or this is the best practice. So I 
tried to use the term `idea`.

Although I add some regular reviewers for modules, review opinions from users 
are highly recommended.

I want to land this before the releasing of clang18 (in the early March). We 
can and should improve this continuously.



>From 404713c8a359a3fbbf1bbc9a5e2bece75f74d464 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 5 Feb 2024 22:31:19 +0800
Subject: [PATCH] [docs] [C++20] [Modules] Ideas for transiting to modules

---
 clang/docs/StandardCPlusPlusModules.rst | 338 
 1 file changed, 338 insertions(+)

diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index c322805d8db5b..97170e92b8e09 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -610,6 +610,344 @@ the following style significantly:
 
 The key part of the tip is to reduce the duplications from the text includes.
 
+Ideas for converting to modules
+---
+
+For new libraries, we encourage them to use modules completely from day one if 
possible and.
+This will be pretty helpful to make the whole ecosystems to get ready.
+
+For many existing libraries, it may be a breaking change to refactor themselves
+into modules completely. So that many existing libraries need to provide 
headers and module
+interfaces for a while to not breaking existing users.
+Here we provide some ideas to ease the transition process for existing 
libraries.
+**Note that the this section is only about helping ideas instead of 
requirement from clang**.
+
+Let's start with the case that there is no dependency or no dependent 
libraries providing
+modules for you library.
+
+ABI non-breaking styles
+~~~
+
+export-using style
+^^
+
+.. code-block:: c++
+
+  module;
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+  export module your_library;
+  export namespace your_namespace {
+using decl_1;
+using decl_2;
+...
+using decl_n;
+  }
+
+As the example shows, you need to include all the headers containing 
declarations needs
+to be exported and `using` such declarations in an `export` block. Then, 
basically,
+we're done.
+
+export extern-C++ style
+^^^
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  extern "C++" {
+#include "header_1.h"
+#include "header_2.h"
+...
+#include "header_n.h"
+  }
+
+Then in your headers (from ``header_1.h`` to ``header_n.h``), you need to 
define the macro:
+
+.. code-block:: c++
+
+  #ifdef IN_MODULE_INTERFACE
+  #define EXPORT export
+  #else
+  #define EXPORT
+  #endif
+
+And you should put ``EXPORT`` to the beginning of the declarations you want to 
export.
+
+Also it is suggested to refactor your headers to include thirdparty headers 
conditionally:
+
+.. code-block:: c++
+
+  + #ifndef IN_MODULE_INTERFACE
+  #include "third_party/A/headers.h"
+  + #endif
+
+  #include "header_x.h"
+
+  ...
+
+This may be helpful to get better diagnostic messages if you forgot to update 
your module 
+interface unit file during maintaining.
+
+The secret for the practice is that the declarations in the language linkage 
are considered
+to be attached to the global module. So the ABI of your library in the modular 
version
+wouldn't change.
+
+While this style looks not as convenient as the export-using style, it is 
easier to convert 
+to other styles.
+
+ABI breaking style
+~~
+
+The term ``ABI breaking`` sounds terrifying generally. But you may want it 
here if you want
+to force your users to introduce your library in a consistent way. E.g., they 
either include
+your headers all the way or they import your modules all the way.
+The style prevents the users to include your headers and import your modules 
in the same repo.
+
+The pattern for ABI breaking style is similar with export extern-C++ style.
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  #include "heade

[clang] [docs] [C++20] [Modules] Ideas for transforming to modules (PR #80687)

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

This patch tries to provide some ideas to transform an existing libraries to 
modules. I feel this is helpful for users who is interested in modules from my 
observation.  While the syntax of modules look easy to understand, the practice 
gets harder if the users want to make compatible work with headers. Especially 
the `std` module can be installed in clang18, I think such document may be 
helpful.

I tried to not be too wordy in this document and I don't want the users to have 
impressions that they have to follow this or this is the best practice. So I 
tried to use the term `idea`.

Although I add some regular reviewers for modules, review opinions from users 
are highly recommended.

I want to land this before the releasing of clang18 (in the early March). We 
can and should improve this continuously.



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


1 Files Affected:

- (modified) clang/docs/StandardCPlusPlusModules.rst (+338) 


``diff
diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index c322805d8db5bc..97170e92b8e093 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -610,6 +610,344 @@ the following style significantly:
 
 The key part of the tip is to reduce the duplications from the text includes.
 
+Ideas for converting to modules
+---
+
+For new libraries, we encourage them to use modules completely from day one if 
possible and.
+This will be pretty helpful to make the whole ecosystems to get ready.
+
+For many existing libraries, it may be a breaking change to refactor themselves
+into modules completely. So that many existing libraries need to provide 
headers and module
+interfaces for a while to not breaking existing users.
+Here we provide some ideas to ease the transition process for existing 
libraries.
+**Note that the this section is only about helping ideas instead of 
requirement from clang**.
+
+Let's start with the case that there is no dependency or no dependent 
libraries providing
+modules for you library.
+
+ABI non-breaking styles
+~~~
+
+export-using style
+^^
+
+.. code-block:: c++
+
+  module;
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+  export module your_library;
+  export namespace your_namespace {
+using decl_1;
+using decl_2;
+...
+using decl_n;
+  }
+
+As the example shows, you need to include all the headers containing 
declarations needs
+to be exported and `using` such declarations in an `export` block. Then, 
basically,
+we're done.
+
+export extern-C++ style
+^^^
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  extern "C++" {
+#include "header_1.h"
+#include "header_2.h"
+...
+#include "header_n.h"
+  }
+
+Then in your headers (from ``header_1.h`` to ``header_n.h``), you need to 
define the macro:
+
+.. code-block:: c++
+
+  #ifdef IN_MODULE_INTERFACE
+  #define EXPORT export
+  #else
+  #define EXPORT
+  #endif
+
+And you should put ``EXPORT`` to the beginning of the declarations you want to 
export.
+
+Also it is suggested to refactor your headers to include thirdparty headers 
conditionally:
+
+.. code-block:: c++
+
+  + #ifndef IN_MODULE_INTERFACE
+  #include "third_party/A/headers.h"
+  + #endif
+
+  #include "header_x.h"
+
+  ...
+
+This may be helpful to get better diagnostic messages if you forgot to update 
your module 
+interface unit file during maintaining.
+
+The secret for the practice is that the declarations in the language linkage 
are considered
+to be attached to the global module. So the ABI of your library in the modular 
version
+wouldn't change.
+
+While this style looks not as convenient as the export-using style, it is 
easier to convert 
+to other styles.
+
+ABI breaking style
+~~
+
+The term ``ABI breaking`` sounds terrifying generally. But you may want it 
here if you want
+to force your users to introduce your library in a consistent way. E.g., they 
either include
+your headers all the way or they import your modules all the way.
+The style prevents the users to include your headers and import your modules 
in the same repo.
+
+The pattern for ABI breaking style is similar with export extern-C++ style.
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+
+  #if the number of .cpp files in your project are small
+  module :

[clang] 5249379 - [AMDGPU] Allow w64 ballot to be used on w32 targets (#80183)

2024-02-05 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-02-05T08:42:28-06:00
New Revision: 5249379d742148728f654665e113084c6b93cdf2

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

LOG: [AMDGPU] Allow w64 ballot to be used on w32 targets (#80183)

Summary:
Currently we cannot compile `__builtin_amdgcn_ballot_w64` on non-wave64
targets even though it is valid. This is relevant for making library
code that can handle both without needing to check the wavefront size.
This patch relaxes the semantic check for w64 so it can be used
normally.

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index e9dd8dcd0b60e..5f8001e61a028 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -151,7 +151,7 @@ BUILTIN(__builtin_amdgcn_mqsad_u32_u8, "V4UiWUiUiV4Ui", 
"nc")
 
//===--===//
 
 TARGET_BUILTIN(__builtin_amdgcn_ballot_w32, "ZUib", "nc", "wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_ballot_w64, "WUib", "nc", "wavefrontsize64")
+BUILTIN(__builtin_amdgcn_ballot_w64, "WUib", "nc")
 
 // Deprecated intrinsics in favor of __builtin_amdgn_ballot_{w32|w64}
 BUILTIN(__builtin_amdgcn_uicmp, "WUiUiUiIi", "nc")

diff  --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl
index 99e93acd9a213..1bbd84d09bf94 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl
@@ -1,13 +1,13 @@
 // RUN: %clang_cc1 -triple amdgcn-- -verify -S -o - %s
-// RUN: %clang_cc1 -triple amdgcn-- -target-feature +wavefrontsize32 -verify 
-S -o - %s
-// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -target-feature 
+wavefrontsize32 -verify -S -o - %s
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -target-feature 
-wavefrontsize64 -verify -S -o - %s
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -verify -S -o - %s
 
+// expected-no-diagnostics
+
 typedef unsigned long ulong;
 
 void test_ballot_wave64(global ulong* out, int a, int b) {
-  *out = __builtin_amdgcn_ballot_w64(a == b);  // expected-error 
{{'__builtin_amdgcn_ballot_w64' needs target feature wavefrontsize64}}
+  *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
 __attribute__((target("wavefrontsize64")))



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


[clang] [AMDGPU] Allow w64 ballot to be used on w32 targets (PR #80183)

2024-02-05 Thread Joseph Huber via cfe-commits

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


[clang] [clang][Interp] Do r-to-l conversion immediately when returning (PR #80662)

2024-02-05 Thread Aaron Ballman via cfe-commits


@@ -119,12 +121,26 @@ template  bool 
EvalEmitter::emitRet(const SourceInfo &Info) {
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
-  EvalResult.setPointer(S.Stk.pop());
+
+  const Pointer &Ptr = S.Stk.pop();
+  // Implicitly convert lvalue to rvalue, if requested.
+  if (ConvertResultToRValue) {
+if (std::optional V = Ptr.toRValue(Ctx)) {
+  EvalResult.setValue(*V);
+} else {
+  return false;
+}
+  } else {
+EvalResult.setPointer(Ptr);
+  }
+
   return true;
 }
 template <> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   if (!isActive())
 return true;
+  // Function pointers are always lvalues to us and cannot be converted
+  // to rvalues, so don't do any conversion here.

AaronBallman wrote:

Whhaaat? Why are function pointers always lvalues?

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


[clang] e4f1ef8 - [clang][Interp] Reject bitcasts to atomic types

2024-02-05 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-05T15:45:26+01:00
New Revision: e4f1ef85fd60c08c9ece4982fccf76e8101011b8

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

LOG: [clang][Interp] Reject bitcasts to atomic types

The current interpreter does this, so follow suit to match its
diagnostics.

Added: 
clang/test/AST/Interp/atomic.c

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/PrimType.h
clang/test/Sema/atomic-expr.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3ca4f56903fda0..74a5284ff812cf 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -191,7 +191,14 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_UserDefinedConversion:
+return this->delegate(SubExpr);
+
   case CK_BitCast:
+if (CE->getType()->isAtomicType()) {
+  if (!this->discard(SubExpr))
+return false;
+  return this->emitInvalidCast(CastKind::Reinterpret, CE);
+}
 return this->delegate(SubExpr);
 
   case CK_IntegralToBoolean:

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 7c7e53564c4b49..e41604e125eba6 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2020,8 +2020,11 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) {
 /// Same here, but only for casts.
 inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind) {
   const SourceLocation &Loc = S.Current->getLocation(OpPC);
-  S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
-  << static_cast(Kind) << S.Current->getRange(OpPC);
+
+  // FIXME: Support diagnosing other invalid cast kinds.
+  if (Kind == CastKind::Reinterpret)
+S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
+<< static_cast(Kind) << S.Current->getRange(OpPC);
   return false;
 }
 

diff  --git a/clang/lib/AST/Interp/PrimType.h b/clang/lib/AST/Interp/PrimType.h
index 8c5e87f37be186..d07c2efe8e3c9b 100644
--- a/clang/lib/AST/Interp/PrimType.h
+++ b/clang/lib/AST/Interp/PrimType.h
@@ -48,6 +48,7 @@ enum PrimType : unsigned {
 
 enum class CastKind : uint8_t {
   Reinterpret,
+  Atomic,
 };
 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
  interp::CastKind CK) {
@@ -55,6 +56,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
   case interp::CastKind::Reinterpret:
 OS << "reinterpret_cast";
 break;
+  case interp::CastKind::Atomic:
+OS << "atomic";
+break;
   }
   return OS;
 }

diff  --git a/clang/test/AST/Interp/atomic.c b/clang/test/AST/Interp/atomic.c
new file mode 100644
index 00..8d93b57c1945bc
--- /dev/null
+++ b/clang/test/AST/Interp/atomic.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref %s
+
+/// FIXME: Copied from test/Sema/atomic-expr.c.
+/// this expression seems to be rejected for weird reasons,
+/// but we imitate the current interpreter's behavior.
+_Atomic int ai = 0;
+// FIXME: &ai is an address constant, so this should be accepted as an
+// initializer, but the bit-cast inserted due to the pointer conversion is
+// tripping up the test for whether the initializer is a constant expression.
+// The warning is correct but the error is not.
+_Atomic(int *) aip3 = &ai; // both-warning {{incompatible pointer types 
initializing '_Atomic(int *)' with an expression of type '_Atomic(int) *'}} \
+   // both-error {{initializer element is not a 
compile-time constant}}

diff  --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index 8eefbf92152b81..7e5219dd3f14ab 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -2,6 +2,11 @@
 // RUN: %clang_cc1 %s -std=c2x -verify=expected,access -fsyntax-only
 // RUN: %clang_cc1 %s -std=c2x -pedantic -verify=expected,access -fsyntax-only
 // RUN: %clang_cc1 %s -verify -fsyntax-only -Wno-atomic-access
+// RUN: %clang_cc1 %s -verify=expected,access -fsyntax-only 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 %s -std=c2x -verify=expected,access -fsyntax-only 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 %s -std=c2x -pedantic -verify=expected,access -fsyntax-only 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wno-atomic-access 
-fexperimental-new-constant-interpreter
+
 
 _Atomic(unsigned int) data1;
 int _Atomic data2;



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

[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-02-05 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/80690

Due to improper use of RecursiveASTVisitor.

Fixes #80630

>From a9e1885ecaf290159a540749552eb9d9d759ef27 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 5 Feb 2024 15:42:21 +0100
Subject: [PATCH] [Clang] Fix looking for immediate calls in default arguments.

Due to improper use of RecursiveASTVisitor.

Fixes #80630
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  6 +++---
 .../SemaCXX/cxx2a-consteval-default-params.cpp | 15 +++
 clang/test/SemaCXX/source_location.cpp | 18 ++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3596109bf044f..fc9acd3f20792 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -201,6 +201,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix evaluation of some immediate calls in default arguments.
+  Fixes (`#80630 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d15278bce5a6b..ab212447f7368 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6198,7 +6198,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitStmt(E);
+return RecursiveASTVisitor::VisitCallExpr(E);
   }
 
   // SourceLocExpr are not immediate invocations
@@ -6222,9 +6222,9 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 
   // Blocks don't support default parameters, and, as for lambdas,
   // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return false; }
+  bool VisitBlockDecl(BlockDecl *B) { return true; }
 
-  bool VisitCompoundStmt(CompoundStmt *B) { return false; }
+  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
 
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
diff --git a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp 
b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
index be8f7cc788589..e4b13725b2dac 100644
--- a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -82,3 +82,18 @@ namespace GH62224 {
   C<> Val; // No error since fwd is defined already.
   static_assert(Val.get() == 42);
 }
+
+namespace GH80630 {
+
+consteval const char* ce() { return "Hello"; }
+
+auto f2(const char* loc = []( char const* fn )
+{ return fn; }  ( ce() ) ) {
+return loc;
+}
+
+auto g() {
+return f2();
+}
+
+}
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 7414fbce7828d..b151fc45fdad6 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -832,3 +832,21 @@ void test() {
 }
 
 }
+
+namespace GH80630 {
+
+#define GH80630_LAMBDA \
+[]( char const* fn ) { \
+static constexpr std::source_location loc = 
std::source_location::current(); \
+return &loc; \
+}( std::source_location::current().function() )
+
+auto f( std::source_location const* loc = GH80630_LAMBDA ) {
+return loc;
+}
+
+auto g() {
+return f();
+}
+
+}

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


[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-02-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

Due to improper use of RecursiveASTVisitor.

Fixes #80630

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-3) 
- (modified) clang/test/SemaCXX/cxx2a-consteval-default-params.cpp (+15) 
- (modified) clang/test/SemaCXX/source_location.cpp (+18) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3596109bf044f..fc9acd3f20792 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -201,6 +201,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix evaluation of some immediate calls in default arguments.
+  Fixes (`#80630 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d15278bce5a6b..ab212447f7368 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6198,7 +6198,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitStmt(E);
+return RecursiveASTVisitor::VisitCallExpr(E);
   }
 
   // SourceLocExpr are not immediate invocations
@@ -6222,9 +6222,9 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 
   // Blocks don't support default parameters, and, as for lambdas,
   // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return false; }
+  bool VisitBlockDecl(BlockDecl *B) { return true; }
 
-  bool VisitCompoundStmt(CompoundStmt *B) { return false; }
+  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
 
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
diff --git a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp 
b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
index be8f7cc788589..e4b13725b2dac 100644
--- a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -82,3 +82,18 @@ namespace GH62224 {
   C<> Val; // No error since fwd is defined already.
   static_assert(Val.get() == 42);
 }
+
+namespace GH80630 {
+
+consteval const char* ce() { return "Hello"; }
+
+auto f2(const char* loc = []( char const* fn )
+{ return fn; }  ( ce() ) ) {
+return loc;
+}
+
+auto g() {
+return f2();
+}
+
+}
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 7414fbce7828d..b151fc45fdad6 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -832,3 +832,21 @@ void test() {
 }
 
 }
+
+namespace GH80630 {
+
+#define GH80630_LAMBDA \
+[]( char const* fn ) { \
+static constexpr std::source_location loc = 
std::source_location::current(); \
+return &loc; \
+}( std::source_location::current().function() )
+
+auto f( std::source_location const* loc = GH80630_LAMBDA ) {
+return loc;
+}
+
+auto g() {
+return f();
+}
+
+}

``




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


[clang] [docs] [C++20] [Modules] Ideas for transforming to modules (PR #80687)

2024-02-05 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/80687

>From 7a9fb425a7dfb6429af969ec741c23c1e577e5fa Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 5 Feb 2024 22:31:19 +0800
Subject: [PATCH] [docs] [C++20] [Modules] Ideas for transiting to modules

---
 clang/docs/StandardCPlusPlusModules.rst | 339 
 1 file changed, 339 insertions(+)

diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index c322805d8db5b..e29aa73bc00af 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -610,6 +610,345 @@ the following style significantly:
 
 The key part of the tip is to reduce the duplications from the text includes.
 
+Ideas for converting to modules
+---
+
+For new libraries, we encourage them to use modules completely from day one if 
possible.
+This will be pretty helpful to make the whole ecosystems to get ready.
+
+For many existing libraries, it may be a breaking change to refactor themselves
+into modules completely. So that many existing libraries need to provide 
headers and module
+interfaces for a while to not break existing users.
+Here we provide some ideas to ease the transition process for existing 
libraries.
+**Note that the this section is only about helping ideas instead of 
requirement from clang**.
+
+Let's start with the case that there is no dependency or no dependent 
libraries providing
+modules for your library.
+
+ABI non-breaking styles
+~~~
+
+export-using style
+^^
+
+.. code-block:: c++
+
+  module;
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+  export module your_library;
+  export namespace your_namespace {
+using decl_1;
+using decl_2;
+...
+using decl_n;
+  }
+
+As the example shows, you need to include all the headers containing 
declarations needs
+to be exported and `using` such declarations in an `export` block. Then, 
basically,
+we're done.
+
+export extern-C++ style
+^^^
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  extern "C++" {
+#include "header_1.h"
+#include "header_2.h"
+...
+#include "header_n.h"
+  }
+
+Then in your headers (from ``header_1.h`` to ``header_n.h``), you need to 
define the macro:
+
+.. code-block:: c++
+
+  #ifdef IN_MODULE_INTERFACE
+  #define EXPORT export
+  #else
+  #define EXPORT
+  #endif
+
+And you should put ``EXPORT`` to the beginning of the declarations you want to 
export.
+
+Also it is suggested to refactor your headers to include thirdparty headers 
conditionally:
+
+.. code-block:: c++
+
+  + #ifndef IN_MODULE_INTERFACE
+  #include "third_party/A/headers.h"
+  + #endif
+
+  #include "header_x.h"
+
+  ...
+
+This may be helpful to get better diagnostic messages if you forgot to update 
your module 
+interface unit file during maintaining.
+
+The reasoning for the practice is that the declarations in the language 
linkage are considered
+to be attached to the global module. So the ABI of your library in the modular 
version
+wouldn't change.
+
+While this style looks not as convenient as the export-using style, it is 
easier to convert 
+to other styles.
+
+ABI breaking style
+~~
+
+The term ``ABI breaking`` sounds terrifying generally. But you may want it 
here if you want
+to force your users to introduce your library in a consistent way. E.g., they 
either include
+your headers all the way or import your modules all the way.
+The style prevents the users to include your headers and import your modules 
at the same time
+in the same repo.
+
+The pattern for ABI breaking style is similar with export extern-C++ style.
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+
+  #if the number of .cpp files in your project are small
+  module :private;
+  #include "source_1.cpp"
+  #include "source_2.cpp"
+  ...
+  #include "source_n.cpp"
+  #else // the number of .cpp files in your project are a lot
+  // Using all the declarations from thirdparty libraries which are
+  // used in the .cpp files.
+  namespace third_party_namespace {
+using third_party_decl_used_in_cpp_1;
+using third_party_decl_used_in_cpp_2;
+...
+using third_party_decl_used_in_cpp_n;
+  }
+  #endif
+
+(And add `EXPORT` and conditional include to the headers as suggested in the 
export
+extern-C++ style section)
+
+Remember that the ABI get changed and we need to compile our source files into 
the
+new ABI format. This is t

[clang] [docs] [C++20] [Modules] Ideas for transitioning to modules (PR #80687)

2024-02-05 Thread Chuanqi Xu via cfe-commits

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


[clang] [docs] [C++20] [Modules] Ideas for transitioning to modules (PR #80687)

2024-02-05 Thread Chuanqi Xu via cfe-commits

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


[clang] [docs] [C++20] [Modules] Ideas for transitioning to modules (PR #80687)

2024-02-05 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/80687

>From 2fcbdb034613ea6fdea4ce9efd5656116edb2ca1 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 5 Feb 2024 22:31:19 +0800
Subject: [PATCH] [docs] [C++20] [Modules] Ideas for transiting to modules

---
 clang/docs/StandardCPlusPlusModules.rst | 339 
 1 file changed, 339 insertions(+)

diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index c322805d8db5b..f4c3c4f0d8813 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -610,6 +610,345 @@ the following style significantly:
 
 The key part of the tip is to reduce the duplications from the text includes.
 
+Ideas for converting to modules
+---
+
+For new libraries, we encourage them to use modules completely from day one if 
possible.
+This will be pretty helpful to make the whole ecosystems to get ready.
+
+For many existing libraries, it may be a breaking change to refactor themselves
+into modules completely. So that many existing libraries need to provide 
headers and module
+interfaces for a while to not break existing users.
+Here we provide some ideas to ease the transition process for existing 
libraries.
+**Note that the this section is only about helping ideas instead of 
requirement from clang**.
+
+Let's start with the case that there is no dependency or no dependent 
libraries providing
+modules for your library.
+
+ABI non-breaking styles
+~~~
+
+export-using style
+^^
+
+.. code-block:: c++
+
+  module;
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+  export module your_library;
+  export namespace your_namespace {
+using decl_1;
+using decl_2;
+...
+using decl_n;
+  }
+
+As the example shows, you need to include all the headers containing 
declarations needs
+to be exported and `using` such declarations in an `export` block. Then, 
basically,
+we're done.
+
+export extern-C++ style
+^^^
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  extern "C++" {
+#include "header_1.h"
+#include "header_2.h"
+...
+#include "header_n.h"
+  }
+
+Then in your headers (from ``header_1.h`` to ``header_n.h``), you need to 
define the macro:
+
+.. code-block:: c++
+
+  #ifdef IN_MODULE_INTERFACE
+  #define EXPORT export
+  #else
+  #define EXPORT
+  #endif
+
+And you should put ``EXPORT`` to the beginning of the declarations you want to 
export.
+
+Also it is suggested to refactor your headers to include thirdparty headers 
conditionally:
+
+.. code-block:: c++
+
+  + #ifndef IN_MODULE_INTERFACE
+  #include "third_party/A/headers.h"
+  + #endif
+
+  #include "header_x.h"
+
+  ...
+
+This may be helpful to get better diagnostic messages if you forgot to update 
your module 
+interface unit file during maintaining.
+
+The reasoning for the practice is that the declarations in the language 
linkage are considered
+to be attached to the global module. So the ABI of your library in the modular 
version
+wouldn't change.
+
+While this style looks not as convenient as the export-using style, it is 
easier to convert 
+to other styles.
+
+ABI breaking style
+~~
+
+The term ``ABI breaking`` sounds terrifying generally. But you may want it 
here if you want
+to force your users to introduce your library in a consistent way. E.g., they 
either include
+your headers all the way or import your modules all the way.
+The style prevents the users to include your headers and import your modules 
at the same time
+in the same repo.
+
+The pattern for ABI breaking style is similar with export extern-C++ style.
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+
+  #if the number of .cpp files in your project are small
+  module :private;
+  #include "source_1.cpp"
+  #include "source_2.cpp"
+  ...
+  #include "source_n.cpp"
+  #else // the number of .cpp files in your project are a lot
+  // Using all the declarations from thirdparty libraries which are
+  // used in the .cpp files.
+  namespace third_party_namespace {
+using third_party_decl_used_in_cpp_1;
+using third_party_decl_used_in_cpp_2;
+...
+using third_party_decl_used_in_cpp_n;
+  }
+  #endif
+
+(And add `EXPORT` and conditional include to the headers as suggested in the 
export
+extern-C++ style section)
+
+Remember that the ABI get changed and we need to compile our source files into 
the
+new ABI format. This is t

[clang] e524ada - [clang][Interp] Support zero init for complex types (#79728)

2024-02-05 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-02-05T15:56:06+01:00
New Revision: e524ada6cbc6912156a713ffa179cb92e5362ebb

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

LOG: [clang][Interp] Support zero init for complex types (#79728)

Initialize both elements to 0.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 74a5284ff812c..cefcebe18c6b6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1939,10 +1939,32 @@ bool 
ByteCodeExprGen::VisitCXXScalarValueInitExpr(
 const CXXScalarValueInitExpr *E) {
   QualType Ty = E->getType();
 
-  if (Ty->isVoidType())
+  if (DiscardResult || Ty->isVoidType())
 return true;
 
-  return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
+  if (std::optional T = classify(Ty))
+return this->visitZeroInitializer(*T, Ty, E);
+
+  assert(Ty->isAnyComplexType());
+  if (!Initializing) {
+std::optional LocalIndex = allocateLocal(E, 
/*IsExtended=*/false);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+  }
+
+  // Initialize both fields to 0.
+  QualType ElemQT = Ty->getAs()->getElementType();
+  PrimType ElemT = classifyPrim(ElemQT);
+
+  for (unsigned I = 0; I != 2; ++I) {
+if (!this->visitZeroInitializer(ElemT, ElemQT, E))
+  return false;
+if (!this->emitInitElem(ElemT, I, E))
+  return false;
+  }
+  return true;
 }
 
 template 

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index fdd1d738de828..7f02bfa18bbdb 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -179,3 +179,18 @@ namespace Sub {
 }
 
 }
+
+namespace ZeroInit {
+  typedef _Complex float fcomplex;
+  typedef _Complex unsigned icomplex;
+
+  constexpr fcomplex test7 = fcomplex();
+  static_assert(__real(test7) == 0.0f, "");
+  static_assert(__imag(test7) == 0.0f, "");
+
+  constexpr icomplex test8 = icomplex();
+  static_assert(__real(test8) == 0, "");
+  static_assert(__imag(test8) == 0, "");
+
+  constexpr int ignored = (fcomplex(), 0);
+}



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


[clang] [clang][Interp] Support zero init for complex types (PR #79728)

2024-02-05 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][AMDGPU][CUDA] Handle __builtin_printf for device printf (PR #68515)

2024-02-05 Thread Mészáros Gergely via cfe-commits

https://github.com/Maetveis updated 
https://github.com/llvm/llvm-project/pull/68515

From b7a87d012dfaa59ed8dc5478f798d2150141e028 Mon Sep 17 00:00:00 2001
From: Gergely Meszaros 
Date: Sun, 8 Oct 2023 09:30:24 +
Subject: [PATCH] [clang][AMDGPU][CUDA] Handle __builtin_printf for device
 printf

Previously __builtin_printf would result to emitting call to printf,
even though directly calling printf was translated.

Ref: #68478
---
 clang/lib/CodeGen/CGBuiltin.cpp  |  1 +
 clang/lib/CodeGen/CGGPUBuiltin.cpp   |  3 ++-
 clang/test/CodeGenCUDA/printf-builtin.cu | 21 +
 clang/test/CodeGenHIP/printf-builtin.hip | 23 +++
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCUDA/printf-builtin.cu
 create mode 100644 clang/test/CodeGenHIP/printf-builtin.hip

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f17e4a83305bf..e051cbc648635 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5710,6 +5710,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Value *HalfVal = Builder.CreateLoad(Address);
 return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getFloatTy()));
   }
+  case Builtin::BI__builtin_printf:
   case Builtin::BIprintf:
 if (getTarget().getTriple().isNVPTX() ||
 getTarget().getTriple().isAMDGCN()) {
diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index e465789a003eb..bd95541647bcf 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -136,7 +136,8 @@ RValue EmitDevicePrintfCallExpr(const CallExpr *E, 
CodeGenFunction *CGF,
 llvm::Function *Decl, bool WithSizeArg) {
   CodeGenModule &CGM = CGF->CGM;
   CGBuilderTy &Builder = CGF->Builder;
-  assert(E->getBuiltinCallee() == Builtin::BIprintf);
+  assert(E->getBuiltinCallee() == Builtin::BIprintf ||
+ E->getBuiltinCallee() == Builtin::BI__builtin_printf);
   assert(E->getNumArgs() >= 1); // printf always has at least one arg.
 
   // Uses the same format as nvptx for the argument packing, but also passes
diff --git a/clang/test/CodeGenCUDA/printf-builtin.cu 
b/clang/test/CodeGenCUDA/printf-builtin.cu
new file mode 100644
index 0..e018d533ed32d
--- /dev/null
+++ b/clang/test/CodeGenCUDA/printf-builtin.cu
@@ -0,0 +1,21 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -emit-llvm -disable-llvm-optzns 
-fno-builtin-printf -fcuda-is-device \
+// RUN:   -o - %s | FileCheck  %s
+
+#define __device__ __attribute__((device))
+
+extern "C" __device__ int printf(const char *format, ...);
+
+// CHECK-LABEL: @_Z4foo1v()
+__device__ int foo1() {
+  // CHECK: call i32 @vprintf
+  // CHECK-NOT: call i32 (ptr, ...) @printf
+  return __builtin_printf("Hello World\n");
+}
+
+// CHECK-LABEL: @_Z4foo2v()
+__device__ int foo2() {
+  // CHECK: call i32 (ptr, ...) @printf
+  return printf("Hello World\n");
+}
diff --git a/clang/test/CodeGenHIP/printf-builtin.hip 
b/clang/test/CodeGenHIP/printf-builtin.hip
new file mode 100644
index 0..df1fbbb6d637a
--- /dev/null
+++ b/clang/test/CodeGenHIP/printf-builtin.hip
@@ -0,0 +1,23 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -disable-llvm-optzns 
-mprintf-kind=hostcall -fno-builtin-printf -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefixes=CHECK,HOSTCALL %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -disable-llvm-optzns 
-mprintf-kind=buffered -fno-builtin-printf -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefixes=CHECK,BUFFERED %s
+
+#define __device__ __attribute__((device))
+
+extern "C" __device__ int printf(const char *format, ...);
+
+// CHECK-LABEL: @_Z4foo1v()
+__device__ int foo1() {
+  // HOSTCALL: call i64 @__ockl_printf_begin
+  // BUFFERED: call ptr addrspace(1) @__printf_alloc
+  // CHECK-NOT: call i32 (ptr, ...) @printf
+  return __builtin_printf("Hello World\n");
+}
+
+// CHECK-LABEL: @_Z4foo2v()
+__device__ int foo2() {
+  // CHECK: call i32 (ptr, ...) @printf
+  return printf("Hello World\n");
+}

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


  1   2   3   4   5   >