[clang] fb21343 - [C++20] [Modules] Don't skip pragma diagnostic mappings

2024-04-29 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-30T13:50:20+08:00
New Revision: fb21343473e33e9a886b42d2fe95d1cec1cd0030

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

LOG: [C++20] [Modules] Don't skip pragma diagnostic mappings

Close https://github.com/llvm/llvm-project/issues/75057

Previously, I thought the diagnostic mappings is not meaningful with
modules incorrectly. And this problem get revealed by another change
recently. So this patch tried to rever the previous "optimization"
partially.

Added: 
clang/test/Modules/pr75057.cppm

Modified: 
clang/lib/Serialization/GeneratePCH.cpp

Removed: 




diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index 7b97b73f7bbd00..53dda5f9a38580 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -114,7 +114,6 @@ void 
CXX20ModulesGenerator::HandleTranslationUnit(ASTContext ) {
   getPreprocessor().getHeaderSearchInfo().getHeaderSearchOpts();
   HSOpts.ModulesSkipDiagnosticOptions = true;
   HSOpts.ModulesSkipHeaderSearchPaths = true;
-  HSOpts.ModulesSkipPragmaDiagnosticMappings = true;
 
   PCHGenerator::HandleTranslationUnit(Ctx);
 

diff  --git a/clang/test/Modules/pr75057.cppm b/clang/test/Modules/pr75057.cppm
new file mode 100644
index 00..374c324e9f495b
--- /dev/null
+++ b/clang/test/Modules/pr75057.cppm
@@ -0,0 +1,62 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// Treat the behavior of using headers as baseline.
+// RUN: %clang_cc1 -std=c++20 %t/use-header.cc -isystem %t -fsyntax-only 
-verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -isystem %t -emit-module-interface -o 
%t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use-module.cc -isystem %t 
-fmodule-file=a=%t/a.pcm -fsyntax-only -verify
+
+//--- sys.h
+#ifndef SYS_H
+#define SYS_H
+
+#pragma GCC system_header
+
+template 
+struct [[deprecated]] iterator {};
+
+_Pragma("GCC diagnostic push")
+_Pragma("GCC diagnostic ignored \"-Wdeprecated\"") 
+_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+
+template 
+struct reverse_iterator 
+: public iterator {};
+
+_Pragma("GCC diagnostic pop")
+
+template 
+class C {
+public:
+void i() {
+reverse_iterator i;
+}
+};
+
+#endif
+
+//--- use-header.cc
+// expected-no-diagnostics
+// However, we see unexpected warnings
+#include 
+
+void use() {
+C().i();
+}
+
+//--- a.cppm
+module;
+#include 
+export module a;
+export using ::iterator;
+export using ::C;
+
+//--- use-module.cc
+// expected-no-diagnostics
+import a;
+
+void use() {
+C().i();
+}



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


[clang] 18268ac - [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to generate module file for C++20 modules instead of PCHGenerator

2024-04-29 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-30T13:30:31+08:00
New Revision: 18268ac0f48d93c2bcddb69732761971669c09ab

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

LOG: [NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to generate 
module file for C++20 modules instead of PCHGenerator

Previously we're re-using PCHGenerator to generate the module file for
C++20 modules. But this is slighty more or less odd. This patch tries
to use a new class 'CXX20ModulesGenerator' to generate the module file
for C++20 modules.

Added: 


Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Serialization/GeneratePCH.cpp
clang/test/Modules/pr67893.cppm
clang/test/Modules/search-partitions.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 6c45b7348b8552..4e433deaaf2dbc 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -928,17 +928,30 @@ class PCHGenerator : public SemaConsumer {
   bool hasEmittedPCH() const { return Buffer->IsComplete; }
 };
 
-class ReducedBMIGenerator : public PCHGenerator {
+class CXX20ModulesGenerator : public PCHGenerator {
 protected:
   virtual Module *getEmittingModule(ASTContext ) override;
 
+  CXX20ModulesGenerator(Preprocessor , InMemoryModuleCache ,
+StringRef OutputFile, bool GeneratingReducedBMI);
+
 public:
-  ReducedBMIGenerator(Preprocessor , InMemoryModuleCache ,
-  StringRef OutputFile);
+  CXX20ModulesGenerator(Preprocessor , InMemoryModuleCache ,
+StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/false) {}
 
   void HandleTranslationUnit(ASTContext ) override;
 };
 
+class ReducedBMIGenerator : public CXX20ModulesGenerator {
+public:
+  ReducedBMIGenerator(Preprocessor , InMemoryModuleCache ,
+  StringRef OutputFile)
+  : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
+  /*GeneratingReducedBMI=*/true) {}
+};
+
 /// If we can elide the definition of \param D in reduced BMI.
 ///
 /// Generally, we can elide the definition of a declaration if it won't affect

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 04eb1041326713..454653a31534cd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -272,14 +272,10 @@ bool GenerateModuleInterfaceAction::BeginSourceFileAction(
 std::unique_ptr
 GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance ,
  StringRef InFile) {
-  CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = true;
-  CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = true;
-  CI.getHeaderSearchOpts().ModulesSkipPragmaDiagnosticMappings = true;
-
-  std::vector> Consumers =
-  CreateMultiplexConsumer(CI, InFile);
-  if (Consumers.empty())
-return nullptr;
+  std::vector> Consumers;
+  Consumers.push_back(std::make_unique(
+  CI.getPreprocessor(), CI.getModuleCache(),
+  CI.getFrontendOpts().OutputFile));
 
   if (CI.getFrontendOpts().GenReducedBMI &&
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {

diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index bed74399098d7f..7b97b73f7bbd00 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -88,31 +88,28 @@ ASTDeserializationListener 
*PCHGenerator::GetASTDeserializationListener() {
   return 
 }
 
-ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor ,
- InMemoryModuleCache ,
- StringRef OutputFile)
+CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor ,
+ InMemoryModuleCache ,
+ StringRef OutputFile,
+ bool GeneratingReducedBMI)
 : PCHGenerator(
   PP, ModuleCache, OutputFile, llvm::StringRef(),
   std::make_shared(),
   /*Extensions=*/ArrayRef>(),
   /*AllowASTWithErrors*/ false, /*IncludeTimestamps=*/false,
   /*BuildingImplicitModule=*/false, /*ShouldCacheASTInMemory=*/false,
-  /*GeneratingReducedBMI=*/true) {}
+  GeneratingReducedBMI) {}
 
-Module *ReducedBMIGenerator::getEmittingModule(ASTContext ) {
+Module *CXX20ModulesGenerator::getEmittingModule(ASTContext ) {
   Module *M = Ctx.getCurrentNamedModule();
   assert(M 

[clang-tools-extra] [clang-tidy] fix false-negative for macros in `readability-math-missing-parentheses` (PR #90279)

2024-04-29 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] fbe4d99 - [clang-tidy] fix false-negative for macros in `readability-math-missing-parentheses` (#90279)

2024-04-29 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-04-30T07:22:30+02:00
New Revision: fbe4d991323b026eb64cd3d0ee811854b54ca33f

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

LOG: [clang-tidy] fix false-negative for macros in 
`readability-math-missing-parentheses` (#90279)

When a binary operator is the last operand of a macro, the end location
that is past the `BinaryOperator` will be inside the macro and therefore
an
invalid location to insert a `FixIt` into, which is why the check bails
when encountering such a pattern.
However, the end location is only required for the `FixIt` and the
diagnostic can still be emitted, just without an attached fix.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index d1e20b9074cec1..65fd296094915b 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -61,19 +61,21 @@ static void addParantheses(const BinaryOperator *BinOp,
 const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
 const clang::SourceLocation EndLoc =
 clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);
-if (EndLoc.isInvalid())
-  return;
 
-Check->diag(StartLoc,
-"'%0' has higher precedence than '%1'; add parentheses to "
-"explicitly specify the order of operations")
+auto Diag =
+Check->diag(StartLoc,
+"'%0' has higher precedence than '%1'; add parentheses to "
+"explicitly specify the order of operations")
 << (Precedence1 > Precedence2 ? BinOp->getOpcodeStr()
   : ParentBinOp->getOpcodeStr())
 << (Precedence1 > Precedence2 ? ParentBinOp->getOpcodeStr()
   : BinOp->getOpcodeStr())
-<< FixItHint::CreateInsertion(StartLoc, "(")
-<< FixItHint::CreateInsertion(EndLoc, ")")
 << SourceRange(StartLoc, EndLoc);
+
+if (EndLoc.isValid()) {
+  Diag << FixItHint::CreateInsertion(StartLoc, "(")
+   << FixItHint::CreateInsertion(EndLoc, ")");
+}
   }
 
   addParantheses(dyn_cast(BinOp->getLHS()->IgnoreImpCasts()),

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
index edbe2e1c37c770..a6045c079a4823 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
@@ -16,6 +16,13 @@ int bar(){
 return 4;
 }
 
+int sink(int);
+#define FUN(ARG) (sink(ARG))
+#define FUN2(ARG) sink((ARG))
+#define FUN3(ARG) sink(ARG)
+#define FUN4(ARG) sink(1 + ARG)
+#define FUN5(ARG) sink(4 * ARG)
+
 class fun{
 public:
 int A;
@@ -117,4 +124,19 @@ void f(){
 //CHECK-MESSAGES: :[[@LINE+2]]:94: warning: '/' has higher precedence than 
'-'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
 //CHECK-FIXES: int q = (1 MACRO_ADD (2 MACRO_MULTIPLY 3)) MACRO_OR ((4 
MACRO_AND 5) MACRO_XOR (6 MACRO_SUBTRACT (7 MACRO_DIVIDE 8)));
 int q = 1 MACRO_ADD 2 MACRO_MULTIPLY 3 MACRO_OR 4 MACRO_AND 5 MACRO_XOR 6 
MACRO_SUBTRACT 7 MACRO_DIVIDE 8; // No warning
+
+//CHECK-MESSAGES: :[[@LINE+1]]:21: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+int r = FUN(0 + 1 * 2);
+
+//CHECK-MESSAGES: :[[@LINE+1]]:22: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+int s = FUN2(0 + 1 * 2);
+
+//CHECK-MESSAGES: :[[@LINE+1]]:22: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+int t = FUN3(0 + 1 * 2);
+
+//CHECK-MESSAGES: :[[@LINE+1]]:18: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+int u = FUN4(1 * 2);
+
+//CHECK-MESSAGES: :[[@LINE+1]]:13: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+int v = FUN5(0 + 

[clang-tools-extra] [clang-tidy] Relax readability-const-return-type (PR #90560)

2024-04-29 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Piotr Zegar (PiotrZSL)


Changes

>From now readability-const-return-type won't provide warnings for returning 
>const types, where const is not on top level. In such case const there is a 
>performance issue, but not a readability.

Closes #73270

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp 
(+4-17) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp 
(+17-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
index e92350632b556b..c13a8010c22210 100644
--- a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -55,14 +55,6 @@ AST_MATCHER(QualType, isLocalConstQualified) {
   return Node.isLocalConstQualified();
 }
 
-AST_MATCHER(QualType, isTypeOfType) {
-  return isa(Node.getTypePtr());
-}
-
-AST_MATCHER(QualType, isTypeOfExprType) {
-  return isa(Node.getTypePtr());
-}
-
 struct CheckResult {
   // Source range of the relevant `const` token in the definition being 
checked.
   CharSourceRange ConstRange;
@@ -110,16 +102,11 @@ void 
ConstReturnTypeCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 void ConstReturnTypeCheck::registerMatchers(MatchFinder *Finder) {
   // Find all function definitions for which the return types are `const`
   // qualified, ignoring decltype types.
-  auto NonLocalConstType =
-  qualType(unless(isLocalConstQualified()),
-   anyOf(decltypeType(), autoType(), isTypeOfType(),
- isTypeOfExprType(), substTemplateTypeParmType()));
   Finder->addMatcher(
-  functionDecl(
-  returns(allOf(isConstQualified(), unless(NonLocalConstType))),
-  anyOf(isDefinition(), cxxMethodDecl(isPure())),
-  // Overridden functions are not actionable.
-  unless(cxxMethodDecl(isOverride(
+  functionDecl(returns(isLocalConstQualified()),
+   anyOf(isDefinition(), cxxMethodDecl(isPure())),
+   // Overridden functions are not actionable.
+   unless(cxxMethodDecl(isOverride(
   .bind("func"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3038d2b125f20d..d8bda2d8aea142 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -312,6 +312,10 @@ Changes in existing checks
   ` check by adding
   fix-its.
 
+- Improved :doc:`readability-const-return-type
+  ` check to eliminate false
+  positives when returning types with const not at the top level.
+
 - Improved :doc:`readability-duplicate-include
   ` check by excluding include
   directives that form the filename using macro.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
index 10b2858c9caa82..76a3555663b180 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
@@ -215,11 +215,9 @@ CREATE_FUNCTION();
 
 using ty = const int;
 ty p21() {}
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty' (aka 'const int') 
is
 
 typedef const int ty2;
 ty2 p22() {}
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty2' (aka 'const int') 
i
 
 // Declaration uses a macro, while definition doesn't.  In this case, we won't
 // fix the declaration, and will instead issue a warning.
@@ -249,7 +247,6 @@ auto p27() -> int const { return 3; }
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 
'const'-qu
 
 std::add_const::type p28() { return 3; }
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 
'std::add_const::typ
 
 // p29, p30 are based on
 // llvm/projects/test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp:
@@ -355,3 +352,20 @@ struct p41 {
   // CHECK-FIXES: T foo() const { return 2; }
 };
 template struct p41;
+
+namespace PR73270 {
+  template
+  struct Pair {
+using first_type = const K;
+using second_type = V;
+  };
+
+  template
+  typename PairType::first_type getFirst() {
+return {};
+  }
+
+  void test() {
+getFirst>();
+  }
+}

``




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


[clang-tools-extra] [clang-tidy] Relax readability-const-return-type (PR #90560)

2024-04-29 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/90560

>From now readability-const-return-type won't provide warnings for returning 
>const types, where const is not on top level. In such case const there is a 
>performance issue, but not a readability.

Closes #73270

>From 72306af4660bdbc5bd475ef3512150c00ec9f24d Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 30 Apr 2024 05:16:55 +
Subject: [PATCH] [clang-tidy] Relax readability-const-return-type

>From now readability-const-return-type won't provide warnings for returning
const types, where const is not on top level. In such case const there is
a performance issue, but not a readability.

Closes #73270
---
 .../readability/ConstReturnTypeCheck.cpp  | 21 ---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../readability/const-return-type.cpp | 20 +++---
 3 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
index e92350632b556b..c13a8010c22210 100644
--- a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -55,14 +55,6 @@ AST_MATCHER(QualType, isLocalConstQualified) {
   return Node.isLocalConstQualified();
 }
 
-AST_MATCHER(QualType, isTypeOfType) {
-  return isa(Node.getTypePtr());
-}
-
-AST_MATCHER(QualType, isTypeOfExprType) {
-  return isa(Node.getTypePtr());
-}
-
 struct CheckResult {
   // Source range of the relevant `const` token in the definition being 
checked.
   CharSourceRange ConstRange;
@@ -110,16 +102,11 @@ void 
ConstReturnTypeCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 void ConstReturnTypeCheck::registerMatchers(MatchFinder *Finder) {
   // Find all function definitions for which the return types are `const`
   // qualified, ignoring decltype types.
-  auto NonLocalConstType =
-  qualType(unless(isLocalConstQualified()),
-   anyOf(decltypeType(), autoType(), isTypeOfType(),
- isTypeOfExprType(), substTemplateTypeParmType()));
   Finder->addMatcher(
-  functionDecl(
-  returns(allOf(isConstQualified(), unless(NonLocalConstType))),
-  anyOf(isDefinition(), cxxMethodDecl(isPure())),
-  // Overridden functions are not actionable.
-  unless(cxxMethodDecl(isOverride(
+  functionDecl(returns(isLocalConstQualified()),
+   anyOf(isDefinition(), cxxMethodDecl(isPure())),
+   // Overridden functions are not actionable.
+   unless(cxxMethodDecl(isOverride(
   .bind("func"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3038d2b125f20d..d8bda2d8aea142 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -312,6 +312,10 @@ Changes in existing checks
   ` check by adding
   fix-its.
 
+- Improved :doc:`readability-const-return-type
+  ` check to eliminate false
+  positives when returning types with const not at the top level.
+
 - Improved :doc:`readability-duplicate-include
   ` check by excluding include
   directives that form the filename using macro.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
index 10b2858c9caa82..76a3555663b180 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
@@ -215,11 +215,9 @@ CREATE_FUNCTION();
 
 using ty = const int;
 ty p21() {}
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty' (aka 'const int') 
is
 
 typedef const int ty2;
 ty2 p22() {}
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty2' (aka 'const int') 
i
 
 // Declaration uses a macro, while definition doesn't.  In this case, we won't
 // fix the declaration, and will instead issue a warning.
@@ -249,7 +247,6 @@ auto p27() -> int const { return 3; }
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 
'const'-qu
 
 std::add_const::type p28() { return 3; }
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 
'std::add_const::typ
 
 // p29, p30 are based on
 // llvm/projects/test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp:
@@ -355,3 +352,20 @@ struct p41 {
   // CHECK-FIXES: T foo() const { return 2; }
 };
 template struct p41;
+
+namespace PR73270 {
+  template
+  struct Pair {
+using first_type = const K;
+using second_type = V;
+  };
+
+  template
+  typename PairType::first_type getFirst() {
+return {};
+  }
+
+  void test() {
+getFirst>();
+  }
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #90389)

2024-04-29 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/90389

>From db18c52f8fd5f397324505bcb2e07343794e5dce Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Sun, 28 Apr 2024 17:14:29 +0800
Subject: [PATCH] [X86_64] Fix empty field error in vaarg of C++.

Such struct types:
```
struct {
  struct{} a;
  long long b;
};

stuct {
  struct{} a;
  double b;
};
```
For such structures, Lo is NoClass and Hi is Integer/SSE. And when
this structure argument is passed, the high part is passed at
offset 8 in memory. So we should do special handling for these types
in EmitVAArg.
---
 clang/lib/CodeGen/Targets/X86.cpp  | 27 +++
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 64 +++---
 2 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 94cf0d86f9bed7..eff54d12ce5496 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3122,9 +3122,24 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction , 
Address VAListAddr,
 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
 
 RegAddr = Tmp.withElementType(LTy);
-  } else if (neededInt) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
gp_offset),
-  LTy, CharUnits::fromQuantity(8));
+  } else if (neededInt || neededSSE == 1) {
+llvm::Value *Offset = neededInt ? gp_offset : fp_offset;
+uint64_t Alignment = neededInt ? 8 : 16;
+Address Tmp = CGF.CreateMemTemp(Ty);
+if (AI.isDirect() && AI.getDirectOffset() == 8) {
+  llvm::StructType *ST = cast(LTy);
+  Tmp = Tmp.withElementType(ST);
+  llvm::Type *TyHi = AI.getCoerceToType();
+  llvm::Value *Addr =
+  CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, Offset);
+  llvm::Value *V = CGF.Builder.CreateAlignedLoad(
+  TyHi, Addr,
+  CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
+  CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
+  RegAddr = Tmp.withElementType(LTy);
+} else
+  RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, Offset),
+LTy, CharUnits::fromQuantity(Alignment));
 
 // Copy to a temporary if necessary to ensure the appropriate alignment.
 auto TInfo = getContext().getTypeInfoInChars(Ty);
@@ -3133,15 +3148,11 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction , 
Address VAListAddr,
 
 // Copy into a temporary if the type is more aligned than the
 // register save area.
-if (TyAlign.getQuantity() > 8) {
-  Address Tmp = CGF.CreateMemTemp(Ty);
+if (neededInt && TyAlign.getQuantity() > 8) {
   CGF.Builder.CreateMemCpy(Tmp, RegAddr, TySize, false);
   RegAddr = Tmp;
 }
 
-  } else if (neededSSE == 1) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
fp_offset),
-  LTy, CharUnits::fromQuantity(16));
   } else {
 assert(neededSSE == 2 && "Invalid number of needed registers!");
 // SSE registers are spaced 16 bytes apart in the register save
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index 985a0cc41a1410..dc6d9f070cf51f 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -32,6 +32,7 @@ typedef struct {
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8
 // CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_S1]], align 8
 // CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
 // CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x 
%struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
 // CHECK-NEXT:call void @llvm.va_start.p0(ptr [[ARRAYDECAY]])
@@ -44,8 +45,11 @@ typedef struct {
 // CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds 
[[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3
 // CHECK-NEXT:[[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16
 // CHECK-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 
[[FP_OFFSET]]
-// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16
-// CHECK-NEXT:store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[TMP1]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = getelementptr inbounds [[STRUCT_S1]], ptr 
[[TMP]], i32 0, i32 1
+// CHECK-NEXT:store double [[TMP2]], ptr [[TMP3]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = add i32 [[FP_OFFSET]], 16
+// CHECK-NEXT:store i32 [[TMP4]], ptr [[FP_OFFSET_P]], align 4
 // CHECK-NEXT:br label [[VAARG_END:%.*]]
 // CHECK:   vaarg.in_mem:
 // CHECK-NEXT:[[OVERFLOW_ARG_AREA_P:%.*]] = getelementptr inbounds 
[[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 2
@@ -54,14 +58,62 @@ typedef struct {
 // 

[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,72 @@
+set(CMAKE_C_COMPILER "/usr/bin/cc")

PiotrZSL wrote:

Looks like simple mistake, plee remove that build directory from a change.

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


[clang] [clang-format] Fix a bug in annotating struct braces (PR #90555)

2024-04-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #60040.

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


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+4-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+13) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3a263955a6a8fe..854428389740d8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3944,8 +3944,11 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
   // We can have macros in between 'class' and the class name.
-  if (!IsNonMacroIdentifier(Previous))
+  if (!IsNonMacroIdentifier(Previous) ||
+  // e.g. `struct macro(a) S { int i; };`
+  Previous->Previous == ) {
 parseParens();
+  }
   break;
 case tok::coloncolon:
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index dff5251d2e9406..01daf8dee505bc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -438,6 +438,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
   EXPECT_TOKEN(Tokens[3], tok::r_brace, TT_StructRBrace);
 
+  Tokens = annotate("struct macro(a) S {};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_StructLBrace);
+  EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_StructRBrace);
+
   Tokens = annotate("struct EXPORT_MACRO [[nodiscard]] C { int i; };");
   ASSERT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_StructLBrace);
@@ -448,6 +453,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_StructLBrace);
   EXPECT_TOKEN(Tokens[16], tok::r_brace, TT_StructRBrace);
 
+  Tokens = annotate("struct macro(a) S {\n"
+"  void f(T );\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_StructLBrace);
+  EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[15], tok::r_brace, TT_StructRBrace);
+
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::less, TT_TemplateOpener);

``




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


[clang] [clang-format] Fix a bug in annotating struct braces (PR #90555)

2024-04-29 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/90555

Fixes #60040.

>From 77d807d47d47ca9916edc03182e1952c27300a8a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 29 Apr 2024 21:11:28 -0700
Subject: [PATCH] [clang-format] Fix a bug in annotating struct braces

Fixes #60040.
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  5 -
 clang/unittests/Format/TokenAnnotatorTest.cpp | 13 +
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3a263955a6a8fe..854428389740d8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3944,8 +3944,11 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
   // We can have macros in between 'class' and the class name.
-  if (!IsNonMacroIdentifier(Previous))
+  if (!IsNonMacroIdentifier(Previous) ||
+  // e.g. `struct macro(a) S { int i; };`
+  Previous->Previous == ) {
 parseParens();
+  }
   break;
 case tok::coloncolon:
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index dff5251d2e9406..01daf8dee505bc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -438,6 +438,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
   EXPECT_TOKEN(Tokens[3], tok::r_brace, TT_StructRBrace);
 
+  Tokens = annotate("struct macro(a) S {};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_StructLBrace);
+  EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_StructRBrace);
+
   Tokens = annotate("struct EXPORT_MACRO [[nodiscard]] C { int i; };");
   ASSERT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_StructLBrace);
@@ -448,6 +453,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_StructLBrace);
   EXPECT_TOKEN(Tokens[16], tok::r_brace, TT_StructRBrace);
 
+  Tokens = annotate("struct macro(a) S {\n"
+"  void f(T );\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_StructLBrace);
+  EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[15], tok::r_brace, TT_StructRBrace);
+
   Tokens = annotate("template  struct S {};");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::less, TT_TemplateOpener);

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/90155

>From 7a741109a6769e2e91d77a82d9a44c7f9c212c48 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Thu, 25 Apr 2024 22:23:26 -0400
Subject: [PATCH] [CUDA] make kernel stub ICF-proof

MSVC linker may merge functions which have identical
set of instructions. CUDA uses kernel stub function as key to
look up kernels in device executables. If kernel stub function
for different kernels are merged by ICF, incorrect kernels
will be launched.

To prevent ICF from merging kernel stub functions, an unique
global variable is created for each kernel stub function
and a volatile store is added to the kernel stub function.
This makes the set of instructions in each kernel function
unique.

Fixes: https://github.com/llvm/llvm-project/issues/3
---
 clang/lib/CodeGen/CGCUDANV.cpp |  27 ++
 clang/test/CodeGenCUDA/kernel-stub-name.cu | 101 +
 2 files changed, 88 insertions(+), 40 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 370642cb3d5364..670bc4bf72cecb 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -424,6 +424,33 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+std::string GlobalVarName = (KernelFunction->getName() + ".id").str();
+
+llvm::GlobalVariable *HandleVar =
+CGM.getModule().getNamedGlobal(GlobalVarName);
+if (!HandleVar) {
+  HandleVar = new llvm::GlobalVariable(
+  CGM.getModule(), CGM.Int8Ty,
+  /*Constant=*/false, KernelFunction->getLinkage(),
+  llvm::ConstantInt::get(CGM.Int8Ty, 0), GlobalVarName);
+  HandleVar->setDSOLocal(KernelFunction->isDSOLocal());
+  HandleVar->setVisibility(KernelFunction->getVisibility());
+  if (KernelFunction->hasComdat())
+HandleVar->setComdat(CGM.getModule().getOrInsertComdat(GlobalVarName));
+}
+
+CGF.Builder.CreateAlignedStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),
+   HandleVar, CharUnits::One(),
+   /*IsVolatile=*/true);
+  }
+
   CGF.EmitBranch(EndBlock);
 
   CGF.EmitBlock(EndBlock);
diff --git a/clang/test/CodeGenCUDA/kernel-stub-name.cu 
b/clang/test/CodeGenCUDA/kernel-stub-name.cu
index 23df7f5d721b56..0faea75cbbe536 100644
--- a/clang/test/CodeGenCUDA/kernel-stub-name.cu
+++ b/clang/test/CodeGenCUDA/kernel-stub-name.cu
@@ -2,7 +2,7 @@
 
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -fcuda-include-gpubinary %t -o - -x hip\
-// RUN:   | FileCheck -check-prefixes=CHECK,GNU %s
+// RUN:   | FileCheck -check-prefixes=CHECK,GNU,GNU-HIP,HIP %s
 
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -fcuda-include-gpubinary %t -o - -x hip\
@@ -11,7 +11,12 @@
 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
 // RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
 // RUN: %t -o - -x hip\
-// RUN:   | FileCheck -check-prefixes=CHECK,MSVC %s
+// RUN:   | FileCheck -check-prefixes=CHECK,MSVC,MSVC-HIP,HIP %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple nvptx64 -fcuda-include-gpubinary \
+// RUN: %t -target-sdk-version=9.2 -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK,MSVC,CUDA %s
 
 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
 // RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
@@ -22,19 +27,23 @@
 
 // Check kernel handles are emitted for non-MSVC target but not for MSVC 
target.
 
-// GNU: @[[HCKERN:ckernel]] = constant ptr @[[CSTUB:__device_stub__ckernel]], 
align 8
-// GNU: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant ptr 
@[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]], align 8
-// GNU: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant ptr 
@[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]], comdat, align 8
-// GNU: @[[HDKERN:_Z11kernel_declv]] = external constant ptr, align 8
-// GNU: @[[HTDKERN:_Z20template_kernel_declIiEvT_]] = external constant ptr, 
align 8
-
-// MSVC: @[[HCKERN:ckernel]] = dso_local constant ptr 
@[[CSTUB:__device_stub__ckernel]], align 8
-// MSVC: @[[HNSKERN:"\?nskernel@ns@@YAXXZ.*"]] = dso_local constant ptr 
@[[NSSTUB:"\?__device_stub__nskernel@ns@@YAXXZ"]], align 8
-// MSVC: @[[HTKERN:"\?\?\$kernelfunc@H@@YAXXZ.*"]] = linkonce_odr dso_local 
constant ptr 

[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-04-29 Thread Yeting Kuo via cfe-commits


@@ -169,6 +169,9 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-relax");
   }
 
+  if (!Args.hasArg(options::OPT_menable_experimental_extensions))
+Features.push_back("+no-experimental-ext");

yetingk wrote:

Fixed. Only use +experimental feature.

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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-04-29 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/89727

>From a43014cf3daa1b0fd9092bfe41da979205ba64aa Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 23 Apr 2024 02:16:04 -0700
Subject: [PATCH 1/4] [RISCV] Teach .option arch to support experimental
 extensions.

Previously .option arch denied extenions are not belongs to RISC-V features. But
experimental features have experimental- prefix, so .option arch can not
serve for experimental extension.
This patch uses the features of extensions to identify extension
existance.
---
 llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 7 ---
 llvm/test/MC/RISCV/option-arch.s   | 9 -
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 3f4a73ad89bf8a..80ff70f1095f4c 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2824,8 +2824,9 @@ bool RISCVAsmParser::parseDirectiveOption() {
 break;
   }
 
-  auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch);
-  if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch ||
+  std::string & = RISCVISAInfo::getTargetFeatureForExtension(Arch);
+  auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature);
+  if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature ||
   !RISCVISAInfo::isSupportedExtension(Arch)) {
 if (isDigit(Arch.back()))
   return Error(
@@ -2834,7 +2835,7 @@ bool RISCVAsmParser::parseDirectiveOption() {
 return Error(Loc, "unknown extension feature");
   }
 
-  Args.emplace_back(Type, Ext->Key);
+  Args.emplace_back(Type, Arch.str());
 
   if (Type == RISCVOptionArchArgType::Plus) {
 FeatureBitset OldFeatureBits = STI->getFeatureBits();
diff --git a/llvm/test/MC/RISCV/option-arch.s b/llvm/test/MC/RISCV/option-arch.s
index 6ee133c7159a27..40675f9e4b434b 100644
--- a/llvm/test/MC/RISCV/option-arch.s
+++ b/llvm/test/MC/RISCV/option-arch.s
@@ -1,7 +1,7 @@
 # RUN: llvm-mc -triple riscv32 -show-encoding < %s \
 # RUN:   | FileCheck -check-prefixes=CHECK %s
 # RUN: llvm-mc -triple riscv32 -filetype=obj < %s \
-# RUN:   | llvm-objdump  --triple=riscv32 --mattr=+c,+m,+a,+f,+zba -d -M 
no-aliases - \
+# RUN:   | llvm-objdump  --triple=riscv32 
--mattr=+c,+m,+a,+f,+zba,+experimental-zicfiss -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefixes=CHECK-INST %s
 
 # Test '.option arch, +' and '.option arch, -' directive
@@ -78,6 +78,13 @@ lr.w t0, (t1)
 # CHECK: encoding: [0xb3,0x22,0x73,0x20]
 sh1add t0, t1, t2
 
+# Test experimental extension
+# CHECK: .option arch, +zicfiss
+.option arch, +zicfiss
+# CHECK-INST: sspopchk ra
+# CHECK: encoding: [0x73,0xc0,0xc0,0xcd]
+sspopchk ra
+
 # Test '.option arch, ' directive
 # CHECK: .option arch, rv32i2p1_m2p0_a2p1_c2p0
 .option arch, rv32i2p1_m2p0_a2p1_c2p0

>From 471abce617a9d18ef91370303eef90bab228d9d3 Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 23 Apr 2024 21:55:12 -0700
Subject: [PATCH 2/4] Make this pr obey menable-experimental-extensions.

---
 clang/lib/Driver/ToolChains/Clang.cpp  | 5 +
 clang/test/Driver/riscv-option-arch.s  | 5 +
 llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 6 ++
 3 files changed, 16 insertions(+)
 create mode 100644 clang/test/Driver/riscv-option-arch.s

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5894a48e0e378b..8b0f523763486f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8449,6 +8449,11 @@ void ClangAs::AddRISCVTargetArgs(const ArgList ,
   CmdArgs.push_back("-mllvm");
   CmdArgs.push_back("-riscv-add-build-attributes");
   }
+
+  if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-riscv-disable-experimental-ext");
+  }
 }
 
 void ClangAs::ConstructJob(Compilation , const JobAction ,
diff --git a/clang/test/Driver/riscv-option-arch.s 
b/clang/test/Driver/riscv-option-arch.s
new file mode 100644
index 00..8ce84dd8ffe79d
--- /dev/null
+++ b/clang/test/Driver/riscv-option-arch.s
@@ -0,0 +1,5 @@
+# RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o 
/dev/null %s
+# RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck 
-check-prefixes=CHECK-ERR %s
+
+.option arch, +zicfiss
+# CHECK-ERR: Unexpected experimental extensions.
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 80ff70f1095f4c..6225e0707015fe 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -51,6 +51,9 @@ STATISTIC(RISCVNumInstrsCompressed,
 
 static cl::opt 

[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-29 Thread Alexander Richardson via cfe-commits


@@ -0,0 +1,288 @@
+// RUN: %clang_cc1 %s -triple=spirv64-unknown-unknown -fsycl-is-device 
-std=c++11 -emit-llvm -o %t.ll -O1 -disable-llvm-passes -fms-extensions 
-fstrict-vtable-pointers
+// FIXME: Assume load should not require -fstrict-vtable-pointers
+
+// RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s

arichardson wrote:

Does not need to be fixed as part of this change but would be great to 
consolidate those tests in a follow-up change.

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-29 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson commented:

Spotted one more duplicate test, otherwise looks good to me with the reworded 
TODO comment suggestion.

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-29 Thread Alexander Richardson via cfe-commits


@@ -1370,7 +1370,7 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable, 
IntrWillReturn] in {
 
 // The result of eh.typeid.for depends on the enclosing function, but inside a
 // given function it is 'const' and may be CSE'd etc.
-def int_eh_typeid_for : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrNoMem]>;
+def int_eh_typeid_for : Intrinsic<[llvm_i32_ty], [llvm_anyptr_ty], 
[IntrNoMem]>;
 
 def int_eh_return_i32 : Intrinsic<[], [llvm_i32_ty, llvm_ptr_ty]>;

arichardson wrote:

Doesn't this intrinsic need the same llvm_anyptr_ty overload?

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-29 Thread Alexander Richardson via cfe-commits


@@ -0,0 +1,288 @@
+// RUN: %clang_cc1 %s -triple=spirv64-unknown-unknown -fsycl-is-device 
-std=c++11 -emit-llvm -o %t.ll -O1 -disable-llvm-passes -fms-extensions 
-fstrict-vtable-pointers
+// FIXME: Assume load should not require -fstrict-vtable-pointers
+
+// RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s

arichardson wrote:

I really don't understand why all these different CHECK lines are here... 
Should just be a single invocation (and could pipe directly to FileCheck). 
Looks like it dates all the way back to https://reviews.llvm.org/D11859.

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-29 Thread Alexander Richardson via cfe-commits

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-29 Thread Alexander Richardson via cfe-commits


@@ -0,0 +1,288 @@
+// RUN: %clang_cc1 %s -triple=spirv64-unknown-unknown -fsycl-is-device 
-std=c++11 -emit-llvm -o %t.ll -O1 -disable-llvm-passes -fms-extensions 
-fstrict-vtable-pointers

arichardson wrote:

This test should be merged with the existing address-space.cpp test. I also 
noticed that the address space one has some missing changes compared to the 
baseline so ideally that would be merged with the base test, but can be done in 
a separate pull request.

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


[clang] 38067c5 - [C++20] [Modules] [Reduced BMI] Avoid force writing static declarations

2024-04-29 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-30T11:34:34+08:00
New Revision: 38067c50a9459caed2892e38b2ae5026a8bff8e2

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

LOG: [C++20] [Modules] [Reduced BMI] Avoid force writing static declarations
within module purview

Close https://github.com/llvm/llvm-project/issues/90259

Technically, the static declarations shouldn't be leaked from the module
interface, otherwise it is an illegal program according to the spec. So
we can get rid of the static declarations from the reduced BMI
technically. Then we can close the above issue.

However, there are too many `static inline` codes in existing headers.
So it will be a pretty big breaking change if we do this globally.

Added: 
clang/test/Modules/pr90259.cppm

Modified: 
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 0408eeb6a95b00..7db60c67d71234 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3205,6 +3205,17 @@ void ASTWriter::WriteType(QualType T) {
 // Declaration Serialization
 
//===--===//
 
+static bool IsInternalDeclFromFileContext(const Decl *D) {
+  auto *ND = dyn_cast(D);
+  if (!ND)
+return false;
+
+  if (!D->getDeclContext()->getRedeclContext()->isFileContext())
+return false;
+
+  return ND->getFormalLinkage() == Linkage::Internal;
+}
+
 /// Write the block containing all of the declaration IDs
 /// lexically declared within the given DeclContext.
 ///
@@ -3225,6 +3236,15 @@ uint64_t 
ASTWriter::WriteDeclContextLexicalBlock(ASTContext ,
 if (DoneWritingDeclsAndTypes && !wasDeclEmitted(D))
   continue;
 
+// We don't need to write decls with internal linkage into reduced BMI.
+// If such decls gets emitted due to it get used from inline functions,
+// the program illegal. However, there are too many use of static inline
+// functions in the global module fragment and it will be breaking change
+// to forbid that. So we have to allow to emit such declarations from GMF.
+if (GeneratingReducedBMI && !D->isFromExplicitGlobalModule() &&
+IsInternalDeclFromFileContext(D))
+  continue;
+
 KindDeclPairs.push_back(D->getKind());
 KindDeclPairs.push_back(GetDeclRef(D).get());
   }
@@ -3886,6 +3906,13 @@ class ASTDeclContextNameLookupTrait {
   !Writer.wasDeclEmitted(DeclForLocalLookup))
 continue;
 
+  // Try to avoid writing internal decls to reduced BMI.
+  // See comments in ASTWriter::WriteDeclContextLexicalBlock for details.
+  if (Writer.isGeneratingReducedBMI() &&
+  !DeclForLocalLookup->isFromExplicitGlobalModule() &&
+  IsInternalDeclFromFileContext(DeclForLocalLookup))
+continue;
+
   DeclIDs.push_back(Writer.GetDeclRef(DeclForLocalLookup));
 }
 return std::make_pair(Start, DeclIDs.size());
@@ -4257,6 +4284,12 @@ uint64_t 
ASTWriter::WriteDeclContextVisibleBlock(ASTContext ,
 if (DoneWritingDeclsAndTypes && !wasDeclEmitted(ND))
   continue;
 
+// We don't need to force emitting internal decls into reduced BMI.
+// See comments in ASTWriter::WriteDeclContextLexicalBlock for details.
+if (GeneratingReducedBMI && !ND->isFromExplicitGlobalModule() &&
+IsInternalDeclFromFileContext(ND))
+  continue;
+
 GetDeclRef(ND);
   }
 }
@@ -4917,8 +4950,7 @@ void ASTWriter::PrepareWritingSpecialDecls(Sema ) 
{
   // is ill-formed. However, in practice, there are a lot of projects
   // uses `static inline` in the headers. So we can't get rid of all
   // static entities in reduced BMI now.
-  if (auto *ND = dyn_cast(D);
-  ND && ND->getFormalLinkage() == Linkage::Internal)
+  if (IsInternalDeclFromFileContext(D))
 continue;
 }
 

diff  --git a/clang/test/Modules/pr90259.cppm b/clang/test/Modules/pr90259.cppm
new file mode 100644
index 00..17786998a2a729
--- /dev/null
+++ b/clang/test/Modules/pr90259.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/mod1.cppm -emit-reduced-module-interface -o 
%t/mod-mod1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/mod.cppm -fprebuilt-module-path=%t  \
+// RUN: -emit-reduced-module-interface -o %t/mod.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fprebuilt-module-path=%t -verify 
-fsyntax-only
+
+//--- mod1.cppm
+export module mod:mod1;
+namespace {
+int abc = 43;
+}
+namespace mod {
+static int def = 44;
+}
+export int f() {
+return abc + mod::def;
+}
+
+//--- mod.cppm
+// expected-no-diagnostics
+export module 

[clang] Skip over std namespace in WebKit checkers. (PR #90552)

2024-04-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes



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


4 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+6) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp (+6) 
- (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+27) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp (+26) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index ae494de58da3da..0ff1a27ff412b9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -53,6 +53,12 @@ class UncountedCallArgsChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
+  bool TraverseNamespaceDecl(NamespaceDecl *Decl) {
+if (safeGetName(Decl) == "std")
+  return true;
+return RecursiveASTVisitor::TraverseNamespaceDecl(Decl);
+  }
+
   bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) {
 if (isRefType(safeGetName(Decl)))
   return true;
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
index 6036ad58cf253c..b27400678a5790 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -134,6 +134,12 @@ class UncountedLocalVarsChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
+  bool TraverseNamespaceDecl(NamespaceDecl *Decl) {
+if (safeGetName(Decl) == "std")
+  return true;
+return RecursiveASTVisitor::TraverseNamespaceDecl(Decl);
+  }
+
   bool VisitVarDecl(VarDecl *V) {
 Checker->visitVarDecl(V);
 return true;
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index 2a4b6bb1f1063a..3a1a2f9e92289e 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -333,3 +333,30 @@ namespace cxx_member_operator_call {
 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and 
unsafe}}
   }
 }
+
+namespace std {
+
+template 
+T* other_function();
+
+template 
+void another_function(T*, T*);
+
+template 
+void some_function(T* a)
+{
+  another_function(other_function(), a);
+}
+
+} // std
+
+namespace ignore_std_namespace {
+
+RefCountable *ref_counted();
+
+void foo() {
+  std::some_function(ref_counted());
+  // expected-warning@-1{{Call argument for parameter 'a' is uncounted and 
unsafe}}
+}
+
+} // ignore_std_namespace
\ No newline at end of file
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
index 00673e91f471ea..c8550b7e2e77f1 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
@@ -187,3 +187,29 @@ void bar() {
 }
 
 } // namespace ignore_for_if
+
+namespace std {
+
+void memcpy(void*, void*, unsigned long);
+
+template 
+void some_function(T* a, T* b)
+{
+  T* temp = new T;
+  memcpy(temp, a, sizeof(T));
+  memcpy(a, b, sizeof(T));
+  memcpy(b, temp, sizeof(T));
+  delete temp;
+}
+
+} // std
+
+namespace ignore_std_namespace {
+
+RefCountable *ref_counted();
+
+void foo() {
+  std::some_function(ref_counted(), ref_counted());
+}
+
+} // ignore_std_namespace

``




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


[clang] Skip over std namespace in WebKit checkers. (PR #90552)

2024-04-29 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/90552

None

>From fa7a6e376b07ae6262dd06920c87dc69705a646d Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 29 Apr 2024 20:24:24 -0700
Subject: [PATCH] Skip over std namespace in WebKit checkers.

---
 .../WebKit/UncountedCallArgsChecker.cpp   |  6 +
 .../WebKit/UncountedLocalVarsChecker.cpp  |  6 +
 .../Analysis/Checkers/WebKit/call-args.cpp| 27 +++
 .../Checkers/WebKit/uncounted-local-vars.cpp  | 26 ++
 4 files changed, 65 insertions(+)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index ae494de58da3da..0ff1a27ff412b9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -53,6 +53,12 @@ class UncountedCallArgsChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
+  bool TraverseNamespaceDecl(NamespaceDecl *Decl) {
+if (safeGetName(Decl) == "std")
+  return true;
+return RecursiveASTVisitor::TraverseNamespaceDecl(Decl);
+  }
+
   bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) {
 if (isRefType(safeGetName(Decl)))
   return true;
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
index 6036ad58cf253c..b27400678a5790 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -134,6 +134,12 @@ class UncountedLocalVarsChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
+  bool TraverseNamespaceDecl(NamespaceDecl *Decl) {
+if (safeGetName(Decl) == "std")
+  return true;
+return RecursiveASTVisitor::TraverseNamespaceDecl(Decl);
+  }
+
   bool VisitVarDecl(VarDecl *V) {
 Checker->visitVarDecl(V);
 return true;
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index 2a4b6bb1f1063a..3a1a2f9e92289e 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -333,3 +333,30 @@ namespace cxx_member_operator_call {
 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and 
unsafe}}
   }
 }
+
+namespace std {
+
+template 
+T* other_function();
+
+template 
+void another_function(T*, T*);
+
+template 
+void some_function(T* a)
+{
+  another_function(other_function(), a);
+}
+
+} // std
+
+namespace ignore_std_namespace {
+
+RefCountable *ref_counted();
+
+void foo() {
+  std::some_function(ref_counted());
+  // expected-warning@-1{{Call argument for parameter 'a' is uncounted and 
unsafe}}
+}
+
+} // ignore_std_namespace
\ No newline at end of file
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
index 00673e91f471ea..c8550b7e2e77f1 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
@@ -187,3 +187,29 @@ void bar() {
 }
 
 } // namespace ignore_for_if
+
+namespace std {
+
+void memcpy(void*, void*, unsigned long);
+
+template 
+void some_function(T* a, T* b)
+{
+  T* temp = new T;
+  memcpy(temp, a, sizeof(T));
+  memcpy(a, b, sizeof(T));
+  memcpy(b, temp, sizeof(T));
+  delete temp;
+}
+
+} // std
+
+namespace ignore_std_namespace {
+
+RefCountable *ref_counted();
+
+void foo() {
+  std::some_function(ref_counted(), ref_counted());
+}
+
+} // ignore_std_namespace

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/90549

>From 1fac46855bf6bb3feb2e8b7a0918e61c8468ea07 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 20:01:29 -0700
Subject: [PATCH] fix build failure

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 790899486ec9d1..57d0a7f037d536 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -5,7 +5,7 @@
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
 // RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
-// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir 
%t/coro-elide-caller.o -fthinlto-index=summary.thinlto.bc -emit-llvm -o - | 
FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Chuanqi Xu via cfe-commits

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


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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Wei Wang via cfe-commits

apolloww wrote:

This should make Buildbot failure like 
https://lab.llvm.org/buildbot/#/builders/38/builds/19079 to go away

```
warning: linking module 'coro-elide-caller.o': Linking two modules of different 
target triples: 'coro-elide-callee.o' is 'x86_64-unknown-linux' whereas 
'coro-elide-caller.o' is 'hexagon-unknown-unknown-elf'
```

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-coroutines

@llvm/pr-subscribers-clang

Author: Wei Wang (apolloww)


Changes

Resolve test failure on non-x86 linux host

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


1 Files Affected:

- (modified) clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp (+1-1) 


``diff
diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 293aef6781677f..50e8648a09d450 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -5,7 +5,7 @@
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o
 // RUN: llvm-lto -thinlto coro-elide-callee.o coro-elide-caller.o -o summary
-// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

``




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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/90549

Resolve test failure on non-x86 linux host

>From 4cdba5174c49682502e65d6f10224bb2bc54f346 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 20:01:29 -0700
Subject: [PATCH] fix build failure

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 293aef6781677f..50e8648a09d450 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -5,7 +5,7 @@
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o
 // RUN: llvm-lto -thinlto coro-elide-callee.o coro-elide-caller.o -o summary
-// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Yaxun Liu via cfe-commits


@@ -424,6 +424,34 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+if (KernelFunction->hasComdat()) {
+  std::string KernelName = KernelFunction->getName().str();
+  std::string GlobalVarName = KernelName + ".id";
+
+  llvm::GlobalVariable *HandleVar =
+  CGM.getModule().getNamedGlobal(GlobalVarName);
+  if (!HandleVar) {
+HandleVar = new llvm::GlobalVariable(
+CGM.getModule(), CGM.Int8Ty,
+/*Constant=*/false, KernelFunction->getLinkage(),
+llvm::ConstantInt::get(CGM.Int8Ty, 0), GlobalVarName);
+HandleVar->setDSOLocal(KernelFunction->isDSOLocal());
+HandleVar->setVisibility(KernelFunction->getVisibility());
+HandleVar->setComdat(CGM.getModule().getOrInsertComdat(GlobalVarName));
+  }
+
+  CGF.Builder.CreateAlignedStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),

yxsamliu wrote:

will do

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


[clang] [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (PR #90467)

2024-04-29 Thread Chen Zheng via cfe-commits


@@ -111,6 +111,20 @@ vector __bool long long v_bll4;  // expected-error 
{{use of 'long long' with
 #endif
 __vector long double  vv_ld3;// expected-error {{cannot use 'long 
double' with '__vector'}}
 vector long double  v_ld4;   // expected-error {{cannot use 'long 
double' with '__vector'}}
+vector float _Complex v_cf;  // expected-error {{cannot use '_Complex' 
with '__vector'}}
+vector double _Complex v_cd; // expected-error {{cannot use '_Complex' 
with '__vector'}}
+#ifndef __VSX__
+ // expected-error@-2 {{use of 'double' 
with '__vector' requires VSX support to be enabled (available on POWER7 or 
later)}}
+#endif
+vector long double _Complex v_cld;   // expected-error {{cannot use '_Complex' 
with '__vector'}}
+ // expected-error@-1 {{cannot use 'long 
double' with '__vector'}}
+__vector float _Complex v_cf2;   // expected-error {{cannot use '_Complex' 
with '__vector'}}
+__vector double _Complex v_cd2;  // expected-error {{cannot use '_Complex' 
with '__vector'}}
+#ifndef __VSX__
+ // expected-error@-2 {{use of 'double' 
with '__vector' requires VSX support to be enabled (available on POWER7 or 
later)}}

chenzheng1030 wrote:

Error message `cannot use '_Complex' with '__vector'` sounds like good enough. 
This error message is not accurate at all?

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


[clang] [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (PR #90467)

2024-04-29 Thread Chen Zheng via cfe-commits


@@ -1191,6 +1191,10 @@ void DeclSpec::Finish(Sema , const PrintingPolicy 
) {
 
   // Validate and finalize AltiVec vector declspec.
   if (TypeAltiVecVector) {
+// Complex vector types are not supported.
+if (TypeSpecComplex != TSC_unspecified)
+  S.Diag(TSCLoc, diag::err_invalid_vector_complex_decl_spec);

chenzheng1030 wrote:

Should we stop diagnosing other errors in this function?

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


[clang] [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (PR #90467)

2024-04-29 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 commented:

Thanks very much for taking care of PPC.

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


[clang] [Clang][Sema] Do not accept "vector _Complex" for AltiVec/ZVector (PR #90467)

2024-04-29 Thread Chen Zheng via cfe-commits

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Yaxun Liu via cfe-commits


@@ -424,6 +424,34 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+if (KernelFunction->hasComdat()) {
+  std::string KernelName = KernelFunction->getName().str();

yxsamliu wrote:

will do

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Yaxun Liu via cfe-commits


@@ -424,6 +424,34 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+if (KernelFunction->hasComdat()) {

yxsamliu wrote:

will do

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


[clang] [clang] fix half && bfloat16 convert node expr codegen (PR #89051)

2024-04-29 Thread via cfe-commits

JinjinLi868 wrote:

ping  

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


[clang] [clang][CodeGen] Fix MSVC ABI for classes with non static data members of reference type (PR #90547)

2024-04-29 Thread Max Winkler via cfe-commits


@@ -1144,11 +1167,13 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
   if (!RD)
 return false;
 
-  bool isTrivialForABI = RD->canPassInRegisters() &&
- isTrivialForMSVC(RD, FI.getReturnType(), CGM);
-
   // MSVC always returns structs indirectly from C++ instance methods.
-  bool isIndirectReturn = !isTrivialForABI || FI.isInstanceMethod();
+  bool isIndirectReturn = FI.isInstanceMethod();

MaxEW707 wrote:

I intentionally moved this around to try to reduce calling `isTrivialForMSVC` 
for methods and potentially now hitting the recursive field loop I added above.
Since methods always return indirectly we can avoid all these extra checks up 
front.

Let me know if you prefer this being a separate PR.

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


[clang] [clang][CodeGen] Fix MSVC ABI for classes with non static data members of reference type (PR #90547)

2024-04-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Max Winkler (MaxEW707)


Changes

https://godbolt.org/z/verKj4cnj for reference.
https://godbolt.org/z/z3W9v7o4n for reference.

For global functions and static methods the MSVC ABI returns structs/classes 
with a reference type non static data member indirectly.
>From local testing this is recursively applied to any inner structs/classes.
>From local testing this ABI holds true for all currently support architectures 
>including ARM64EC.

I tested locally against MSVC 1939 and MSVC 1929.

The only reference I could find on MSDN to this ABI constraint is this quote, 
"and no non-static data members of reference type", 
[here](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values).

Pointer fields do not exhibit this behaviour.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+31-6) 
- (added) clang/test/CodeGen/x64-microsoft-arguments.cpp (+64) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4aedfafcb26aea..8f228bb4d296e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -63,6 +63,9 @@ ABI Changes in This Version
   MSVC uses a different mangling for these objects, compatibility is not 
affected.
   (#GH85423).
 
+- Fixed Microsoft calling convention when returning classes that have a 
reference type
+  as a field. Such a class should be returned indirectly.
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d38a26940a3cb6..b0798550ba9775 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1103,8 +1103,27 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl 
GD) const {
   return isDeletingDtor(GD);
 }
 
+static bool fieldIsTrivialForMSVC(const FieldDecl *Field,
+  const ASTContext ) {
+  if (Field->getType()->isReferenceType())
+return false;
+
+  const RecordType *RT =
+  Context.getBaseElementType(Field->getType())->getAs();
+  if (!RT)
+return true;
+
+  CXXRecordDecl *RD = cast(RT->getDecl());
+
+  for (const FieldDecl *RDField : RD->fields())
+if (!fieldIsTrivialForMSVC(RDField, Context))
+  return false;
+
+  return true;
+}
+
 static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
- CodeGenModule ) {
+ CodeGenModule , const ASTContext ) {
   // On AArch64, HVAs that can be passed in registers can also be returned
   // in registers. (Note this is using the MSVC definition of an HVA; see
   // isPermittedToBeHomogeneousAggregate().)
@@ -1122,7 +1141,8 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, 
QualType Ty,
   //   No base classes
   //   No virtual functions
   // Additionally, we need to ensure that there is a trivial copy assignment
-  // operator, a trivial destructor and no user-provided constructors.
+  // operator, a trivial destructor, no user-provided constructors and no
+  // non static data members of reference type.
   if (RD->hasProtectedFields() || RD->hasPrivateFields())
 return false;
   if (RD->getNumBases() > 0)
@@ -1136,6 +1156,9 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, 
QualType Ty,
   return false;
   if (RD->hasNonTrivialDestructor())
 return false;
+  for (const FieldDecl *Field : RD->fields())
+if (!fieldIsTrivialForMSVC(Field, Context))
+  return false;
   return true;
 }
 
@@ -1144,11 +1167,13 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
   if (!RD)
 return false;
 
-  bool isTrivialForABI = RD->canPassInRegisters() &&
- isTrivialForMSVC(RD, FI.getReturnType(), CGM);
-
   // MSVC always returns structs indirectly from C++ instance methods.
-  bool isIndirectReturn = !isTrivialForABI || FI.isInstanceMethod();
+  bool isIndirectReturn = FI.isInstanceMethod();
+  if (!isIndirectReturn) {
+isIndirectReturn =
+!(RD->canPassInRegisters() &&
+  isTrivialForMSVC(RD, FI.getReturnType(), CGM, getContext()));
+  }
 
   if (isIndirectReturn) {
 CharUnits Align = CGM.getContext().getTypeAlignInChars(FI.getReturnType());
diff --git a/clang/test/CodeGen/x64-microsoft-arguments.cpp 
b/clang/test/CodeGen/x64-microsoft-arguments.cpp
new file mode 100644
index 00..9e89b59924ae49
--- /dev/null
+++ b/clang/test/CodeGen/x64-microsoft-arguments.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -ffreestanding -emit-llvm -O0 \
+// RUN: -x c++ -o - %s | FileCheck %s
+
+int global_i = 0;
+
+// Pass and return object with a reference type (pass directly, return 
indirectly).
+// CHECK: define dso_local void @"?f1@@YA?AUS1@@XZ"(ptr 

[clang] [clang][CodeGen] Fix MSVC ABI for classes with non static data members of reference type (PR #90547)

2024-04-29 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 created 
https://github.com/llvm/llvm-project/pull/90547

https://godbolt.org/z/verKj4cnj for reference.
https://godbolt.org/z/z3W9v7o4n for reference.

For global functions and static methods the MSVC ABI returns structs/classes 
with a reference type non static data member indirectly.
>From local testing this is recursively applied to any inner structs/classes.
>From local testing this ABI holds true for all currently support architectures 
>including ARM64EC.

I tested locally against MSVC 1939 and MSVC 1929.

The only reference I could find on MSDN to this ABI constraint is this quote, 
"and no non-static data members of reference type", 
[here](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values).

Pointer fields do not exhibit this behaviour.

>From cafb799de05af9197891de4dbf451b10cc26df65 Mon Sep 17 00:00:00 2001
From: MaxEW707 
Date: Mon, 29 Apr 2024 22:09:52 -0400
Subject: [PATCH] [clang][CodeGen] Fix MS ABI for classes with non static data
 members of reference type

---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 37 +--
 .../test/CodeGen/x64-microsoft-arguments.cpp  | 64 +++
 3 files changed, 98 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/x64-microsoft-arguments.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4aedfafcb26aea..8f228bb4d296e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -63,6 +63,9 @@ ABI Changes in This Version
   MSVC uses a different mangling for these objects, compatibility is not 
affected.
   (#GH85423).
 
+- Fixed Microsoft calling convention when returning classes that have a 
reference type
+  as a field. Such a class should be returned indirectly.
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d38a26940a3cb6..b0798550ba9775 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1103,8 +1103,27 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl 
GD) const {
   return isDeletingDtor(GD);
 }
 
+static bool fieldIsTrivialForMSVC(const FieldDecl *Field,
+  const ASTContext ) {
+  if (Field->getType()->isReferenceType())
+return false;
+
+  const RecordType *RT =
+  Context.getBaseElementType(Field->getType())->getAs();
+  if (!RT)
+return true;
+
+  CXXRecordDecl *RD = cast(RT->getDecl());
+
+  for (const FieldDecl *RDField : RD->fields())
+if (!fieldIsTrivialForMSVC(RDField, Context))
+  return false;
+
+  return true;
+}
+
 static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
- CodeGenModule ) {
+ CodeGenModule , const ASTContext ) {
   // On AArch64, HVAs that can be passed in registers can also be returned
   // in registers. (Note this is using the MSVC definition of an HVA; see
   // isPermittedToBeHomogeneousAggregate().)
@@ -1122,7 +1141,8 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, 
QualType Ty,
   //   No base classes
   //   No virtual functions
   // Additionally, we need to ensure that there is a trivial copy assignment
-  // operator, a trivial destructor and no user-provided constructors.
+  // operator, a trivial destructor, no user-provided constructors and no
+  // non static data members of reference type.
   if (RD->hasProtectedFields() || RD->hasPrivateFields())
 return false;
   if (RD->getNumBases() > 0)
@@ -1136,6 +1156,9 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, 
QualType Ty,
   return false;
   if (RD->hasNonTrivialDestructor())
 return false;
+  for (const FieldDecl *Field : RD->fields())
+if (!fieldIsTrivialForMSVC(Field, Context))
+  return false;
   return true;
 }
 
@@ -1144,11 +1167,13 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
) const {
   if (!RD)
 return false;
 
-  bool isTrivialForABI = RD->canPassInRegisters() &&
- isTrivialForMSVC(RD, FI.getReturnType(), CGM);
-
   // MSVC always returns structs indirectly from C++ instance methods.
-  bool isIndirectReturn = !isTrivialForABI || FI.isInstanceMethod();
+  bool isIndirectReturn = FI.isInstanceMethod();
+  if (!isIndirectReturn) {
+isIndirectReturn =
+!(RD->canPassInRegisters() &&
+  isTrivialForMSVC(RD, FI.getReturnType(), CGM, getContext()));
+  }
 
   if (isIndirectReturn) {
 CharUnits Align = CGM.getContext().getTypeAlignInChars(FI.getReturnType());
diff --git a/clang/test/CodeGen/x64-microsoft-arguments.cpp 
b/clang/test/CodeGen/x64-microsoft-arguments.cpp
new file mode 100644
index 00..9e89b59924ae49
--- /dev/null
+++ b/clang/test/CodeGen/x64-microsoft-arguments.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -triple 

[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-29 Thread Chuanqi Xu via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

ChuanqiXu9 wrote:

> Also, maybe this would become moot if we address 
> https://discourse.llvm.org/t/coro-pre-split-handling-of-the-suspend-edge/75043
>  like @jyknight suggested (i.e. not even have the misleading edge)?

But IIRC, it is still possible that we'll have code inserted between 
`llvm.coro.await.suspend.{.*}` and `llvm.coro.suspend`, which is the problem 
we're discussing.

> Sorry for insisting on this, it's maybe because I got "bitten" before (with 
> the suspend), but what other examples do we have where, silently, 
> instructions don't get executed after a call?

If I read correctly, @zmodem said he'd like to mention this in the doc or check 
it by assertions or verifiers. So it looks consensus to me?

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-29 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From 03266b74d973075eb5dfa27f32bb9c1bb75d73f9 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Mon, 29 Apr 2024 16:46:31 -0700
Subject: [PATCH 1/3] [BoundsSafety] Allow 'counted_by' attribute on pointers
 in structs in C

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointers
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

This patch also introduces late parsing of the attribute when used
in the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on pointers this now allows the possiblity of
writing the attribute in the type attribute position. For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

This work in based on a patch originally written by Yeoul Na.

rdar://125400257
---
 clang/docs/ReleaseNotes.rst   |  19 +-
 clang/include/clang/AST/Type.h|   1 +
 clang/include/clang/Basic/Attr.td |   3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +-
 clang/include/clang/Parse/Parser.h|  11 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/AST/Type.cpp|  12 ++
 clang/lib/Parse/ParseDecl.cpp | 112 +++-
 clang/lib/Parse/ParseObjc.cpp |   6 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  71 ++--
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/AST/attr-counted-by-late-parsed.c  |  31 
 .../Sema/attr-counted-by-late-parsed-off.c|  26 +++
 .../attr-counted-by-late-parsed-struct-ptrs.c | 169 ++
 ...tr-counted-by-struct-ptrs-sizeless-types.c |  17 ++
 clang/test/Sema/attr-counted-by-struct-ptrs.c | 163 +
 clang/test/Sema/attr-counted-by.c |   5 +-
 18 files changed, 636 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-off.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..81d0a89b294878 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,7 +258,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attributes`` enables an experimental feature to
   allow late parsing certain attributes in specific contexts where they would
-  not normally be late parsed.
+  not normally be late parsed. Currently this allows late parsing the
+  `counted_by` attribute in C. See `Attribute Changes in Clang`_.
 
 Deprecated Compiler Flags
 -
@@ -335,6 +336,22 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``counted_by`` attribute can now be late parsed in C when
+  ``-fexperimental-late-parse-attributes`` is passed but only when attribute is
+  used in the declaration attribute position. This allows using the
+  attribute on existing code where it previously impossible to do so without
+  re-ordering struct field declarations would break ABI as shown below.
+
+  .. code-block:: c
+
+ struct BufferTy {
+   /* Refering to `count` requires late parsing */
+   char* buffer __counted_by(count);
+   /* Swapping `buffer` and `count` to avoid late parsing would break ABI 
*/
+   size_t count;
+ };
+
+
 Improvements to Clang's diagnostics
 

[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-29 Thread Dan Liew via cfe-commits

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


[clang] b1867e1 - [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (#88596)

2024-04-29 Thread via cfe-commits

Author: Dan Liew
Date: 2024-04-29T18:37:47-07:00
New Revision: b1867e18c346e9621e14270bea2d1acb7d2a9ce0

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

LOG: [Attributes] Support Attributes being declared as supporting an 
experimental late parsing mode "extension" (#88596)

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be
an instantiation of the new `LateAttrParseKind` class. The instation can be one 
of the following:

* `LateAttrParsingNever` - Corresponds with the false value of `LateParsed` 
prior to this patch (the default for an attribute).
* `LateAttrParseStandard` - Corresponds with the true value of `LateParsed` 
prior to this patch.
* `LateAttrParseExperimentalExt` - A new mode described below.

`LateAttrParseExperimentalExt` is an experimental extension to
`LateAttrParseStandard`. Essentially this allows
`Parser::ParseGNUAttributes(...)` to distinguish between these cases:

1. Only `LateAttrParseExperimentalExt` attributes should be late parsed.
2. Both `LateAttrParseExperimentalExt` and `LateAttrParseStandard`
  attributes should be late parsed.

Callers (and indirect callers) of `Parser::ParseGNUAttributes(...)`
indicate the desired behavior by setting a flag in the
`LateParsedAttrList` object that is passed to the function.

In addition to the above, a new driver and frontend flag
(`-fexperimental-late-parse-attributes`) with a corresponding LangOpt
(`ExperimentalLateParseAttributes`) is added that changes how
`LateAttrParseExperimentalExt` attributes are parsed.

* When the flag is disabled (default), in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be parsed immediately (i.e. **NOT** late parsed). This
  allows the attribute to act just like a `LateAttrParseStandard`
  attribute when the flag is disabled.

* When the flag is enabled, in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be late parsed.

The motivation behind this change is to allow the new `counted_by`
attribute (part of `-fbounds-safety`) to support late parsing but
**only** when `-fexperimental-late-parse-attributes` is enabled. This
attribute needs to support late parsing to allow it to refer to fields
later in a struct definition (or function parameters declared later).
However, there isn't a precedent for supporting late attribute parsing
in C so this flag allows the new behavior to exist in Clang but not be
on by default. This behavior was requested as part of the
`-fbounds-safety` RFC process
(https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

This patch doesn't introduce any uses of `LateAttrParseExperimentalExt`.
This will be added for the `counted_by` attribute in a future patch
(https://github.com/llvm/llvm-project/pull/87596). A consequence is the
new behavior added in this patch is not yet testable. Hence, the lack of
tests covering the new behavior.

rdar://125400257

Added: 
clang/test/Driver/experimental-late-parse-attributes.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Parse/Parser.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Parse/ParseDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 676f38a8e94c81..4c0fe5bcf6b122 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -256,6 +256,10 @@ New Compiler Flags
 - ``-fexperimental-modules-reduced-bmi`` enables the Reduced BMI for C++20 
named modules.
   See the document of standard C++ modules for details.
 
+- ``-fexperimental-late-parse-attributes`` enables an experimental feature to
+  allow late parsing certain attributes in specific contexts where they would
+  not normally be late parsed.
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 97e06fe7d2e6aa..0225598cbbe8ad 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,49 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Enumeration specifying what kind of behavior should be used for late
+// parsing of attributes.
+class LateAttrParseKind  {
+  int Kind = val;
+}
+
+// Never late parsed
+def LateAttrParseNever : LateAttrParseKind<0>;
+
+// Standard late attribute parsing
+//
+// This is language dependent. For example:
+//
+// * For C++ enables late parsing of a declaration attributes
+// * For C does not enable late parsing 

[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-29 Thread Dan Liew via cfe-commits

delcypher wrote:

@erichkeane Thanks for approving. I'll rebase, check this builds and then land 
this.

@AaronBallman When you're back please let me know if there's any follow up 
changes you want.

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


[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-29 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/88596

>From 07ab74ac8829e6c3e4365e1a87148d21800437d3 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Tue, 23 Apr 2024 14:57:46 -0700
Subject: [PATCH] [Attributes] Support Attributes being declared as supporting
 an experimental late parsing mode "extension"

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be
an instantiation of the new `LateAttrParseKind` class. The instation can be one 
of the following:

* `LateAttrParsingNever` - Corresponds with the false value of `LateParsed` 
prior to this patch (the default for an attribute).
* `LateAttrParseStandard` - Corresponds with the true value of `LateParsed` 
prior to this patch.
* `LateAttrParseExperimentalExt` - A new mode described below.

`LateAttrParseExperimentalExt` is an experimental extension to
`LateAttrParseStandard`. Essentially this allows
`Parser::ParseGNUAttributes(...)` to distinguish between these cases:

1. Only `LateAttrParseExperimentalExt` attributes should be late parsed.
2. Both `LateAttrParseExperimentalExt` and `LateAttrParseStandard`
  attributes should be late parsed.

Callers (and indirect callers) of `Parser::ParseGNUAttributes(...)`
indicate the desired behavior by setting a flag in the
`LateParsedAttrList` object that is passed to the function.

In addition to the above, a new driver and frontend flag
(`-fexperimental-late-parse-attributes`) with a corresponding LangOpt
(`ExperimentalLateParseAttributes`) is added that changes how
`LateAttrParseExperimentalExt` attributes are parsed.

* When the flag is disabled (default), in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be parsed immediately (i.e. **NOT** late parsed). This
  allows the attribute to act just like a `LateAttrParseStandard`
  attribute when the flag is disabled.

* When the flag is enabled, in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be late parsed.

The motivation behind this change is to allow the new `counted_by`
attribute (part of `-fbounds-safety`) to support late parsing but
**only** when `-fexperimental-late-parse-attributes` is enabled. This
attribute needs to support late parsing to allow it to refer to fields
later in a struct definition (or function parameters declared later).
However, there isn't a precedent for supporting late attribute parsing
in C so this flag allows the new behavior to exist in Clang but not be
on by default. This behavior was requested as part of the
`-fbounds-safety` RFC process
(https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

This patch doesn't introduce any uses of `LateAttrParseExperimentalExt`.
This will be added for the `counted_by` attribute in a future patch
(https://github.com/llvm/llvm-project/pull/87596). A consequence is the
new behavior added in this patch is not yet testable. Hence, the lack of
tests covering the new behavior.

rdar://125400257
---
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/include/clang/Basic/Attr.td |  79 +++---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Parse/Parser.h|  13 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Parse/ParseDecl.cpp |  40 -
 .../experimental-late-parse-attributes.c  |  12 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 137 --
 9 files changed, 254 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/Driver/experimental-late-parse-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 676f38a8e94c81..4c0fe5bcf6b122 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -256,6 +256,10 @@ New Compiler Flags
 - ``-fexperimental-modules-reduced-bmi`` enables the Reduced BMI for C++20 
named modules.
   See the document of standard C++ modules for details.
 
+- ``-fexperimental-late-parse-attributes`` enables an experimental feature to
+  allow late parsing certain attributes in specific contexts where they would
+  not normally be late parsed.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 97e06fe7d2e6aa..0225598cbbe8ad 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,49 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Enumeration specifying what kind of behavior should be used for late
+// parsing of attributes.
+class LateAttrParseKind  {
+  int Kind = val;
+}
+
+// Never late parsed
+def LateAttrParseNever : LateAttrParseKind<0>;
+
+// Standard late attribute parsing
+//
+// This is language dependent. For example:
+//
+// * For C++ enables 

[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-29 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From b859cf056df24daa85f3fd305ef56f32e0f266ed Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Fri, 12 Apr 2024 17:36:19 -0700
Subject: [PATCH 1/4] [Attributes] Support Attributes being declared as
 supporting an experimental late parsing mode "extension"

This patch changes the `LateParsed` field of `Attr` in `Attr.td` to be
an instantiation of the new `LateAttrParseKind` class. The instation can be one 
of the following:

* `LateAttrParsingNever` - Corresponds with the false value of `LateParsed` 
prior to this patch (the default for an attribute).
* `LateAttrParseStandard` - Corresponds with the true value of `LateParsed` 
prior to this patch.
* `LateAttrParseExperimentalExt` - A new mode described below.

`LateAttrParseExperimentalExt` is an experimental extension to
`LateAttrParseStandard`. Essentially this allows
`Parser::ParseGNUAttributes(...)` to distinguish between these cases:

1. Only `LateAttrParseExperimentalExt` attributes should be late parsed.
2. Both `LateAttrParseExperimentalExt` and `LateAttrParseStandard`
  attributes should be late parsed.

Callers (and indirect callers) of `Parser::ParseGNUAttributes(...)`
indicate the desired behavior by setting a flag in the
`LateParsedAttrList` object that is passed to the function.

In addition to the above, a new driver and frontend flag
(`-fexperimental-late-parse-attributes`) with a corresponding LangOpt
(`ExperimentalLateParseAttributes`) is added that changes how
`LateAttrParseExperimentalExt` attributes are parsed.

* When the flag is disabled (default), in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be parsed immediately (i.e. **NOT** late parsed). This
  allows the attribute to act just like a `LateAttrParseStandard`
  attribute when the flag is disabled.

* When the flag is enabled, in cases where only
  `LateAttrParsingExperimentalOnly` late parsing is requested, the
  attribute will be late parsed.

The motivation behind this change is to allow the new `counted_by`
attribute (part of `-fbounds-safety`) to support late parsing but
**only** when `-fexperimental-late-parse-attributes` is enabled. This
attribute needs to support late parsing to allow it to refer to fields
later in a struct definition (or function parameters declared later).
However, there isn't a precedent for supporting late attribute parsing
in C so this flag allows the new behavior to exist in Clang but not be
on by default. This behavior was requested as part of the
`-fbounds-safety` RFC process
(https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854/68).

This patch doesn't introduce any uses of `LateAttrParseExperimentalExt`.
This will be added for the `counted_by` attribute in a future patch
(https://github.com/llvm/llvm-project/pull/87596). A consequence is the
new behavior added in this patch is not yet testable. Hence, the lack of
tests covering the new behavior.

rdar://125400257
---
 clang/include/clang/Basic/Attr.td |  78 +++---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Parse/Parser.h|  15 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Parse/ParseDecl.cpp |  42 +-
 .../experimental-late-parse-attributes.c  |  12 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 136 +++---
 8 files changed, 251 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/Driver/experimental-late-parse-attributes.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..0df80118286c89 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -592,6 +592,48 @@ class AttrSubjectMatcherAggregateRule 
{
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule;
 
+// Late Attribute parsing mode enum
+class LateAttrParseKind  {
+  int Kind = val;
+}
+
+// Never late parsed
+def LateAttrParseNever : LateAttrParseKind<0>;
+
+// Standard late attribute parsing
+//
+// This is language dependent. For example:
+//
+// * For C++ enables late parsing of a declaration attributes
+// * For C does not enable late parsing of attributes
+//
+def LateAttrParseStandard: LateAttrParseKind<1>;
+
+// Experimental extension to standard late attribute parsing
+//
+// This extension behaves like `LateAttrParseStandard` but allows
+// late parsing attributes in more contexts.
+//
+// In contexts where `LateAttrParseStandard` attributes are late
+// parsed, `LateAttrParseExperimentalExt` attributes will also
+// be late parsed.
+//
+// In contexts that only late parse `LateAttrParseExperimentalExt` attributes
+// (see `LateParsedAttrList::lateAttrParseExperimentalExtOnly()`)
+//
+// * If `-fexperimental-late-parse-attributes`
+//   

[clang] [llvm] [x86] Add tan intrinsic part 4 (PR #90503)

2024-04-29 Thread Craig Topper via cfe-commits


@@ -654,6 +655,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine 
,
   setOperationAction(ISD::FSIN   , VT, Expand);
   setOperationAction(ISD::FCOS   , VT, Expand);
   setOperationAction(ISD::FSINCOS, VT, Expand);
+  setOperationAction(ISD::FTAN, VT, Expand);

topperc wrote:

I want to tell you to match the existing code that uses extra spaces to keep 
things in columns, but I guess clang-format will complain.

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


[clang] [Clang] Implement P2809: Trivial infinite loops are not Undefined Behavior (PR #90066)

2024-04-29 Thread via cfe-commits

yronglin wrote:

I'd like to add the test case from the paper:

```
#include 

int main() {
  while (true)
; 
}

void unreachable() {
  std::cout << "Hello world!" << std::endl;
}
```

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


[clang] [llvm] Implement resource binding type prefix mismatch errors (PR #87578)

2024-04-29 Thread Tex Riddell via cfe-commits


@@ -44,7 +44,7 @@ void foo2() {
   // expected-warning@+1 {{'register' attribute only applies to 
cbuffer/tbuffer and external global variables}}
   extern RWBuffer U2 : register(u5);
 }
-// FIXME: expect-error once fix 
https://github.com/llvm/llvm-project/issues/57886.
+// expected-error@+1 {{invalid register name prefix 'u' for 'float' (expected 
't')}}

tex3d wrote:

We should consider deprecating the register binding of this style: `float b : 
register(c0);`, since it's not supported by DXC, and was only supported by FXC 
for DX9 targets.  Register binding should only be applicable to global 
resource/sampler declarations and cbuffer/tbuffer declarations.  So the answer 
to "what prefix should that be" is: we don't support register bindings on 
values that go into the constant buffer, so there is no valid prefix to use 
here.  The closest equivalent to these legacy register bindings that we do 
support are `packoffset` annotations.

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


[clang] [llvm] [x86] Add tan intrinsic part 4 (PR #90503)

2024-04-29 Thread Farzon Lotfi via cfe-commits


@@ -674,6 +674,9 @@
 # DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
 # DEBUG-NEXT: .. the first uncovered type index: 1, OK
 # DEBUG-NEXT: .. the first uncovered imm index: 0, OK
+# DEBUG-NEXT: G_FTAN (opcode {{[0-9]+}}): 1 type index, 0 imm indices

farzonl wrote:

I know. There is no way to do a `G_FTAN` that isn't exposed across all 
backends. 

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


[clang] [llvm] Implement resource binding type prefix mismatch errors (PR #87578)

2024-04-29 Thread Joshua Batista via cfe-commits


@@ -44,7 +44,7 @@ void foo2() {
   // expected-warning@+1 {{'register' attribute only applies to 
cbuffer/tbuffer and external global variables}}
   extern RWBuffer U2 : register(u5);
 }
-// FIXME: expect-error once fix 
https://github.com/llvm/llvm-project/issues/57886.
+// expected-error@+1 {{invalid register name prefix 'u' for 'float' (expected 
't')}}

bob80905 wrote:

According to @tex3d 's comment, the ` expected 'b', 'c', or 'i' binding` is no 
longer supported, so I don't think I should weave that into this 
implementation. I did ask what we should expect the prefix to be, but I haven't 
received an answer yet. Sounds to me like you think it should be 'b', because 
it's a constant inside a CBuffer?

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


[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-04-29 Thread Bill Wendling via cfe-commits

bwendling wrote:

Another ping...

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


[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

2024-04-29 Thread Shafik Yaghmour via cfe-commits


@@ -67,6 +68,69 @@ void B::g() requires true;
 
 } // namespace cwg2847
 
+namespace cwg2851 { // cwg2851: 19
+
+#if __cplusplus >= 202002L
+template struct Val { static constexpr T value = v; };
+
+
+// Floating-point promotions
+
+static_assert(Val::value == 0.0L);
+static_assert(Val::value == 0.0L);
+static_assert(Val::value == 0.0);
+static_assert(Val::value == -0.0L);
+
+static_assert(!__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val(__builtin_nanf(""))>));
+static_assert(__is_same(Val, Val(__builtin_nansf(""))>));
+static_assert(__is_same(Val, Val(__builtin_nanf("0x1"))>));
+static_assert(__is_same(Val, Val(__builtin_nansf("0x1"))>));
+
+
+// Floating-point conversions where the source value can be represented 
exactly in the destination type
+
+static_assert(Val::value == 0.0L);
+static_assert(__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+static_assert(!__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val));
+Val _1;
+// since-cxx20-error-re@-1 {{non-type template argument evaluates to {{.+}} 
which cannot be exactly represented in type 'float'}}
+Val(__FLT_DENORM_MIN__) / 2.0L> _2;
+// since-cxx20-error-re@-1 {{non-type template argument evaluates to {{.+}} 
which cannot be exactly represented in type 'float'}}
+Val _3;
+// since-cxx20-error-re@-1 {{non-type template argument evaluates to {{.+}} 
which cannot be exactly represented in type 'float'}}
+
+static_assert(__is_same(Val, Val));
+
+static_assert(__is_same(Val, Val(__builtin_nanl(""))>));
+static_assert(__is_same(Val, Val(__builtin_nansl(""))>));
+#if __SIZEOF_LONG_DOUBLE__ > 8
+// since-cxx20-error@-2 {{non-type template argument evaluates to nan which 
cannot be exactly represented in type 'float'}}
+#endif
+// Payload is shifted right so these payloads will be preserved
+static_assert(__is_same(Val, Val(__builtin_nan("0xFF"))>));
+static_assert(__is_same(Val, Val(__builtin_nans("0xFF"))>));
+static_assert(__is_same(Val, Val(__builtin_nanl("0x1"))>));

shafik wrote:

Why does `nanl` fail but `nans` does not? I am not sure this is consistent with 
[CWG2864](https://cplusplus.github.io/CWG/issues/2864.html), which is not final 
yet either.

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


[clang] 1cb3371 - Ensure test writes objects to test temp dir

2024-04-29 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2024-04-29T23:50:18Z
New Revision: 1cb33713910501c6352d0eb2a15b7a15e6e18695

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

LOG: Ensure test writes objects to test temp dir

Added: 


Modified: 
clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

Removed: 




diff  --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 293aef6781677f..790899486ec9d1 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -2,10 +2,10 @@
 // This test is adapted from coro-elide.cpp and splits functions into two 
files.
 //
 // RUN: split-file %s %t
-// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
-// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o
-// RUN: llvm-lto -thinlto coro-elide-callee.o coro-elide-caller.o -o summary
-// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
+// RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
+// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once



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


[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits


@@ -0,0 +1,1026 @@
+//===-- ExpandVariadicsPass.cpp *- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is an optimization pass for variadic functions. If called from codegen,
+// it can serve as the implementation of variadic functions for a given target.
+//
+// The strategy is to turn the ... part of a varidic function into a va_list
+// and fix up the call sites. This is completely effective if the calling
+// convention can declare that to be the right thing, e.g. on GPUs or where
+// the application is wholly statically linked. In the usual case, it will
+// replace known calls to known variadic functions with calls that are amenable
+// to inlining and other optimisations.
+//
+// The target-dependent parts are in class VariadicABIInfo. Enabling a new
+// target means adding a case to VariadicABIInfo::create() along with tests.
+// This will be especially simple if the va_list representation is a char*.
+//
+// The majority of the plumbing is splitting the variadic function into a
+// single basic block that packs the variadic arguments into a va_list and
+// a second function that does the work of the original. The target specific
+// part is packing arguments into a contiguous buffer that the clang expansion
+// of va_arg will do the right thing with.
+//
+// The aggregate effect is to unblock other transforms, most critically the
+// general purpose inliner. Known calls to variadic functions become zero cost.
+//
+// Consistency with clang is primarily tested by emitting va_arg using clang
+// then expanding the variadic functions using this pass, followed by trying
+// to constant fold the functions to no-ops.
+//
+// Target specific behaviour is tested in IR - mainly checking that values are
+// put into positions in call frames that make sense for that particular 
target.
+//
+//===--===//
+
+#include "llvm/Transforms/IPO/ExpandVariadics.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
+
+#define DEBUG_TYPE "expand-variadics"
+
+using namespace llvm;
+
+cl::opt ExpandVariadicsModeOption(
+DEBUG_TYPE "-override", cl::desc("Override the behaviour of " DEBUG_TYPE),
+cl::init(ExpandVariadicsMode::Unspecified),
+cl::values(clEnumValN(ExpandVariadicsMode::Unspecified, "unspecified",
+  "Use the implementation defaults"),
+   clEnumValN(ExpandVariadicsMode::Disable, "disable",
+  "Disable the pass entirely"),
+   clEnumValN(ExpandVariadicsMode::Optimize, "optimize",
+  "Optimise without changing ABI"),
+   clEnumValN(ExpandVariadicsMode::Lowering, "lowering",
+  "Change variadic calling convention")));
+
+namespace {
+
+// At present Intrinsic:: has no interface to test if a declaration is in the
+// module without creating one. Inserting a declaration and then testing if it
+// has any uses and then deleting it seems a bad way to do the query.
+// Module implements getFunction() which returns nullptr on missing declaration
+// and getOrInsertFunction which creates one when absent. Intrinsics.h
+// implements getDeclaration which creates one when missing. This should be
+// changed to be consistent with Module()'s naming. Implementing as a local
+// function here in the meantime to decouple from that process.
+Function *getPreexistingDeclaration(Module *M, Intrinsic::ID id,
+ArrayRef Tys = std::nullopt) {
+  auto *FT = Intrinsic::getType(M->getContext(), id, Tys);
+  return M->getFunction(Tys.empty() ? Intrinsic::getName(id)
+: Intrinsic::getName(id, Tys, M, FT));
+}
+
+// Lots of targets use a void* pointed at a buffer for va_list.
+// Some use more complicated iterator constructs. Type erase that
+// so the rest of the pass can operation on either.
+// Virtual functions where different targets want different behaviour,
+// normal where all implemented targets presently have the same.
+struct VAListInterface {
+  virtual ~VAListInterface() {}
+
+  // Whether a valist instance is passed by value or by address
+  // I.e. does it need to be alloca'ed and stored into, or can
+  // it be passed directly in a SSA 

[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits


@@ -0,0 +1,1026 @@
+//===-- ExpandVariadicsPass.cpp *- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is an optimization pass for variadic functions. If called from codegen,
+// it can serve as the implementation of variadic functions for a given target.
+//
+// The strategy is to turn the ... part of a varidic function into a va_list
+// and fix up the call sites. This is completely effective if the calling
+// convention can declare that to be the right thing, e.g. on GPUs or where
+// the application is wholly statically linked. In the usual case, it will
+// replace known calls to known variadic functions with calls that are amenable
+// to inlining and other optimisations.
+//
+// The target-dependent parts are in class VariadicABIInfo. Enabling a new
+// target means adding a case to VariadicABIInfo::create() along with tests.
+// This will be especially simple if the va_list representation is a char*.
+//
+// The majority of the plumbing is splitting the variadic function into a
+// single basic block that packs the variadic arguments into a va_list and
+// a second function that does the work of the original. The target specific
+// part is packing arguments into a contiguous buffer that the clang expansion
+// of va_arg will do the right thing with.
+//
+// The aggregate effect is to unblock other transforms, most critically the
+// general purpose inliner. Known calls to variadic functions become zero cost.
+//
+// Consistency with clang is primarily tested by emitting va_arg using clang
+// then expanding the variadic functions using this pass, followed by trying
+// to constant fold the functions to no-ops.
+//
+// Target specific behaviour is tested in IR - mainly checking that values are
+// put into positions in call frames that make sense for that particular 
target.
+//
+//===--===//
+
+#include "llvm/Transforms/IPO/ExpandVariadics.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
+
+#define DEBUG_TYPE "expand-variadics"
+
+using namespace llvm;
+
+cl::opt ExpandVariadicsModeOption(
+DEBUG_TYPE "-override", cl::desc("Override the behaviour of " DEBUG_TYPE),
+cl::init(ExpandVariadicsMode::Unspecified),
+cl::values(clEnumValN(ExpandVariadicsMode::Unspecified, "unspecified",
+  "Use the implementation defaults"),
+   clEnumValN(ExpandVariadicsMode::Disable, "disable",
+  "Disable the pass entirely"),
+   clEnumValN(ExpandVariadicsMode::Optimize, "optimize",
+  "Optimise without changing ABI"),
+   clEnumValN(ExpandVariadicsMode::Lowering, "lowering",
+  "Change variadic calling convention")));
+
+namespace {
+
+// At present Intrinsic:: has no interface to test if a declaration is in the
+// module without creating one. Inserting a declaration and then testing if it
+// has any uses and then deleting it seems a bad way to do the query.
+// Module implements getFunction() which returns nullptr on missing declaration
+// and getOrInsertFunction which creates one when absent. Intrinsics.h
+// implements getDeclaration which creates one when missing. This should be
+// changed to be consistent with Module()'s naming. Implementing as a local
+// function here in the meantime to decouple from that process.
+Function *getPreexistingDeclaration(Module *M, Intrinsic::ID id,
+ArrayRef Tys = std::nullopt) {
+  auto *FT = Intrinsic::getType(M->getContext(), id, Tys);
+  return M->getFunction(Tys.empty() ? Intrinsic::getName(id)
+: Intrinsic::getName(id, Tys, M, FT));
+}
+
+// Lots of targets use a void* pointed at a buffer for va_list.
+// Some use more complicated iterator constructs. Type erase that
+// so the rest of the pass can operation on either.
+// Virtual functions where different targets want different behaviour,
+// normal where all implemented targets presently have the same.
+struct VAListInterface {
+  virtual ~VAListInterface() {}
+
+  // Whether a valist instance is passed by value or by address
+  // I.e. does it need to be alloca'ed and stored into, or can
+  // it be passed directly in a SSA 

[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits


@@ -0,0 +1,1026 @@
+//===-- ExpandVariadicsPass.cpp *- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is an optimization pass for variadic functions. If called from codegen,
+// it can serve as the implementation of variadic functions for a given target.
+//
+// The strategy is to turn the ... part of a varidic function into a va_list
+// and fix up the call sites. This is completely effective if the calling
+// convention can declare that to be the right thing, e.g. on GPUs or where
+// the application is wholly statically linked. In the usual case, it will
+// replace known calls to known variadic functions with calls that are amenable
+// to inlining and other optimisations.
+//
+// The target-dependent parts are in class VariadicABIInfo. Enabling a new
+// target means adding a case to VariadicABIInfo::create() along with tests.
+// This will be especially simple if the va_list representation is a char*.
+//
+// The majority of the plumbing is splitting the variadic function into a
+// single basic block that packs the variadic arguments into a va_list and
+// a second function that does the work of the original. The target specific
+// part is packing arguments into a contiguous buffer that the clang expansion
+// of va_arg will do the right thing with.
+//
+// The aggregate effect is to unblock other transforms, most critically the
+// general purpose inliner. Known calls to variadic functions become zero cost.
+//
+// Consistency with clang is primarily tested by emitting va_arg using clang
+// then expanding the variadic functions using this pass, followed by trying
+// to constant fold the functions to no-ops.
+//
+// Target specific behaviour is tested in IR - mainly checking that values are
+// put into positions in call frames that make sense for that particular 
target.
+//
+//===--===//
+
+#include "llvm/Transforms/IPO/ExpandVariadics.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
+
+#define DEBUG_TYPE "expand-variadics"
+
+using namespace llvm;
+
+cl::opt ExpandVariadicsModeOption(
+DEBUG_TYPE "-override", cl::desc("Override the behaviour of " DEBUG_TYPE),
+cl::init(ExpandVariadicsMode::Unspecified),
+cl::values(clEnumValN(ExpandVariadicsMode::Unspecified, "unspecified",
+  "Use the implementation defaults"),
+   clEnumValN(ExpandVariadicsMode::Disable, "disable",
+  "Disable the pass entirely"),
+   clEnumValN(ExpandVariadicsMode::Optimize, "optimize",
+  "Optimise without changing ABI"),
+   clEnumValN(ExpandVariadicsMode::Lowering, "lowering",
+  "Change variadic calling convention")));
+
+namespace {
+
+// At present Intrinsic:: has no interface to test if a declaration is in the
+// module without creating one. Inserting a declaration and then testing if it
+// has any uses and then deleting it seems a bad way to do the query.
+// Module implements getFunction() which returns nullptr on missing declaration
+// and getOrInsertFunction which creates one when absent. Intrinsics.h
+// implements getDeclaration which creates one when missing. This should be
+// changed to be consistent with Module()'s naming. Implementing as a local
+// function here in the meantime to decouple from that process.
+Function *getPreexistingDeclaration(Module *M, Intrinsic::ID id,
+ArrayRef Tys = std::nullopt) {
+  auto *FT = Intrinsic::getType(M->getContext(), id, Tys);
+  return M->getFunction(Tys.empty() ? Intrinsic::getName(id)
+: Intrinsic::getName(id, Tys, M, FT));
+}
+
+// Lots of targets use a void* pointed at a buffer for va_list.
+// Some use more complicated iterator constructs. Type erase that
+// so the rest of the pass can operation on either.
+// Virtual functions where different targets want different behaviour,
+// normal where all implemented targets presently have the same.
+struct VAListInterface {
+  virtual ~VAListInterface() {}
+
+  // Whether a valist instance is passed by value or by address
+  // I.e. does it need to be alloca'ed and stored into, or can
+  // it be passed directly in a SSA 

[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits


@@ -0,0 +1,1026 @@
+//===-- ExpandVariadicsPass.cpp *- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is an optimization pass for variadic functions. If called from codegen,
+// it can serve as the implementation of variadic functions for a given target.
+//
+// The strategy is to turn the ... part of a varidic function into a va_list
+// and fix up the call sites. This is completely effective if the calling
+// convention can declare that to be the right thing, e.g. on GPUs or where
+// the application is wholly statically linked. In the usual case, it will
+// replace known calls to known variadic functions with calls that are amenable
+// to inlining and other optimisations.
+//
+// The target-dependent parts are in class VariadicABIInfo. Enabling a new
+// target means adding a case to VariadicABIInfo::create() along with tests.
+// This will be especially simple if the va_list representation is a char*.
+//
+// The majority of the plumbing is splitting the variadic function into a
+// single basic block that packs the variadic arguments into a va_list and
+// a second function that does the work of the original. The target specific
+// part is packing arguments into a contiguous buffer that the clang expansion
+// of va_arg will do the right thing with.
+//
+// The aggregate effect is to unblock other transforms, most critically the
+// general purpose inliner. Known calls to variadic functions become zero cost.
+//
+// Consistency with clang is primarily tested by emitting va_arg using clang
+// then expanding the variadic functions using this pass, followed by trying
+// to constant fold the functions to no-ops.
+//
+// Target specific behaviour is tested in IR - mainly checking that values are
+// put into positions in call frames that make sense for that particular 
target.
+//
+//===--===//
+
+#include "llvm/Transforms/IPO/ExpandVariadics.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
+
+#define DEBUG_TYPE "expand-variadics"
+
+using namespace llvm;
+
+cl::opt ExpandVariadicsModeOption(
+DEBUG_TYPE "-override", cl::desc("Override the behaviour of " DEBUG_TYPE),
+cl::init(ExpandVariadicsMode::Unspecified),
+cl::values(clEnumValN(ExpandVariadicsMode::Unspecified, "unspecified",
+  "Use the implementation defaults"),
+   clEnumValN(ExpandVariadicsMode::Disable, "disable",
+  "Disable the pass entirely"),
+   clEnumValN(ExpandVariadicsMode::Optimize, "optimize",
+  "Optimise without changing ABI"),
+   clEnumValN(ExpandVariadicsMode::Lowering, "lowering",
+  "Change variadic calling convention")));
+
+namespace {
+
+// At present Intrinsic:: has no interface to test if a declaration is in the
+// module without creating one. Inserting a declaration and then testing if it
+// has any uses and then deleting it seems a bad way to do the query.
+// Module implements getFunction() which returns nullptr on missing declaration
+// and getOrInsertFunction which creates one when absent. Intrinsics.h
+// implements getDeclaration which creates one when missing. This should be
+// changed to be consistent with Module()'s naming. Implementing as a local
+// function here in the meantime to decouple from that process.
+Function *getPreexistingDeclaration(Module *M, Intrinsic::ID id,

jdoerfert wrote:

```suggestion
Function *getPreexistingDeclaration(Module *M, Intrinsic::ID Id,
```

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


[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits


@@ -0,0 +1,1026 @@
+//===-- ExpandVariadicsPass.cpp *- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is an optimization pass for variadic functions. If called from codegen,
+// it can serve as the implementation of variadic functions for a given target.
+//
+// The strategy is to turn the ... part of a varidic function into a va_list
+// and fix up the call sites. This is completely effective if the calling
+// convention can declare that to be the right thing, e.g. on GPUs or where
+// the application is wholly statically linked. In the usual case, it will
+// replace known calls to known variadic functions with calls that are amenable
+// to inlining and other optimisations.
+//
+// The target-dependent parts are in class VariadicABIInfo. Enabling a new
+// target means adding a case to VariadicABIInfo::create() along with tests.
+// This will be especially simple if the va_list representation is a char*.
+//
+// The majority of the plumbing is splitting the variadic function into a
+// single basic block that packs the variadic arguments into a va_list and
+// a second function that does the work of the original. The target specific
+// part is packing arguments into a contiguous buffer that the clang expansion
+// of va_arg will do the right thing with.
+//
+// The aggregate effect is to unblock other transforms, most critically the
+// general purpose inliner. Known calls to variadic functions become zero cost.
+//
+// Consistency with clang is primarily tested by emitting va_arg using clang
+// then expanding the variadic functions using this pass, followed by trying
+// to constant fold the functions to no-ops.
+//
+// Target specific behaviour is tested in IR - mainly checking that values are
+// put into positions in call frames that make sense for that particular 
target.
+//
+//===--===//
+
+#include "llvm/Transforms/IPO/ExpandVariadics.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
+
+#define DEBUG_TYPE "expand-variadics"
+
+using namespace llvm;
+
+cl::opt ExpandVariadicsModeOption(
+DEBUG_TYPE "-override", cl::desc("Override the behaviour of " DEBUG_TYPE),
+cl::init(ExpandVariadicsMode::Unspecified),
+cl::values(clEnumValN(ExpandVariadicsMode::Unspecified, "unspecified",
+  "Use the implementation defaults"),
+   clEnumValN(ExpandVariadicsMode::Disable, "disable",
+  "Disable the pass entirely"),
+   clEnumValN(ExpandVariadicsMode::Optimize, "optimize",
+  "Optimise without changing ABI"),
+   clEnumValN(ExpandVariadicsMode::Lowering, "lowering",
+  "Change variadic calling convention")));
+
+namespace {
+
+// At present Intrinsic:: has no interface to test if a declaration is in the
+// module without creating one. Inserting a declaration and then testing if it
+// has any uses and then deleting it seems a bad way to do the query.
+// Module implements getFunction() which returns nullptr on missing declaration
+// and getOrInsertFunction which creates one when absent. Intrinsics.h
+// implements getDeclaration which creates one when missing. This should be
+// changed to be consistent with Module()'s naming. Implementing as a local
+// function here in the meantime to decouple from that process.
+Function *getPreexistingDeclaration(Module *M, Intrinsic::ID id,
+ArrayRef Tys = std::nullopt) {
+  auto *FT = Intrinsic::getType(M->getContext(), id, Tys);
+  return M->getFunction(Tys.empty() ? Intrinsic::getName(id)
+: Intrinsic::getName(id, Tys, M, FT));
+}
+
+// Lots of targets use a void* pointed at a buffer for va_list.
+// Some use more complicated iterator constructs. Type erase that
+// so the rest of the pass can operation on either.
+// Virtual functions where different targets want different behaviour,
+// normal where all implemented targets presently have the same.
+struct VAListInterface {
+  virtual ~VAListInterface() {}
+
+  // Whether a valist instance is passed by value or by address
+  // I.e. does it need to be alloca'ed and stored into, or can
+  // it be passed directly in a SSA 

[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits


@@ -0,0 +1,1026 @@
+//===-- ExpandVariadicsPass.cpp *- C++ -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is an optimization pass for variadic functions. If called from codegen,
+// it can serve as the implementation of variadic functions for a given target.
+//
+// The strategy is to turn the ... part of a varidic function into a va_list
+// and fix up the call sites. This is completely effective if the calling
+// convention can declare that to be the right thing, e.g. on GPUs or where
+// the application is wholly statically linked. In the usual case, it will
+// replace known calls to known variadic functions with calls that are amenable
+// to inlining and other optimisations.
+//
+// The target-dependent parts are in class VariadicABIInfo. Enabling a new
+// target means adding a case to VariadicABIInfo::create() along with tests.
+// This will be especially simple if the va_list representation is a char*.
+//
+// The majority of the plumbing is splitting the variadic function into a
+// single basic block that packs the variadic arguments into a va_list and
+// a second function that does the work of the original. The target specific
+// part is packing arguments into a contiguous buffer that the clang expansion
+// of va_arg will do the right thing with.
+//
+// The aggregate effect is to unblock other transforms, most critically the
+// general purpose inliner. Known calls to variadic functions become zero cost.
+//
+// Consistency with clang is primarily tested by emitting va_arg using clang
+// then expanding the variadic functions using this pass, followed by trying
+// to constant fold the functions to no-ops.
+//
+// Target specific behaviour is tested in IR - mainly checking that values are
+// put into positions in call frames that make sense for that particular 
target.
+//
+//===--===//
+
+#include "llvm/Transforms/IPO/ExpandVariadics.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
+
+#define DEBUG_TYPE "expand-variadics"
+
+using namespace llvm;
+
+cl::opt ExpandVariadicsModeOption(
+DEBUG_TYPE "-override", cl::desc("Override the behaviour of " DEBUG_TYPE),
+cl::init(ExpandVariadicsMode::Unspecified),
+cl::values(clEnumValN(ExpandVariadicsMode::Unspecified, "unspecified",
+  "Use the implementation defaults"),
+   clEnumValN(ExpandVariadicsMode::Disable, "disable",
+  "Disable the pass entirely"),
+   clEnumValN(ExpandVariadicsMode::Optimize, "optimize",
+  "Optimise without changing ABI"),
+   clEnumValN(ExpandVariadicsMode::Lowering, "lowering",
+  "Change variadic calling convention")));
+
+namespace {
+
+// At present Intrinsic:: has no interface to test if a declaration is in the
+// module without creating one. Inserting a declaration and then testing if it
+// has any uses and then deleting it seems a bad way to do the query.
+// Module implements getFunction() which returns nullptr on missing declaration
+// and getOrInsertFunction which creates one when absent. Intrinsics.h
+// implements getDeclaration which creates one when missing. This should be
+// changed to be consistent with Module()'s naming. Implementing as a local
+// function here in the meantime to decouple from that process.
+Function *getPreexistingDeclaration(Module *M, Intrinsic::ID id,
+ArrayRef Tys = std::nullopt) {
+  auto *FT = Intrinsic::getType(M->getContext(), id, Tys);
+  return M->getFunction(Tys.empty() ? Intrinsic::getName(id)
+: Intrinsic::getName(id, Tys, M, FT));
+}
+
+// Lots of targets use a void* pointed at a buffer for va_list.
+// Some use more complicated iterator constructs. Type erase that
+// so the rest of the pass can operation on either.
+// Virtual functions where different targets want different behaviour,
+// normal where all implemented targets presently have the same.
+struct VAListInterface {
+  virtual ~VAListInterface() {}
+
+  // Whether a valist instance is passed by value or by address
+  // I.e. does it need to be alloca'ed and stored into, or can
+  // it be passed directly in a SSA 

[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert commented:

I just read over this and left some comments.


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


[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-04-29 Thread Johannes Doerfert via cfe-commits

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


[clang] [SemaCXX] Implement CWG2351 `void{}` (PR #78060)

2024-04-29 Thread Richard Smith via cfe-commits

zygoloid wrote:

> Note that the AST for the expression `T{}` looks like:
> 
> ```
> // using T = int;
> CXXFunctionalCastExpr 'T':'int' functional cast to T 
> `-InitListExpr 'T':'int'
> // using T = const int;
> CXXFunctionalCastExpr 'int' functional cast to T 
> `-InitListExpr 'int'
> // using T = void;
> CXXFunctionalCastExpr 'void' functional cast to T 
> `-InitListExpr 'void'
> // using T = const void;
> CXXFunctionalCastExpr 'void' functional cast to T 
> `-InitListExpr 'void'
> ```
> 
> (Since the `InitListExpr` already has `void` before anything is done, the 
> type doesn't need to be adjusted)

Nonetheless, I think it'd be more reasonable to use `CK_ToVoid` here rather 
than `CK_NoOp`. The `void` type for the `InitListExpr` is just a placeholder 
and not meant to mean that it's a real expression of type `void`. (We really 
ought to use a better placeholder there, so we can print the type out as 
`` instead of as `void` in diagnostics.)

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


[clang] [SemaCXX] Implement CWG2351 `void{}` (PR #78060)

2024-04-29 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

@MitalAshok ping 

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Reid Kleckner via cfe-commits


@@ -424,6 +424,34 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+if (KernelFunction->hasComdat()) {
+  std::string KernelName = KernelFunction->getName().str();
+  std::string GlobalVarName = KernelName + ".id";
+
+  llvm::GlobalVariable *HandleVar =
+  CGM.getModule().getNamedGlobal(GlobalVarName);
+  if (!HandleVar) {
+HandleVar = new llvm::GlobalVariable(
+CGM.getModule(), CGM.Int8Ty,
+/*Constant=*/false, KernelFunction->getLinkage(),
+llvm::ConstantInt::get(CGM.Int8Ty, 0), GlobalVarName);
+HandleVar->setDSOLocal(KernelFunction->isDSOLocal());
+HandleVar->setVisibility(KernelFunction->getVisibility());
+HandleVar->setComdat(CGM.getModule().getOrInsertComdat(GlobalVarName));
+  }
+
+  CGF.Builder.CreateAlignedStore(llvm::ConstantInt::get(CGM.Int8Ty, 1),

rnk wrote:

LLVM knows how to optimize away a single write to an otherwise unused global, 
so I would mark this store volatile.

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Reid Kleckner via cfe-commits


@@ -424,6 +424,34 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+if (KernelFunction->hasComdat()) {
+  std::string KernelName = KernelFunction->getName().str();

rnk wrote:

Please avoid making an extra copy of the original name, since C++ names can be 
many kilobytes. Use `(KernelFunction->getName() + ".id").str()` to construct 
the `std::string`.

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


[clang] [CUDA] make kernel stub ICF-proof (PR #90155)

2024-04-29 Thread Reid Kleckner via cfe-commits


@@ -424,6 +424,34 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction ,
   CGM.CreateRuntimeFunction(FTy, LaunchKernelName);
   CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
+
+  // To prevent CUDA device stub functions from being merged by ICF in MSVC
+  // environment, create an unique global variable for each kernel and write to
+  // the variable in the device stub.
+  if (CGM.getContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+  !CGF.getLangOpts().HIP) {
+llvm::Function *KernelFunction = llvm::cast(Kernel);
+if (KernelFunction->hasComdat()) {

rnk wrote:

ICF may apply to all functions under 
[`/Gy`](https://learn.microsoft.com/en-us/cpp/build/reference/gy-enable-function-level-linking?view=msvc-170),
 and those are not reflected in the IR, so I would just do this for all kernels.

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-04-29 Thread Adrian Prantl via cfe-commits


@@ -27,6 +27,9 @@ namespace llvm {
   }
 }
 
+// Prefix for __builtin_verbose_trap.
+#define CLANG_VERBOSE_TRAP_PREFIX "__llvm_verbose_trap"

adrian-prantl wrote:

Does this have to be a macro or could it be a C++ constant?

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


[clang] [llvm] Implement resource binding type prefix mismatch errors (PR #87578)

2024-04-29 Thread Xiang Li via cfe-commits


@@ -44,7 +44,7 @@ void foo2() {
   // expected-warning@+1 {{'register' attribute only applies to 
cbuffer/tbuffer and external global variables}}
   extern RWBuffer U2 : register(u5);
 }
-// FIXME: expect-error once fix 
https://github.com/llvm/llvm-project/issues/57886.
+// expected-error@+1 {{invalid register name prefix 'u' for 'float' (expected 
't')}}

python3kgae wrote:

Since here the float is in global scope, it will be treated as constant inside 
Global CBuffer.

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


[clang] [llvm] Implement resource binding type prefix mismatch errors (PR #87578)

2024-04-29 Thread Xiang Li via cfe-commits


@@ -44,7 +44,7 @@ void foo2() {
   // expected-warning@+1 {{'register' attribute only applies to 
cbuffer/tbuffer and external global variables}}
   extern RWBuffer U2 : register(u5);
 }
-// FIXME: expect-error once fix 
https://github.com/llvm/llvm-project/issues/57886.
+// expected-error@+1 {{invalid register name prefix 'u' for 'float' (expected 
't')}}

python3kgae wrote:

dxc will report
error: invalid register specification, expected 'b', 'c', or 'i' binding
float t : register(u0);
  ^
fxc will just ignore the register(u0).

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


[clang] [WebAssembly] Add preprocessor define for half-precision (PR #90528)

2024-04-29 Thread Thomas Lively via cfe-commits

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


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


[clang] [clang] Handle trivial_abi attribute for Microsoft ABI. (PR #88857)

2024-04-29 Thread Reid Kleckner via cfe-commits


@@ -1105,6 +1105,11 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl 
GD) const {
 
 static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
  CodeGenModule ) {
+  // If the record is marked with the trivial_abi attribute, we don't
+  // have to conform to the standard MSVC ABI.
+  if (RD->hasAttr())

rnk wrote:

The pseudo code version is something like:
  bool containsTrivialAbiSubobject(CXXRecordDecl *RD) {
if (RD->hasAttr()) return true;
for (auto B : RD->bases()) {
  if (containsTrivialAbiSubobject(B->getAsCXXRecordDecl()))
return true;
}
for (auto F : RD->fields()) {
  const CXXRecordDecl* FRD = F->getType()->getAsCXXRecordDecl();
  if (FRD && containsTrivialAbiSubobject(FRD))
return true;
}
return false;
  }

A bit of a gross inefficient DFS, with some CXXBaseSpecifier details omitted. 
It might also be worth tracking Visited records to handle fields of the same 
record type without recursing over all subobjects again.

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


[clang] [llvm] Implement resource binding type prefix mismatch errors (PR #87578)

2024-04-29 Thread Joshua Batista via cfe-commits


@@ -44,7 +44,7 @@ void foo2() {
   // expected-warning@+1 {{'register' attribute only applies to 
cbuffer/tbuffer and external global variables}}
   extern RWBuffer U2 : register(u5);
 }
-// FIXME: expect-error once fix 
https://github.com/llvm/llvm-project/issues/57886.
+// expected-error@+1 {{invalid register name prefix 'u' for 'float' (expected 
't')}}

bob80905 wrote:

I don't have a prior example to base this off of at hand, but I think I saw 
some hlsl with a builtin type bound to a register and the valid prefix was 't'.
To answer your question, the assignment is represented as a VarDecl, so the 
compiler assumes this resource is a Sampler, UAV, or  SRV. Then the resource 
type is analyzed to see if it's a builtin (float happens to be a builtin).
Then we check the binding prefix to see if it's 't', and if not, emit an error. 
float is a builtin type, and the prefix isn't t, so that's why this test case 
expects 't'.
What prefix should it expect, if any?

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


[clang] [WebAssembly] Add preprocessor define for half-precision (PR #90528)

2024-04-29 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-clang

Author: Heejin Ahn (aheejin)


Changes

This adds the preprocessor define for the half-precision feature and also adds 
preprocessor tests.

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+2) 
- (modified) clang/test/Preprocessor/wasm-target-features.c (+12) 


``diff
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 0db7b668d8a0ac..1f0418b21c1f86 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -100,6 +100,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const 
LangOptions ,
 Builder.defineMacro("__wasm_extended_const__");
   if (HasMultiMemory)
 Builder.defineMacro("__wasm_multimemory__");
+  if (HasHalfPrecision)
+Builder.defineMacro("__wasm_half_precision__");
 
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 19bd918543dfea..72ecc60a6e7898 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -43,6 +43,15 @@
 //
 // EXTENDED-CONST: #define __wasm_extended_const__ 1{{$}}
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mhalf-precision \
+// RUN:   | FileCheck %s -check-prefix=HALF-PRECISION
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mhalf-precision \
+// RUN:   | FileCheck %s -check-prefix=HALF-PRECISION
+//
+// HALF-PRECISION: #define __wasm_half_precision__ 1{{$}}
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mmultimemory \
 // RUN:   | FileCheck %s -check-prefix=MULTIMEMORY
@@ -135,6 +144,7 @@
 // MVP-NOT: #define __wasm_bulk_memory__ 1{{$}}
 // MVP-NOT: #define __wasm_exception_handling__ 1{{$}}
 // MVP-NOT: #define __wasm_extended_const__ 1{{$}}
+// MVP-NOT: #define __wasm_half_precision__ 1{{$}}
 // MVP-NOT: #define __wasm_multimemory__ 1{{$}}
 // MVP-NOT: #define __wasm_multivalue__ 1{{$}}
 // MVP-NOT: #define __wasm_mutable_globals__ 1{{$}}
@@ -168,6 +178,7 @@
 // GENERIC-NOT: #define __wasm_bulk_memory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
 // GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
+// GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
@@ -183,6 +194,7 @@
 //
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_atomics__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
+// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_half_precision__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}

``




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


[clang] [WebAssembly] Add preprocessor define for half-precision (PR #90528)

2024-04-29 Thread Heejin Ahn via cfe-commits

aheejin wrote:

cc @brendandahl (I couldn't add you as a reviewer because you didn't pop up in 
the reviewers list)

Also, this just adds the preprocessor directive, but I'm wondering whether you 
really meant to add this to bleeding-edge: 
https://github.com/llvm/llvm-project/commit/d9fd0ddef38bb9d5cce7300ff820272183c09fcd#r141495634

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


[clang] [OpenMP][TR12] change property of map-type modifier. (PR #90499)

2024-04-29 Thread via cfe-commits

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


[clang] [WebAssembly] Add preprocessor define for half-precision (PR #90528)

2024-04-29 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin created 
https://github.com/llvm/llvm-project/pull/90528

This adds the preprocessor define for the half-precision feature and also adds 
preprocessor tests.

>From 036d8a7486eab8ee2b434826c6ad5807daba2574 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Mon, 29 Apr 2024 22:02:52 +
Subject: [PATCH] [WebAssembly] Add preprocessor define for half-precision

This adds the preprocessor define for the half-precision feature and
also adds preprocessor tests.
---
 clang/lib/Basic/Targets/WebAssembly.cpp|  2 ++
 clang/test/Preprocessor/wasm-target-features.c | 12 
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 0db7b668d8a0ac..1f0418b21c1f86 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -100,6 +100,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const 
LangOptions ,
 Builder.defineMacro("__wasm_extended_const__");
   if (HasMultiMemory)
 Builder.defineMacro("__wasm_multimemory__");
+  if (HasHalfPrecision)
+Builder.defineMacro("__wasm_half_precision__");
 
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 19bd918543dfea..72ecc60a6e7898 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -43,6 +43,15 @@
 //
 // EXTENDED-CONST: #define __wasm_extended_const__ 1{{$}}
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mhalf-precision \
+// RUN:   | FileCheck %s -check-prefix=HALF-PRECISION
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mhalf-precision \
+// RUN:   | FileCheck %s -check-prefix=HALF-PRECISION
+//
+// HALF-PRECISION: #define __wasm_half_precision__ 1{{$}}
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mmultimemory \
 // RUN:   | FileCheck %s -check-prefix=MULTIMEMORY
@@ -135,6 +144,7 @@
 // MVP-NOT: #define __wasm_bulk_memory__ 1{{$}}
 // MVP-NOT: #define __wasm_exception_handling__ 1{{$}}
 // MVP-NOT: #define __wasm_extended_const__ 1{{$}}
+// MVP-NOT: #define __wasm_half_precision__ 1{{$}}
 // MVP-NOT: #define __wasm_multimemory__ 1{{$}}
 // MVP-NOT: #define __wasm_multivalue__ 1{{$}}
 // MVP-NOT: #define __wasm_mutable_globals__ 1{{$}}
@@ -168,6 +178,7 @@
 // GENERIC-NOT: #define __wasm_bulk_memory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
 // GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
+// GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
@@ -183,6 +194,7 @@
 //
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_atomics__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
+// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_half_precision__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits


@@ -44,9 +44,10 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder 
*Finder) {
   callee(cxxMethodDecl(hasName("find")).bind("findfun")),
   on(hasType(StringType)),
   // ... with some search expression ...
-  hasArgument(0, expr().bind("needle")),
+  hasArgument(0, expr().ignoringParenImpCasts().bind("needle")),

jkorous-apple wrote:

What is the intent of using `ignoringParenImpCasts` here?

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits

https://github.com/jkorous-apple requested changes to this pull request.

Please start with removing all files that shouldn't be part of the PR.
Then please remove changes that affect only format/whitespace.

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits


@@ -22,7 +22,7 @@ namespace clang::tidy::abseil {
 //  - Make it work in macros if the outer and inner StrCats are both in the
 //argument.
 
-void RedundantStrcatCallsCheck::registerMatchers(MatchFinder* Finder) {
+void RedundantStrcatCallsCheck::registerMatchers(MatchFinder *Finder) {

jkorous-apple wrote:

Please leave out format-only changes from the PR. It makes the diff larger and 
it takes more effort to review it.

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits


@@ -0,0 +1,5 @@
+Script started on 2024-04-27 13:50:15+05:30 [TERM="xterm-256color" 
TTY="/dev/pts/0" COLUMNS="100" LINES="18"]

jkorous-apple wrote:

Please clean up the PR so it doesn't contain files that shouldn't be merged.

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits


@@ -0,0 +1,72 @@
+set(CMAKE_C_COMPILER "/usr/bin/cc")

jkorous-apple wrote:

Also, why are we adding binaries?

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits


@@ -0,0 +1,72 @@
+set(CMAKE_C_COMPILER "/usr/bin/cc")

jkorous-apple wrote:

Why does this PR touch any CMake files? Is it necessary for the intended change 
of behavior of one or two AST matchers?

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


[clang] [clang-tools-extra] [llvm] Add ``ignoringParenImpCasts`` in arguments of hasArgument (PR #89553)

2024-04-29 Thread via cfe-commits

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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-04-29 Thread Craig Topper via cfe-commits

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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-04-29 Thread Craig Topper via cfe-commits


@@ -169,6 +169,9 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-relax");
   }
 
+  if (!Args.hasArg(options::OPT_menable_experimental_extensions))
+Features.push_back("+no-experimental-ext");

topperc wrote:

We also check `OPT_menable_experimental_extensions` in `getArchFeatures` and 
push a different feature when it set. Do we need 2 extensions that are the 
opposite of each other?

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


[clang] [Clang] Address post commit feedbacks in #89906 (PR #90495)

2024-04-29 Thread via cfe-commits


@@ -177,7 +177,7 @@ C++2c implementation status
  
   Attributes for Structured Bindings
   https://wg21.link/P0609R3;>P0609R3
-  No
+  Clang 19

cor3ntin wrote:

Ugh, how did that happen? Thanks for noticing!

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


[clang] 1f44a0b - Make minor improvements to the creduce wrapper script

2024-04-29 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2024-04-29T22:09:09Z
New Revision: 1f44a0b1ff2daebe10b9916da228f7c0ba66827c

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

LOG: Make minor improvements to the creduce wrapper script

Use shlex.quote instead of pipes.quote. We don't need to support Python
2.7 anymore.

Remove -fcolor-diagnostics first, because that can sometimes interfere
with the interestingness test.

Added: 


Modified: 
clang/utils/creduce-clang-crash.py

Removed: 




diff  --git a/clang/utils/creduce-clang-crash.py 
b/clang/utils/creduce-clang-crash.py
index 27361bb8850581..4d0c8224d8b499 100755
--- a/clang/utils/creduce-clang-crash.py
+++ b/clang/utils/creduce-clang-crash.py
@@ -15,7 +15,6 @@
 import stat
 import sys
 import subprocess
-import pipes
 import shlex
 import tempfile
 import shutil
@@ -61,7 +60,7 @@ def check_cmd(cmd_name, cmd_dir, cmd_path=None):
 
 
 def quote_cmd(cmd):
-return " ".join(pipes.quote(arg) for arg in cmd)
+return " ".join(shlex.quote(arg) for arg in cmd)
 
 
 def write_to_script(text, filename):
@@ -220,7 +219,7 @@ def write_interestingness_test(self):
 )
 
 for msg in self.expected_output:
-output += "grep -F %s t.log || exit 1\n" % pipes.quote(msg)
+output += "grep -F %s t.log || exit 1\n" % shlex.quote(msg)
 
 write_to_script(output, self.testfile)
 self.check_interestingness()
@@ -318,9 +317,17 @@ def simplify_clang_args(self):
 interestingness test takes to run.
 """
 print("\nSimplifying the clang command...")
+new_args = self.clang_args
+
+# Remove the color diagnostics flag to make it easier to match error
+# text.
+new_args = self.try_remove_args(
+new_args,
+msg="Removed -fcolor-diagnostics",
+opts_equal=["-fcolor-diagnostics"],
+)
 
 # Remove some clang arguments to speed up the interestingness test
-new_args = self.clang_args
 new_args = self.try_remove_args(
 new_args,
 msg="Removed debug info options",



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


[clang] [llvm] [CodeGen][i386] Move -mregparm storage earlier and fix Runtime calls (PR #89707)

2024-04-29 Thread Kees Cook via cfe-commits

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


[clang] 869ffcf - [CodeGen][i386] Move -mregparm storage earlier and fix Runtime calls (#89707)

2024-04-29 Thread via cfe-commits

Author: Kees Cook
Date: 2024-04-29T14:54:10-07:00
New Revision: 869ffcf3f6ca74c8a0ec6eb250d45e6ea0680c81

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

LOG: [CodeGen][i386] Move -mregparm storage earlier and fix Runtime calls 
(#89707)

When building the Linux kernel for i386, the -mregparm=3 option is
enabled. Crashes were observed in the sanitizer handler functions, and
the problem was found to be mismatched calling convention.

As was fixed in commit c167c0a4dcdb ("[BuildLibCalls] infer inreg param
attrs from NumRegisterParameters"), call arguments need to be marked as
"in register" when -mregparm is set. Use the same helper developed there
to update the function arguments.

Since CreateRuntimeFunction() is actually part of CodeGenModule, storage
of the -mregparm value is also moved to the constructor, as doing this
in Release() is too late.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/regparm-flag.c
llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d085e735ecb443..c8898ce196c1ed 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -73,6 +73,7 @@
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
+#include "llvm/Transforms/Utils/BuildLibCalls.h"
 #include 
 
 using namespace clang;
@@ -442,6 +443,11 @@ CodeGenModule::CodeGenModule(ASTContext ,
   }
 ModuleNameHash = llvm::getUniqueInternalLinkagePostfix(Path);
   }
+
+  // Record mregparm value now so it is visible through all of codegen.
+  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
+getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
+  CodeGenOpts.NumRegisterParameters);
 }
 
 CodeGenModule::~CodeGenModule() {}
@@ -980,11 +986,6 @@ void CodeGenModule::Release() {
   NMD->addOperand(MD);
   }
 
-  // Record mregparm value now so it is visible through rest of codegen.
-  if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
-getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
-  CodeGenOpts.NumRegisterParameters);
-
   if (CodeGenOpts.DwarfVersion) {
 getModule().addModuleFlag(llvm::Module::Max, "Dwarf Version",
   CodeGenOpts.DwarfVersion);
@@ -4781,6 +4782,10 @@ CodeGenModule::CreateRuntimeFunction(llvm::FunctionType 
*FTy, StringRef Name,
 }
   }
   setDSOLocal(F);
+  // FIXME: We should use CodeGenModule::SetLLVMFunctionAttributes() 
instead
+  // of trying to approximate the attributes using the LLVM function
+  // signature. This requires revising the API of CreateRuntimeFunction().
+  markRegisterParameterAttributes(F);
 }
   }
 

diff  --git a/clang/test/CodeGen/regparm-flag.c 
b/clang/test/CodeGen/regparm-flag.c
index c35b53cd4e1990..d888c1e344c03b 100644
--- a/clang/test/CodeGen/regparm-flag.c
+++ b/clang/test/CodeGen/regparm-flag.c
@@ -1,4 +1,8 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown -mregparm 4 %s -emit-llvm -o - 
| FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fsanitize=array-bounds %s 
-emit-llvm -o - | FileCheck %s --check-prefix=RUNTIME0
+// RUN: %clang_cc1 -triple i386-unknown-unknown -mregparm 1 
-fsanitize=array-bounds %s -emit-llvm -o - | FileCheck %s 
--check-prefix=RUNTIME1
+// RUN: %clang_cc1 -triple i386-unknown-unknown -mregparm 2 
-fsanitize=array-bounds %s -emit-llvm -o - | FileCheck %s 
--check-prefix=RUNTIME2
+// RUN: %clang_cc1 -triple i386-unknown-unknown -mregparm 3 
-fsanitize=array-bounds %s -emit-llvm -o - | FileCheck %s 
--check-prefix=RUNTIME2
 
 void f1(int a, int b, int c, int d,
 int e, int f, int g, int h);
@@ -13,7 +17,21 @@ void f0(void) {
   f2(1, 2);
 }
 
+struct has_array {
+  int a;
+  int b[4];
+  int c;
+};
+
+int access(struct has_array *p, int index)
+{
+  return p->b[index];
+}
+
 // CHECK: declare void @f1(i32 inreg noundef, i32 inreg noundef, i32 inreg 
noundef, i32 inreg noundef,
 // CHECK: i32 noundef, i32 noundef, i32 noundef, i32 noundef)
 // CHECK: declare void @f2(i32 noundef, i32 noundef)
 
+// RUNTIME0: declare void @__ubsan_handle_out_of_bounds_abort(ptr, i32)
+// RUNTIME1: declare void @__ubsan_handle_out_of_bounds_abort(ptr inreg, i32)
+// RUNTIME2: declare void @__ubsan_handle_out_of_bounds_abort(ptr inreg, i32 
inreg)

diff  --git a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h 

[clang] [Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (PR #90490)

2024-04-29 Thread via cfe-commits


@@ -6714,14 +6714,16 @@ void Sema::CodeCompleteQualifiedId(Scope *S, 
CXXScopeSpec ,
 
   // If the scope is a concept-constrained type parameter, infer nested
   // members based on the constraints.
-  if (const auto *TTPT =
-  dyn_cast_or_null(NNS->getAsType())) {
-for (const auto  : ConceptInfo(*TTPT, S).members()) {
-  if (R.Operator != ConceptInfo::Member::Colons)
-continue;
-  Results.AddResult(CodeCompletionResult(
-  R.render(*this, CodeCompleter->getAllocator(),
-   CodeCompleter->getCodeCompletionTUInfo(;
+  if (NNS) {

smanna12 wrote:

Thanks @shafik for reviews!

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


[clang] [OpenMP][TR12] change property of map-type modifier. (PR #90499)

2024-04-29 Thread via cfe-commits


@@ -113,7 +114,7 @@ struct SA {
 #pragma omp target map(b[true:true])
 {}
 
-#pragma omp target map(: c,f) // expected-error {{missing map type}}
+#pragma omp target map(: c,f) // lt60-error {{missing map type}}

jyu2-git wrote:

Hi Alexey, could you specify where 4.2 says that.  I back look at 6.8.3

map-type locator-list Keyword: alloc, delete,
from, release, to, tofrom
default

Thanks.



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


[clang] [Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (PR #90490)

2024-04-29 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Looks good, I will let Tom make the final accept.

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


[clang] [Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (PR #90490)

2024-04-29 Thread Shafik Yaghmour via cfe-commits


@@ -6714,14 +6714,16 @@ void Sema::CodeCompleteQualifiedId(Scope *S, 
CXXScopeSpec ,
 
   // If the scope is a concept-constrained type parameter, infer nested
   // members based on the constraints.
-  if (const auto *TTPT =
-  dyn_cast_or_null(NNS->getAsType())) {
-for (const auto  : ConceptInfo(*TTPT, S).members()) {
-  if (R.Operator != ConceptInfo::Member::Colons)
-continue;
-  Results.AddResult(CodeCompletionResult(
-  R.render(*this, CodeCompleter->getAllocator(),
-   CodeCompleter->getCodeCompletionTUInfo(;
+  if (NNS) {

shafik wrote:

This looks good, We can even seen above `NNS` is checked before access. This 
looks like an unfortunate oversight.

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


[clang] [Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (PR #90490)

2024-04-29 Thread Shafik Yaghmour via cfe-commits

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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-04-29 Thread Sergei Barannikov via cfe-commits


@@ -263,7 +263,10 @@ SparcV9ABIInfo::classifyType(QualType Ty, unsigned 
SizeLimit) const {
 
   CoerceBuilder CB(getVMContext(), getDataLayout());
   CB.addStruct(0, StrTy);
-  CB.pad(llvm::alignTo(CB.DL.getTypeSizeInBits(StrTy), 64));
+  // All structs, even empty ones, should take up a register argument slot,
+  // so pin the minimum struct size to one bit.
+  CB.pad(llvm::alignTo(
+  std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), 1UL), 64));

s-barannikov wrote:

A slightly more cleaner way of handling this would be to
`return ABIArgInfo::getDirect(llvm::Type::getInt64Ty(getVMContext()));`
early.


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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-04-29 Thread Sergei Barannikov via cfe-commits


@@ -21,6 +21,12 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
+// Empty struct is lowered as a placeholder word parameter.
+struct empty {};
+
+// CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
+struct empty f_empty(struct empty x) { return x; }
+

s-barannikov wrote:

There are corner cases like a struct with an empty base class or a struct with 
flexible array member (or a sturct containing such struct / array of 
structs...). These needs to be tested, too. See `isEmptyRecord` if it can help.
There are also functions with variadic arguments, they also need to be tested.


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


[clang] [Modules] Detect ODR mismatches for enums in non-C++ like in C++. (PR #90298)

2024-04-29 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

> Not sure I'm following the response here - but I guess what I'm trying to 
> say, with more words, is that my understanding was that C doesn't have an 
> ODR, and you can have different definitions of a type, with the same name, in 
> C and that's OK.

In different translation units you can still use different types with the same 
name. And you can use enum constant with the same name but different values. It 
is still OK from the compiler's perspective.

> And it sounds like this change makes that not OK in some way? (either by 
> diagnosing/erroring on such divergent types, or assuming they won't diverge 
> and carrying on silently)

The change is for Clang modules only. In the non-modular world including the 
same file twice (no header guards, no pragma once) would result in a type 
redefinition. But with modules it is more likely to find the same type 
definition in multiple modules. To make the compiler more practical we don't 
reject such situations. Though we detect when the types aren't identical and 
don't try to use them interchangeably. The change extends the existing behavior 
for structs/unions to enums.

If you have use cases when different enums should be used interchangeably, I 
can see how to accommodate such use cases.

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


[clang] [WebAssembly] Enable multivalue and reference-types in generic CPU config (PR #80923)

2024-04-29 Thread Heejin Ahn via cfe-commits

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


[clang] 5bbf1ea - [WebAssembly] Enable multivalue and reference-types in generic CPU config (#80923)

2024-04-29 Thread via cfe-commits

Author: Heejin Ahn
Date: 2024-04-29T14:23:08-07:00
New Revision: 5bbf1ea8f18d1f99637b7b8bf6b985c186c808f6

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

LOG: [WebAssembly] Enable multivalue and reference-types in generic CPU config 
(#80923)

This enables multivalue and reference-types in `-mcpu=generic`   
configuration. These proposals have been standardized and supported in   
all major browsers for several years at this point:  
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/WebAssembly.cpp
clang/test/Preprocessor/wasm-target-features.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 55e1670b7e2fa0..676f38a8e94c81 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -718,6 +718,11 @@ AIX Support
 WebAssembly Support
 ^^^
 
+The -mcpu=generic configuration now enables multivalue and 
reference-types.These
+proposals are standardized and available in all major engines. Enabling
+multivalue here only enables the language feature but does not turn on the
+multivalue ABI (this enables non-ABI uses of multivalue, like exnref).
+
 AVR Support
 ^^^
 

diff  --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 3d76411f890a86..0db7b668d8a0ac 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -148,20 +148,26 @@ void 
WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap ,
 bool WebAssemblyTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
-  if (CPU == "bleeding-edge") {
+  auto addGenericFeatures = [&]() {
+Features["multivalue"] = true;
+Features["mutable-globals"] = true;
+Features["reference-types"] = true;
+Features["sign-ext"] = true;
+  };
+  auto addBleedingEdgeFeatures = [&]() {
+addGenericFeatures();
 Features["atomics"] = true;
 Features["bulk-memory"] = true;
 Features["multimemory"] = true;
-Features["mutable-globals"] = true;
 Features["nontrapping-fptoint"] = true;
-Features["reference-types"] = true;
-Features["sign-ext"] = true;
 Features["tail-call"] = true;
 Features["half-precision"] = true;
 setSIMDLevel(Features, SIMD128, true);
-  } else if (CPU == "generic") {
-Features["mutable-globals"] = true;
-Features["sign-ext"] = true;
+  };
+  if (CPU == "generic") {
+addGenericFeatures();
+  } else if (CPU == "bleeding-edge") {
+addBleedingEdgeFeatures();
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);

diff  --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 32e24ad1b71656..19bd918543dfea 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -152,7 +152,9 @@
 // RUN: -target wasm64-unknown-unknown -mcpu=generic \
 // RUN:   | FileCheck %s -check-prefix=GENERIC-INCLUDE
 //
+// GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
+// GENERIC-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
@@ -167,9 +169,7 @@
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
 // GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
-// GENERIC-NOT: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
-// GENERIC-NOT: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
 // GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT: #define __wasm_tail_call__ 1{{$}}
@@ -184,6 +184,7 @@
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_atomics__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
+// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
 // BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
@@ -200,7 +201,6 @@
 //
 // BLEEDING-EDGE-NOT: #define __wasm_exception_handling__ 1{{$}}
 // BLEEDING-EDGE-NOT: #define __wasm_extended_const__ 1{{$}}
-// BLEEDING-EDGE-NOT: #define __wasm_multivalue__ 1{{$}}
 // BLEEDING-EDGE-NOT: #define __wasm_relaxed_simd__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 

[clang] [WebAssembly] Enable multivalue and reference-types in generic CPU config (PR #80923)

2024-04-29 Thread Heejin Ahn via cfe-commits

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


  1   2   3   4   5   >