[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread Ian Anderson via cfe-commits

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


[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread Ian Anderson via cfe-commits

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


[clang] d3df2a8 - [C++20] [Modules] Handle transitive import in the module properly

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

Author: Chuanqi Xu
Date: 2024-03-06T15:46:55+08:00
New Revision: d3df2a834cf6febb44c699d109b9e7f622194837

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

LOG: [C++20] [Modules] Handle transitive import in the module properly

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

Per [module.import]p7:

> Additionally, when a module-import-declaration in a module unit of
> some module M imports another module unit U of M, it also imports all
> translation units imported by non-exported module-import-declarations
> in the module unit purview of U.

However, we only tried to implement it during the implicit import of
primary module interface for module implementation unit.

Also we didn't implement the last sentence from [module.import]p7
completely:

> These rules can in turn lead to the importation of yet more
> translation units.

This patch tries to care the both issues.

Added: 
clang/test/Modules/transitive-import.cppm

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
clang/lib/Sema/SemaModule.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e0352a7eaf6cd..b074055a4eaf69 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -86,6 +86,11 @@ C++20 Feature Support
 - Implemented the `__is_layout_compatible` intrinsic to support
   `P0466R5: Layout-compatibility and Pointer-interconvertibility Traits 
`_.
 
+- Clang now implements [module.import]p7 fully. Clang now will import module
+  units transitively for the module units coming from the same module of the
+  current module units.
+  Fixes `#84002 `_.
+
 C++23 Feature Support
 ^
 

diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 30ec9c99315092..9f62c058ca0da0 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -598,6 +598,11 @@ class alignas(8) Module {
Kind == ModulePartitionImplementation;
   }
 
+  /// Is this a module partition implementation unit.
+  bool isModulePartitionImplementation() const {
+return Kind == ModulePartitionImplementation;
+  }
+
   /// Is this a module implementation.
   bool isModuleImplementation() const {
 return Kind == ModuleImplementationUnit;
@@ -853,12 +858,6 @@ class VisibleModuleSet {
   VisibleCallback Vis = [](Module *) {},
   ConflictCallback Cb = [](ArrayRef, Module *,
StringRef) {});
-
-  /// Make transitive imports visible for [module.import]/7.
-  void makeTransitiveImportsVisible(
-  Module *M, SourceLocation Loc, VisibleCallback Vis = [](Module *) {},
-  ConflictCallback Cb = [](ArrayRef, Module *, StringRef) {});
-
 private:
   /// Import locations for each visible module. Indexed by the module's
   /// VisibilityID.

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 1c5043a618fff3..9f597dcf8b0f5a 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -722,14 +722,6 @@ void VisibleModuleSet::setVisible(Module *M, 
SourceLocation Loc,
   VisitModule({M, nullptr});
 }
 
-void VisibleModuleSet::makeTransitiveImportsVisible(Module *M,
-SourceLocation Loc,
-VisibleCallback Vis,
-ConflictCallback Cb) {
-  for (auto *I : M->Imports)
-setVisible(I, Loc, Vis, Cb);
-}
-
 ASTSourceDescriptor::ASTSourceDescriptor(Module )
 : Signature(M.Signature), ClangModule() {
   if (M.Directory)

diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index ed7f626971f345..f08c1cb3a13ef5 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -73,6 +73,90 @@ static std::string stringFromPath(ModuleIdPath Path) {
   return Name;
 }
 
+/// Helper function for makeTransitiveImportsVisible to decide whether
+/// the \param Imported module unit is in the same module with the \param
+/// CurrentModule.
+/// \param FoundPrimaryModuleInterface is a helper parameter to record the
+/// primary module interface unit corresponding to the module \param
+/// CurrentModule. Since currently it is expensive to decide whether two module
+/// units come from the same module by comparing the module name.
+static bool
+isImportingModuleUnitFromSameModule(Module *Imported, Module *CurrentModule,
+Module *) {
+  if (!Imported->isNamedModule())
+return false;
+
+  // The a partition unit we're importing must be in 

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread via cfe-commits


@@ -268,20 +268,24 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isTypeName(IsCpp)) {

mydeveloperday wrote:

Thanks fine, we'll live with it..

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


[clang] [CUDA] Correctly set CUDA default architecture (PR #84017)

2024-03-05 Thread Jonas Hahnfeld via cfe-commits


@@ -2,56 +2,56 @@
 // REQUIRES: nvptx-registered-target
 // REQUIRES: zlib
 
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gz 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gz 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf 
-fdebug-info-for-profiling 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf -fdebug-info-for-profiling 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-2 
-gsplit-dwarf 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-2 -gsplit-dwarf 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-3 -glldb 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-3 -glldb 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-4 -gcodeview 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-4 -gcodeview 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-5 -gmodules 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-5 -gmodules 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb1 -fdebug-macro 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb1 -fdebug-macro 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb2 -ggnu-pubnames 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb2 -ggnu-pubnames 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb3 -gdwarf-aranges 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb3 -gdwarf-aranges 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gcolumn-info 
-fdebug-types-section 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gcolumn-info -fdebug-types-section 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
 
 // Same tests for OpenMP
-// RUN: not %clang -### --target=x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -fopenmp=libomp -c %s \

hahnjo wrote:

Please note that this completely dropped 
`-fopenmp-targets=nvptx64-nvidia-cuda`, so the test likely lost coverage...

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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

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

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH 1/6] [clang-format] Handle common C++ non-keyword types as
 such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle ) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -408,11 

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -620,6 +620,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("#define FOO(bar) foo((uint64_t))");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_CastRParen);
+  EXPECT_TOKEN(Tokens[11], tok::amp, TT_UnaryOperator);
+
+  Tokens = annotate("#define FOO(bar) foo((time_t) & bar)");

owenca wrote:

I intentionally excluded `time_t`, but on second thought I'll add it, along 
with `clock_t`.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -268,20 +268,24 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isTypeName(IsCpp)) {

owenca wrote:

Neither am I, but I don't know of a better way. BTW, 
`Token::isSimpleTypeSpecifier(const LangOptions )` also has a similar 
parameter.

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

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


@@ -71,8 +71,21 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"int16_t",  "int32_t",  "int64_t",  "int8_t",  "intptr_t",  "size_t",

owenca wrote:

`ssize_t` is a POSIX type. Regarding the fixed-width integer types, I wanted to 
start with a few common ones. (I will add `ptrdiff_t` though.)

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


[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/84127

>From e34ccad2b82b75c050d12bbb987529c320c0df9d Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Tue, 5 Mar 2024 22:56:36 -0800
Subject: [PATCH] [clang][modules] giving the __stddef_ headers their own
 modules can cause redeclaration errors with
 -fbuiltin-headers-in-system-modules

On Apple platforms, some of the stddef.h types are also declared in system 
headers. In particular NULL has a conflicting declaration in 
. When that's in a different module from <__stddef_null.h>, 
redeclaration errors can occur.

Make the __stddef_ headers be non-modular in 
-fbuiltin-headers-in-system-modules and restore them back to not respecting 
their header guards. Still define the header guards though. 
__stddef_max_align_t.h was in _Builtin_stddef_max_align_t prior to the addition 
of _Builtin_stddef, and it needs to stay in a module because struct's can't be 
type merged. __stddef_wint_t.h didn't used to have a module, but leave it in it 
current module since it doesn't really belong to stddef.h.
---
 clang/lib/Basic/Module.cpp|  7 ++--
 clang/lib/Headers/__stddef_null.h |  2 +-
 clang/lib/Headers/__stddef_nullptr_t.h|  7 +++-
 clang/lib/Headers/__stddef_offsetof.h |  7 +++-
 clang/lib/Headers/__stddef_ptrdiff_t.h|  7 +++-
 clang/lib/Headers/__stddef_rsize_t.h  |  7 +++-
 clang/lib/Headers/__stddef_size_t.h   |  7 +++-
 clang/lib/Headers/__stddef_unreachable.h  |  7 +++-
 clang/lib/Headers/__stddef_wchar_t.h  |  7 +++-
 clang/lib/Headers/module.modulemap| 20 ++--
 clang/lib/Lex/ModuleMap.cpp   |  9 --
 .../no-undeclared-includes-builtins.cpp   |  2 +-
 clang/test/Modules/stddef.c   | 32 +++
 13 files changed, 80 insertions(+), 41 deletions(-)

diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 1c5043a618fff3..f68a556fb455bf 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -301,10 +301,9 @@ bool Module::directlyUses(const Module *Requested) {
 if (Requested->isSubModuleOf(Use))
   return true;
 
-  // Anyone is allowed to use our builtin stdarg.h and stddef.h and their
-  // accompanying modules.
-  if (Requested->getTopLevelModuleName() == "_Builtin_stdarg" ||
-  Requested->getTopLevelModuleName() == "_Builtin_stddef")
+  // Anyone is allowed to use our builtin stddef.h and its accompanying 
modules.
+  if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) ||
+  Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"}))
 return true;
 
   if (NoUndeclaredIncludes)
diff --git a/clang/lib/Headers/__stddef_null.h 
b/clang/lib/Headers/__stddef_null.h
index 7336fdab389723..c10bd2d7d9887c 100644
--- a/clang/lib/Headers/__stddef_null.h
+++ b/clang/lib/Headers/__stddef_null.h
@@ -7,7 +7,7 @@
  *===---===
  */
 
-#if !defined(NULL) || !__has_feature(modules)
+#if !defined(NULL) || !__building_module(_Builtin_stddef)
 
 /* linux/stddef.h will define NULL to 0. glibc (and other) headers then define
  * __need_NULL and rely on stddef.h to redefine NULL to the correct value 
again.
diff --git a/clang/lib/Headers/__stddef_nullptr_t.h 
b/clang/lib/Headers/__stddef_nullptr_t.h
index 183d394d56c1b7..7f3fbe6fe0d3a8 100644
--- a/clang/lib/Headers/__stddef_nullptr_t.h
+++ b/clang/lib/Headers/__stddef_nullptr_t.h
@@ -7,7 +7,12 @@
  *===---===
  */
 
-#ifndef _NULLPTR_T
+/*
+ * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
+ * and needs to behave as if it was textual.
+ */
+#if !defined(_NULLPTR_T) ||
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define _NULLPTR_T
 
 #ifdef __cplusplus
diff --git a/clang/lib/Headers/__stddef_offsetof.h 
b/clang/lib/Headers/__stddef_offsetof.h
index 3b347b3b92f62c..84172c6cd27352 100644
--- a/clang/lib/Headers/__stddef_offsetof.h
+++ b/clang/lib/Headers/__stddef_offsetof.h
@@ -7,6 +7,11 @@
  *===---===
  */
 
-#ifndef offsetof
+/*
+ * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
+ * and needs to behave as if it was textual.
+ */
+#if !defined(offsetof) ||  
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define offsetof(t, d) __builtin_offsetof(t, d)
 #endif
diff --git a/clang/lib/Headers/__stddef_ptrdiff_t.h 
b/clang/lib/Headers/__stddef_ptrdiff_t.h
index 3ea6d7d2852e1c..fd3c893c66c979 100644
--- a/clang/lib/Headers/__stddef_ptrdiff_t.h
+++ b/clang/lib/Headers/__stddef_ptrdiff_t.h
@@ -7,7 +7,12 @@
  

[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread Ian Anderson via cfe-commits


@@ -7,7 +7,7 @@
  *===---===
  */
 
-#if !defined(NULL) || !__has_feature(modules)
+#if !defined(NULL) || !__building_module(_Builtin_stddef)

ian-twilightcoder wrote:

```
#if !defined(NULL) || !__has_feature(modules) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
```
If `!__has_feature(modules)` then `__building_module(anything)` is `0`. So you 
can make these substitutions without changing the logic.
```
!__has_feature(modules)
!__has_feature(modules) && !__building_module(_Builtin_stddef)

!__has_feature(modules) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
(!__has_feature(modules) && !__building_module(_Builtin_stddef)) || 
(__has_feature(modules) && !__building_module(_Builtin_stddef))

(!a && b) || (a && b)
b

(!__has_feature(modules) && !__building_module(_Builtin_stddef)) || 
(__has_feature(modules) && !__building_module(_Builtin_stddef))
!__building_module(_Builtin_stddef)
```

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


[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)

2024-03-05 Thread Craig Topper via cfe-commits

topperc wrote:

> > By the way, is there any plan to support `CFLUSH.I.L1` in the future?
> 
> Flushing the instruction cache doesn't make sense given it can never be 
> dirty. Invalidating/discarding does, but that's just what fence.i is doing?

A cflush.i.l1 did appear in some SiFive manual at some point, but I don't think 
any hardware implements it.

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


[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff bf631c63d01057321c070520a56a150ede32e47d 
0cc4b77fce06730f6a6a8b242384036018ebfe79 -- clang/lib/Basic/Module.cpp 
clang/lib/Headers/__stddef_null.h clang/lib/Headers/__stddef_nullptr_t.h 
clang/lib/Headers/__stddef_offsetof.h clang/lib/Headers/__stddef_ptrdiff_t.h 
clang/lib/Headers/__stddef_rsize_t.h clang/lib/Headers/__stddef_size_t.h 
clang/lib/Headers/__stddef_unreachable.h clang/lib/Headers/__stddef_wchar_t.h 
clang/lib/Lex/ModuleMap.cpp 
clang/test/Modules/no-undeclared-includes-builtins.cpp 
clang/test/Modules/stddef.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/__stddef_nullptr_t.h 
b/clang/lib/Headers/__stddef_nullptr_t.h
index d724b5cba1..7f3fbe6fe0 100644
--- a/clang/lib/Headers/__stddef_nullptr_t.h
+++ b/clang/lib/Headers/__stddef_nullptr_t.h
@@ -11,7 +11,8 @@
  * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
  * and needs to behave as if it was textual.
  */
-#if !defined(_NULLPTR_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
+#if !defined(_NULLPTR_T) ||
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define _NULLPTR_T
 
 #ifdef __cplusplus
diff --git a/clang/lib/Headers/__stddef_offsetof.h 
b/clang/lib/Headers/__stddef_offsetof.h
index 62c49c78bd..84172c6cd2 100644
--- a/clang/lib/Headers/__stddef_offsetof.h
+++ b/clang/lib/Headers/__stddef_offsetof.h
@@ -11,6 +11,7 @@
  * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
  * and needs to behave as if it was textual.
  */
-#if !defined(offsetof) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
+#if !defined(offsetof) ||  
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define offsetof(t, d) __builtin_offsetof(t, d)
 #endif
diff --git a/clang/lib/Headers/__stddef_ptrdiff_t.h 
b/clang/lib/Headers/__stddef_ptrdiff_t.h
index 31ecc00b62..fd3c893c66 100644
--- a/clang/lib/Headers/__stddef_ptrdiff_t.h
+++ b/clang/lib/Headers/__stddef_ptrdiff_t.h
@@ -11,7 +11,8 @@
  * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
  * and needs to behave as if it was textual.
  */
-#if !defined(_PTRDIFF_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
+#if !defined(_PTRDIFF_T) ||
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define _PTRDIFF_T
 
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
diff --git a/clang/lib/Headers/__stddef_rsize_t.h 
b/clang/lib/Headers/__stddef_rsize_t.h
index 9cb9c26611..dd433d40d9 100644
--- a/clang/lib/Headers/__stddef_rsize_t.h
+++ b/clang/lib/Headers/__stddef_rsize_t.h
@@ -11,7 +11,8 @@
  * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
  * and needs to behave as if it was textual.
  */
-#if !defined(_RSIZE_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
+#if !defined(_RSIZE_T) ||  
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define _RSIZE_T
 
 typedef __SIZE_TYPE__ rsize_t;
diff --git a/clang/lib/Headers/__stddef_size_t.h 
b/clang/lib/Headers/__stddef_size_t.h
index 01d3a0c480..3dd7b1f379 100644
--- a/clang/lib/Headers/__stddef_size_t.h
+++ b/clang/lib/Headers/__stddef_size_t.h
@@ -11,7 +11,8 @@
  * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
  * and needs to behave as if it was textual.
  */
-#if !defined(_SIZE_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
+#if !defined(_SIZE_T) ||   
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define _SIZE_T
 
 typedef __SIZE_TYPE__ size_t;
diff --git a/clang/lib/Headers/__stddef_unreachable.h 
b/clang/lib/Headers/__stddef_unreachable.h
index 1f9254f6bb..518580c92d 100644
--- a/clang/lib/Headers/__stddef_unreachable.h
+++ b/clang/lib/Headers/__stddef_unreachable.h
@@ -11,6 +11,7 @@
  * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
  * and needs to behave as if it was textual.
  */
-#if !defined(unreachable) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
+#if !defined(unreachable) ||   
\
+(__has_feature(modules) && !__building_module(_Builtin_stddef))
 #define unreachable() __builtin_unreachable()
 #endif
diff --git a/clang/lib/Headers/__stddef_wchar_t.h 
b/clang/lib/Headers/__stddef_wchar_t.h
index 4239f619f0..bd69f63225 100644
--- a/clang/lib/Headers/__stddef_wchar_t.h
+++ 

[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

We should consider this for LLVM 18, it's a regression from 
https://reviews.llvm.org/D159064

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


[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: Ian Anderson (ian-twilightcoder)


Changes

On Apple platforms, some of the stddef.h types are also declared in system 
headers. In particular NULL has a conflicting declaration in 
sys/_types/_null.h. When that's in a different module from 
__stddef_null.h, redeclaration errors can occur.

Make the __stddef_ headers be non-modular in 
-fbuiltin-headers-in-system-modules and restore them back to not respecting 
their header guards. Still define the header guards though. 
__stddef_max_align_t.h was in _Builtin_stddef_max_align_t prior to the addition 
of _Builtin_stddef, and it needs to stay in a module because struct's can't be 
type merged. __stddef_wint_t.h didn't used to have a module, but leave it in it 
current module since it doesn't really belong to stddef.h.

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


13 Files Affected:

- (modified) clang/lib/Basic/Module.cpp (+3-4) 
- (modified) clang/lib/Headers/__stddef_null.h (+1-1) 
- (modified) clang/lib/Headers/__stddef_nullptr_t.h (+5-1) 
- (modified) clang/lib/Headers/__stddef_offsetof.h (+5-1) 
- (modified) clang/lib/Headers/__stddef_ptrdiff_t.h (+5-1) 
- (modified) clang/lib/Headers/__stddef_rsize_t.h (+5-1) 
- (modified) clang/lib/Headers/__stddef_size_t.h (+5-1) 
- (modified) clang/lib/Headers/__stddef_unreachable.h (+5-1) 
- (modified) clang/lib/Headers/__stddef_wchar_t.h (+5-1) 
- (modified) clang/lib/Headers/module.modulemap (+9-11) 
- (modified) clang/lib/Lex/ModuleMap.cpp (+6-3) 
- (modified) clang/test/Modules/no-undeclared-includes-builtins.cpp (+1-1) 
- (modified) clang/test/Modules/stddef.c (+18-14) 


``diff
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 1c5043a618fff3..f68a556fb455bf 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -301,10 +301,9 @@ bool Module::directlyUses(const Module *Requested) {
 if (Requested->isSubModuleOf(Use))
   return true;
 
-  // Anyone is allowed to use our builtin stdarg.h and stddef.h and their
-  // accompanying modules.
-  if (Requested->getTopLevelModuleName() == "_Builtin_stdarg" ||
-  Requested->getTopLevelModuleName() == "_Builtin_stddef")
+  // Anyone is allowed to use our builtin stddef.h and its accompanying 
modules.
+  if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) ||
+  Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"}))
 return true;
 
   if (NoUndeclaredIncludes)
diff --git a/clang/lib/Headers/__stddef_null.h 
b/clang/lib/Headers/__stddef_null.h
index 7336fdab389723..c10bd2d7d9887c 100644
--- a/clang/lib/Headers/__stddef_null.h
+++ b/clang/lib/Headers/__stddef_null.h
@@ -7,7 +7,7 @@
  *===---===
  */
 
-#if !defined(NULL) || !__has_feature(modules)
+#if !defined(NULL) || !__building_module(_Builtin_stddef)
 
 /* linux/stddef.h will define NULL to 0. glibc (and other) headers then define
  * __need_NULL and rely on stddef.h to redefine NULL to the correct value 
again.
diff --git a/clang/lib/Headers/__stddef_nullptr_t.h 
b/clang/lib/Headers/__stddef_nullptr_t.h
index 183d394d56c1b7..d724b5cba18294 100644
--- a/clang/lib/Headers/__stddef_nullptr_t.h
+++ b/clang/lib/Headers/__stddef_nullptr_t.h
@@ -7,7 +7,11 @@
  *===---===
  */
 
-#ifndef _NULLPTR_T
+/*
+ * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
+ * and needs to behave as if it was textual.
+ */
+#if !defined(_NULLPTR_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
 #define _NULLPTR_T
 
 #ifdef __cplusplus
diff --git a/clang/lib/Headers/__stddef_offsetof.h 
b/clang/lib/Headers/__stddef_offsetof.h
index 3b347b3b92f62c..62c49c78bd0516 100644
--- a/clang/lib/Headers/__stddef_offsetof.h
+++ b/clang/lib/Headers/__stddef_offsetof.h
@@ -7,6 +7,10 @@
  *===---===
  */
 
-#ifndef offsetof
+/*
+ * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
+ * and needs to behave as if it was textual.
+ */
+#if !defined(offsetof) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
 #define offsetof(t, d) __builtin_offsetof(t, d)
 #endif
diff --git a/clang/lib/Headers/__stddef_ptrdiff_t.h 
b/clang/lib/Headers/__stddef_ptrdiff_t.h
index 3ea6d7d2852e1c..31ecc00b624602 100644
--- a/clang/lib/Headers/__stddef_ptrdiff_t.h
+++ b/clang/lib/Headers/__stddef_ptrdiff_t.h
@@ -7,7 +7,11 @@
  *===---===
  */
 
-#ifndef _PTRDIFF_T
+/*
+ * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
+ * and needs to behave as if it was textual.
+ */
+#if !defined(_PTRDIFF_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
 #define _PTRDIFF_T
 
 typedef 

[clang] [clang][modules] giving the __stddef_ headers their own modules can cause redeclaration errors with -fbuiltin-headers-in-system-modules (PR #84127)

2024-03-05 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder created 
https://github.com/llvm/llvm-project/pull/84127

On Apple platforms, some of the stddef.h types are also declared in system 
headers. In particular NULL has a conflicting declaration in 
. When that's in a different module from <__stddef_null.h>, 
redeclaration errors can occur.

Make the __stddef_ headers be non-modular in 
-fbuiltin-headers-in-system-modules and restore them back to not respecting 
their header guards. Still define the header guards though. 
__stddef_max_align_t.h was in _Builtin_stddef_max_align_t prior to the addition 
of _Builtin_stddef, and it needs to stay in a module because struct's can't be 
type merged. __stddef_wint_t.h didn't used to have a module, but leave it in it 
current module since it doesn't really belong to stddef.h.

>From 0cc4b77fce06730f6a6a8b242384036018ebfe79 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Tue, 5 Mar 2024 22:56:36 -0800
Subject: [PATCH] [clang][modules] giving the __stddef_ headers their own
 modules can cause redeclaration errors with
 -fbuiltin-headers-in-system-modules

On Apple platforms, some of the stddef.h types are also declared in system 
headers. In particular NULL has a conflicting declaration in 
. When that's in a different module from <__stddef_null.h>, 
redeclaration errors can occur.

Make the __stddef_ headers be non-modular in 
-fbuiltin-headers-in-system-modules and restore them back to not respecting 
their header guards. Still define the header guards though. 
__stddef_max_align_t.h was in _Builtin_stddef_max_align_t prior to the addition 
of _Builtin_stddef, and it needs to stay in a module because struct's can't be 
type merged. __stddef_wint_t.h didn't used to have a module, but leave it in it 
current module since it doesn't really belong to stddef.h.
---
 clang/lib/Basic/Module.cpp|  7 ++--
 clang/lib/Headers/__stddef_null.h |  2 +-
 clang/lib/Headers/__stddef_nullptr_t.h|  6 +++-
 clang/lib/Headers/__stddef_offsetof.h |  6 +++-
 clang/lib/Headers/__stddef_ptrdiff_t.h|  6 +++-
 clang/lib/Headers/__stddef_rsize_t.h  |  6 +++-
 clang/lib/Headers/__stddef_size_t.h   |  6 +++-
 clang/lib/Headers/__stddef_unreachable.h  |  6 +++-
 clang/lib/Headers/__stddef_wchar_t.h  |  6 +++-
 clang/lib/Headers/module.modulemap| 20 ++--
 clang/lib/Lex/ModuleMap.cpp   |  9 --
 .../no-undeclared-includes-builtins.cpp   |  2 +-
 clang/test/Modules/stddef.c   | 32 +++
 13 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 1c5043a618fff3..f68a556fb455bf 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -301,10 +301,9 @@ bool Module::directlyUses(const Module *Requested) {
 if (Requested->isSubModuleOf(Use))
   return true;
 
-  // Anyone is allowed to use our builtin stdarg.h and stddef.h and their
-  // accompanying modules.
-  if (Requested->getTopLevelModuleName() == "_Builtin_stdarg" ||
-  Requested->getTopLevelModuleName() == "_Builtin_stddef")
+  // Anyone is allowed to use our builtin stddef.h and its accompanying 
modules.
+  if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) ||
+  Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"}))
 return true;
 
   if (NoUndeclaredIncludes)
diff --git a/clang/lib/Headers/__stddef_null.h 
b/clang/lib/Headers/__stddef_null.h
index 7336fdab389723..c10bd2d7d9887c 100644
--- a/clang/lib/Headers/__stddef_null.h
+++ b/clang/lib/Headers/__stddef_null.h
@@ -7,7 +7,7 @@
  *===---===
  */
 
-#if !defined(NULL) || !__has_feature(modules)
+#if !defined(NULL) || !__building_module(_Builtin_stddef)
 
 /* linux/stddef.h will define NULL to 0. glibc (and other) headers then define
  * __need_NULL and rely on stddef.h to redefine NULL to the correct value 
again.
diff --git a/clang/lib/Headers/__stddef_nullptr_t.h 
b/clang/lib/Headers/__stddef_nullptr_t.h
index 183d394d56c1b7..d724b5cba18294 100644
--- a/clang/lib/Headers/__stddef_nullptr_t.h
+++ b/clang/lib/Headers/__stddef_nullptr_t.h
@@ -7,7 +7,11 @@
  *===---===
  */
 
-#ifndef _NULLPTR_T
+/*
+ * When -fbuiltin-headers-in-system-modules is set this is a non-modular header
+ * and needs to behave as if it was textual.
+ */
+#if !defined(_NULLPTR_T) || (__has_feature(modules) && 
!__building_module(_Builtin_stddef))
 #define _NULLPTR_T
 
 #ifdef __cplusplus
diff --git a/clang/lib/Headers/__stddef_offsetof.h 
b/clang/lib/Headers/__stddef_offsetof.h
index 3b347b3b92f62c..62c49c78bd0516 100644
--- a/clang/lib/Headers/__stddef_offsetof.h
+++ b/clang/lib/Headers/__stddef_offsetof.h
@@ -7,6 +7,10 @@
  *===---===
  */
 

[clang] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted object references within trivial statements (PR #82229)

2024-03-05 Thread Ryosuke Niwa via cfe-commits


@@ -474,4 +504,22 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   return Result;
 }
 
+bool TrivialFunctionAnalysis::isTrivialImpl(
+const Stmt *S, TrivialFunctionAnalysis::CacheTy ) {
+  // If the statement isn't in the cache, conservatively assume that
+  // it's not trivial until analysis completes. Unlike a function case,
+  // we don't insert an entry into the cache until Visit returns
+  // since Visit* functions themselves make use of the cache.

rniwa wrote:

Sure, I need to make TrivialFunctionAnalysisVisitor reference the cache via a 
reference instead of via copy though.

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


[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)

2024-03-05 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

> By the way, is there any plan to support `CFLUSH.I.L1` in the future?

Flushing the instruction cache doesn't make sense given it can never be dirty. 
Invalidating/discarding does, but that's just what fence.i is doing?

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


[clang] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted object references within trivial statements (PR #82229)

2024-03-05 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82229

>From 234e301ab2721ddb2f4b43589785015a7d0aa304 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 19 Feb 2024 01:07:13 -0800
Subject: [PATCH 1/7] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted
 object references within trivial statements

This PR makes alpha.webkit.UncountedLocalVarsChecker ignore raw references and 
pointers to
a ref counted type which appears within "trival" statements. To do this, this 
PR extends
TrivialFunctionAnalysis so that it can also analyze "triviality" of statements 
as well as
that of functions Each Visit* function is now augmented with withCachedResult, 
which is
responsible for looking up and updating the cache for each Visit* functions.

As this PR dramatically improves the false positive rate of the checker, it 
also deletes
the code to ignore raw pointers and references within if and for statements.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 222 --
 .../Checkers/WebKit/PtrTypesSemantics.h   |  21 +-
 .../WebKit/UncountedLocalVarsChecker.cpp  |  69 +++---
 .../Analysis/Checkers/WebKit/mock-types.h |   2 +
 .../Checkers/WebKit/uncounted-local-vars.cpp  |  92 +++-
 5 files changed, 285 insertions(+), 121 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 01b191ab0eeaf4..6c9a8aedb38a4c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -245,18 +245,41 @@ class TrivialFunctionAnalysisVisitor
 
   // Returns false if at least one child is non-trivial.
   bool VisitChildren(const Stmt *S) {
-for (const Stmt *Child : S->children()) {
-  if (Child && !Visit(Child))
+return withCachedResult(S, [&]() {
+  for (const Stmt *Child : S->children()) {
+if (Child && !Visit(Child))
+  return false;
+  }
+  return true;
+});
+  }
+
+  bool VisitSubExpr(const Expr *Parent, const Expr *E) {
+return withCachedResult(Parent, [&]() {
+  if (!Visit(E))
 return false;
-}
+  return true;
+});
+  }
 
-return true;
+  template 
+  bool withCachedResult(const StmtType *S, CheckFunction Function) {
+// Insert false to the cache first to avoid infinite recursion.
+auto [It, IsNew] = StatementCache.insert(std::make_pair(S, false));
+if (!IsNew)
+  return It->second;
+bool Result = Function();
+It->second = Result;
+return Result;
   }
 
 public:
-  using CacheTy = TrivialFunctionAnalysis::CacheTy;
+  using FunctionCacheTy = TrivialFunctionAnalysis::FunctionCacheTy;
+  using StatementCacheTy = TrivialFunctionAnalysis::StatementCacheTy;
 
-  TrivialFunctionAnalysisVisitor(CacheTy ) : Cache(Cache) {}
+  TrivialFunctionAnalysisVisitor(FunctionCacheTy ,
+ StatementCacheTy )
+  : FunctionCache(FunctionCache), StatementCache(StatementCache) {}
 
   bool VisitStmt(const Stmt *S) {
 // All statements are non-trivial unless overriden later.
@@ -272,13 +295,21 @@ class TrivialFunctionAnalysisVisitor
 
   bool VisitReturnStmt(const ReturnStmt *RS) {
 // A return statement is allowed as long as the return value is trivial.
-if (auto *RV = RS->getRetValue())
-  return Visit(RV);
-return true;
+return withCachedResult(RS, [&]() {
+  if (auto *RV = RS->getRetValue())
+return Visit(RV);
+  return true;
+});
+  }
+
+  bool VisitCXXForRangeStmt(const CXXForRangeStmt *FS) {
+return VisitChildren(FS);
   }
 
   bool VisitDeclStmt(const DeclStmt *DS) { return VisitChildren(DS); }
   bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
+  bool VisitForStmt(const ForStmt *FS) { return VisitChildren(FS); }
+  bool VisitWhileStmt(const WhileStmt *WS) { return VisitChildren(WS); }
   bool VisitIfStmt(const IfStmt *IS) { return VisitChildren(IS); }
   bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
   bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
@@ -286,17 +317,26 @@ class TrivialFunctionAnalysisVisitor
 
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
-if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
-UO->getOpcode() == UO_LNot)
-  return Visit(UO->getSubExpr());
-
-// Other operators are non-trivial.
-return false;
+return withCachedResult(UO, [&]() {
+  auto op = UO->getOpcode();
+  if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+return Visit(UO->getSubExpr());
+  if (UO->isIncrementOp() || UO->isDecrementOp()) {
+if (auto *RefExpr = dyn_cast(UO->getSubExpr())) {
+  if (auto *Decl = dyn_cast(RefExpr->getDecl()))
+return Decl->isLocalVarDeclOrParm() &&
+ 

[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread Nemanja Ivanovic via cfe-commits


@@ -364,7 +364,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   // have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
   static constexpr int MINIMUM_AIX_OS_MAJOR = 7;
   static constexpr int MINIMUM_AIX_OS_MINOR = 2;
-  bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
+  bool supportsCpuSupports() const override {

nemanjai wrote:

My personal preference is to keep them separate as the added verbosity makes it 
very obvious what is being queried.

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread Nemanja Ivanovic via cfe-commits


@@ -141,23 +149,30 @@ PPC_LNX_CPU("power10",47)
   #define AIX_BUILTIN_PPC_TRUE 1
   #define AIX_BUILTIN_PPC_FALSE 0
   #define USE_SYS_CONF 2
+  #define SYS_CALL 3
 
   // Supported COMPARE_OP values.
   #define COMP_EQ  0
+  #define COMP_GT 1
+  #define COMP_GE 2
+  #define COMP_NE 3

nemanjai wrote:

Can we not omit this and use `CmpInst::Predicate` in the function-style macros 
(thereby eliminating the need for the switch statement that uses them as well)?

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread Nemanja Ivanovic via cfe-commits


@@ -0,0 +1,171 @@
+// RUN: echo "int main() { return __builtin_cpu_supports(\"4xxmac\");}" > %t.c

nemanjai wrote:

This is an interesting way of testing, where we create each test on the fly. I 
am not against it if it works on all platforms (including Windows). However, I 
would like to see one test case where we have multiple calls to the builtins, 
with multiple uses of each "support method" in the same compilation unit.

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread Nemanja Ivanovic via cfe-commits


@@ -16570,32 +16570,72 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 
 #include "llvm/TargetParser/PPCTargetParser.def"
   auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx,

nemanjai wrote:

This is now a very large lambda function AFAICT. Please extract it into a 
static function to aid readability.

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-03-05 Thread Nemanja Ivanovic via cfe-commits


@@ -141,23 +149,30 @@ PPC_LNX_CPU("power10",47)
   #define AIX_BUILTIN_PPC_TRUE 1
   #define AIX_BUILTIN_PPC_FALSE 0
   #define USE_SYS_CONF 2
+  #define SYS_CALL 3
 
   // Supported COMPARE_OP values.
   #define COMP_EQ  0
+  #define COMP_GT 1
+  #define COMP_GE 2
+  #define COMP_NE 3
 
 #endif
 
 // The value of SUPPORT_METHOD can be AIX_BUILTIN_PPC_TRUE,
-// AIX_BUILTIN_PPC_FALSE, or USE_SYS_CONF.
-// When the value of SUPPORT_METHOD is USE_SYS_CONF, the return value
-// depends on the result of comparing the data member of
-// _system_configuration specified by INDEX with a certain value.
+// AIX_BUILTIN_PPC_FALSE, USE_SYS_CONF, SYS_CALL.
+// When the value of SUPPORT_METHOD is set to USE_SYS_CONF, the return value
+// depends on comparing VALUE with the specified data member of
+// _system_configuration at INDEX, where the data member is masked by Mask.
+// When the SUPPORT_METHOD value is set to SYS_CALL, the return value depends
+// on comparing a VALUE with the return value of calling `getsystemcfg`
+//  with the parameter INDEX, which is then masked by Mask.

nemanjai wrote:

And presumably:
```
// AIX_BUILTIN_PPC_TRUE and AIX_BUILTIN_PPC_FALSE are for features
// that are supported or unsupported on all systems respectively.
```
?

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


[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)

2024-03-05 Thread Shao-Ce SUN via cfe-commits

sunshaoce wrote:

By the way, is there any plan to support `CFLUSH.I.L1` in the future?

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-03-05 Thread Phoebe Wang via cfe-commits

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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

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

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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

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

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-03-05 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,165 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=i686-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X86
+; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X32
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X64
+
+@x = thread_local global i32 0, align 4
+@y = internal thread_local global i32 0, align 4

phoebewang wrote:

Thanks @frobtech for the explanation. IIUC, GCC will use `_TLS_MODULE_BASE_` if 
there are more than 1 local TLS variables, right?

I have no idea how to do it smartly in codegen in LLVM since we lower it 
statelessly. Maybe let's land this first? @MaskRay @frobtech 

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -1237,6 +1259,101 @@ void InstrLowerer::maybeSetComdat(GlobalVariable *GV, 
Function *Fn,
 GV->setLinkage(GlobalValue::InternalLinkage);
 }
 
+static inline bool shouldRecordVTableAddr(GlobalVariable *GV) {
+  if (!profDataReferencedByCode(*GV->getParent()))
+return false;
+
+  if (!GV->hasLinkOnceLinkage() && !GV->hasLocalLinkage() &&
+  !GV->hasAvailableExternallyLinkage())
+return true;
+
+  // This avoids the profile data from referencing internal symbols in
+  // COMDAT.
+  if (GV->hasLocalLinkage() && GV->hasComdat())
+return false;
+
+  return true;
+}
+
+// FIXME: Introduce an internal alias like what's done for functions to reduce
+// the number of relocation entries.
+static inline Constant *getVTableAddrForProfData(GlobalVariable *GV) {
+  auto *Int8PtrTy = PointerType::getUnqual(GV->getContext());
+
+  // Store a nullptr in __profvt_ if a real address shouldn't be used.
+  if (!shouldRecordVTableAddr(GV))
+return ConstantPointerNull::get(Int8PtrTy);
+
+  return ConstantExpr::getBitCast(GV, Int8PtrTy);
+}
+
+void InstrLowerer::getOrCreateVTableProfData(GlobalVariable *GV) {
+  assert(!DebugInfoCorrelate &&
+ "Value profiling is not supported with lightweight instrumentation");
+  if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
+return;
+
+  if (GV->getName().starts_with("llvm.") ||
+  GV->getName().starts_with("__llvm") ||
+  GV->getName().starts_with("__prof"))
+return;
+
+  // VTableProfData already created
+  auto It = VTableDataMap.find(GV);
+  if (It != VTableDataMap.end() && It->second)
+return;
+
+  GlobalValue::LinkageTypes Linkage = GV->getLinkage();
+  GlobalValue::VisibilityTypes Visibility = GV->getVisibility();
+
+  // This is to keep consistent with per-function profile data
+  // for correctness.
+  if (TT.isOSBinFormatXCOFF()) {
+Linkage = GlobalValue::InternalLinkage;
+Visibility = GlobalValue::DefaultVisibility;
+  }
+
+  LLVMContext  = M.getContext();
+  Type *DataTypes[] = {
+#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) LLVMType,
+#include "llvm/ProfileData/InstrProfData.inc"
+  };
+
+  auto *DataTy = StructType::get(Ctx, ArrayRef(DataTypes));
+
+  // Used by INSTR_PROF_VTABLE_DATA MACRO
+  Constant *VTableAddr = getVTableAddrForProfData(GV);
+  const std::string PGOVTableName = getPGOName(*GV);
+  // Record the length of the vtable. This is needed since vtable pointers
+  // loaded from C++ objects might be from the middle of a vtable definition.
+  uint32_t VTableSizeVal =
+  M.getDataLayout().getTypeAllocSize(GV->getValueType());
+
+  Constant *DataVals[] = {
+#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) Init,
+#include "llvm/ProfileData/InstrProfData.inc"
+  };
+
+  std::string VarName = getInstrProfVTableVarPrefix().str() + PGOVTableName;

minglotus-6 wrote:

done.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -605,6 +703,19 @@ Function* InstrProfSymtab::getFunction(uint64_t 
FuncMD5Hash) {
   return nullptr;
 }
 
+GlobalVariable *
+InstrProfSymtab::getGlobalVariable(uint64_t GlobalVariableMD5Hash) {
+  finalizeSymtab();

minglotus-6 wrote:

Indeed. With a DenseMap there is no need to call 'finalizeSymtab' (which sorts 
the vectors for look-up). Done.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -538,14 +541,30 @@ Error RawInstrProfReader::readNextHeader(const 
char *CurrentPos) {
 
 template 
 Error RawInstrProfReader::createSymtab(InstrProfSymtab ) {
-  if (Error E = Symtab.create(StringRef(NamesStart, NamesEnd - NamesStart)))
+  if (Error E = Symtab.create(StringRef(NamesStart, NamesEnd - NamesStart),
+  StringRef(VNamesStart, VNamesEnd - VNamesStart)))
 return error(std::move(E));
   for (const RawInstrProf::ProfileData *I = Data; I != DataEnd; ++I) {
 const IntPtrT FPtr = swap(I->FunctionPointer);
 if (!FPtr)
   continue;
 Symtab.mapAddress(FPtr, swap(I->NameRef));
   }
+
+  if (VTableBegin != nullptr && VTableEnd != nullptr) {
+for (const RawInstrProf::VTableProfileData *I = VTableBegin;
+ I != VTableEnd; ++I) {
+  const IntPtrT VPtr = swap(I->VTablePointer);

minglotus-6 wrote:

`swap` handles byte order properly for fields in raw profiles. Interestingly I 
thought it was 'std::swap' until spotting the bug related with endianness 
(fixed by https://github.com/llvm/llvm-project/pull/76312)

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -1237,6 +1259,101 @@ void InstrLowerer::maybeSetComdat(GlobalVariable *GV, 
Function *Fn,
 GV->setLinkage(GlobalValue::InternalLinkage);
 }
 
+static inline bool shouldRecordVTableAddr(GlobalVariable *GV) {
+  if (!profDataReferencedByCode(*GV->getParent()))
+return false;
+
+  if (!GV->hasLinkOnceLinkage() && !GV->hasLocalLinkage() &&
+  !GV->hasAvailableExternallyLinkage())
+return true;
+
+  // This avoids the profile data from referencing internal symbols in
+  // COMDAT.
+  if (GV->hasLocalLinkage() && GV->hasComdat())
+return false;
+
+  return true;
+}
+
+// FIXME: Introduce an internal alias like what's done for functions to reduce
+// the number of relocation entries.
+static inline Constant *getVTableAddrForProfData(GlobalVariable *GV) {
+  auto *Int8PtrTy = PointerType::getUnqual(GV->getContext());
+
+  // Store a nullptr in __profvt_ if a real address shouldn't be used.
+  if (!shouldRecordVTableAddr(GV))
+return ConstantPointerNull::get(Int8PtrTy);
+
+  return ConstantExpr::getBitCast(GV, Int8PtrTy);
+}
+
+void InstrLowerer::getOrCreateVTableProfData(GlobalVariable *GV) {
+  assert(!DebugInfoCorrelate &&
+ "Value profiling is not supported with lightweight instrumentation");
+  if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
+return;
+
+  if (GV->getName().starts_with("llvm.") ||

minglotus-6 wrote:

done.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -1237,6 +1259,101 @@ void InstrLowerer::maybeSetComdat(GlobalVariable *GV, 
Function *Fn,
 GV->setLinkage(GlobalValue::InternalLinkage);
 }
 
+static inline bool shouldRecordVTableAddr(GlobalVariable *GV) {
+  if (!profDataReferencedByCode(*GV->getParent()))
+return false;
+
+  if (!GV->hasLinkOnceLinkage() && !GV->hasLocalLinkage() &&
+  !GV->hasAvailableExternallyLinkage())
+return true;
+
+  // This avoids the profile data from referencing internal symbols in
+  // COMDAT.
+  if (GV->hasLocalLinkage() && GV->hasComdat())
+return false;
+
+  return true;
+}
+
+// FIXME: Introduce an internal alias like what's done for functions to reduce
+// the number of relocation entries.
+static inline Constant *getVTableAddrForProfData(GlobalVariable *GV) {
+  auto *Int8PtrTy = PointerType::getUnqual(GV->getContext());
+
+  // Store a nullptr in __profvt_ if a real address shouldn't be used.
+  if (!shouldRecordVTableAddr(GV))
+return ConstantPointerNull::get(Int8PtrTy);
+
+  return ConstantExpr::getBitCast(GV, Int8PtrTy);
+}
+
+void InstrLowerer::getOrCreateVTableProfData(GlobalVariable *GV) {
+  assert(!DebugInfoCorrelate &&
+ "Value profiling is not supported with lightweight instrumentation");
+  if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
+return;
+
+  if (GV->getName().starts_with("llvm.") ||
+  GV->getName().starts_with("__llvm") ||
+  GV->getName().starts_with("__prof"))
+return;
+
+  // VTableProfData already created
+  auto It = VTableDataMap.find(GV);
+  if (It != VTableDataMap.end() && It->second)
+return;
+
+  GlobalValue::LinkageTypes Linkage = GV->getLinkage();
+  GlobalValue::VisibilityTypes Visibility = GV->getVisibility();
+
+  // This is to keep consistent with per-function profile data
+  // for correctness.
+  if (TT.isOSBinFormatXCOFF()) {
+Linkage = GlobalValue::InternalLinkage;
+Visibility = GlobalValue::DefaultVisibility;
+  }
+
+  LLVMContext  = M.getContext();
+  Type *DataTypes[] = {
+#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) LLVMType,
+#include "llvm/ProfileData/InstrProfData.inc"
+  };
+
+  auto *DataTy = StructType::get(Ctx, ArrayRef(DataTypes));
+
+  // Used by INSTR_PROF_VTABLE_DATA MACRO
+  Constant *VTableAddr = getVTableAddrForProfData(GV);
+  const std::string PGOVTableName = getPGOName(*GV);
+  // Record the length of the vtable. This is needed since vtable pointers
+  // loaded from C++ objects might be from the middle of a vtable definition.
+  uint32_t VTableSizeVal =
+  M.getDataLayout().getTypeAllocSize(GV->getValueType());
+
+  Constant *DataVals[] = {
+#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) Init,
+#include "llvm/ProfileData/InstrProfData.inc"
+  };
+
+  std::string VarName = getInstrProfVTableVarPrefix().str() + PGOVTableName;
+  auto *Data =
+  new GlobalVariable(M, DataTy, false /* constant */, Linkage,

minglotus-6 wrote:

done.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -567,6 +643,21 @@ Error InstrProfSymtab::create(const NameIterRange 
) {
   return Error::success();
 }
 
+template 
+Error InstrProfSymtab::create(const FuncNameIterRange ,
+  const VTableNameIterRange ) {
+  for (auto Name : FuncIterRange)

minglotus-6 wrote:

Spell out 'auto' by using 'StringRef'. `for (StringRef str : strs)` should be 
efficient whether `strs` is `std::vector` or 
`std::vector`.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -560,6 +602,28 @@ Error InstrProfSymtab::addFuncWithName(Function , 
StringRef PGOFuncName) {
   return Error::success();
 }
 
+uint64_t InstrProfSymtab::getVTableHashFromAddress(uint64_t Address) {
+  finalizeSymtab();

minglotus-6 wrote:

This is to make sure the vectors are sorted.
* `finalizeSymtab` runs `llvm::sort` the first time it's called and marks 
`Sorted` as true ; subsequent calls returns early if `Sorted` is true.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -459,6 +472,16 @@ Error InstrProfSymtab::create(Module , bool InLTO) {
 if (Error E = addFuncWithName(F, getPGOFuncName(F, InLTO)))
   return E;
   }
+
+  SmallVector Types;
+  for (GlobalVariable  : M.globals()) {
+if (!G.hasName())
+  continue;
+Types.clear();
+G.getMetadata(LLVMContext::MD_type, Types);
+if (!Types.empty())

minglotus-6 wrote:

yes, and this is more consistent with vtable detection in InstrProfiling.cpp. 
Done. 

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 commented:

> Here are some things I noticed, haven't looked at the tests yet.

@snehasish Thanks for the review! 

Talking about tests, I wonder if it looks better if I change the current LLVM 
IR test under `llvm/test/tools/llvm-profdata/` into a compiler-rt test under 
`compiler-rt/test/profile/Linux`, demonstrated in 
https://github.com/llvm/llvm-project/commit/167d5ce49e41ca098085cda315687ade194981b1

A compiler-rt test requires less files (e.g., no need to submit `.profraw` or 
its re-generation shell script in the llvm repo) and more self-contained, but 
it's put under `profile/Linux` so people using non-Linux environments won't run 
it (less coverage compared with LLVM IR test in this sense). However the 
support is limited to ELF. 
* The compiler-rt test should work for Darwins (apple). But since this test 
involves matching mangled names, the matchers could be exact (no regex 
matching) if test could assume it runs only on ELF.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -490,6 +591,23 @@ Error InstrProfSymtab::addFuncWithName(Function , 
StringRef PGOFuncName) {
   return Error::success();
 }
 
+uint64_t InstrProfSymtab::getVTableHashFromAddress(uint64_t Address) {
+  finalizeSymtab();
+  auto It = lower_bound(
+  VTableAddrRangeToMD5Map, Address,

minglotus-6 wrote:

IntervalMap could save the {sort, unique, lower_bound} over vectors. I tried to 
use it, but I thinkits implementation overhead doesn't make it an obvious win 
over STL usages 
1) IntervalMap 
[coalesces](https://github.com/llvm/llvm-project/blob/7bad74e66756ca2fd1fe4f5864e7123fb4553d78/llvm/include/llvm/ADT/IntervalMap.h#L127)
 adjacent ranges. `[a, b)` and `[c, d)` are considered adjacent `b + 1 == c` 
with the 
[default](https://github.com/llvm/llvm-project/blob/7bad74e66756ca2fd1fe4f5864e7123fb4553d78/llvm/include/llvm/ADT/IntervalMap.h#L155)
 trait. While vtables in `.data.rel.ro` may not be adjacent in real binaries,  
a custom trait which doesn't coalesce adjacent ranges is more foolproof and 
less likely to go wrong.
2) The code might look a little quirky w.r.t class method interfaces.
 a) This 
[line](https://github.com/llvm/llvm-project/blob/7bad74e66756ca2fd1fe4f5864e7123fb4553d78/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp#L901)
 uses the implicit move assignment operator of `InstrProfSymtab`.
 b) `IntervalMap` constructor 
[requires](https://github.com/llvm/llvm-project/blob/7bad74e66756ca2fd1fe4f5864e7123fb4553d78/llvm/include/llvm/ADT/IntervalMap.h#L1041)
 an allocator, and the allocator is owned outside of interval map.
 c) Allocator doesn't have implicit move assignment operator because it 
[defines](https://github.com/llvm/llvm-project/blob/7bad74e66756ca2fd1fe4f5864e7123fb4553d78/llvm/include/llvm/Support/RecyclingAllocator.h#L37)
 destructor. 
   Considering a) and c), if 'InstrProfSymtab' has 'allocator' as a member, it 
needs to implement move assignment operator. Alternatively, since only raw 
profile reader sees profiled address and uses this map, raw profile reader 
could have an allocator member and pass it to `InstrSymtab::create` for 
interval map creation. But this way the code doesn't look very clean either.


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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -16,23 +16,72 @@
 #include 
 
 namespace llvm {
-// Visitor class that finds all indirect call.
+// Visitor class that finds indirect calls or instructions that gives vtable
+// value, depending on Type.
 struct PGOIndirectCallVisitor : public InstVisitor {
+  enum class InstructionType {
+kIndirectCall = 0,
+kVTableVal = 1,
+  };
   std::vector IndirectCalls;
-  PGOIndirectCallVisitor() = default;
+  std::vector ProfiledAddresses;
+  PGOIndirectCallVisitor(InstructionType Type) : Type(Type) {}
 
   void visitCallBase(CallBase ) {
-if (Call.isIndirectCall())
+if (Call.isIndirectCall()) {

minglotus-6 wrote:

done.

I also updated the code such that 'IndirectCalls' is maintained iff 'Type' is 
'kIndirectCall' and 'ProfiledAddresses' is maintained iff 'Type' is 
'kVTableVal'.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -378,6 +384,13 @@ std::string getPGOFuncName(const Function , bool InLTO, 
uint64_t Version) {
   return getPGOFuncName(F.getName(), GlobalValue::ExternalLinkage, "");
 }
 
+std::string getPGOName(const GlobalVariable , bool InLTO) {
+  // PGONameMetadata should be set by compiler at profile use time
+  // and read by symtab creation to look up symbols corresponding to
+  // a MD5 hash.
+  return getIRPGOObjectName(V, InLTO, nullptr /* PGONameMetadata */);

minglotus-6 wrote:

done.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -1237,6 +1259,101 @@ void InstrLowerer::maybeSetComdat(GlobalVariable *GV, 
Function *Fn,
 GV->setLinkage(GlobalValue::InternalLinkage);
 }
 
+static inline bool shouldRecordVTableAddr(GlobalVariable *GV) {
+  if (!profDataReferencedByCode(*GV->getParent()))
+return false;
+
+  if (!GV->hasLinkOnceLinkage() && !GV->hasLocalLinkage() &&
+  !GV->hasAvailableExternallyLinkage())
+return true;
+
+  // This avoids the profile data from referencing internal symbols in
+  // COMDAT.
+  if (GV->hasLocalLinkage() && GV->hasComdat())
+return false;
+
+  return true;
+}
+
+// FIXME: Introduce an internal alias like what's done for functions to reduce
+// the number of relocation entries.
+static inline Constant *getVTableAddrForProfData(GlobalVariable *GV) {
+  auto *Int8PtrTy = PointerType::getUnqual(GV->getContext());
+
+  // Store a nullptr in __profvt_ if a real address shouldn't be used.
+  if (!shouldRecordVTableAddr(GV))
+return ConstantPointerNull::get(Int8PtrTy);
+
+  return ConstantExpr::getBitCast(GV, Int8PtrTy);
+}
+
+void InstrLowerer::getOrCreateVTableProfData(GlobalVariable *GV) {
+  assert(!DebugInfoCorrelate &&
+ "Value profiling is not supported with lightweight instrumentation");
+  if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
+return;
+
+  if (GV->getName().starts_with("llvm.") ||
+  GV->getName().starts_with("__llvm") ||
+  GV->getName().starts_with("__prof"))
+return;
+
+  // VTableProfData already created
+  auto It = VTableDataMap.find(GV);
+  if (It != VTableDataMap.end() && It->second)
+return;
+
+  GlobalValue::LinkageTypes Linkage = GV->getLinkage();
+  GlobalValue::VisibilityTypes Visibility = GV->getVisibility();
+
+  // This is to keep consistent with per-function profile data
+  // for correctness.
+  if (TT.isOSBinFormatXCOFF()) {
+Linkage = GlobalValue::InternalLinkage;
+Visibility = GlobalValue::DefaultVisibility;
+  }
+
+  LLVMContext  = M.getContext();
+  Type *DataTypes[] = {
+#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) LLVMType,
+#include "llvm/ProfileData/InstrProfData.inc"
+  };

minglotus-6 wrote:

done.

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits

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


[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

2024-03-05 Thread Mingming Liu via cfe-commits


@@ -429,20 +439,36 @@ uint64_t ComputeHash(StringRef K);
 class InstrProfSymtab {
 public:
   using AddrHashMap = std::vector>;
+  using RangeHashMap =
+  std::vector, uint64_t>>;

minglotus-6 wrote:

done, and making the struct definition private to class 'InstrProfSymtab'.

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits


@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the 
user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU
+supports features specified in string argument. It returns positive integer
+if all features are supported and 0 otherwise. Names of features and format is
+target specific. For example on AArch64 features are combined using ``+`` like
+this ``__builtin_cpu_supports("flagm+sha3+lse+rcpc2+fcma+memtag+bti+sme2")``.
+If feature name is not supported or format is wrong, compiler will issue a

MaskRay wrote:

If a feature is not supported, Clang will ...

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits


@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the 
user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU
+supports features specified in string argument. It returns positive integer

MaskRay wrote:

a positive integer

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits


@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the 
user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU
+supports features specified in string argument. It returns positive integer
+if all features are supported and 0 otherwise. Names of features and format is
+target specific. For example on AArch64 features are combined using ``+`` like

MaskRay wrote:

Remove: "For example". I believe other targets don't support `+`.

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits


@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the 
user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU

MaskRay wrote:

"target CPU" can cause confusion: is this the CPU specified at compile time?

run-time CPU is clearer.

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits


@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the 
user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU
+supports features specified in string argument. It returns positive integer
+if all features are supported and 0 otherwise. Names of features and format is

MaskRay wrote:

Feature names are target-specific.

"format" seems not useful in this context?

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Fangrui Song via cfe-commits

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


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


[clang] [UBSAN] Preserve ubsan code with ubsan-unique-traps (PR #83470)

2024-03-05 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> If you are going to remove this feature, I would rather you simply revert the 
> old commit. There is no point leaving the flag in at this point.
> 
> I had explored earlier dealing with the optimization at a later time in the 
> compilation pipeline, but got nowhere and this solution was ideal for my use 
> case, binary size constraints limited any inlining so I never ran into the 
> issue. I appreciate you cleaning this up! :)

Actually I am here because I want to use the flag to avoid merging basic blocks.
We are going to opt-out ubsan checks based on PGO, per basic block hotness 
https://github.com/llvm/llvm-project/pull/83471 

However I am considering introducing a special intrinsic for that, the this 
patch will not be needed.


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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

The dependency of a lambda inside of a `RequiresExprBodyDecl` was previously 
affected by its parent, e.g., `ClassTemplateSpecializationDecl`. This made the 
lambda always dependent regardless of the template arguments we had, which 
caused some crashes on the constraint evaluation later.

This fixes https://github.com/llvm/llvm-project/issues/56556, 
https://github.com/llvm/llvm-project/issues/82849 and a case demonstrated by 
https://github.com/llvm/llvm-project/issues/49570#issuecomment-1664966972.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/TreeTransform.h (+21-2) 
- (modified) clang/test/SemaTemplate/concepts-lambda.cpp (+52) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e0352a7eaf6cd..9c64cd2b5f6a10 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -311,6 +311,8 @@ Bug Fixes to C++ Support
   Fixes (#GH80630)
 - Fix a crash when an explicit template argument list is used with a name for 
which lookup
   finds a non-template function and a dependent using declarator.
+- Fixed an issue where the ``RequiresExprBody`` was involved in the lambda 
dependency
+  calculation. (#GH56556), (#GH82849).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..84348e13567e71 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13649,10 +13649,29 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
   // use evaluation contexts to distinguish the function parameter case.
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
   CXXRecordDecl::LDK_Unknown;
+  DeclContext *DC = getSema().CurContext;
+  // A RequiresExprBodyDecl is not interesting for dependencies.
+  // For the following case,
+  //
+  // template 
+  // concept C = requires { [] {}; };
+  //
+  // template 
+  // struct Widget;
+  //
+  // template 
+  // struct Widget {};
+  //
+  // While we are here in substitution for Widget, the parent of DC would be
+  // the template specialization itself. Thus, the lambda expression
+  // will be deemed as dependent even if we have non-dependent template
+  // arguments.
+  // (A ClassTemplateSpecializationDecl is always a dependent context.)
+  if (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
+DC = DC->getParent();
   if ((getSema().isUnevaluatedContext() ||
getSema().isConstantEvaluatedContext()) &&
-  (getSema().CurContext->isFileContext() ||
-   !getSema().CurContext->getParent()->isDependentContext()))
+  (DC->isFileContext() || !DC->getParent()->isDependentContext()))
 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
 
   CXXRecordDecl *OldClass = E->getLambdaClass();
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 0b7580f91043c7..ef04cad4eef98b 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -90,6 +90,58 @@ struct Foo {
 
 static_assert(ConstructibleWithN);
 
+namespace GH56556 {
+
+template 
+inline constexpr It declare ();
+
+template  typename Template>
+concept D = requires {
+   { []  (Template &) {}(declare()) };
+};
+
+template 
+struct B {};
+
+template 
+struct Adapter;
+
+template  T>
+struct Adapter {};
+
+template struct Adapter>;
+
+} // namespace GH56556
+
+namespace GH82849 {
+
+template 
+concept C = requires(T t) {
+  [](T) {}(t);
+};
+
+template 
+struct Widget;
+
+template 
+struct Widget {
+  static F create(F from) {
+return from;
+  }
+};
+
+template 
+bool foo() {
+  return C;
+}
+
+void bar() {
+  // https://github.com/llvm/llvm-project/issues/49570#issuecomment-1664966972
+  Widget::create(0);
+}
+
+} // namespace GH82849
+
 }
 
 // GH60642 reported an assert being hit, make sure we don't assert.

``




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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

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

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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

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

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

>From 69414d7352b170f6fcff22c6f5dfa91cc76b0b58 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 5 Mar 2024 19:56:59 +0800
Subject: [PATCH 1/2] gh56556

---
 clang/lib/Sema/TreeTransform.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..c96ffcb97a7591 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13649,10 +13649,12 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
   // use evaluation contexts to distinguish the function parameter case.
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
   CXXRecordDecl::LDK_Unknown;
+  DeclContext *DC = getSema().CurContext;
+  if (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
+DC = DC->getParent();
   if ((getSema().isUnevaluatedContext() ||
getSema().isConstantEvaluatedContext()) &&
-  (getSema().CurContext->isFileContext() ||
-   !getSema().CurContext->getParent()->isDependentContext()))
+  (DC->isFileContext() || !DC->getParent()->isDependentContext()))
 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
 
   CXXRecordDecl *OldClass = E->getLambdaClass();

>From b905083e5d5186ad08ac3d553be3e8f47dabc1b6 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 6 Mar 2024 13:46:43 +0800
Subject: [PATCH 2/2] Tests & release notes

---
 clang/docs/ReleaseNotes.rst |  2 +
 clang/lib/Sema/TreeTransform.h  | 17 +++
 clang/test/SemaTemplate/concepts-lambda.cpp | 52 +
 3 files changed, 71 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4e6bcf661da1a..141099fb68a200 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -302,6 +302,8 @@ Bug Fixes to C++ Support
   our attention by an attempt to fix in (#GH77703). Fixes (#GH83385).
 - Fix evaluation of some immediate calls in default arguments.
   Fixes (#GH80630)
+- Fixed an issue where the ``RequiresExprBody`` was involved in the lambda 
dependency
+  calculation. (#GH56556), (#GH82849).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c96ffcb97a7591..84348e13567e71 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13650,6 +13650,23 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
   CXXRecordDecl::LDK_Unknown;
   DeclContext *DC = getSema().CurContext;
+  // A RequiresExprBodyDecl is not interesting for dependencies.
+  // For the following case,
+  //
+  // template 
+  // concept C = requires { [] {}; };
+  //
+  // template 
+  // struct Widget;
+  //
+  // template 
+  // struct Widget {};
+  //
+  // While we are here in substitution for Widget, the parent of DC would be
+  // the template specialization itself. Thus, the lambda expression
+  // will be deemed as dependent even if we have non-dependent template
+  // arguments.
+  // (A ClassTemplateSpecializationDecl is always a dependent context.)
   if (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
 DC = DC->getParent();
   if ((getSema().isUnevaluatedContext() ||
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 0b7580f91043c7..ef04cad4eef98b 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -90,6 +90,58 @@ struct Foo {
 
 static_assert(ConstructibleWithN);
 
+namespace GH56556 {
+
+template 
+inline constexpr It declare ();
+
+template  typename Template>
+concept D = requires {
+   { []  (Template &) {}(declare()) };
+};
+
+template 
+struct B {};
+
+template 
+struct Adapter;
+
+template  T>
+struct Adapter {};
+
+template struct Adapter>;
+
+} // namespace GH56556
+
+namespace GH82849 {
+
+template 
+concept C = requires(T t) {
+  [](T) {}(t);
+};
+
+template 
+struct Widget;
+
+template 
+struct Widget {
+  static F create(F from) {
+return from;
+  }
+};
+
+template 
+bool foo() {
+  return C;
+}
+
+void bar() {
+  // https://github.com/llvm/llvm-project/issues/49570#issuecomment-1664966972
+  Widget::create(0);
+}
+
+} // namespace GH82849
+
 }
 
 // GH60642 reported an assert being hit, make sure we don't assert.

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


[clang] [llvm] [Driver] Default -msmall-data-limit= to 0 and clean up code (PR #83093)

2024-03-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Ping:)

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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

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

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


[clang] [Sema] gh56556 (PR #83997)

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

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Takuto Ikuta (atetubou)


Changes

This fixes incorrect trace for 
https://github.com/llvm/llvm-project/issues/56554.

This shows trace like
https://ui.perfetto.dev/#!/?s=aa809778dc50f2b155b062317fa18bbe2bb2fb9175e6282add8121c7c178214e
for the case shown in https://github.com/llvm/llvm-project/issues/83236.

https://github.com/llvm/llvm-project/pull/83778 is preparing PR.

Fix #56554

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


4 Files Affected:

- (modified) clang/lib/Sema/Sema.cpp (+6-4) 
- (modified) llvm/include/llvm/Support/TimeProfiler.h (+25-9) 
- (modified) llvm/lib/Support/TimeProfiler.cpp (+71-30) 
- (modified) llvm/unittests/Support/TimeProfilerTest.cpp (+11) 


``diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..2fb12e327c304d 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -135,6 +135,7 @@ namespace sema {
 class SemaPPCallbacks : public PPCallbacks {
   Sema *S = nullptr;
   llvm::SmallVector IncludeStack;
+  llvm::SmallVector ProfilerStack;
 
 public:
   void set(Sema ) { this->S =  }
@@ -153,8 +154,8 @@ class SemaPPCallbacks : public PPCallbacks {
   if (IncludeLoc.isValid()) {
 if (llvm::timeTraceProfilerEnabled()) {
   OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
-  llvm::timeTraceProfilerBegin("Source", FE ? FE->getName()
-: StringRef(""));
+  ProfilerStack.push_back(llvm::timeTraceAsyncProfilerBegin(
+  "Source", FE ? FE->getName() : StringRef("")));
 }
 
 IncludeStack.push_back(IncludeLoc);
@@ -166,8 +167,9 @@ class SemaPPCallbacks : public PPCallbacks {
 }
 case ExitFile:
   if (!IncludeStack.empty()) {
-if (llvm::timeTraceProfilerEnabled())
-  llvm::timeTraceProfilerEnd();
+if (llvm::timeTraceProfilerEnabled()) {
+  llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val());
+}
 
 S->DiagnoseNonDefaultPragmaAlignPack(
 Sema::PragmaAlignPackDiagnoseKind::ChangedStateAtExit,
diff --git a/llvm/include/llvm/Support/TimeProfiler.h 
b/llvm/include/llvm/Support/TimeProfiler.h
index 454a65f70231f4..31f7df10916db9 100644
--- a/llvm/include/llvm/Support/TimeProfiler.h
+++ b/llvm/include/llvm/Support/TimeProfiler.h
@@ -86,6 +86,8 @@ class raw_pwrite_stream;
 struct TimeTraceProfiler;
 TimeTraceProfiler *getTimeTraceProfilerInstance();
 
+struct TimeTraceProfilerEntry;
+
 /// Initialize the time trace profiler.
 /// This sets up the global \p TimeTraceProfilerInstance
 /// variable to be the profiler instance.
@@ -120,19 +122,30 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName,
 /// Profiler copies the string data, so the pointers can be given into
 /// temporaries. Time sections can be hierarchical; every Begin must have a
 /// matching End pair but they can nest.
-void timeTraceProfilerBegin(StringRef Name, StringRef Detail);
-void timeTraceProfilerBegin(StringRef Name,
-llvm::function_ref Detail);
+TimeTraceProfilerEntry *timeTraceProfilerBegin(StringRef Name,
+   StringRef Detail);
+TimeTraceProfilerEntry *
+timeTraceProfilerBegin(StringRef Name,
+   llvm::function_ref Detail);
+
+/// Manually begin a time section, with the given \p Name and \p Detail.
+/// This starts Async Events having \p Name as a category which is shown
+/// separately from other traces. See
+/// 
https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1
+/// for more details.
+TimeTraceProfilerEntry *timeTraceAsyncProfilerBegin(StringRef Name,
+StringRef Detail);
 
 /// Manually end the last time section.
 void timeTraceProfilerEnd();
+void timeTraceProfilerEnd(TimeTraceProfilerEntry *E);
 
 /// The TimeTraceScope is a helper class to call the begin and end functions
 /// of the time trace profiler.  When the object is constructed, it begins
 /// the section; and when it is destroyed, it stops it. If the time profiler
 /// is not initialized, the overhead is a single branch.
-struct TimeTraceScope {
-
+class TimeTraceScope {
+public:
   TimeTraceScope() = delete;
   TimeTraceScope(const TimeTraceScope &) = delete;
   TimeTraceScope =(const TimeTraceScope &) = delete;
@@ -141,20 +154,23 @@ struct TimeTraceScope {
 
   TimeTraceScope(StringRef Name) {
 if (getTimeTraceProfilerInstance() != nullptr)
-  timeTraceProfilerBegin(Name, StringRef(""));
+  Entry = timeTraceProfilerBegin(Name, StringRef(""));
   }
   TimeTraceScope(StringRef Name, StringRef Detail) {
 if (getTimeTraceProfilerInstance() != nullptr)
-  timeTraceProfilerBegin(Name, Detail);
+  Entry = timeTraceProfilerBegin(Name, Detail);
   }
   TimeTraceScope(StringRef 

[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-05 Thread Takuto Ikuta via cfe-commits

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-05 Thread Takuto Ikuta via cfe-commits

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


[clang] [Sema] gh56556 (PR #83997)

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

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

>From 69414d7352b170f6fcff22c6f5dfa91cc76b0b58 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 5 Mar 2024 19:56:59 +0800
Subject: [PATCH 1/2] gh56556

---
 clang/lib/Sema/TreeTransform.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..c96ffcb97a7591 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13649,10 +13649,12 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
   // use evaluation contexts to distinguish the function parameter case.
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
   CXXRecordDecl::LDK_Unknown;
+  DeclContext *DC = getSema().CurContext;
+  if (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
+DC = DC->getParent();
   if ((getSema().isUnevaluatedContext() ||
getSema().isConstantEvaluatedContext()) &&
-  (getSema().CurContext->isFileContext() ||
-   !getSema().CurContext->getParent()->isDependentContext()))
+  (DC->isFileContext() || !DC->getParent()->isDependentContext()))
 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
 
   CXXRecordDecl *OldClass = E->getLambdaClass();

>From b905083e5d5186ad08ac3d553be3e8f47dabc1b6 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 6 Mar 2024 13:46:43 +0800
Subject: [PATCH 2/2] Tests & release notes

---
 clang/docs/ReleaseNotes.rst |  2 +
 clang/lib/Sema/TreeTransform.h  | 17 +++
 clang/test/SemaTemplate/concepts-lambda.cpp | 52 +
 3 files changed, 71 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4e6bcf661da1a..141099fb68a200 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -302,6 +302,8 @@ Bug Fixes to C++ Support
   our attention by an attempt to fix in (#GH77703). Fixes (#GH83385).
 - Fix evaluation of some immediate calls in default arguments.
   Fixes (#GH80630)
+- Fixed an issue where the ``RequiresExprBody`` was involved in the lambda 
dependency
+  calculation. (#GH56556), (#GH82849).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c96ffcb97a7591..84348e13567e71 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13650,6 +13650,23 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
   CXXRecordDecl::LDK_Unknown;
   DeclContext *DC = getSema().CurContext;
+  // A RequiresExprBodyDecl is not interesting for dependencies.
+  // For the following case,
+  //
+  // template 
+  // concept C = requires { [] {}; };
+  //
+  // template 
+  // struct Widget;
+  //
+  // template 
+  // struct Widget {};
+  //
+  // While we are here in substitution for Widget, the parent of DC would be
+  // the template specialization itself. Thus, the lambda expression
+  // will be deemed as dependent even if we have non-dependent template
+  // arguments.
+  // (A ClassTemplateSpecializationDecl is always a dependent context.)
   if (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
 DC = DC->getParent();
   if ((getSema().isUnevaluatedContext() ||
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 0b7580f91043c7..ef04cad4eef98b 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -90,6 +90,58 @@ struct Foo {
 
 static_assert(ConstructibleWithN);
 
+namespace GH56556 {
+
+template 
+inline constexpr It declare ();
+
+template  typename Template>
+concept D = requires {
+   { []  (Template &) {}(declare()) };
+};
+
+template 
+struct B {};
+
+template 
+struct Adapter;
+
+template  T>
+struct Adapter {};
+
+template struct Adapter>;
+
+} // namespace GH56556
+
+namespace GH82849 {
+
+template 
+concept C = requires(T t) {
+  [](T) {}(t);
+};
+
+template 
+struct Widget;
+
+template 
+struct Widget {
+  static F create(F from) {
+return from;
+  }
+};
+
+template 
+bool foo() {
+  return C;
+}
+
+void bar() {
+  // https://github.com/llvm/llvm-project/issues/49570#issuecomment-1664966972
+  Widget::create(0);
+}
+
+} // namespace GH82849
+
 }
 
 // GH60642 reported an assert being hit, make sure we don't assert.

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


[clang] [Driver,CrossWindows] Remove -isystem-after (PR #84121)

2024-03-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

Commit 88879e6559a3ae8593e32568900707b1dbf3f060 added -isystem-after
(not in GCC) for CrossWindows (see
543a78b55ee993c2977fc2984f278f7ec0125765; *-windows-itanium).
I have heard two reports that the documented option
(https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-isystem-after-directory)
is causing confusion as other ToolChains accept and ignore
`-isystem-after`, not leading to an error.

I think -isystem-after can just be deleted. The use cases can be
approximated with -idirafter.


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


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (-3) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (-7) 
- (modified) clang/lib/Driver/ToolChains/CrossWindows.cpp (+1-9) 
- (modified) clang/test/Driver/windows-cross.c (+6-6) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..522e377ea24c99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4335,9 +4335,6 @@ def isysroot : JoinedOrSeparate<["-"], "isysroot">, 
Group,
 def isystem : JoinedOrSeparate<["-"], "isystem">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to SYSTEM include search path">, 
MetaVarName<"">;
-def isystem_after : JoinedOrSeparate<["-"], "isystem-after">,
-  Group, Flags<[NoXarchOption]>, MetaVarName<"">,
-  HelpText<"Add directory to end of the SYSTEM include search path">;
 def iwithprefixbefore : JoinedOrSeparate<["-"], "iwithprefixbefore">, 
Group,
   HelpText<"Set directory to include search path with prefix">, 
MetaVarName<"">,
   Visibility<[ClangOption, CC1Option]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 858d20fbfac015..2d9d1950a65999 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1219,13 +1219,6 @@ void Clang::AddPreprocessingOptions(Compilation , 
const JobAction ,
<< A->getAsString(Args);
 }
   }
-} else if (A->getOption().matches(options::OPT_isystem_after)) {
-  // Handling of paths which must come late.  These entries are handled by
-  // the toolchain itself after the resource dir is inserted in the right
-  // search order.
-  // Do not claim the argument so that the use of the argument does not
-  // silently go unnoticed on toolchains which do not honour the option.
-  continue;
 } else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
   // Translated to -internal-isystem by the driver, no need to pass to cc1.
   continue;
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp 
b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8e..1319451461843c 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -239,15 +239,8 @@ AddClangSystemIncludeArgs(const llvm::opt::ArgList 
,
   const Driver  = getDriver();
   const std::string  = D.SysRoot;
 
-  auto AddSystemAfterIncludes = [&]() {
-for (const auto  : 
DriverArgs.getAllArgValues(options::OPT_isystem_after))
-  addSystemInclude(DriverArgs, CC1Args, P);
-  };
-
-  if (DriverArgs.hasArg(options::OPT_nostdinc)) {
-AddSystemAfterIncludes();
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
-  }
 
   addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
@@ -255,7 +248,6 @@ AddClangSystemIncludeArgs(const llvm::opt::ArgList 
,
 llvm::sys::path::append(ResourceDir, "include");
 addSystemInclude(DriverArgs, CC1Args, ResourceDir);
   }
-  AddSystemAfterIncludes();
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
 }
 
diff --git a/clang/test/Driver/windows-cross.c 
b/clang/test/Driver/windows-cross.c
index 75490b992d78da..4e131d43612b33 100644
--- a/clang/test/Driver/windows-cross.c
+++ b/clang/test/Driver/windows-cross.c
@@ -72,16 +72,16 @@
 // CHECK-SANITIZE-TSAN: error: unsupported argument 'tsan' to option 
'-fsanitize='
 // CHECK-SANITIZE-TSAN-NOT: "-fsanitize={{.*}}"
 
-// RUN: %clang -### -target armv7-windows-itanium -isystem-after "Windows 
Kits/10/Include/10.0.10586.0/ucrt" -isystem-after "Windows 
Kits/10/Include/10.0.10586.0/um" -isystem-after "Windows 
Kits/10/Include/10.0.10586.0/shared" -c %s -o /dev/null 2>&1 \
+// RUN: %clang -### --target=armv7-windows-itanium -idirafter "Windows 
Kits/10/Include/10.0.10586.0/ucrt" -idirafter "Windows 
Kits/10/Include/10.0.10586.0/um" -idirafter "Windows 
Kits/10/Include/10.0.10586.0/shared" -c %s -o /dev/null 2>&1 \
 // RUN: | FileCheck %s --check-prefix CHECK-ISYSTEM-AFTER
 // CHECK-ISYSTEM-AFTER: "-resource-dir" 

[clang] [Driver,CrossWindows] Remove -isystem-after (PR #84121)

2024-03-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/84121

Commit 88879e6559a3ae8593e32568900707b1dbf3f060 added -isystem-after
(not in GCC) for CrossWindows (see
543a78b55ee993c2977fc2984f278f7ec0125765; *-windows-itanium).
I have heard two reports that the documented option
(https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-isystem-after-directory)
is causing confusion as other ToolChains accept and ignore
`-isystem-after`, not leading to an error.

I think -isystem-after can just be deleted. The use cases can be
approximated with -idirafter.


>From 40aef52d69c5051e5a236fcdd56259ad0333ab6d Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 5 Mar 2024 21:36:40 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Driver/Options.td|  3 ---
 clang/lib/Driver/ToolChains/Clang.cpp|  7 ---
 clang/lib/Driver/ToolChains/CrossWindows.cpp | 10 +-
 clang/test/Driver/windows-cross.c| 12 ++--
 4 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..522e377ea24c99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4335,9 +4335,6 @@ def isysroot : JoinedOrSeparate<["-"], "isysroot">, 
Group,
 def isystem : JoinedOrSeparate<["-"], "isystem">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to SYSTEM include search path">, 
MetaVarName<"">;
-def isystem_after : JoinedOrSeparate<["-"], "isystem-after">,
-  Group, Flags<[NoXarchOption]>, MetaVarName<"">,
-  HelpText<"Add directory to end of the SYSTEM include search path">;
 def iwithprefixbefore : JoinedOrSeparate<["-"], "iwithprefixbefore">, 
Group,
   HelpText<"Set directory to include search path with prefix">, 
MetaVarName<"">,
   Visibility<[ClangOption, CC1Option]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 858d20fbfac015..2d9d1950a65999 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1219,13 +1219,6 @@ void Clang::AddPreprocessingOptions(Compilation , 
const JobAction ,
<< A->getAsString(Args);
 }
   }
-} else if (A->getOption().matches(options::OPT_isystem_after)) {
-  // Handling of paths which must come late.  These entries are handled by
-  // the toolchain itself after the resource dir is inserted in the right
-  // search order.
-  // Do not claim the argument so that the use of the argument does not
-  // silently go unnoticed on toolchains which do not honour the option.
-  continue;
 } else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
   // Translated to -internal-isystem by the driver, no need to pass to cc1.
   continue;
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp 
b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8e..1319451461843c 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -239,15 +239,8 @@ AddClangSystemIncludeArgs(const llvm::opt::ArgList 
,
   const Driver  = getDriver();
   const std::string  = D.SysRoot;
 
-  auto AddSystemAfterIncludes = [&]() {
-for (const auto  : 
DriverArgs.getAllArgValues(options::OPT_isystem_after))
-  addSystemInclude(DriverArgs, CC1Args, P);
-  };
-
-  if (DriverArgs.hasArg(options::OPT_nostdinc)) {
-AddSystemAfterIncludes();
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
-  }
 
   addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
@@ -255,7 +248,6 @@ AddClangSystemIncludeArgs(const llvm::opt::ArgList 
,
 llvm::sys::path::append(ResourceDir, "include");
 addSystemInclude(DriverArgs, CC1Args, ResourceDir);
   }
-  AddSystemAfterIncludes();
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
 }
 
diff --git a/clang/test/Driver/windows-cross.c 
b/clang/test/Driver/windows-cross.c
index 75490b992d78da..4e131d43612b33 100644
--- a/clang/test/Driver/windows-cross.c
+++ b/clang/test/Driver/windows-cross.c
@@ -72,16 +72,16 @@
 // CHECK-SANITIZE-TSAN: error: unsupported argument 'tsan' to option 
'-fsanitize='
 // CHECK-SANITIZE-TSAN-NOT: "-fsanitize={{.*}}"
 
-// RUN: %clang -### -target armv7-windows-itanium -isystem-after "Windows 
Kits/10/Include/10.0.10586.0/ucrt" -isystem-after "Windows 
Kits/10/Include/10.0.10586.0/um" -isystem-after "Windows 
Kits/10/Include/10.0.10586.0/shared" -c %s -o /dev/null 2>&1 \
+// RUN: %clang -### --target=armv7-windows-itanium -idirafter "Windows 

[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-03-05 Thread Sandeep Kosuri via cfe-commits

https://github.com/sandeepkosuri updated 
https://github.com/llvm/llvm-project/pull/83223

>From cbf1b4409e379309ae3d942b3dbec0964b9ee0d1 Mon Sep 17 00:00:00 2001
From: Sandeep Kosuri 
Date: Tue, 27 Feb 2024 23:19:41 -0600
Subject: [PATCH 1/3] [OpenMP] Parse and Sema support for declare target in
 local scope

---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +++
 clang/lib/Parse/ParseOpenMP.cpp   | 23 ++-
 clang/lib/Sema/SemaOpenMP.cpp |  9 
 .../test/OpenMP/declare_target_ast_print.cpp  | 19 +++
 clang/test/OpenMP/declare_target_messages.cpp |  9 
 5 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a7f2858477bee6..faa7d1872ae3f1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error<
 def err_omp_wrong_device_function_call : Error<
   "function with 'device_type(%0)' is not available on %select{device|host}1">;
 def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' 
here">;
+def warn_omp_declare_target_has_local_vars : Warning<
+  "local variable '%0' ignored in 'declare target' directive; ">,
+  InGroup;
 def warn_omp_declare_target_after_first_use : Warning<
   "declaration marked as declare target after first use, it may lead to 
incorrect results">,
   InGroup;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index bfc31f2653c237..814126e321d3bc 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2984,8 +2984,29 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 OMPDirectiveScope.Exit();
 break;
   }
+  case OMPD_declare_target: {
+SourceLocation DTLoc = ConsumeAnyToken();
+bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
+Sema::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+if (HasClauses)
+  ParseOMPDeclareTargetClauses(DTCI);
+bool HasImplicitMappings =
+!HasClauses || (DTCI.ExplicitlyMapped.empty() && DTCI.Indirect);
+
+if (HasImplicitMappings) {
+  Diag(Tok, diag::err_omp_unexpected_directive)
+  << 1 << getOpenMPDirectiveName(DKind);
+  SkipUntil(tok::annot_pragma_openmp_end);
+  break;
+}
+
+// Skip the last annot_pragma_openmp_end.
+ConsumeAnyToken();
+
+Actions.ActOnFinishedOpenMPDeclareTargetContext(DTCI);
+break;
+  }
   case OMPD_declare_simd:
-  case OMPD_declare_target:
   case OMPD_begin_declare_target:
   case OMPD_end_declare_target:
   case OMPD_requires:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7f75cfc5b54f35..0cd8ff065a3419 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, 
SourceLocation Loc,
   isa(ND)) &&
  "Expected variable, function or function template.");
 
+  if (auto *VD = dyn_cast(ND)) {
+// Only global variables can be marked as declare target.
+if (!VD->isFileVarDecl() && !VD->isStaticLocal() &&
+!VD->isStaticDataMember()) {
+  Diag(Loc, diag::warn_omp_declare_target_has_local_vars)
+  << VD->getNameAsString();
+  return;
+}
+  }
   // Diagnose marking after use as it may lead to incorrect diagnosis and
   // codegen.
   if (LangOpts.OpenMP >= 50 &&
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index 40c5dd299abd96..43cccf763e97c3 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -360,6 +360,17 @@ int inner_link;
 // CHECK-NEXT: int inner_link;
 // CHECK-NEXT: #pragma omp end declare target
 
+void foo2() { return ;}
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: void foo2() {
+// CHECK-NEXT: return;
+// CHECK-NEXT: }
+
+int x;
+// CHECK: #pragma omp declare target link
+// CHECK-NEXT: int x;
+// CHECK-NEXT: #pragma omp end declare target
+
 int main (int argc, char **argv) {
   foo();
   foo_c();
@@ -367,6 +378,14 @@ int main (int argc, char **argv) {
   test1();
   baz();
   baz();
+
+#if _OPENMP == 202111
+#pragma omp declare target enter(foo2)
+#else
+#pragma omp declare target to (foo2)
+#endif
+
+  #pragma omp declare target link(x)
   return (0);
 }
 
diff --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index cf034aca7c9136..39616bc47b2ccb 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -182,11 +182,20 @@ struct S {
 #pragma omp end declare target
 };
 
+void foo3() {
+  return;
+}
+
+int *y;
+int **w = 
 int main (int argc, char **argv) {
+  int a = 2;
 #pragma omp declare target // expected-error 

[clang] [UBSAN] Preserve ubsan code with ubsan-unique-traps (PR #83470)

2024-03-05 Thread Oskar Wirga via cfe-commits

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

If you are going to remove this feature, I would rather you simply revert the 
old commit. There is no point leaving the flag in at this point. 

I had explored earlier dealing with the optimization at a later time in the 
compilation pipeline, but got nowhere and this solution was ideal for my use 
case, binary size constraints limited any inlining so I never ran into the 
issue. I appreciate you cleaning this up! :)

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


[clang] [clang][Sema] Warn on self move for inlined static cast (PR #76646)

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

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

Much better, thanks.

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


[clang] [llvm] Use TimeTraceProfilerEntry for Source span (PR #83961)

2024-03-05 Thread Takuto Ikuta via cfe-commits

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


[clang] [llvm] Use TimeTraceProfilerEntry for Source span (PR #83961)

2024-03-05 Thread Takuto Ikuta via cfe-commits

https://github.com/atetubou updated 
https://github.com/llvm/llvm-project/pull/83961

>From 90ebde07f7fa426a37dd4bdc362e1a809aaf0844 Mon Sep 17 00:00:00 2001
From: Takuto Ikuta 
Date: Mon, 4 Mar 2024 19:12:31 +0900
Subject: [PATCH 1/2] Expose TimeTraceProfiler for Async Events

---
 llvm/include/llvm/Support/TimeProfiler.h|  34 +--
 llvm/lib/Support/TimeProfiler.cpp   | 101 ++--
 llvm/unittests/Support/TimeProfilerTest.cpp |  11 +++
 3 files changed, 107 insertions(+), 39 deletions(-)

diff --git a/llvm/include/llvm/Support/TimeProfiler.h 
b/llvm/include/llvm/Support/TimeProfiler.h
index 454a65f70231f4..31f7df10916db9 100644
--- a/llvm/include/llvm/Support/TimeProfiler.h
+++ b/llvm/include/llvm/Support/TimeProfiler.h
@@ -86,6 +86,8 @@ class raw_pwrite_stream;
 struct TimeTraceProfiler;
 TimeTraceProfiler *getTimeTraceProfilerInstance();
 
+struct TimeTraceProfilerEntry;
+
 /// Initialize the time trace profiler.
 /// This sets up the global \p TimeTraceProfilerInstance
 /// variable to be the profiler instance.
@@ -120,19 +122,30 @@ Error timeTraceProfilerWrite(StringRef PreferredFileName,
 /// Profiler copies the string data, so the pointers can be given into
 /// temporaries. Time sections can be hierarchical; every Begin must have a
 /// matching End pair but they can nest.
-void timeTraceProfilerBegin(StringRef Name, StringRef Detail);
-void timeTraceProfilerBegin(StringRef Name,
-llvm::function_ref Detail);
+TimeTraceProfilerEntry *timeTraceProfilerBegin(StringRef Name,
+   StringRef Detail);
+TimeTraceProfilerEntry *
+timeTraceProfilerBegin(StringRef Name,
+   llvm::function_ref Detail);
+
+/// Manually begin a time section, with the given \p Name and \p Detail.
+/// This starts Async Events having \p Name as a category which is shown
+/// separately from other traces. See
+/// 
https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1
+/// for more details.
+TimeTraceProfilerEntry *timeTraceAsyncProfilerBegin(StringRef Name,
+StringRef Detail);
 
 /// Manually end the last time section.
 void timeTraceProfilerEnd();
+void timeTraceProfilerEnd(TimeTraceProfilerEntry *E);
 
 /// The TimeTraceScope is a helper class to call the begin and end functions
 /// of the time trace profiler.  When the object is constructed, it begins
 /// the section; and when it is destroyed, it stops it. If the time profiler
 /// is not initialized, the overhead is a single branch.
-struct TimeTraceScope {
-
+class TimeTraceScope {
+public:
   TimeTraceScope() = delete;
   TimeTraceScope(const TimeTraceScope &) = delete;
   TimeTraceScope =(const TimeTraceScope &) = delete;
@@ -141,20 +154,23 @@ struct TimeTraceScope {
 
   TimeTraceScope(StringRef Name) {
 if (getTimeTraceProfilerInstance() != nullptr)
-  timeTraceProfilerBegin(Name, StringRef(""));
+  Entry = timeTraceProfilerBegin(Name, StringRef(""));
   }
   TimeTraceScope(StringRef Name, StringRef Detail) {
 if (getTimeTraceProfilerInstance() != nullptr)
-  timeTraceProfilerBegin(Name, Detail);
+  Entry = timeTraceProfilerBegin(Name, Detail);
   }
   TimeTraceScope(StringRef Name, llvm::function_ref Detail) {
 if (getTimeTraceProfilerInstance() != nullptr)
-  timeTraceProfilerBegin(Name, Detail);
+  Entry = timeTraceProfilerBegin(Name, Detail);
   }
   ~TimeTraceScope() {
 if (getTimeTraceProfilerInstance() != nullptr)
-  timeTraceProfilerEnd();
+  timeTraceProfilerEnd(Entry);
   }
+
+private:
+  TimeTraceProfilerEntry *Entry = nullptr;
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Support/TimeProfiler.cpp 
b/llvm/lib/Support/TimeProfiler.cpp
index 4d625b3eb5b170..3114f8e7ded598 100644
--- a/llvm/lib/Support/TimeProfiler.cpp
+++ b/llvm/lib/Support/TimeProfiler.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "llvm/Support/TimeProfiler.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/JSON.h"
@@ -20,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -64,17 +66,19 @@ using CountAndDurationType = std::pair;
 using NameAndCountAndDurationType =
 std::pair;
 
+} // anonymous namespace
+
 /// Represents an open or completed time section entry to be captured.
-struct TimeTraceProfilerEntry {
+struct llvm::TimeTraceProfilerEntry {
   const TimePointType Start;
   TimePointType End;
   const std::string Name;
   const std::string Detail;
-
+  const bool AsyncEvent = false;
   TimeTraceProfilerEntry(TimePointType &, TimePointType &, std::string &,
- std::string &)
+ std::string &, bool Ae)
   : Start(std::move(S)), End(std::move(E)), Name(std::move(N)),

[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)

2024-03-05 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/83896

>From 9434f834c4d48559aeec94403c927f48b15763e3 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Mon, 4 Mar 2024 11:24:34 -0800
Subject: [PATCH 1/4] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1
 instructions.

These were in LLVM 17 but removed from LLVM 18 due to an incorrect
extension name being used.

This restores them with new extension names that match SiFive's
downstream compiler. The extension name has been used internally
for some time. It uses XSiFive instead of XSf like the newer extensions.

The spec for the instructions is here 
https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf
though the extension name is not listed.

Column width in the extension printing had to be changed to accomodate
a longer extension name.
---
 .../test/Preprocessor/riscv-target-features.c |  18 +
 llvm/docs/RISCVUsage.rst  |   6 +
 llvm/lib/Support/RISCVISAInfo.cpp |   4 +-
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |   6 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  16 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td|  22 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 324 +-
 7 files changed, 234 insertions(+), 162 deletions(-)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 664279cb123949..f8d4800aabbb44 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -60,6 +60,8 @@
 // CHECK-NOT: __riscv_xsfvfwmaccqqq {{.*$}}
 // CHECK-NOT: __riscv_xsfqmaccdod {{.*$}}
 // CHECK-NOT: __riscv_xsfvqmaccqoq {{.*$}}
+// CHECK-NOT: __riscv_sifivecdiscarddlone {{.*$}}
+// CHECK-NOT: __riscv_sifivecflushdlone {{.*$}}
 // CHECK-NOT: __riscv_xtheadba {{.*$}}
 // CHECK-NOT: __riscv_xtheadbb {{.*$}}
 // CHECK-NOT: __riscv_xtheadbs {{.*$}}
@@ -548,6 +550,22 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-XSFVQMACCQOQ-EXT %s
 // CHECK-XSFVQMACCQOQ-EXT: __riscv_xsfvqmaccqoq 100{{$}}
 
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN:   -march=rv32ixsifivecdiscarddlone -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XSIFIVECDISCARDDLONE-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN:   -march=rv64ixsifivecdiscarddlone -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XSIFIVECDISCARDDLONE-EXT %s
+// CHECK-XSIFIVECDISCARDDLONE-EXT: __riscv_xsifivecdiscarddlone 100{{$}}
+
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN:   -march=rv32ixsifivecflushdlone -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XSIFIVECFLUSHDLONE-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN:   -march=rv64ixsifivecflushdlone -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XSIFIVECFLUSHDLONE-EXT %s
+// CHECK-XSIFIVECFLUSHDLONE-EXT: __riscv_xsifivecflushdlone 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32ixtheadba -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-XTHEADBA-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 8d293b02144307..f1e2e86390c838 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -352,6 +352,12 @@ The current vendor extensions supported are:
 ``XCVbi``
   LLVM implements `version 1.0.0 of the CORE-V immediate branching custom 
instructions specification 
`__
 by OpenHW Group.  All instructions are prefixed with `cv.` as described in the 
specification. These instructions are only available for riscv32 at this time.
 
+``XSiFivecdiscarddlone``
+  LLVM implements `the SiFive cdiscard.d.l1 instruction specified in 
`_
 by SiFive.
+
+``XSiFivecflushdlone``
+  LLVM implements `the SiFive cflush.d.l1 instruction specified in 
`_
 by SiFive.
+
 Experimental C Intrinsics
 =
 
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 68f5c36e8fafc6..8dbb40f97bf338 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -94,6 +94,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"xsfvfwmaccqqq", {1, 0}},
 {"xsfvqmaccdod", {1, 0}},
 {"xsfvqmaccqoq", {1, 0}},
+{"xsifivecdiscarddlone", {1, 0}},
+{"xsifivecflushdlone", {1, 0}},
 {"xtheadba", {1, 0}},
 {"xtheadbb", {1, 0}},
 {"xtheadbs", {1, 0}},
@@ -257,7 +259,7 @@ static void PrintExtension(StringRef Name, StringRef 
Version,
StringRef Description) {
   

[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-03-05 Thread Sandeep Kosuri via cfe-commits


@@ -11326,6 +11326,8 @@ def err_omp_device_type_mismatch : Error<
 def err_omp_wrong_device_function_call : Error<
   "function with 'device_type(%0)' is not available on %select{device|host}1">;
 def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' 
here">;
+def err_omp_declare_target_has_local_vars : Error<
+  "local variable '%0' ignored in 'declare target' directive; ">;

sandeepkosuri wrote:

Yeah, will fix that

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


[clang] Revert "[Driver] Default riscv*- triples to -fdebug-default-version=4" (PR #84119)

2024-03-05 Thread Fangrui Song via cfe-commits

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


[clang] Revert "[Driver] Default riscv*- triples to -fdebug-default-version=4" (PR #84119)

2024-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Fangrui Song (MaskRay)


Changes

This reverts commit bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
(https://reviews.llvm.org/D157663).

With this change, the next major release 19.1 will generate
R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 relocations, which require
lld=18 or binutils=2.41.
binutils 2.41 is relatively new, but GCC has been producing
R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 for some time now.


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


3 Files Affected:

- (modified) clang/include/clang/Driver/ToolChain.h (+1-1) 
- (modified) clang/lib/Driver/ToolChain.cpp (-6) 
- (modified) clang/test/Driver/clang-g-opts.c (-5) 


``diff
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index fbe2e8fe8e88d8..a4f9cad98aa8b1 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -580,7 +580,7 @@ class ToolChain {
 
   // Return the DWARF version to emit, in the absence of arguments
   // to the contrary.
-  virtual unsigned GetDefaultDwarfVersion() const;
+  virtual unsigned GetDefaultDwarfVersion() const { return 5; }
 
   // Some toolchains may have different restrictions on the DWARF version and
   // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when 
host
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08b1fd01b3c0ac..03450fc0f57b93 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -453,12 +453,6 @@ ToolChain::getDefaultUnwindTableLevel(const ArgList ) 
const {
   return UnwindTableLevel::None;
 }
 
-unsigned ToolChain::GetDefaultDwarfVersion() const {
-  // TODO: Remove the RISC-V special case when R_RISCV_SET_ULEB128 linker
-  // support becomes more widely available.
-  return getTriple().isRISCV() ? 4 : 5;
-}
-
 Tool *ToolChain::getClang() const {
   if (!Clang)
 Clang.reset(new tools::Clang(*this, useIntegratedBackend()));
diff --git a/clang/test/Driver/clang-g-opts.c b/clang/test/Driver/clang-g-opts.c
index b73602a155b009..fdbe0b96420c51 100644
--- a/clang/test/Driver/clang-g-opts.c
+++ b/clang/test/Driver/clang-g-opts.c
@@ -42,8 +42,3 @@
 
 // CHECK-WITH-G-STANDALONE: "-debug-info-kind=standalone"
 // CHECK-WITH-G-STANDALONE: "-dwarf-version=2"
-
-/// TODO: Special case before R_RISCV_SET_ULEB128 linker support becomes more 
widely available.
-// RUN: %clang -### -S %s -g --target=riscv64-linux-gnu 2>&1 | FileCheck 
--check-prefix=VERSION4 %s
-// RUN: %clang -### -S %s -g --target=riscv64-unknown-elf 2>&1 | FileCheck 
--check-prefix=VERSION4 %s
-// VERSION4: "-dwarf-version=4"

``




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


[clang] Revert "[Driver] Default riscv*- triples to -fdebug-default-version=4" (PR #84119)

2024-03-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/84119

This reverts commit bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
(https://reviews.llvm.org/D157663).

With this change, the next major release 19.1 will generate
R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 relocations, which require
lld>=18 or binutils>=2.41.
binutils 2.41 is relatively new, but GCC has been producing
R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 for some time now.


>From 7d55c2a4673ff3419a39a4eb2a8c18efb554a497 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 5 Mar 2024 20:57:25 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Driver/ToolChain.h | 2 +-
 clang/lib/Driver/ToolChain.cpp | 6 --
 clang/test/Driver/clang-g-opts.c   | 5 -
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index fbe2e8fe8e88d8..a4f9cad98aa8b1 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -580,7 +580,7 @@ class ToolChain {
 
   // Return the DWARF version to emit, in the absence of arguments
   // to the contrary.
-  virtual unsigned GetDefaultDwarfVersion() const;
+  virtual unsigned GetDefaultDwarfVersion() const { return 5; }
 
   // Some toolchains may have different restrictions on the DWARF version and
   // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when 
host
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08b1fd01b3c0ac..03450fc0f57b93 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -453,12 +453,6 @@ ToolChain::getDefaultUnwindTableLevel(const ArgList ) 
const {
   return UnwindTableLevel::None;
 }
 
-unsigned ToolChain::GetDefaultDwarfVersion() const {
-  // TODO: Remove the RISC-V special case when R_RISCV_SET_ULEB128 linker
-  // support becomes more widely available.
-  return getTriple().isRISCV() ? 4 : 5;
-}
-
 Tool *ToolChain::getClang() const {
   if (!Clang)
 Clang.reset(new tools::Clang(*this, useIntegratedBackend()));
diff --git a/clang/test/Driver/clang-g-opts.c b/clang/test/Driver/clang-g-opts.c
index b73602a155b009..fdbe0b96420c51 100644
--- a/clang/test/Driver/clang-g-opts.c
+++ b/clang/test/Driver/clang-g-opts.c
@@ -42,8 +42,3 @@
 
 // CHECK-WITH-G-STANDALONE: "-debug-info-kind=standalone"
 // CHECK-WITH-G-STANDALONE: "-dwarf-version=2"
-
-/// TODO: Special case before R_RISCV_SET_ULEB128 linker support becomes more 
widely available.
-// RUN: %clang -### -S %s -g --target=riscv64-linux-gnu 2>&1 | FileCheck 
--check-prefix=VERSION4 %s
-// RUN: %clang -### -S %s -g --target=riscv64-unknown-elf 2>&1 | FileCheck 
--check-prefix=VERSION4 %s
-// VERSION4: "-dwarf-version=4"

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


[clang] [llvm] [openmp] [libomptarget] Build plugins-nextgen for SystemZ (PR #83978)

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

jhuber6 wrote:

Please format before landing

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


[clang] [llvm] [openmp] [libomptarget] Build plugins-nextgen for SystemZ (PR #83978)

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

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


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


[clang] [clang-tools-extra] clangd: Show argument names for function pointer struct fields (PR #69011)

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

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


[clang-tools-extra] 7bad74e - [clangd] Show argument names for function pointer struct fields (#69011)

2024-03-05 Thread via cfe-commits

Author: Qwinci
Date: 2024-03-05T23:33:55-05:00
New Revision: 7bad74e66756ca2fd1fe4f5864e7123fb4553d78

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

LOG: [clangd] Show argument names for function pointer struct fields (#69011)

Show argument names in signature help when calling a function pointer
struct field.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 6d387fec9b3851..5721feecd58ea8 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1462,6 +1462,23 @@ TEST(SignatureHelpTest, FunctionPointers) {
 typedef void (__stdcall *fn)(int x, int y);
 fn foo;
 int main() { foo(^); }
+  )cpp",
+  // Field of function pointer type
+  R"cpp(
+struct S {
+  void (*foo)(int x, int y);
+};
+S s;
+int main() { s.foo(^); }
+  )cpp",
+  // Field of function pointer typedef type
+  R"cpp(
+typedef void (*fn)(int x, int y);
+struct S {
+  fn foo;
+};
+S s;
+int main() { s.foo(^); }
   )cpp"};
   for (auto Test : Tests)
 EXPECT_THAT(signatures(Test).signatures,

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index c44be0df9b0a85..8d75239009401e 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6137,6 +6137,7 @@ ProduceSignatureHelp(Sema , 
MutableArrayRef Candidates,
 // so that we can recover argument names from it.
 static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
   TypeLoc Target;
+
   if (const auto *T = Fn->getType().getTypePtr()->getAs()) {
 Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
 
@@ -6145,6 +6146,11 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
 if (const auto *const VD = dyn_cast(D)) {
   Target = VD->getTypeSourceInfo()->getTypeLoc();
 }
+  } else if (const auto *ME = dyn_cast(Fn)) {
+const auto *MD = ME->getMemberDecl();
+if (const auto *FD = dyn_cast(MD)) {
+  Target = FD->getTypeSourceInfo()->getTypeLoc();
+}
   }
 
   if (!Target)



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


[clang] [clang-tools-extra] clangd: Show argument names for function pointer struct fields (PR #69011)

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

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

Thanks!

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


[clang] [llvm] [RISCV] RISCV vector calling convention (1/2) (PR #77560)

2024-03-05 Thread Brandon Wu via cfe-commits


@@ -3439,6 +3439,8 @@ StringRef FunctionType::getNameForCallConv(CallingConv 
CC) {
   case CC_PreserveAll: return "preserve_all";
   case CC_M68kRTD: return "m68k_rtd";
   case CC_PreserveNone: return "preserve_none";
+  case CC_RISCVVectorCall:

4vtomat wrote:

Sure~

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


[clang-tools-extra] [clangd] Remove calls to getFileLoc() in declToSym() (PR #83532)

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

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


[clang-tools-extra] d1aec79 - [clangd] Remove calls to getFileLoc() in declToSym() (#83532)

2024-03-05 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-03-05T23:12:43-05:00
New Revision: d1aec79a2ce077e49da7699c4ca2dee239d0a249

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

LOG: [clangd] Remove calls to getFileLoc() in declToSym() (#83532)

toHalfOpenFileRange() already handles translating macro locations to
file locations, and it can provide a better result by knowing about both
ends of the range.

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

Added: 


Modified: 
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index 5b3e46a7b4dc16..5244a4e893769e 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -223,8 +223,8 @@ std::string getSymbolDetail(ASTContext , const 
NamedDecl ) {
 std::optional declToSym(ASTContext , const NamedDecl ) {
   auto  = Ctx.getSourceManager();
 
-  SourceLocation BeginLoc = SM.getFileLoc(ND.getBeginLoc());
-  SourceLocation EndLoc = SM.getFileLoc(ND.getEndLoc());
+  SourceLocation BeginLoc = ND.getBeginLoc();
+  SourceLocation EndLoc = ND.getEndLoc();
   const auto SymbolRange =
   toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
   if (!SymbolRange)

diff  --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp 
b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index b1b8b4ccd184c2..4276a44275f535 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -750,6 +750,9 @@ TEST(DocumentSymbols, RangeFromMacro) {
 $fullDef[[FF3() {
   int var = 42;
 }]]
+
+#define FF4(name) int name = 0
+$FooRange[[FF4($FooSelectionRange[[foo]])]];
   )");
   TU.Code = Main.code().str();
   EXPECT_THAT(
@@ -766,7 +769,11 @@ TEST(DocumentSymbols, RangeFromMacro) {
   AllOf(withName("FF3"), withDetail("()"),
 symRange(Main.range("fullDef")),
 children(AllOf(withName("waldo"), withDetail("void ()"),
-   symRange(Main.range("fullDef")));
+   symRange(Main.range("fullDef"),
+  AllOf(
+  withName("FF4"), withDetail("(foo)"),
+  children(AllOf(withName("foo"), symRange(Main.range("FooRange")),
+ 
symNameRange(Main.range("FooSelectionRange")));
 }
 
 TEST(DocumentSymbols, FuncTemplates) {



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


[clang-tools-extra] [clangd] Make all calls to format::getStyle() go through getFormatStyleForFile() (PR #82948)

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

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


[clang-tools-extra] 5549b01 - [clangd] Make all calls to format::getStyle() go through getFormatStyleForFile() (#82948)

2024-03-05 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-03-05T23:11:29-05:00
New Revision: 5549b0173661155d4ca9acf4958fe6dce34c2cd5

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

LOG: [clangd] Make all calls to format::getStyle() go through 
getFormatStyleForFile() (#82948)

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/IncludeCleaner.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 3f9fd012819428..2907e3ba3c303c 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -551,15 +551,10 @@ void ClangdServer::formatOnType(PathRef File, Position 
Pos,
   auto Action = [File = File.str(), Code = std::move(*Code),
  TriggerText = TriggerText.str(), CursorPos = *CursorPos,
  CB = std::move(CB), this]() mutable {
-auto Style = format::getStyle(format::DefaultFormatStyle, File,
-  format::DefaultFallbackStyle, Code,
-  TFS.view(/*CWD=*/std::nullopt).get());
-if (!Style)
-  return CB(Style.takeError());
-
+auto Style = getFormatStyleForFile(File, Code, TFS);
 std::vector Result;
 for (const tooling::Replacement  :
- formatIncremental(Code, CursorPos, TriggerText, *Style))
+ formatIncremental(Code, CursorPos, TriggerText, Style))
   Result.push_back(replacementToEdit(Code, R));
 return CB(Result);
   };

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index f86a121340f7fb..7375b7b0860917 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -111,21 +111,15 @@ bool mayConsiderUnused(const Inclusion , ParsedAST 
,
 
 std::vector generateMissingIncludeDiagnostics(
 ParsedAST , llvm::ArrayRef MissingIncludes,
-llvm::StringRef Code, HeaderFilter IgnoreHeaders) {
+llvm::StringRef Code, HeaderFilter IgnoreHeaders, const ThreadsafeFS ) 
{
   std::vector Result;
   const SourceManager  = AST.getSourceManager();
   const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
 
-  auto FileStyle = format::getStyle(
-  format::DefaultFormatStyle, AST.tuPath(), format::DefaultFallbackStyle,
-  Code, ().getVirtualFileSystem());
-  if (!FileStyle) {
-elog("Couldn't infer style", FileStyle.takeError());
-FileStyle = format::getLLVMStyle();
-  }
+  auto FileStyle = getFormatStyleForFile(AST.tuPath(), Code, TFS);
 
   tooling::HeaderIncludes HeaderIncludes(AST.tuPath(), Code,
- FileStyle->IncludeStyle);
+ FileStyle.IncludeStyle);
   for (const auto  : MissingIncludes) {
 llvm::StringRef ResolvedPath =
 SymbolWithMissingInclude.Providers.front().resolvedPath();
@@ -459,6 +453,7 @@ bool isPreferredProvider(const Inclusion ,
 std::vector
 issueIncludeCleanerDiagnostics(ParsedAST , llvm::StringRef Code,
const IncludeCleanerFindings ,
+   const ThreadsafeFS ,
HeaderFilter IgnoreHeaders) {
   trace::Span Tracer("IncludeCleaner::issueIncludeCleanerDiagnostics");
   std::vector UnusedIncludes = generateUnusedIncludeDiagnostics(
@@ -466,7 +461,7 @@ issueIncludeCleanerDiagnostics(ParsedAST , 
llvm::StringRef Code,
   std::optional RemoveAllUnused = removeAllUnusedIncludes(UnusedIncludes);
 
   std::vector MissingIncludeDiags = generateMissingIncludeDiagnostics(
-  AST, Findings.MissingIncludes, Code, IgnoreHeaders);
+  AST, Findings.MissingIncludes, Code, IgnoreHeaders, TFS);
   std::optional AddAllMissing = 
addAllMissingIncludes(MissingIncludeDiags);
 
   std::optional FixAll;

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.h 
b/clang-tools-extra/clangd/IncludeCleaner.h
index b3ba3a716083e8..387763de340767 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.h
+++ b/clang-tools-extra/clangd/IncludeCleaner.h
@@ -59,6 +59,7 @@ using HeaderFilter = 
llvm::ArrayRef>;
 std::vector
 issueIncludeCleanerDiagnostics(ParsedAST , llvm::StringRef Code,
const IncludeCleanerFindings ,
+   const ThreadsafeFS ,
HeaderFilter IgnoreHeader = {});
 
 /// Affects whether standard library includes should be considered for

diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index bbb0e2c77b3f31..862f06196a7100 100644
--- 

[clang] [AMDGPU] Introduce 'amdgpu_num_workgroups_{xyz}' builtin (PR #83927)

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

jhuber6 wrote:

> I think we would be better off teaching an IR optimizer pass to recognize the 
> divide pattern and remap it to the load from the new location, rather than 
> forcing the complexity into every frontend

That's fair. I would've argued that this version should've been the builtin and 
the grid size be the computed one but it's definitely not ideal to have 
multiple versions of this. I'll try to find a place to do this peephole 
optimization. 

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


[clang] [CUDA] Correctly set CUDA default architecture (PR #84017)

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

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


[clang] 433b711 - [CUDA] Correctly set CUDA default architecture (#84017)

2024-03-05 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-03-05T22:03:00-06:00
New Revision: 433b71188da9649a9040f0db5338c65369fa3e90

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

LOG: [CUDA] Correctly set CUDA default architecture (#84017)

Summary:
We already had a special CUDA default that better tracked the state as
of modern CUDA installations. Recently this was bumped up to `sm_52`,
but there was a location that wasn't respecting this. Fix that.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/cuda-detect.cu
clang/test/Driver/cuda-march.cu
clang/test/Driver/cuda-omp-unsupported-debug-options.cu
clang/test/Driver/cuda-options.cu
clang/test/Driver/cuda-ptxas-path.cu
clang/test/Driver/dwarf-target-version-clamp.cu

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index de8ceb2f0898bb..cecd34acbc92c0 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3234,7 +3234,7 @@ class OffloadingActionBuilder final {
 CudaActionBuilder(Compilation , DerivedArgList ,
   const Driver::InputList )
 : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_Cuda) {
-  DefaultCudaArch = CudaArch::SM_35;
+  DefaultCudaArch = CudaArch::CudaDefault;
 }
 
 StringRef getCanonicalOffloadArch(StringRef ArchStr) override {

diff  --git a/clang/test/Driver/cuda-detect.cu 
b/clang/test/Driver/cuda-detect.cu
index 077d555a3128f2..49e58004e672c3 100644
--- a/clang/test/Driver/cuda-detect.cu
+++ b/clang/test/Driver/cuda-detect.cu
@@ -11,7 +11,6 @@
 // RUN: %clang -v --target=x86_64-apple-macosx \
 // RUN:   --sysroot=%S/no-cuda-there --cuda-path-ignore-env 2>&1 | FileCheck 
%s -check-prefix NOCUDA
 
-
 // RUN: %clang -v --target=i386-unknown-linux \
 // RUN:   --sysroot=%S/Inputs/CUDA --cuda-path-ignore-env 2>&1 | FileCheck %s
 // RUN: %clang -v --target=i386-apple-macosx \
@@ -146,9 +145,9 @@
 // RUN: -check-prefix NOCUDAINC
 
 // Verify that C++ include paths are passed for both host and device frontends.
-// RUN: not %clang -### --target=x86_64-linux-gnu %s \
+// RUN: %clang -### --target=x86_64-linux-gnu %s \
 // RUN: --stdlib=libstdc++ --sysroot=%S/Inputs/ubuntu_14.04_multiarch_tree2 \
-// RUN: --gcc-toolchain="" 2>&1 \
+// RUN: -nogpulib -nogpuinc --gcc-toolchain="" 2>&1 \
 // RUN: | FileCheck %s --check-prefix CHECK-CXXINCLUDE
 
 // Verify that CUDA SDK version is propagated to the CC1 compilations.

diff  --git a/clang/test/Driver/cuda-march.cu b/clang/test/Driver/cuda-march.cu
index 7003e9fd4198c6..25fd6f3a10f2a2 100644
--- a/clang/test/Driver/cuda-march.cu
+++ b/clang/test/Driver/cuda-march.cu
@@ -5,15 +5,15 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 
-// RUN: not %clang -### --target=x86_64-linux-gnu -c \
-// RUN: -march=haswell %s 2>&1 | FileCheck %s
-// RUN: not %clang -### --target=x86_64-linux-gnu -c \
-// RUN: -march=haswell --cuda-gpu-arch=sm_35 %s 2>&1 | FileCheck %s
+// RUN: %clang -### --target=x86_64-linux-gnu -c \
+// RUN: -nogpulib -nogpuinc -march=haswell %s 2>&1 | FileCheck %s
+// RUN: %clang -### --target=x86_64-linux-gnu -c \
+// RUN: -nogpulib -nogpuinc -march=haswell --cuda-gpu-arch=sm_52 %s 2>&1 | 
FileCheck %s
 
 // CHECK: "-cc1"{{.*}} "-triple" "nvptx
-// CHECK-SAME: "-target-cpu" "sm_35"
+// CHECK-SAME: "-target-cpu" "sm_52"
 
 // CHECK: ptxas
-// CHECK-SAME: "--gpu-name" "sm_35"
+// CHECK-SAME: "--gpu-name" "sm_52"
 
 // CHECK: "-cc1"{{.*}} "-target-cpu" "haswell"

diff  --git a/clang/test/Driver/cuda-omp-unsupported-debug-options.cu 
b/clang/test/Driver/cuda-omp-unsupported-debug-options.cu
index 77cfa6925e387f..8e1bb2e496c749 100644
--- a/clang/test/Driver/cuda-omp-unsupported-debug-options.cu
+++ b/clang/test/Driver/cuda-omp-unsupported-debug-options.cu
@@ -2,56 +2,56 @@
 // REQUIRES: nvptx-registered-target
 // REQUIRES: zlib
 
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gz 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gz 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf 
-fdebug-info-for-profiling 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf -fdebug-info-for-profiling 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-2 
-gsplit-dwarf 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-2 -gsplit-dwarf 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-3 -glldb 2>&1 \
+// RUN: %clang -### 

[clang] [llvm] [AMDGPU] Implement 'llvm.get.fpenv' and 'llvm.set.fpenv' (PR #83906)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/83906

>From 1ff47a0c18e5f163bad9c0bd45c987ff7a33ab83 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 1 Mar 2024 15:28:32 -0600
Subject: [PATCH 1/2] [AMDGPU] Implement 'llvm.get.fpenv' and 'llvm.set.fpenv'

Summary:
This patch implements the LLVM floating point environment control
intrinsics and also exposes it through clang. We encode the floating
point environment as a 64-bit value that simply concatenates the values
of the mode registers and the current trap status. We only fetch the
bits relevant for floating point instructions. That is, rounding mode,
denormalization mode, ieee, dx10 clamp, debug, enabled traps, f16
overflow, and active exceptions.
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  11 +
 clang/lib/Sema/SemaChecking.cpp   |   7 +
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  12 +
 .../test/SemaOpenCL/builtins-amdgcn-error.cl  |   8 +
 llvm/docs/AMDGPUUsage.rst |   7 +
 llvm/docs/LangRef.rst |   2 +
 llvm/docs/ReleaseNotes.rst|   2 +
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |  52 +++
 llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.h  |   5 +
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  72 
 llvm/lib/Target/AMDGPU/SIISelLowering.h   |   2 +
 llvm/test/CodeGen/AMDGPU/fpenv.ll | 374 ++
 14 files changed, 561 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/fpenv.ll

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 213311b96df74f..6628e8f265fe48 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -325,6 +325,9 @@ BUILTIN(__builtin_amdgcn_read_exec_hi, "Ui", "nc")
 
 BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
 
+BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
+BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")
+
 
//===--===//
 // R600-NI only builtins.
 
//===--===//
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b50a4895e171b5..58a65b87afb84b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6826,6 +6826,10 @@ def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup>, DefaultIgnore;
 
+def warn_fenv_access : Warning<
+  "floating point environment access without #pragma STDC FENV_ACCESS set ON">,
+  InGroup>;
+
 def err_setting_eval_method_used_in_unsafe_context : Error <
   "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be 
used with "
   "%select{option 'fapprox-func'|option 'mreassociate'|option 
'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'|'#pragma 
clang fp reciprocal'}1">;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee51ca7142c77..a2e43634786a4f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18406,6 +18406,17 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 CGM.getIntrinsic(Intrinsic::amdgcn_global_load_tr, {ArgTy});
 return Builder.CreateCall(F, {Addr});
   }
+  case AMDGPU::BI__builtin_amdgcn_get_fpenv: {
+Function *F = CGM.getIntrinsic(Intrinsic::get_fpenv,
+   {llvm::Type::getInt64Ty(getLLVMContext())});
+return Builder.CreateCall(F);
+  }
+  case AMDGPU::BI__builtin_amdgcn_set_fpenv: {
+Function *F = CGM.getIntrinsic(Intrinsic::set_fpenv,
+   {llvm::Type::getInt64Ty(getLLVMContext())});
+llvm::Value *Env = EmitScalarExpr(E->getArg(0));
+return Builder.CreateCall(F, {Env});
+  }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
 return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0d4d57db01c93a..7a28c8472fc0dd 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5307,6 +5307,13 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   // position of memory order and scope arguments in the builtin
   unsigned OrderIndex, ScopeIndex;
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_get_fpenv:
+  case AMDGPU::BI__builtin_amdgcn_set_fpenv:
+// Emit a warning if the user accesses the AMDGPU floating point 
environment
+// without access being set.
+if (!CurFPFeatures.getAllowFEnvAccess())
+  Diag(TheCall->getBeginLoc(), diag::warn_fenv_access);
+

[clang] [llvm] [AMDGPU] Implement 'llvm.get.fpenv' and 'llvm.set.fpenv' (PR #83906)

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


@@ -6826,6 +6826,10 @@ def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup>, DefaultIgnore;
 
+def warn_fenv_access : Warning<
+  "floating point environment access without #pragma STDC FENV_ACCESS set ON">,
+  InGroup>;

jhuber6 wrote:

I'm not specifically knowledgeable about how this should be handled in the 
grander scheme. Could I get rid of the warning and leave that for a separate 
patch?

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


[clang] [llvm] [AMDGPU] Implement 'llvm.get.fpenv' and 'llvm.set.fpenv' (PR #83906)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/83906

>From 1ff47a0c18e5f163bad9c0bd45c987ff7a33ab83 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 1 Mar 2024 15:28:32 -0600
Subject: [PATCH] [AMDGPU] Implement 'llvm.get.fpenv' and 'llvm.set.fpenv'

Summary:
This patch implements the LLVM floating point environment control
intrinsics and also exposes it through clang. We encode the floating
point environment as a 64-bit value that simply concatenates the values
of the mode registers and the current trap status. We only fetch the
bits relevant for floating point instructions. That is, rounding mode,
denormalization mode, ieee, dx10 clamp, debug, enabled traps, f16
overflow, and active exceptions.
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  11 +
 clang/lib/Sema/SemaChecking.cpp   |   7 +
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  12 +
 .../test/SemaOpenCL/builtins-amdgcn-error.cl  |   8 +
 llvm/docs/AMDGPUUsage.rst |   7 +
 llvm/docs/LangRef.rst |   2 +
 llvm/docs/ReleaseNotes.rst|   2 +
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |  52 +++
 llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.h  |   5 +
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  72 
 llvm/lib/Target/AMDGPU/SIISelLowering.h   |   2 +
 llvm/test/CodeGen/AMDGPU/fpenv.ll | 374 ++
 14 files changed, 561 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/fpenv.ll

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 213311b96df74f..6628e8f265fe48 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -325,6 +325,9 @@ BUILTIN(__builtin_amdgcn_read_exec_hi, "Ui", "nc")
 
 BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
 
+BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
+BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")
+
 
//===--===//
 // R600-NI only builtins.
 
//===--===//
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b50a4895e171b5..58a65b87afb84b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6826,6 +6826,10 @@ def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup>, DefaultIgnore;
 
+def warn_fenv_access : Warning<
+  "floating point environment access without #pragma STDC FENV_ACCESS set ON">,
+  InGroup>;
+
 def err_setting_eval_method_used_in_unsafe_context : Error <
   "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be 
used with "
   "%select{option 'fapprox-func'|option 'mreassociate'|option 
'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'|'#pragma 
clang fp reciprocal'}1">;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee51ca7142c77..a2e43634786a4f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18406,6 +18406,17 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 CGM.getIntrinsic(Intrinsic::amdgcn_global_load_tr, {ArgTy});
 return Builder.CreateCall(F, {Addr});
   }
+  case AMDGPU::BI__builtin_amdgcn_get_fpenv: {
+Function *F = CGM.getIntrinsic(Intrinsic::get_fpenv,
+   {llvm::Type::getInt64Ty(getLLVMContext())});
+return Builder.CreateCall(F);
+  }
+  case AMDGPU::BI__builtin_amdgcn_set_fpenv: {
+Function *F = CGM.getIntrinsic(Intrinsic::set_fpenv,
+   {llvm::Type::getInt64Ty(getLLVMContext())});
+llvm::Value *Env = EmitScalarExpr(E->getArg(0));
+return Builder.CreateCall(F, {Env});
+  }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
 return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0d4d57db01c93a..7a28c8472fc0dd 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5307,6 +5307,13 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   // position of memory order and scope arguments in the builtin
   unsigned OrderIndex, ScopeIndex;
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_get_fpenv:
+  case AMDGPU::BI__builtin_amdgcn_set_fpenv:
+// Emit a warning if the user accesses the AMDGPU floating point 
environment
+// without access being set.
+if (!CurFPFeatures.getAllowFEnvAccess())
+  Diag(TheCall->getBeginLoc(), diag::warn_fenv_access);
+return 

[clang] [openmp] [OpenMP] Respect LLVM per-target install directories (PR #83282)

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

jhuber6 wrote:

> Fixed the issue 
> [0fa04b6](https://github.com/llvm/llvm-project/commit/0fa04b6e2cd2169a8e3d22ae879394dbf07c0466)
>  Unrelated to building as projects.

Hah, I probably should've noticed that. Explains why I didn't notice because I 
always have tests enabled.

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


[clang] [openmp] [OpenMP] Respect LLVM per-target install directories (PR #83282)

2024-03-05 Thread Ye Luo via cfe-commits

ye-luo wrote:

Fixed the issue 
https://github.com/llvm/llvm-project/commit/0fa04b6e2cd2169a8e3d22ae879394dbf07c0466
Unrelated to building as projects.

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


[clang] [llvm] [RISCV] RISCV vector calling convention (1/2) (PR #77560)

2024-03-05 Thread Craig Topper via cfe-commits


@@ -3439,6 +3439,8 @@ StringRef FunctionType::getNameForCallConv(CallingConv 
CC) {
   case CC_PreserveAll: return "preserve_all";
   case CC_M68kRTD: return "m68k_rtd";
   case CC_PreserveNone: return "preserve_none";
+  case CC_RISCVVectorCall:

topperc wrote:

Put this on the same line to match the prevailing style? Add `clang-format off` 
and `clang-format off` comments around the switch if clang-format gives you 
trouble.

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


[clang] [llvm] [RISCV] RISCV vector calling convention (1/2) (PR #77560)

2024-03-05 Thread Craig Topper via cfe-commits


@@ -74,6 +74,8 @@ unsigned 
CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
   case CC_SwiftAsync: return llvm::CallingConv::SwiftTail;
   case CC_M68kRTD: return llvm::CallingConv::M68k_RTD;
   case CC_PreserveNone: return llvm::CallingConv::PreserveNone;
+  case CC_RISCVVectorCall:

topperc wrote:

Use one line to match the prevailing style

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


[clang] [clang][RISCV] Enable RVV with function attribute __attribute__((target("arch=+v"))) (PR #83674)

2024-03-05 Thread Brandon Wu via cfe-commits

4vtomat wrote:

Rebase.

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


[clang] [clang][RISCV] Enable RVV with function attribute __attribute__((target("arch=+v"))) (PR #83674)

2024-03-05 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/83674

>From faab3d0d9163e99185fb6a2d3efd21549ed33e00 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Fri, 1 Mar 2024 09:52:35 -0800
Subject: [PATCH 1/3] [clang][RISCV] Enable RVV with function attribute
 __attribute__((target("arch=+v")))

It is currently not possible to use "RVV type" and "RVV intrinsics" if
the "zve32x" is not enabled globally. However in some cases we may want
to use them only in some functions, for instance:
```
#include 

__attribute__((target("+zve32x")))
vint32m1_t rvv_add(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}

int other_add(int i1, int i2) {
  return i1 + i2;
}
```
, it is supposed to be compilable even the vector is not specified, e.g.
`clang -target riscv64 -march=rv64gc -S test.c`.
---
 clang/include/clang/Sema/Sema.h   |  3 +-
 clang/lib/Basic/Targets/RISCV.cpp |  3 +-
 clang/lib/Sema/Sema.cpp   |  7 +-
 clang/lib/Sema/SemaChecking.cpp   | 70 +++
 clang/lib/Sema/SemaDecl.cpp   |  9 ++-
 .../RISCV/rvb-intrinsics/riscv32-zbb-error.c  |  4 +-
 .../RISCV/rvb-intrinsics/riscv64-zbkb-error.c | 12 ++--
 .../rvv-intrinsics-handcrafted/rvv-error.c|  2 +-
 clang/test/Sema/riscv-function-target-attr.c  | 41 +++
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 --
 10 files changed, 73 insertions(+), 82 deletions(-)
 create mode 100644 clang/test/Sema/riscv-function-target-attr.c

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 25c4c58ad4ae43..229ae7c1050cd6 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14081,7 +14081,8 @@ class Sema final {
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo , unsigned BuiltinID,
  CallExpr *TheCall);
-  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D);
+  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
+   const llvm::StringMap );
   bool CheckLoongArchBuiltinFunctionCall(const TargetInfo ,
  unsigned BuiltinID, CallExpr 
*TheCall);
   bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo ,
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..6991caa21d23b4 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -463,7 +463,8 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef 
Features) const {
 Ret.Duplicate = "tune=";
 
   Ret.Tune = AttrString;
-}
+} else if (Feature.starts_with("+"))
+  Ret.Features.push_back(Feature.str());
   }
   return Ret;
 }
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..41c7bfb25a7921 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2077,8 +2077,11 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
-if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType())
-  checkRVVTypeSupport(Ty, Loc, D);
+if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
+  llvm::StringMap CallerFeatureMap;
+  Context.getFunctionFeatureMap(CallerFeatureMap, FD);
+  checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
+}
 
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 561764edd08100..2a6aceaefa9b19 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5429,57 +5429,6 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo 
, CallExpr *TheCall,
 bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo ,
  unsigned BuiltinID,
  CallExpr *TheCall) {
-  // CodeGenFunction can also detect this, but this gives a better error
-  // message.
-  bool FeatureMissing = false;
-  SmallVector ReqFeatures;
-  StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
-  Features.split(ReqFeatures, ',', -1, false);
-
-  // Check if each required feature is included
-  for (StringRef F : ReqFeatures) {
-SmallVector ReqOpFeatures;
-F.split(ReqOpFeatures, '|');
-
-if (llvm::none_of(ReqOpFeatures,
-  [](StringRef OF) { return TI.hasFeature(OF); })) {
-  std::string FeatureStrs;
-  bool IsExtension = true;
-  for (StringRef OF : ReqOpFeatures) {
-// If the feature is 64bit, alter the string so it will print better in
-// the diagnostic.
-if (OF == "64bit") {
-  

[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Jon Roelofs via cfe-commits


@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the 
user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU
+supports features specified in string argument. It returns positive integer
+if all features are supported and 0 otherwise. Names of features and format is
+target specific. For example on AArch64 features are combined using ``+`` like
+this ``__builtin_cpu_supports("flagm+sha3+lse+rcpc2+fcma+memtag+bti+sme2")``.
+If feature name is not supported or format is wrong, compiler will issue a
+warning and replace builtin by constant 0.
+
+Query for this feature with ``__has_builtin(__builtin_cpu_supports)``.

jroelofs wrote:

```suggestion
The ``__builtin_cpu_supports`` function detects at runtime if the target CPU
supports features specified in string argument. It returns a positive integer
if all features are supported and 0 otherwise. Names of features and format are
target specific. For example on AArch64 features are combined using ``+`` like
this ``__builtin_cpu_supports("flagm+sha3+lse+rcpc2+fcma+memtag+bti+sme2")``.
If a feature name is not supported or the format is wrong, the compiler will 
issue a
warning and replace builtin by the constant 0.

Query for this feature with ``__has_builtin(__builtin_cpu_supports)``.
```

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Jon Roelofs via cfe-commits

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

Some small nits, but LGTM.

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


[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

2024-03-05 Thread Jon Roelofs via cfe-commits

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


[clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)

2024-03-05 Thread Mehdi Amini via cfe-commits


@@ -104,7 +104,7 @@ static std::recursive_mutex *g_debugger_list_mutex_ptr =
 nullptr; // NOTE: intentional leak to avoid issues with C++ destructor 
chain
 static Debugger::DebuggerList *g_debugger_list_ptr =
 nullptr; // NOTE: intentional leak to avoid issues with C++ destructor 
chain
-static llvm::ThreadPool *g_thread_pool = nullptr;
+static llvm::DefaultThreadPoolThreadPool *g_thread_pool = nullptr;

joker-eph wrote:

Weirdly this issue wasn't caught in CI!

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


  1   2   3   4   5   6   >