[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@peterwaller-arm Ohh, there is so many `-none-unknown-` in current code. I 
guess it may be widely used.
Do we really want to change all of them?

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


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libclc] [libcxx] [libcxxabi] [libunwind] [lld] [lldb] [llvm] [mlir] [openmp] [polly] [pstl] Update IDE Folders (PR #89153)

2024-04-23 Thread James Henderson via cfe-commits

jh7370 wrote:

> This looks like a nice improvement for folks using those generators. Even 
> though most of these changes look straightforward, it would be a lot easier 
> to review if this was broken up per subproject. Is there any reason that's 
> not possible?

+1 to this: 195 files is too many to review in a single PR really, so if we 
have an alternative, incremental approach, we should take that. (Also big +1 to 
the improvement though).

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


[clang] a046242 - [clang] Set correct FPOptions if attribute 'optnone' presents (#85605)

2024-04-23 Thread via cfe-commits

Author: Serge Pavlov
Date: 2024-04-23T14:14:02+07:00
New Revision: a04624206ddf03dc54d5c372e7eac13575b4124b

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

LOG: [clang] Set correct FPOptions if attribute 'optnone' presents (#85605)

Attribute `optnone` must turn off all optimizations including fast-math
ones. Actually AST nodes in the 'optnone' function still had fast-math
flags. This change implements fixing FP options before function body is
parsed.

Added: 
clang/test/AST/ast-dump-fpfeatures.m
clang/test/AST/ast-dump-late-parsing.cpp

Modified: 
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/test/AST/ast-dump-fpfeatures.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 75562284ec7de0..ae4715921d1665 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -878,6 +878,8 @@ class FPOptions {
   /// Return 
diff erence with the given option set.
   FPOptionsOverride getChangesFrom(const FPOptions &Base) const;
 
+  void applyChanges(FPOptionsOverride FPO);
+
   // We can define most of the accessors automatically:
 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)
\
   TYPE get##NAME() const { 
\
@@ -959,6 +961,11 @@ class FPOptionsOverride {
   setAllowFPContractAcrossStatement();
   }
 
+  void setDisallowOptimizations() {
+setFPPreciseEnabled(true);
+setDisallowFPContract();
+  }
+
   storage_type getAsOpaqueInt() const {
 return (static_cast(Options.getAsOpaqueInt())
 << FPOptions::StorageBitSize) |
@@ -1015,6 +1022,10 @@ inline FPOptionsOverride FPOptions::getChangesFrom(const 
FPOptions &Base) const
   return getChangesSlow(Base);
 }
 
+inline void FPOptions::applyChanges(FPOptionsOverride FPO) {
+  *this = FPO.applyOverrides(*this);
+}
+
 /// Describes the kind of translation unit being processed.
 enum TranslationUnitKind {
   /// The translation unit is a complete translation unit.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 64607b91acbfc9..1ca523ec88c2f9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3084,6 +3084,7 @@ class Sema final : public SemaBase {
   Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,
 SkipBodyInfo *SkipBody = nullptr,
 FnBodyKind BodyKind = FnBodyKind::Other);
+  void applyFunctionAttributesBeforeParsingBody(Decl *FD);
 
   /// Determine whether we can delay parsing the body of a function or
   /// function template until it is used, assuming we don't care about emitting

diff  --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp 
b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index d054eda279b8c8..a26568dfd6aae3 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -603,6 +603,8 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
   // to be re-used for method bodies as well.
   ParseScope FnScope(this, Scope::FnScope | Scope::DeclScope |
Scope::CompoundStmtScope);
+  Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
+
   Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
 
   if (Tok.is(tok::kw_try)) {

diff  --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 671dcb71e51a37..8e54fe012c55d7 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -3736,6 +3736,7 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, 
bool parseMethod) {
   ParseScope BodyScope(this, (parseMethod ? Scope::ObjCMethodScope : 0) |
  Scope::FnScope | Scope::DeclScope |
  Scope::CompoundStmtScope);
+  Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
 
   // Tell the actions module that we have entered a method or c-function 
definition
   // with the specified Declarator for the method/function.

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index ef46fc74cedc14..adcbe5858bc78e 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1497,6 +1497,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator 
&D,
 return Actions.ActOnFinishFunctionBody(Res, nullptr, false);
   }
 
+  Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
+
   if (Tok.is(tok::kw_try))
 return ParseFunctionTryBlock(Res, BodyScope);
 

diff  --git a/clang/

[clang] [clang] Set correct FPOptions if attribute 'optnone' presents (PR #85605)

2024-04-23 Thread Serge Pavlov via cfe-commits

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


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/89638

>From 11ae27aeb512b661a3423a8b92642a9ec08ca6a1 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Apr 2024 01:36:17 +0800
Subject: [PATCH] Triple::normalize: Set OS for 3-component triple with none as
 middle

If the middle component of a 3-component triple fails to parse as known
Arch/Vendor/OS/Env, it will fallback as Vendor. While for some cases,
we may wish to recognize it as OS, such as `arm64-none-elf`.

In this patch, we will set OS as `none`, if:
1) Arch is found;
2) Env is found;
3) OS is not found and thus is set as empty;
4) Vendor is not found while is set as "none",
we will swap Component[2] and Component[3].

Use this new triple for these tests:
  - clang/docs/Multilib.rst
  - clang/test/CodeGen/Inputs/linker-diagnostic1.ll
  - clang/test/CodeGen/linker-diagnostic.ll
  - clang/test/Driver/arm-ias-Wa.s
  - clang/test/Driver/arm-triple.c
  - clang/test/Driver/baremetal-multilib-exclusive-group.yaml
  - clang/test/Driver/baremetal-multilib-group-error.yaml
  - clang/test/Driver/baremetal-multilib-layered.yaml
  - clang/test/Driver/baremetal-multilib.yaml
  - clang/test/Driver/baremetal-sysroot.cpp
  - clang/test/Driver/baremetal.cpp
  - clang/test/Driver/print-multi-selection-flags.c
  - clang/test/Driver/program-path-priority.c
  - clang/test/Preprocessor/init-arm.c
  - clang/unittests/Driver/MultilibTest.cpp
  - clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
  - libcxx/utils/ci/run-buildbot
  - lld/test/ELF/lto/arm.ll
  - llvm/test/CodeGen/ARM/machine-sink-multidef.mir
  - llvm/test/CodeGen/ARM/store-prepostinc.mir
  - llvm/test/CodeGen/ARM/unschedule-reg-sequence.ll
  - llvm/test/CodeGen/Thumb/consthoist-few-dependents.ll
  - llvm/test/CodeGen/Thumb/consthoist-imm8-costs-1.ll
  - llvm/test/CodeGen/Thumb/pr42760.ll
  - llvm/test/CodeGen/Thumb/smul_fix.ll
  - llvm/test/CodeGen/Thumb/smul_fix_sat.ll
  - llvm/test/CodeGen/Thumb/umul_fix.ll
  - llvm/test/CodeGen/Thumb/umul_fix_sat.ll
  - llvm/test/CodeGen/Thumb2/LowOverheadLoops/spillingmove.mir
  - llvm/test/CodeGen/Thumb2/LowOverheadLoops/wls-search-pred.mir
  - llvm/test/CodeGen/Thumb2/high-reg-spill.mir
  - llvm/test/CodeGen/Thumb2/mve-pred-constfold.mir
  - llvm/test/CodeGen/Thumb2/mve-vpt-block-debug.mir
  - llvm/test/CodeGen/Thumb2/pipeliner-preserve-ties.mir
  - llvm/test/CodeGen/Thumb2/store-prepostinc.mir
  - llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
  - llvm/test/Transforms/LoopVectorize/ARM/mve-hoist-runtime-checks.ll
  - llvm/unittests/TargetParser/TripleTest.cpp

Fixes: #89582.
---
 clang/docs/Multilib.rst   |  4 +-
 .../test/CodeGen/Inputs/linker-diagnostic1.ll |  2 +-
 clang/test/CodeGen/linker-diagnostic.ll   |  4 +-
 clang/test/Driver/arm-ias-Wa.s|  2 +-
 clang/test/Driver/arm-triple.c| 10 +--
 .../baremetal-multilib-exclusive-group.yaml   | 22 +++
 .../baremetal-multilib-group-error.yaml   |  4 +-
 .../Driver/baremetal-multilib-layered.yaml|  2 +-
 clang/test/Driver/baremetal-multilib.yaml | 64 +--
 clang/test/Driver/baremetal-sysroot.cpp   |  2 +-
 clang/test/Driver/baremetal.cpp   |  2 +-
 .../test/Driver/print-multi-selection-flags.c | 14 ++--
 clang/test/Driver/program-path-priority.c |  4 +-
 clang/test/Preprocessor/init-arm.c|  4 +-
 clang/unittests/Driver/MultilibTest.cpp   | 52 +++
 .../IncrementalCompilerBuilderTest.cpp|  2 +-
 libcxx/utils/ci/run-buildbot  |  2 +-
 lld/test/ELF/lto/arm.ll   |  4 +-
 llvm/lib/TargetParser/Triple.cpp  |  7 ++
 .../CodeGen/ARM/machine-sink-multidef.mir |  2 +-
 llvm/test/CodeGen/ARM/store-prepostinc.mir|  2 +-
 .../CodeGen/ARM/unschedule-reg-sequence.ll|  2 +-
 .../Thumb/consthoist-few-dependents.ll|  2 +-
 .../CodeGen/Thumb/consthoist-imm8-costs-1.ll  |  2 +-
 llvm/test/CodeGen/Thumb/pr42760.ll|  2 +-
 llvm/test/CodeGen/Thumb/smul_fix.ll   |  2 +-
 llvm/test/CodeGen/Thumb/smul_fix_sat.ll   |  2 +-
 llvm/test/CodeGen/Thumb/umul_fix.ll   |  2 +-
 llvm/test/CodeGen/Thumb/umul_fix_sat.ll   |  2 +-
 .../Thumb2/LowOverheadLoops/spillingmove.mir  |  2 +-
 .../LowOverheadLoops/wls-search-pred.mir  |  2 +-
 llvm/test/CodeGen/Thumb2/high-reg-spill.mir   |  2 +-
 .../CodeGen/Thumb2/mve-pred-constfold.mir |  2 +-
 .../CodeGen/Thumb2/mve-vpt-block-debug.mir|  2 +-
 .../Thumb2/pipeliner-preserve-ties.mir|  2 +-
 llvm/test/CodeGen/Thumb2/store-prepostinc.mir |  2 +-
 .../InferFunctionAttrs/norecurse_debug.ll |  2 +-
 .../ARM/mve-hoist-runtime-checks.ll   |  2 +-
 llvm/unittests/TargetParser/TripleTest.cpp|  2 +-
 39 files changed, 127 insertions(+), 120 deletions(-)

diff --git a/clang/docs/Multilib.rst b/clang/docs/Multilib.rst
index ab737e43b97d23..063fe9a336f2fe 100

[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@llvm/pr-subscribers-backend-arm @llvm/pr-subscribers-backend-aarch64 

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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Younan Zhang via cfe-commits

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

>From ba2e2a4bd2f7442003d6aa21f3d848cfef5061f6 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 20 Apr 2024 02:52:16 +0800
Subject: [PATCH] [Clang][Parser] Don't always destroy template annotations at
 the end of a declaration

Since 6163aa9, we have introduced an optimization that almost always
destroys TemplateIdAnnotations at the end of a function declaration.
This doesn't always work properly: a lambda within a default template
argument could also result in such deallocation and hence a use-after-free
bug while building a type constraint on the template parameter.

Fixes https://github.com/llvm/llvm-project/issues/67235
Fixes https://github.com/llvm/llvm-project/issues/89127
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Parse/Parser.h| 24 +++
 clang/lib/Parse/ParseTemplate.cpp |  5 
 .../cxx2a-constrained-template-param.cpp  | 20 +++-
 4 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index efc32212f300cf..0cf81a59493faf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -535,6 +535,7 @@ Bug Fixes to C++ Support
 - Fix a crash when deducing ``auto`` from an invalid dereference (#GH88329).
 - Fix a crash in requires expression with templated base class member 
function. Fixes (#GH84020).
 - Placement new initializes typedef array with correct size (#GH41441)
+- Fixed a use-after-free bug in parsing of type constraints with default 
arguments that involve lambdas. (#GH67235)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 23b268126de4e0..2a08b3d56e0cd1 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -313,7 +313,15 @@ class Parser : public CodeCompletionHandler {
   /// top-level declaration is finished.
   SmallVector TemplateIds;
 
+  /// Don't destroy template annotations in MaybeDestroyTemplateIds even if
+  /// we're at the end of a declaration. Instead, we defer the destruction 
until
+  /// after a top-level declaration.
+  /// Use DelayTemplateIdDestructionRAII rather than setting it directly.
+  bool DelayTemplateIdDestruction = false;
+
   void MaybeDestroyTemplateIds() {
+if (DelayTemplateIdDestruction)
+  return;
 if (!TemplateIds.empty() &&
 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
   DestroyTemplateIds();
@@ -329,6 +337,22 @@ class Parser : public CodeCompletionHandler {
 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
   };
 
+  struct DelayTemplateIdDestructionRAII {
+Parser &Self;
+bool PrevDelayTemplateIdDestruction;
+
+DelayTemplateIdDestructionRAII(Parser &Self,
+   bool DelayTemplateIdDestruction) noexcept
+: Self(Self),
+  PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
+  Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
+}
+
+~DelayTemplateIdDestructionRAII() noexcept {
+  Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
+}
+  };
+
   /// Identifiers which have been declared within a tentative parse.
   SmallVector TentativelyDeclaredIdentifiers;
 
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index b07ce451e878eb..665253a6674d27 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -733,7 +733,12 @@ NamedDecl *Parser::ParseTypeParameter(unsigned Depth, 
unsigned Position) {
   // we introduce the type parameter into the local scope.
   SourceLocation EqualLoc;
   ParsedType DefaultArg;
+  std::optional DontDestructTemplateIds;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
+// The default argument might contain a lambda declaration; avoid 
destroying
+// parsed template ids at the end of that declaration because they can be
+// used in a type constraint later.
+DontDestructTemplateIds.emplace(*this, 
/*DelayTemplateIdDestruction=*/true);
 // The default argument may declare template parameters, notably
 // if it contains a generic lambda, so we need to increase
 // the template depth as these parameters would not be instantiated
diff --git a/clang/test/Parser/cxx2a-constrained-template-param.cpp 
b/clang/test/Parser/cxx2a-constrained-template-param.cpp
index 6f14b66419c498..5afa99ea50cf91 100644
--- a/clang/test/Parser/cxx2a-constrained-template-param.cpp
+++ b/clang/test/Parser/cxx2a-constrained-template-param.cpp
@@ -49,4 +49,22 @@ namespace temp
   template // expected-error{{use of class template 
'test1' requires template arguments}}
   // expected-error@-1 2{{concept named in type constraint is not a type 
concept}}
   using A = TT; // expected-error{{exp

[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Younan Zhang via cfe-commits

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

>From 3d5d4d973b9a76d9a07cdd6b89b304e2c7f37308 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 20 Apr 2024 02:52:16 +0800
Subject: [PATCH] [Clang][Parser] Don't always destroy template annotations at
 the end of a declaration

Since 6163aa9, we have introduced an optimization that almost always
destroys TemplateIdAnnotations at the end of a function declaration.
This doesn't always work properly: a lambda within a default template
argument could also result in such deallocation and hence a use-after-free
bug while building a type constraint on the template parameter.

Fixes https://github.com/llvm/llvm-project/issues/67235
Fixes https://github.com/llvm/llvm-project/issues/89127
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Parse/Parser.h| 24 +++
 clang/lib/Parse/ParseTemplate.cpp |  5 
 .../cxx2a-constrained-template-param.cpp  | 20 +++-
 4 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f339fab6e8428f..3db558a1c11a3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -560,6 +560,7 @@ Bug Fixes to C++ Support
 - Fix the Itanium mangling of lambdas defined in a member of a local class 
(#GH88906)
 - Fixed a crash when trying to evaluate a user-defined ``static_assert`` 
message whose ``size()``
   function returns a large or negative value. Fixes (#GH89407).
+- Fixed a use-after-free bug in parsing of type constraints with default 
arguments that involve lambdas. (#GH67235)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 00a2f35d7f7041..fb117bf04087ee 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -313,7 +313,15 @@ class Parser : public CodeCompletionHandler {
   /// top-level declaration is finished.
   SmallVector TemplateIds;
 
+  /// Don't destroy template annotations in MaybeDestroyTemplateIds even if
+  /// we're at the end of a declaration. Instead, we defer the destruction 
until
+  /// after a top-level declaration.
+  /// Use DelayTemplateIdDestructionRAII rather than setting it directly.
+  bool DelayTemplateIdDestruction = false;
+
   void MaybeDestroyTemplateIds() {
+if (DelayTemplateIdDestruction)
+  return;
 if (!TemplateIds.empty() &&
 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
   DestroyTemplateIds();
@@ -329,6 +337,22 @@ class Parser : public CodeCompletionHandler {
 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
   };
 
+  struct DelayTemplateIdDestructionRAII {
+Parser &Self;
+bool PrevDelayTemplateIdDestruction;
+
+DelayTemplateIdDestructionRAII(Parser &Self,
+   bool DelayTemplateIdDestruction) noexcept
+: Self(Self),
+  PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
+  Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
+}
+
+~DelayTemplateIdDestructionRAII() noexcept {
+  Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
+}
+  };
+
   /// Identifiers which have been declared within a tentative parse.
   SmallVector TentativelyDeclaredIdentifiers;
 
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index b07ce451e878eb..665253a6674d27 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -733,7 +733,12 @@ NamedDecl *Parser::ParseTypeParameter(unsigned Depth, 
unsigned Position) {
   // we introduce the type parameter into the local scope.
   SourceLocation EqualLoc;
   ParsedType DefaultArg;
+  std::optional DontDestructTemplateIds;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
+// The default argument might contain a lambda declaration; avoid 
destroying
+// parsed template ids at the end of that declaration because they can be
+// used in a type constraint later.
+DontDestructTemplateIds.emplace(*this, 
/*DelayTemplateIdDestruction=*/true);
 // The default argument may declare template parameters, notably
 // if it contains a generic lambda, so we need to increase
 // the template depth as these parameters would not be instantiated
diff --git a/clang/test/Parser/cxx2a-constrained-template-param.cpp 
b/clang/test/Parser/cxx2a-constrained-template-param.cpp
index 6f14b66419c498..d27f0f8db9b885 100644
--- a/clang/test/Parser/cxx2a-constrained-template-param.cpp
+++ b/clang/test/Parser/cxx2a-constrained-template-param.cpp
@@ -49,4 +49,22 @@ namespace temp
   template // expected-error{{use of class template 
'test1' requires template arguments}}
   // expected-error@-1 2{{concept named in type constraint is not a type 
concept}}
   using A = TT; // expected-error{{

[clang] [clang] pointer to member with qualified-id closed in parantheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread via cfe-commits

https://github.com/zwuis created https://github.com/llvm/llvm-project/pull/89713

clang don't check whether the operand of the & operator is enclosed in 
parantheses when pointer to member is formed in unevaluated context, for 
example:

```cpp
struct foo { int val; };

int main() { decltype(&(foo::val)) ptr; }
```

`decltype(&(foo::val))` should be invalid, but clang accepts it. This PR fixes 
this issue.

Fixes #40906.

>From f6fd1e5e5f42b3c72cb5aeaf9e6d4e91d5424bee Mon Sep 17 00:00:00 2001
From: YanzuoLiu 
Date: Tue, 23 Apr 2024 14:56:12 +0800
Subject: [PATCH] Add missing check when making pointer to member

---
 clang/lib/Sema/SemaExpr.cpp| 11 +++
 .../CXX/expr/expr.unary/expr.unary.op/p3.cpp   | 18 +-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5c861467bc1023..824667fb722365 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14644,6 +14644,17 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
 return QualType();
   }
 
+  // C++11 [expr.unary.op] p4:
+  // A pointer to member is only formed when an explicit & is used and
+  // its operand is a qualified-id not enclosed in parentheses.
+  if (isa(OrigOp.get())) {
+// `op->getEndLoc()` is the last part of the qualified-id.
+// For example, "baz" in "foo::bar::baz".
+Diag(op->getEndLoc(), diag::err_invalid_non_static_member_use)
+<< dcl->getDeclName() << op->getSourceRange();
+return QualType();
+  }
+
   while (cast(Ctx)->isAnonymousStructOrUnion())
 Ctx = Ctx->getParent();
 
diff --git a/clang/test/CXX/expr/expr.unary/expr.unary.op/p3.cpp 
b/clang/test/CXX/expr/expr.unary/expr.unary.op/p3.cpp
index 08ab0ca56fb632..73d850a6839da7 100644
--- a/clang/test/CXX/expr/expr.unary/expr.unary.op/p3.cpp
+++ b/clang/test/CXX/expr/expr.unary/expr.unary.op/p3.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only %s -verify 
-// expected-no-diagnostics
 
 namespace rdar10544564 {
   // Check that we don't attempt to use an overloaded operator& when
@@ -27,3 +26,20 @@ namespace rdar10544564 {
   X (Y::*func_mem_ptr1)() = &Y::memfunc1;
   X (Y::*func_mem_ptr2)() = &Y::memfunc2;
 }
+
+namespace test2 {
+  struct A {
+int val;
+void func() {}
+  };
+
+  void test() {
+decltype(&(A::val)) ptr1; // expected-error {{invalid use of non-static 
data member 'val'}}
+int A::* ptr2 = &(A::val); // expected-error {{invalid use of non-static 
data member 'val'}}
+
+// FIXME: Error messages in these cases are less than clear, we can do
+// better.
+int size = sizeof(&(A::func)); // expected-error {{call to non-static 
member function without an object argument}}
+void (A::* ptr3)() = &(A::func); // expected-error {{call to non-static 
member function without an object argument}}
+  }
+}

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


[clang] 05c1447 - [clang][ExtractAPI] Serialize platform specific unavailable attribute in symbol graphs (#89277)

2024-04-23 Thread via cfe-commits

Author: Daniel Grumberg
Date: 2024-04-23T09:00:08+01:00
New Revision: 05c1447b3eabe9cc4a27866094e46c57350c5d5a

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

LOG: [clang][ExtractAPI] Serialize platform specific unavailable attribute in 
symbol graphs (#89277)

rdar://12565

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/ExtractAPI/availability.c

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 57f966c8b2be35..8b1dcb4a4144f4 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -164,27 +164,29 @@ std::optional serializeAvailability(const 
AvailabilityInfo &Avail) {
   if (Avail.isDefault())
 return std::nullopt;
 
-  Object Availability;
   Array AvailabilityArray;
-  Availability["domain"] = Avail.Domain;
-  serializeObject(Availability, "introduced",
-  serializeSemanticVersion(Avail.Introduced));
-  serializeObject(Availability, "deprecated",
-  serializeSemanticVersion(Avail.Deprecated));
-  serializeObject(Availability, "obsoleted",
-  serializeSemanticVersion(Avail.Obsoleted));
+
   if (Avail.isUnconditionallyDeprecated()) {
 Object UnconditionallyDeprecated;
 UnconditionallyDeprecated["domain"] = "*";
 UnconditionallyDeprecated["isUnconditionallyDeprecated"] = true;
 AvailabilityArray.emplace_back(std::move(UnconditionallyDeprecated));
   }
-  if (Avail.isUnconditionallyUnavailable()) {
-Object UnconditionallyUnavailable;
-UnconditionallyUnavailable["domain"] = "*";
-UnconditionallyUnavailable["isUnconditionallyUnavailable"] = true;
-AvailabilityArray.emplace_back(std::move(UnconditionallyUnavailable));
+  Object Availability;
+
+  Availability["domain"] = Avail.Domain;
+
+  if (Avail.isUnavailable()) {
+Availability["isUnconditionallyUnavailable"] = true;
+  } else {
+serializeObject(Availability, "introduced",
+serializeSemanticVersion(Avail.Introduced));
+serializeObject(Availability, "deprecated",
+serializeSemanticVersion(Avail.Deprecated));
+serializeObject(Availability, "obsoleted",
+serializeSemanticVersion(Avail.Obsoleted));
   }
+
   AvailabilityArray.emplace_back(std::move(Availability));
   return AvailabilityArray;
 }

diff  --git a/clang/test/ExtractAPI/availability.c 
b/clang/test/ExtractAPI/availability.c
index 12ac73f0d4295a..237b2ffa55d7dc 100644
--- a/clang/test/ExtractAPI/availability.c
+++ b/clang/test/ExtractAPI/availability.c
@@ -1,446 +1,101 @@
 // RUN: rm -rf %t
-// RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
-// RUN: %t/reference.output.json.in >> %t/reference.output.json
-// RUN: %clang_cc1 -extract-api --pretty-sgf --product-name=Availability 
-triple arm64-apple-macosx -x c-header %t/input.h -o %t/output.json -verify
+// RUN: %clang_cc1 -extract-api --pretty-sgf 
--emit-sgf-symbol-labels-for-testing -triple arm64-apple-macosx \
+// RUN:   -x c-header %s -o %t/output.symbols.json -verify
 
-// Generator version is not consistent across test runs, normalize it.
-// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
-// RUN: %t/output.json >> %t/output-normalized.json
-// RUN: 
diff  %t/reference.output.json %t/output-normalized.json
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix A
+void a(void) __attribute__((availability(macos, introduced=12.0)));
+// A-LABEL: "!testLabel": "c:@F@a"
+// A:  "availability": [
+// A-NEXT:   {
+// A-NEXT: "domain": "macos",
+// A-NEXT: "introduced": {
+// A-NEXT:   "major": 12,
+// A-NEXT:   "minor": 0,
+// A-NEXT:   "patch": 0
+// A-NEXT: }
+// A-NEXT:   }
+// A-NEXT: ]
 
-// CHECK-NOT: error:
-// CHECK-NOT: warning:
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix B
+void b(void) __attribute__((availability(macos, introduced=11.0, 
deprecated=12.0, obsoleted=20.0)));
+// B-LABEL: "!testLabel": "c:@F@b"
+// B:  "availability": [
+// B-NEXT:   {
+// B-NEXT: "deprecated": {
+// B-NEXT:   "major": 12,
+// B-NEXT:   "minor": 0,
+// B-NEXT:   "patch": 0
+// B-NEXT: },
+// B-NEXT: "domain": "macos",
+// B-NEXT: "introduced": {
+// B-NEXT:   "major": 11,
+// B-NEXT:   "minor": 0,
+// B-NEXT:   "patch": 0
+// B-NEXT: },
+// B-NEXT: "obsoleted": {
+// B-NEXT:   "major": 20,
+// B-NEXT:   "minor": 0,
+// B-NEXT:   "patch": 0
+// B-NEXT: }
+// B-NEXT:   }
+// B-NEXT: ]
 
-//--- input.h
-void a(void);
+// RUN: FileCheck %s -

[clang] [clang][ExtractAPI] Serialize platform specific unavailable attribute in symbol graphs (PR #89277)

2024-04-23 Thread Daniel Grumberg via cfe-commits

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


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

2024-04-23 Thread Felix via cfe-commits

orcguru wrote:

> It looks like a few of the regression tests are failing on the 
> reverse-iteration buildbot 
> (https://lab.llvm.org/buildbot/#/builders/54/builds/9683)

Thank you! Posted: https://github.com/llvm/llvm-project/pull/89714

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


[clang] [clang][RISCV] Support RVV bfloat16 C intrinsics (PR #89354)

2024-04-23 Thread Kito Cheng via cfe-commits

https://github.com/kito-cheng approved this pull request.

LGTM

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-23 Thread Haojian Wu via cfe-commits

hokein wrote:

> > > Regarding the __is_deducible type trait, GCC also provides one, but it 
> > > was hidden from users and only used for internal CTAD implementation. I'm 
> > > not sure if we should follow the same strategy in clang, ideas?
> > 
> > 
> > I have mixed feeling. What do you think @AaronBallman ?
> 
> Personally, I do not like exposing type traits that aren't for use with the 
> STL. 

This is a valid argument. This type trait is supposed to be clang-internal only 
and should not be used in other places. The main benefit of exposing it is for 
testing purposes, and I personally found it to be really useful for debugging.

> One idea would be to remove the type trait from TokenKinds.def and instead 
> manually add `BTT_IsDeducible` to:
> 
> https://github.com/llvm/llvm-project/blob/c61f0a8e94004b05d9ec115d3bff8cff331b4491/clang/include/clang/Basic/TypeTraits.h#L21
> 
> along with a comment explaining that this is for internal use only rather 
> than be exposed to users. (You'd have to see if there are other places using 
> `TYPE_TRAIT_2` that might need adjustment as well.) Then we can remove the 
> release note, error checking can become assertions, etc.

This approach is doable technically, but it feels hacky and fragile. What if we 
emit an error (or warning) diagnostic and reject the code when we parse the 
`__is_deducible` type trait?

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-23 Thread Haojian Wu via cfe-commits


@@ -868,13 +868,7 @@ C++20 implementation status
 
   Class template argument deduction for alias templates
   https://wg21.link/p1814r0";>P1814R0
-  
-
-  Clang 19 (Partial)
-  The associated constraints (over.match.class.deduct#3.3) for the
-  synthesized deduction guides are not yet implemented.
-
-  
+  Clang 19 (Partial)

hokein wrote:

With this patch, this feature is completed. However, I suspect that there maybe 
issues, and it needs some time to be productized. Therefore, I hesitate to say 
that it is "ready" (although I'm not sure what the common practice is).

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


[clang] ce763bf - [analyzer] Fix performance of getTaintedSymbolsImpl() (#89606)

2024-04-23 Thread via cfe-commits

Author: NagyDonat
Date: 2024-04-23T10:20:34+02:00
New Revision: ce763bff081f8e97c7c3610ed0f15f14d60e875f

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

LOG: [analyzer] Fix performance of getTaintedSymbolsImpl() (#89606)

Previously the function
```
std::vector taint::getTaintedSymbolsImpl(ProgramStateRef State,
const MemRegion *Reg,
TaintTagType K,
bool returnFirstOnly)
```
(one of the 4 overloaded variants under this name) was handling element
regions in a highly inefficient manner: it performed the "also examine
the super-region" step twice. (Once in the branch for element regions,
and once in the more general branch for all `SubRegion`s -- note that
`ElementRegion` is a subclass of `SubRegion`.)

As pointer arithmetic produces `ElementRegion`s, it's not too difficult
to get a chain of N nested element regions where this inefficient
recursion would produce 2^N calls.

This commit is essentially NFC, apart from the performance improvements
and the removal of (probably irrelevant) duplicate entries from the
return value of `getTaintedSymbols()` calls.

Fixes #89045

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/Taint.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp 
b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
index 4edb671753bf45..6362c82b009d72 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
@@ -216,21 +216,17 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   std::vector TaintedSymbols;
   if (!Reg)
 return TaintedSymbols;
-  // Element region (array element) is tainted if either the base or the offset
-  // are tainted.
+
+  // Element region (array element) is tainted if the offset is tainted.
   if (const ElementRegion *ER = dyn_cast(Reg)) {
 std::vector TaintedIndex =
 getTaintedSymbolsImpl(State, ER->getIndex(), K, returnFirstOnly);
 llvm::append_range(TaintedSymbols, TaintedIndex);
 if (returnFirstOnly && !TaintedSymbols.empty())
   return TaintedSymbols; // return early if needed
-std::vector TaintedSuperRegion =
-getTaintedSymbolsImpl(State, ER->getSuperRegion(), K, returnFirstOnly);
-llvm::append_range(TaintedSymbols, TaintedSuperRegion);
-if (returnFirstOnly && !TaintedSymbols.empty())
-  return TaintedSymbols; // return early if needed
   }
 
+  // Symbolic region is tainted if the corresponding symbol is tainted.
   if (const SymbolicRegion *SR = dyn_cast(Reg)) {
 std::vector TaintedRegions =
 getTaintedSymbolsImpl(State, SR->getSymbol(), K, returnFirstOnly);
@@ -239,6 +235,8 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   return TaintedSymbols; // return early if needed
   }
 
+  // Any subregion (including Element and Symbolic regions) is tainted if its
+  // super-region is tainted.
   if (const SubRegion *ER = dyn_cast(Reg)) {
 std::vector TaintedSubRegions =
 getTaintedSymbolsImpl(State, ER->getSuperRegion(), K, returnFirstOnly);
@@ -318,4 +316,4 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
 }
   }
   return TaintedSymbols;
-}
\ No newline at end of file
+}



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


[clang] [analyzer] Fix performance of getTaintedSymbolsImpl() (PR #89606)

2024-04-23 Thread via cfe-commits

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


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread Sander de Smalen via cfe-commits


@@ -1149,6 +1149,13 @@ std::string Triple::normalize(StringRef Str) {
 }
   }
 
+  // For 3-component triples, the middle component is used to set Vendor;
+  // while if it is "none", we'd prefer to set OS.
+  // This is for some baremetal cases, such as "arm-none-elf".
+  if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
+  Components[1].equals("none") && Components[2].empty())
+std::swap(Components[1], Components[2]);

sdesmalen-arm wrote:

This change, along with the change in libcxx/utils/ci/run-buildbot, look like 
the only functional changes in this patch. Is it worth committing the 
non-functional changes (i.e. most of the tests) in a separate NFC patch?

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-23 Thread via cfe-commits

cor3ntin wrote:

> This approach is doable technically, but it feels hacky and fragile. What if 
> we emit an error (or warning) diagnostic and reject the code when we parse 
> the __is_deducible type trait?

Why do you think it is fragile? I think a comment around `BTT_IsDeducible` 
would take care of that

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-23 Thread via cfe-commits


@@ -868,13 +868,7 @@ C++20 implementation status
 
   Class template argument deduction for alias templates
   https://wg21.link/p1814r0";>P1814R0
-  
-
-  Clang 19 (Partial)
-  The associated constraints (over.match.class.deduct#3.3) for the
-  synthesized deduction guides are not yet implemented.
-
-  
+  Clang 19 (Partial)

cor3ntin wrote:

Can you add back a details saying that the feature macro has not been updated?
However, i suspect that we do want to finalize the feature for Clang 19.

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


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread Peter Waller via cfe-commits

peterwaller-arm wrote:

I have tested building a toolchain using `aarch64-none-elf`, and the problems 
described in my comment on 
https://github.com/llvm/llvm-project/pull/89234#issuecomment-2069019606 are 
resolved. The only change I had to make was to update some references to 
`aarch64-none-elf` to reference `aarch64-unknown-none-elf`, reflecting the 
change in compiler-rt install paths introduced in #89234.

I concur with Sander that it seems prudent to have the functional change in its 
own commit, in case it requires further revert flip-flop.

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


[clang] b8e3b2a - [NFC] [Serialization] Turn type alias LocalDeclID into class

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

Author: Chuanqi Xu
Date: 2024-04-23T16:56:14+08:00
New Revision: b8e3b2ad66cf78ad2b7832577b1d58dc93c5da21

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

LOG: [NFC] [Serialization] Turn type alias LocalDeclID into class

Previously, the LocalDeclID and GlobalDeclID are defined as:

```
using LocalDeclID = DeclID;
using GlobalDeclID = DeclID;
```

This is more or less concerning that we may misuse LocalDeclID and
GlobalDeclID without understanding it. There is also a FIXME saying
this.

This patch tries to turn LocalDeclID into a class to improve the type
safety here.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index c91a1c1c82edd4..ca51a2dff3d57b 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -69,9 +69,18 @@ using IdentifierID = uint32_t;
 /// FIXME: Merge with Decl::DeclID
 using DeclID = uint32_t;
 
-// FIXME: Turn these into classes so we can have some type safety when
+class LocalDeclID {
+public:
+  explicit LocalDeclID(DeclID ID) : ID(ID) {}
+
+  DeclID get() const { return ID; }
+
+private:
+  DeclID ID;
+};
+
+// FIXME: Turn GlobalDeclID into class so we can have some type safety when
 // we go from local ID to global and vice-versa.
-using LocalDeclID = DeclID;
 using GlobalDeclID = DeclID;
 
 /// An ID number that refers to a type in an AST file.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index fe9644eaca4916..42aecf059907e8 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1924,7 +1924,7 @@ class ASTReader
   Decl *GetExistingDecl(serialization::DeclID ID);
 
   /// Reads a declaration with the given local ID in the given module.
-  Decl *GetLocalDecl(ModuleFile &F, serialization::DeclID LocalID) {
+  Decl *GetLocalDecl(ModuleFile &F, serialization::LocalDeclID LocalID) {
 return GetDecl(getGlobalDeclID(F, LocalID));
   }
 
@@ -1932,7 +1932,7 @@ class ASTReader
   ///
   /// \returns The requested declaration, casted to the given return type.
   template 
-  T *GetLocalDeclAs(ModuleFile &F, serialization::DeclID LocalID) {
+  T *GetLocalDeclAs(ModuleFile &F, serialization::LocalDeclID LocalID) {
 return cast_or_null(GetLocalDecl(F, LocalID));
   }
 

diff  --git a/clang/include/clang/Serialization/ModuleFile.h 
b/clang/include/clang/Serialization/ModuleFile.h
index 675e1e9bc355c5..492c35dceb08d4 100644
--- a/clang/include/clang/Serialization/ModuleFile.h
+++ b/clang/include/clang/Serialization/ModuleFile.h
@@ -474,7 +474,7 @@ class ModuleFile {
   llvm::DenseMap GlobalToLocalDeclIDs;
 
   /// Array of file-level DeclIDs sorted by file.
-  const serialization::DeclID *FileSortedDecls = nullptr;
+  const serialization::LocalDeclID *FileSortedDecls = nullptr;
   unsigned NumFileSortedDecls = 0;
 
   /// Array of category list location information within this

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 9764fdc6cd2d49..cfb6ab42c36bd7 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -954,14 +954,16 @@ ASTSelectorLookupTrait::ReadData(Selector, const unsigned 
char* d,
   // Load instance methods
   for (unsigned I = 0; I != NumInstanceMethods; ++I) {
 if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs(
-F, endian::readNext(d)))
+F,
+LocalDeclID(endian::readNext(d
   Result.Instance.push_back(Method);
   }
 
   // Load factory methods
   for (unsigned I = 0; I != NumFactoryMethods; ++I) {
 if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs(
-F, endian::readNext(d)))
+F,
+LocalDeclID(endian::readNext(d
   Result.Factory.push_back(Method);
   }
 
@@ -1091,7 +1093,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const 
internal_key_type& k,
 SmallVector DeclIDs;
 for (; DataLen > 0; DataLen -= sizeof(DeclID))
   DeclIDs.push_back(Reader.getGlobalDeclID(
-  F, endian::readNext(d)));
+  F,
+  LocalDeclID(endian::readNext(d;
 Reader.SetGloballyVisibleDecls(II, DeclIDs);
   }
 
@@ -1212,7 +1215,7 @@ void 
ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type,
   using namespace llvm::support;
 
   for (unsigned NumDecls = DataLen / siz

[clang] [clang] pointer to member with qualified-id closed in parantheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread via cfe-commits

cor3ntin wrote:

I should note that while i think this is correct per the standard, no one seems 
to be conforming here

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


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread David Spickett via cfe-commits

DavidSpickett wrote:

> Ohh, there is so many -none-unknown- in current code. I guess it may be 
> widely used. Do we really want to change all of them?

In current test cases, which were likely generated using clang. So they are 
likely not relying on that exact form of the triple, it's just what clang put 
out at the time. So they don't prove anything either way, unless they fail 
after this change of course.

Thank you Peter for testing this PR, I've also asked another downstream team to 
test their bare metal builds with this. That'll be our best indication for now 
if this makes sense.

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


[clang] [clang] pointer to member with qualified-id closed in parantheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread via cfe-commits


@@ -27,3 +26,20 @@ namespace rdar10544564 {
   X (Y::*func_mem_ptr1)() = &Y::memfunc1;
   X (Y::*func_mem_ptr2)() = &Y::memfunc2;
 }
+
+namespace test2 {
+  struct A {
+int val;
+void func() {}
+  };
+
+  void test() {
+decltype(&(A::val)) ptr1; // expected-error {{invalid use of non-static 
data member 'val'}}
+int A::* ptr2 = &(A::val); // expected-error {{invalid use of non-static 
data member 'val'}}
+
+// FIXME: Error messages in these cases are less than clear, we can do
+// better.
+int size = sizeof(&(A::func)); // expected-error {{call to non-static 
member function without an object argument}}
+void (A::* ptr3)() = &(A::func); // expected-error {{call to non-static 
member function without an object argument}}

cor3ntin wrote:

I would expect `err_invalid_non_static_member_use` to be used there too (or 
rather, that case should be consistent with above)

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


[clang] [clang] pointer to member with qualified-id closed in parantheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread via cfe-commits


@@ -14644,6 +14644,17 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
 return QualType();
   }
 
+  // C++11 [expr.unary.op] p4:
+  // A pointer to member is only formed when an explicit & is used and
+  // its operand is a qualified-id not enclosed in parentheses.
+  if (isa(OrigOp.get())) {
+// `op->getEndLoc()` is the last part of the qualified-id.
+// For example, "baz" in "foo::bar::baz".
+Diag(op->getEndLoc(), diag::err_invalid_non_static_member_use)
+<< dcl->getDeclName() << op->getSourceRange();

cor3ntin wrote:

Maybe we could have a more specific error, like "cannot form a pointer to 
member from a parenthesized expression" ?
I would expect the error to point to the opening paren (`OrigOp->getBeginLoc()` 
presumably)

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


[clang] [clang] pointer to member with qualified-id closed in parantheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread via cfe-commits


@@ -14644,6 +14644,17 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
 return QualType();
   }
 
+  // C++11 [expr.unary.op] p4:
+  // A pointer to member is only formed when an explicit & is used and
+  // its operand is a qualified-id not enclosed in parentheses.
+  if (isa(OrigOp.get())) {
+// `op->getEndLoc()` is the last part of the qualified-id.
+// For example, "baz" in "foo::bar::baz".
+Diag(op->getEndLoc(), diag::err_invalid_non_static_member_use)
+<< dcl->getDeclName() << op->getSourceRange();
+return QualType();

cor3ntin wrote:

Continuing might lead to better error recovery here

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


[clang] [clang] pointer to member with qualified-id closed in parantheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread via cfe-commits


@@ -27,3 +26,20 @@ namespace rdar10544564 {
   X (Y::*func_mem_ptr1)() = &Y::memfunc1;
   X (Y::*func_mem_ptr2)() = &Y::memfunc2;
 }
+
+namespace test2 {

cor3ntin wrote:

```suggestion
namespace GH40906 {
```

The test should probably be moved to 
clang/test/CXX/expr/expr.unary/expr.unary.op/p4.cpp

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


[clang] fast math test overhaul (PR #89687)

2024-04-23 Thread Matt Arsenault via cfe-commits

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

I think this works for the test. I'm slightly confused by the PR not-stacking 
with the test changes on top of the other PR 

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


[clang] [clang][modules] Only modulemaps of included textual headers are affecting (PR #89729)

2024-04-23 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall created 
https://github.com/llvm/llvm-project/pull/89729

Prior to this change, modulemaps describing textual headers are considered
to affect the current module whenever HeaderFileInfos for those headers exist.

This wastes creates false dependencies that (among other things) waste
SourceLocation space.

After this change, textual headers don't cause their modulemap to be considered
affecting, unless those textual headers are included (in which case their
modulemap is required e.g. for layering check).


>From 9165d6086e2570198fba1c333d0c9cb9c09037c7 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 19 Apr 2024 12:13:06 -0700
Subject: [PATCH 1/2] [clang][modules] Allow module map files with textual
 header be non-affecting

---
 clang/lib/Serialization/ASTWriter.cpp | 10 ---
 ...e-non-affecting-module-map-files-textual.c | 26 +++
 2 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/Modules/prune-non-affecting-module-map-files-textual.c

diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 8a4b36207c4734..4825c245a4b846 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -187,7 +187,8 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module 
*RootModule) {
   continue;
 
 const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
-if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+if (!HFI || ((HFI->isModuleHeader || HFI->isTextualModuleHeader) &&
+ !HFI->isCompilingModuleHeader))
   continue;
 
 for (const auto &KH : HS.findResolvedModulesForHeader(*File)) {
@@ -2055,11 +2056,12 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch 
&HS) {
 
 // Get the file info. Skip emitting this file if we have no information on
 // it as a header file (in which case HFI will be null) or if it hasn't
-// changed since it was loaded. Also skip it if it's for a modular header
-// from a different module; in that case, we rely on the module(s)
+// changed since it was loaded. Also skip it if it's for a non-excluded
+// header from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
 const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
-if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+if (!HFI || ((HFI->isModuleHeader || HFI->isTextualModuleHeader) &&
+ !HFI->isCompilingModuleHeader))
   continue;
 
 // Massage the file path into an appropriate form.
diff --git a/clang/test/Modules/prune-non-affecting-module-map-files-textual.c 
b/clang/test/Modules/prune-non-affecting-module-map-files-textual.c
new file mode 100644
index 00..8f8f00560b1834
--- /dev/null
+++ b/clang/test/Modules/prune-non-affecting-module-map-files-textual.c
@@ -0,0 +1,26 @@
+// This test checks that a module map with a textual header can be marked as
+// non-affecting.
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- A.modulemap
+module A { textual header "A.h" }
+//--- B.modulemap
+module B { header "B.h" export * }
+//--- A.h
+typedef int A_int;
+//--- B.h
+#include "A.h"
+typedef A_int B_int;
+
+// RUN: %clang_cc1 -fmodules -emit-module %t/A.modulemap -fmodule-name=A -o 
%t/A.pcm \
+// RUN:   -fmodule-map-file=%t/A.modulemap -fmodule-map-file=%t/B.modulemap
+
+// RUN: %clang_cc1 -fmodules -emit-module %t/B.modulemap -fmodule-name=B -o 
%t/B0.pcm \
+// RUN:   -fmodule-map-file=%t/A.modulemap -fmodule-map-file=%t/B.modulemap 
-fmodule-file=%t/A.pcm
+
+// RUN: %clang_cc1 -fmodules -emit-module %t/B.modulemap -fmodule-name=B -o 
%t/B1.pcm \
+// RUN:-fmodule-map-file=%t/B.modulemap 
-fmodule-file=%t/A.pcm
+
+// RUN: diff %t/B0.pcm %t/B1.pcm

>From 0bf2b1583b9b4f5fdbee2e690d075f1b41905532 Mon Sep 17 00:00:00 2001
From: Sam McCall 
Date: Tue, 23 Apr 2024 11:04:32 +0200
Subject: [PATCH 2/2] Track textually included files, and consider their
 modulemaps affecting.

Those modulemaps affect the legality of the inclusions and therefore
the module's compilation.
---
 clang/include/clang/Lex/HeaderSearch.h|  4 ++
 clang/lib/Lex/HeaderSearch.cpp|  4 ++
 clang/lib/Lex/PPDirectives.cpp|  1 +
 ...e-non-affecting-module-map-files-textual.c | 47 ++-
 4 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index c5f90ef4cb3682..c24ef15005f36b 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -544,6 +544,10 @@ class HeaderSearch {
   bool isImport, bool ModulesEnabled, Module *M,
   bool &IsFirstIncludeOfFile);
 
+  /// Record that we're parsing this file as pa

[clang] [clang][modules] Only modulemaps of included textual headers are affecting (PR #89729)

2024-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sam McCall (sam-mccall)


Changes

Prior to this change, modulemaps describing textual headers are considered
to affect the current module whenever HeaderFileInfos for those headers exist.

This wastes creates false dependencies that (among other things) waste
SourceLocation space.

After this change, textual headers don't cause their modulemap to be considered
affecting, unless those textual headers are included (in which case their
modulemap is required e.g. for layering check).


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


5 Files Affected:

- (modified) clang/include/clang/Lex/HeaderSearch.h (+4) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (+4) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+6-4) 
- (added) clang/test/Modules/prune-non-affecting-module-map-files-textual.c 
(+47) 


``diff
diff --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index c5f90ef4cb3682..c24ef15005f36b 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -544,6 +544,10 @@ class HeaderSearch {
   bool isImport, bool ModulesEnabled, Module *M,
   bool &IsFirstIncludeOfFile);
 
+  /// Record that we're parsing this file as part of the current module, if 
any.
+  /// The header's owning modulemap is considered to affect the current module.
+  void EnteredTextualFile(FileEntryRef File);
+
   /// Return whether the specified file is a normal header,
   /// a system header, or a C++ friendly system header.
   SrcMgr::CharacteristicKind getFileDirFlavor(FileEntryRef File) {
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 0632882b296146..84c7e09638d574 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1441,6 +1441,10 @@ void HeaderSearch::MarkFileModuleHeader(FileEntryRef FE,
   HFI.isCompilingModuleHeader |= isCompilingModuleHeader;
 }
 
+void HeaderSearch::EnteredTextualFile(FileEntryRef File) {
+  getFileInfo(File).isCompilingModuleHeader = true;
+}
+
 bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
   FileEntryRef File, bool isImport,
   bool ModulesEnabled, Module *M,
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 0b22139ebe81de..196c7795ca05e8 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2609,6 +2609,7 @@ Preprocessor::ImportAction 
Preprocessor::HandleHeaderIncludeOrImport(
   }
 
   assert(!IsImportDecl && "failed to diagnose missing module for import decl");
+  HeaderInfo.EnteredTextualFile(*File);
   return {ImportAction::None};
 }
 
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 8a4b36207c4734..4825c245a4b846 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -187,7 +187,8 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module 
*RootModule) {
   continue;
 
 const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
-if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+if (!HFI || ((HFI->isModuleHeader || HFI->isTextualModuleHeader) &&
+ !HFI->isCompilingModuleHeader))
   continue;
 
 for (const auto &KH : HS.findResolvedModulesForHeader(*File)) {
@@ -2055,11 +2056,12 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch 
&HS) {
 
 // Get the file info. Skip emitting this file if we have no information on
 // it as a header file (in which case HFI will be null) or if it hasn't
-// changed since it was loaded. Also skip it if it's for a modular header
-// from a different module; in that case, we rely on the module(s)
+// changed since it was loaded. Also skip it if it's for a non-excluded
+// header from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
 const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
-if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+if (!HFI || ((HFI->isModuleHeader || HFI->isTextualModuleHeader) &&
+ !HFI->isCompilingModuleHeader))
   continue;
 
 // Massage the file path into an appropriate form.
diff --git a/clang/test/Modules/prune-non-affecting-module-map-files-textual.c 
b/clang/test/Modules/prune-non-affecting-module-map-files-textual.c
new file mode 100644
index 00..12a42c52a940b9
--- /dev/null
+++ b/clang/test/Modules/prune-non-affecting-module-map-files-textual.c
@@ -0,0 +1,47 @@
+// This test checks that a module map with a textual header can be marked as
+// non-affecting.
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- X.mod

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-23 Thread Francesco Petrogalli via cfe-commits

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


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


[clang] [clang] cororoutine: generate valid mangled name in CodeGenFunction::generateAwaitSuspendWrapper (PR #89731)

2024-04-23 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/89731

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

>From 6d292f1d3bddb5a52ca63babd4bb785266277674 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 23 Apr 2024 11:48:12 +0200
Subject: [PATCH] [clang] cororoutine: generate valid mangled name in
 CodeGenFunction::generateAwaitSuspendWrapper

Fixes https://github.com/llvm/llvm-project/issues/89723
---
 clang/lib/CodeGen/CGCoroutine.cpp   |  6 ++
 clang/test/CodeGenCoroutines/coro-await.cpp | 12 ++--
 clang/test/CodeGenCoroutines/coro-dwarf.cpp |  4 ++--
 clang/test/CodeGenCoroutines/pr65054.cpp|  2 +-
 4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..567e85a02dc612 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -413,10 +413,8 @@ llvm::Function *
 CodeGenFunction::generateAwaitSuspendWrapper(Twine const &CoroName,
  Twine const &SuspendPointName,
  CoroutineSuspendExpr const &S) {
-  std::string FuncName = "__await_suspend_wrapper_";
-  FuncName += CoroName.str();
-  FuncName += '_';
-  FuncName += SuspendPointName.str();
+  std::string FuncName =
+  (CoroName + ".__await_suspend_wrapper__" + SuspendPointName).str();
 
   ASTContext &C = getContext();
 
diff --git a/clang/test/CodeGenCoroutines/coro-await.cpp 
b/clang/test/CodeGenCoroutines/coro-await.cpp
index 75851d8805bb6e..65bfb099468817 100644
--- a/clang/test/CodeGenCoroutines/coro-await.cpp
+++ b/clang/test/CodeGenCoroutines/coro-await.cpp
@@ -73,7 +73,7 @@ extern "C" void f0() {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: call void @llvm.coro.await.suspend.void(ptr %[[AWAITABLE]], 
ptr %[[FRAME]], ptr @__await_suspend_wrapper_f0_await)
+  // CHECK-NEXT: call void @llvm.coro.await.suspend.void(ptr %[[AWAITABLE]], 
ptr %[[FRAME]], ptr @f0.__await_suspend_wrapper__await)
   // -
   // Generate a suspend point:
   // -
@@ -100,7 +100,7 @@ extern "C" void f0() {
   // CHECK: call i8 @llvm.coro.suspend(token %[[FINALSP_ID]], i1 true)
 
   // Await suspend wrapper
-  // CHECK: define{{.*}} @__await_suspend_wrapper_f0_await(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
+  // CHECK: define{{.*}} @f0.__await_suspend_wrapper__await(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
   // CHECK: store ptr %[[AWAITABLE_ARG]], ptr %[[AWAITABLE_TMP:.+]],
   // CHECK: store ptr %[[FRAME_ARG]], ptr %[[FRAME_TMP:.+]],
   // CHECK: %[[AWAITABLE:.+]] = load ptr, ptr %[[AWAITABLE_TMP]]
@@ -149,7 +149,7 @@ extern "C" void f1(int) {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: %[[YES:.+]] = call i1 @llvm.coro.await.suspend.bool(ptr 
%[[AWAITABLE]], ptr %[[FRAME]], ptr @__await_suspend_wrapper_f1_yield)
+  // CHECK-NEXT: %[[YES:.+]] = call i1 @llvm.coro.await.suspend.bool(ptr 
%[[AWAITABLE]], ptr %[[FRAME]], ptr @f1.__await_suspend_wrapper__yield)
   // ---
   // See if await_suspend decided not to suspend
   // ---
@@ -162,7 +162,7 @@ extern "C" void f1(int) {
   // CHECK: call void @_ZN13suspend_maybe12await_resumeEv(ptr {{[^,]*}} 
%[[AWAITABLE]])
 
   // Await suspend wrapper
-  // CHECK: define {{.*}} i1 @__await_suspend_wrapper_f1_yield(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
+  // CHECK: define {{.*}} i1 @f1.__await_suspend_wrapper__yield(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
   // CHECK: store ptr %[[AWAITABLE_ARG]], ptr %[[AWAITABLE_TMP:.+]],
   // CHECK: store ptr %[[FRAME_ARG]], ptr %[[FRAME_TMP:.+]],
   // CHECK: %[[AWAITABLE:.+]] = load ptr, ptr %[[AWAITABLE_TMP]]
@@ -370,7 +370,7 @@ extern "C" void TestTailcall() {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: %[[RESUMED:.+]] = call ptr 
@llvm.coro.await.suspend.handle(ptr %[[AWAITABLE]], ptr %[[FRAME]], ptr 
@__await_suspend_wrapper_TestTailcall_await)
+  // CHECK-NEXT: %[[RESUMED:.+]] = call ptr 
@llvm.coro.await.suspend.handle(ptr %[[AWAITABLE]], ptr %[[FRAME]], ptr 
@TestTailcall.__await_suspend_wrapper__await)
   // CHECK-NEXT: call void @llvm.coro.resume(ptr %[[RESUMED]])
   // CHECK-NEXT: %[[OUTCOME:.+]] = call i8 @llvm.coro.suspend(token 
%[[SUSPEND_ID]], i1 false)
   // CHECK-NEXT: switch i8 %[[OUTCOME]], label %[[RET_BB:.+]] [
@@ -379,7 +379,7 @@ extern "C" void TestTailcall() {
   // CHECK-NEXT: ]
 
   // Await suspend wrapper
-  // CHECK: define {{.*}} ptr @__await_suspend_wrapper_TestTailcall_await(ptr 
{{[^,]*}} %[[AWAITABLE_ARG:.+]], ptr {{[^,]*}}

[clang] [clang] coroutine: generate valid mangled name in CodeGenFunction::generateAwaitSuspendWrapper (PR #89731)

2024-04-23 Thread Haojian Wu via cfe-commits

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


[clang] [clang] coroutine: generate valid mangled name in CodeGenFunction::generateAwaitSuspendWrapper (PR #89731)

2024-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

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

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


4 Files Affected:

- (modified) clang/lib/CodeGen/CGCoroutine.cpp (+2-4) 
- (modified) clang/test/CodeGenCoroutines/coro-await.cpp (+6-6) 
- (modified) clang/test/CodeGenCoroutines/coro-dwarf.cpp (+2-2) 
- (modified) clang/test/CodeGenCoroutines/pr65054.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..567e85a02dc612 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -413,10 +413,8 @@ llvm::Function *
 CodeGenFunction::generateAwaitSuspendWrapper(Twine const &CoroName,
  Twine const &SuspendPointName,
  CoroutineSuspendExpr const &S) {
-  std::string FuncName = "__await_suspend_wrapper_";
-  FuncName += CoroName.str();
-  FuncName += '_';
-  FuncName += SuspendPointName.str();
+  std::string FuncName =
+  (CoroName + ".__await_suspend_wrapper__" + SuspendPointName).str();
 
   ASTContext &C = getContext();
 
diff --git a/clang/test/CodeGenCoroutines/coro-await.cpp 
b/clang/test/CodeGenCoroutines/coro-await.cpp
index 75851d8805bb6e..65bfb099468817 100644
--- a/clang/test/CodeGenCoroutines/coro-await.cpp
+++ b/clang/test/CodeGenCoroutines/coro-await.cpp
@@ -73,7 +73,7 @@ extern "C" void f0() {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: call void @llvm.coro.await.suspend.void(ptr %[[AWAITABLE]], 
ptr %[[FRAME]], ptr @__await_suspend_wrapper_f0_await)
+  // CHECK-NEXT: call void @llvm.coro.await.suspend.void(ptr %[[AWAITABLE]], 
ptr %[[FRAME]], ptr @f0.__await_suspend_wrapper__await)
   // -
   // Generate a suspend point:
   // -
@@ -100,7 +100,7 @@ extern "C" void f0() {
   // CHECK: call i8 @llvm.coro.suspend(token %[[FINALSP_ID]], i1 true)
 
   // Await suspend wrapper
-  // CHECK: define{{.*}} @__await_suspend_wrapper_f0_await(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
+  // CHECK: define{{.*}} @f0.__await_suspend_wrapper__await(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
   // CHECK: store ptr %[[AWAITABLE_ARG]], ptr %[[AWAITABLE_TMP:.+]],
   // CHECK: store ptr %[[FRAME_ARG]], ptr %[[FRAME_TMP:.+]],
   // CHECK: %[[AWAITABLE:.+]] = load ptr, ptr %[[AWAITABLE_TMP]]
@@ -149,7 +149,7 @@ extern "C" void f1(int) {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: %[[YES:.+]] = call i1 @llvm.coro.await.suspend.bool(ptr 
%[[AWAITABLE]], ptr %[[FRAME]], ptr @__await_suspend_wrapper_f1_yield)
+  // CHECK-NEXT: %[[YES:.+]] = call i1 @llvm.coro.await.suspend.bool(ptr 
%[[AWAITABLE]], ptr %[[FRAME]], ptr @f1.__await_suspend_wrapper__yield)
   // ---
   // See if await_suspend decided not to suspend
   // ---
@@ -162,7 +162,7 @@ extern "C" void f1(int) {
   // CHECK: call void @_ZN13suspend_maybe12await_resumeEv(ptr {{[^,]*}} 
%[[AWAITABLE]])
 
   // Await suspend wrapper
-  // CHECK: define {{.*}} i1 @__await_suspend_wrapper_f1_yield(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
+  // CHECK: define {{.*}} i1 @f1.__await_suspend_wrapper__yield(ptr {{[^,]*}} 
%[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
   // CHECK: store ptr %[[AWAITABLE_ARG]], ptr %[[AWAITABLE_TMP:.+]],
   // CHECK: store ptr %[[FRAME_ARG]], ptr %[[FRAME_TMP:.+]],
   // CHECK: %[[AWAITABLE:.+]] = load ptr, ptr %[[AWAITABLE_TMP]]
@@ -370,7 +370,7 @@ extern "C" void TestTailcall() {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: %[[RESUMED:.+]] = call ptr 
@llvm.coro.await.suspend.handle(ptr %[[AWAITABLE]], ptr %[[FRAME]], ptr 
@__await_suspend_wrapper_TestTailcall_await)
+  // CHECK-NEXT: %[[RESUMED:.+]] = call ptr 
@llvm.coro.await.suspend.handle(ptr %[[AWAITABLE]], ptr %[[FRAME]], ptr 
@TestTailcall.__await_suspend_wrapper__await)
   // CHECK-NEXT: call void @llvm.coro.resume(ptr %[[RESUMED]])
   // CHECK-NEXT: %[[OUTCOME:.+]] = call i8 @llvm.coro.suspend(token 
%[[SUSPEND_ID]], i1 false)
   // CHECK-NEXT: switch i8 %[[OUTCOME]], label %[[RET_BB:.+]] [
@@ -379,7 +379,7 @@ extern "C" void TestTailcall() {
   // CHECK-NEXT: ]
 
   // Await suspend wrapper
-  // CHECK: define {{.*}} ptr @__await_suspend_wrapper_TestTailcall_await(ptr 
{{[^,]*}} %[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
+  // CHECK: define {{.*}} ptr @TestTailcall.__await_suspend_wrapper__await(ptr 
{{[^,]*}} %[[AWAITABLE_ARG:.+]], ptr {{[^,]*}} %[[FRAME_ARG:.+]])
   // CHECK: store ptr %[[AWAITABLE_ARG]], ptr %[[AWAITABLE_TMP

[clang] b467c6b - [NFC] [Serialization] Turn type alias GlobalDeclID into a class

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

Author: Chuanqi Xu
Date: 2024-04-23T17:52:58+08:00
New Revision: b467c6b53660dcaa458c2b5d7fbf5f93ee2af910

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

LOG: [NFC] [Serialization] Turn type alias GlobalDeclID into a class

Succsessor of b8e3b2ad66cf78ad2b. This patch also converts the type
alias GlobalDeclID to a class to improve the readability and type
safety.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTRecordReader.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTReaderInternals.h
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index ca51a2dff3d57b..dcfa4ac0c19677 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -79,9 +79,71 @@ class LocalDeclID {
   DeclID ID;
 };
 
-// FIXME: Turn GlobalDeclID into class so we can have some type safety when
-// we go from local ID to global and vice-versa.
-using GlobalDeclID = DeclID;
+/// Wrapper class for DeclID. This is helpful to not mix the use of LocalDeclID
+/// and GlobalDeclID to improve the type safety.
+class GlobalDeclID {
+public:
+  GlobalDeclID() : ID(0) {}
+  explicit GlobalDeclID(DeclID ID) : ID(ID) {}
+
+  DeclID get() const { return ID; }
+
+  explicit operator DeclID() const { return ID; }
+
+  friend bool operator==(const GlobalDeclID &LHS, const GlobalDeclID &RHS) {
+return LHS.ID == RHS.ID;
+  }
+  friend bool operator!=(const GlobalDeclID &LHS, const GlobalDeclID &RHS) {
+return LHS.ID != RHS.ID;
+  }
+  // We may sort the global decl ID.
+  friend bool operator<(const GlobalDeclID &LHS, const GlobalDeclID &RHS) {
+return LHS.ID < RHS.ID;
+  }
+  friend bool operator>(const GlobalDeclID &LHS, const GlobalDeclID &RHS) {
+return LHS.ID > RHS.ID;
+  }
+  friend bool operator<=(const GlobalDeclID &LHS, const GlobalDeclID &RHS) {
+return LHS.ID <= RHS.ID;
+  }
+  friend bool operator>=(const GlobalDeclID &LHS, const GlobalDeclID &RHS) {
+return LHS.ID >= RHS.ID;
+  }
+
+private:
+  DeclID ID;
+};
+
+/// A helper iterator adaptor to convert the iterators to `SmallVector`
+/// to the iterators to `SmallVector`.
+class GlobalDeclIDIterator
+: public llvm::iterator_adaptor_base {
+public:
+  GlobalDeclIDIterator() : iterator_adaptor_base(nullptr) {}
+
+  GlobalDeclIDIterator(const DeclID *ID) : iterator_adaptor_base(ID) {}
+
+  value_type operator*() const { return GlobalDeclID(*I); }
+
+  bool operator==(const GlobalDeclIDIterator &RHS) const { return I == RHS.I; }
+};
+
+/// A helper iterator adaptor to convert the iterators to
+/// `SmallVector` to the iterators to `SmallVector`.
+class DeclIDIterator
+: public llvm::iterator_adaptor_base {
+public:
+  DeclIDIterator() : iterator_adaptor_base(nullptr) {}
+
+  DeclIDIterator(const GlobalDeclID *ID) : iterator_adaptor_base(ID) {}
+
+  value_type operator*() const { return DeclID(*I); }
+
+  bool operator==(const DeclIDIterator &RHS) const { return I == RHS.I; }
+};
 
 /// An ID number that refers to a type in an AST file.
 ///
@@ -2169,6 +2231,27 @@ template <> struct 
DenseMapInfo {
   }
 };
 
+template <> struct DenseMapInfo {
+  using DeclID = clang::serialization::DeclID;
+  using GlobalDeclID = clang::serialization::GlobalDeclID;
+
+  static GlobalDeclID getEmptyKey() {
+return GlobalDeclID(DenseMapInfo::getEmptyKey());
+  }
+
+  static GlobalDeclID getTombstoneKey() {
+return GlobalDeclID(DenseMapInfo::getTombstoneKey());
+  }
+
+  static unsigned getHashValue(const GlobalDeclID &Key) {
+return DenseMapInfo::getHashValue(Key.get());
+  }
+
+  static bool isEqual(const GlobalDeclID &L, const GlobalDeclID &R) {
+return L == R;
+  }
+};
+
 } // namespace llvm
 
 #endif // LLVM_CLANG_SERIALIZATION_ASTBITCODES_H

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 42aecf059907e8..ed917aa1642293 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -504,7 +504,7 @@ class ASTReader
   static_assert(std::is_same_v);
 
   using GlobalDeclMapType =
-  ContinuousRangeMap;
+  ContinuousRangeMap;
 
   /// Mapping from global declaration IDs to the module in which the
   /// declaration resides.
@@ -513,14 +513,14 @@ class ASTReader
   using FileOffset = std::pair;
   using FileOffsetsTy = SmallVector;
   using DeclUpdateOffsetsMap =
-  llvm::DenseMap;
+  llvm::DenseMap;
 
   /// Declarations that have modifications resid

[clang] [clang] coroutine: generate valid mangled name in CodeGenFunction::generateAwaitSuspendWrapper (PR #89731)

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

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

LGTM. Thanks.

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


[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-23 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/89497

>From 91915f68902ade86c0bf8eba643428017ae8bb3c Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 20 Apr 2024 17:58:19 +0800
Subject: [PATCH 1/6] [tidy] add new check
 bugprone-return-const-ref-from-parameter

Detects the function which returns the const reference from parameter which
causes potential use after free if the caller uses xvalue as argument.
In c++, const reference parameter can accept xvalue which will be destructed
after the call. When the function returns this parameter also as const 
reference,
then the returned reference can be used after the object it refers to has been
destroyed.
Fixes: #85253
---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../ReturnConstRefFromParameterCheck.cpp  | 41 +++
 .../ReturnConstRefFromParameterCheck.h| 35 
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +++
 .../return-const-ref-from-parameter.rst   | 30 ++
 .../docs/clang-tidy/checks/list.rst   |  9 ++--
 .../return-const-ref-from-parameter.cpp   | 31 ++
 8 files changed, 152 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 2931325d8b5798..1b92d2e60cc173 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -54,6 +54,7 @@
 #include "PosixReturnCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
+#include "ReturnConstRefFromParameterCheck.h"
 #include "SharedPtrArrayMismatchCheck.h"
 #include "SignalHandlerCheck.h"
 #include "SignedCharMisuseCheck.h"
@@ -137,6 +138,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 081ba67efe1538..2d303191f88650 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
new file mode 100644
index 00..87fc663231496e
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -0,0 +1,41 @@
+//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReturnConstRefFromParameterCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+std::optional
+ReturnConstRefFromParameterCheck::getCheckTraversalKind() const {
+  // Use 'AsIs' to make sure the return type is exactly the same as the
+  // parameter type.
+  return TK_AsIs;
+}
+
+void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType(
+ hasCanonicalType(matchers::isReferenceToConst(
+  .bind("ret"),
+  this);
+}
+
+void ReturnConstRefFromParameterCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *R = Result.Nodes.getNodeAs("ret");
+  diag(R->getRetValue()->getBeginLoc(),
+   "return const reference parameter cause potential use-after-free "
+ 

[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-23 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/89497

>From 91915f68902ade86c0bf8eba643428017ae8bb3c Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 20 Apr 2024 17:58:19 +0800
Subject: [PATCH 1/7] [tidy] add new check
 bugprone-return-const-ref-from-parameter

Detects the function which returns the const reference from parameter which
causes potential use after free if the caller uses xvalue as argument.
In c++, const reference parameter can accept xvalue which will be destructed
after the call. When the function returns this parameter also as const 
reference,
then the returned reference can be used after the object it refers to has been
destroyed.
Fixes: #85253
---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../ReturnConstRefFromParameterCheck.cpp  | 41 +++
 .../ReturnConstRefFromParameterCheck.h| 35 
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +++
 .../return-const-ref-from-parameter.rst   | 30 ++
 .../docs/clang-tidy/checks/list.rst   |  9 ++--
 .../return-const-ref-from-parameter.cpp   | 31 ++
 8 files changed, 152 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 2931325d8b5798..1b92d2e60cc173 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -54,6 +54,7 @@
 #include "PosixReturnCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
+#include "ReturnConstRefFromParameterCheck.h"
 #include "SharedPtrArrayMismatchCheck.h"
 #include "SignalHandlerCheck.h"
 #include "SignedCharMisuseCheck.h"
@@ -137,6 +138,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 081ba67efe1538..2d303191f88650 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
new file mode 100644
index 00..87fc663231496e
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -0,0 +1,41 @@
+//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReturnConstRefFromParameterCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+std::optional
+ReturnConstRefFromParameterCheck::getCheckTraversalKind() const {
+  // Use 'AsIs' to make sure the return type is exactly the same as the
+  // parameter type.
+  return TK_AsIs;
+}
+
+void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType(
+ hasCanonicalType(matchers::isReferenceToConst(
+  .bind("ret"),
+  this);
+}
+
+void ReturnConstRefFromParameterCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *R = Result.Nodes.getNodeAs("ret");
+  diag(R->getRetValue()->getBeginLoc(),
+   "return const reference parameter cause potential use-after-free "
+ 

[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

2024-04-23 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/89497

>From 91915f68902ade86c0bf8eba643428017ae8bb3c Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 20 Apr 2024 17:58:19 +0800
Subject: [PATCH 1/8] [tidy] add new check
 bugprone-return-const-ref-from-parameter

Detects the function which returns the const reference from parameter which
causes potential use after free if the caller uses xvalue as argument.
In c++, const reference parameter can accept xvalue which will be destructed
after the call. When the function returns this parameter also as const 
reference,
then the returned reference can be used after the object it refers to has been
destroyed.
Fixes: #85253
---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../ReturnConstRefFromParameterCheck.cpp  | 41 +++
 .../ReturnConstRefFromParameterCheck.h| 35 
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +++
 .../return-const-ref-from-parameter.rst   | 30 ++
 .../docs/clang-tidy/checks/list.rst   |  9 ++--
 .../return-const-ref-from-parameter.cpp   | 31 ++
 8 files changed, 152 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 2931325d8b5798..1b92d2e60cc173 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -54,6 +54,7 @@
 #include "PosixReturnCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
+#include "ReturnConstRefFromParameterCheck.h"
 #include "SharedPtrArrayMismatchCheck.h"
 #include "SignalHandlerCheck.h"
 #include "SignedCharMisuseCheck.h"
@@ -137,6 +138,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 081ba67efe1538..2d303191f88650 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
new file mode 100644
index 00..87fc663231496e
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -0,0 +1,41 @@
+//===--- ReturnConstRefFromParameterCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReturnConstRefFromParameterCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+std::optional
+ReturnConstRefFromParameterCheck::getCheckTraversalKind() const {
+  // Use 'AsIs' to make sure the return type is exactly the same as the
+  // parameter type.
+  return TK_AsIs;
+}
+
+void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType(
+ hasCanonicalType(matchers::isReferenceToConst(
+  .bind("ret"),
+  this);
+}
+
+void ReturnConstRefFromParameterCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *R = Result.Nodes.getNodeAs("ret");
+  diag(R->getRetValue()->getBeginLoc(),
+   "return const reference parameter cause potential use-after-free "
+ 

[clang] [clang] Set correct FPOptions if attribute 'optnone' presents (PR #85605)

2024-04-23 Thread Serge Pavlov via cfe-commits

spavloff wrote:

Thanks!

> Is there any existing bookkeeping we no longer need to do if we're going to 
> have this RAII object in scope during function parsing?

It seems handling fast-math is the only case that prevented using this RAII 
object.

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


[clang] [clang][modules] Allow module maps with textual headers to be non-affecting (PR #89441)

2024-04-23 Thread Sam McCall via cfe-commits

sam-mccall wrote:

> @sam-mccall That makes sense.
> 
> I think one option we have here is to consider all module maps describing a 
> textual header that got included as affecting. I'm concerned that a long 
> chain of textual header includes might again be problematic.

Yeah, that's the option that comes closest to preserving previous behavior, and 
the one that I think most precisely captures the "affecting" semantics - 
including the module maps that were required for the compilation.

I've sent a version of this as https://github.com/llvm/llvm-project/pull/89729, 
based on your first commit here.

> For this particular test, we only need to consider the module maps describing 
> `use`d modules affecting to keep `-fmodules-strict-decluse` happy, which 
> seems like a more precise solution.

I'm not sure this is correct in general: if A uses B which uses C, and both B 
and C are textual, then C.modulemap affects the compilation of A.pcm but won't 
be picked up.

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


[clang] [llvm] [AArch64] Add intrinsics for 16-bit non-widening FMLA/FMLS (PR #88553)

2024-04-23 Thread Momchil Velikov via cfe-commits


@@ -458,6 +458,40 @@ let TargetGuard = "sme2,sme-f64f64" in {
   def SVMLS_LANE_VG1x4_F64 : Inst<"svmls_lane_za64[_{d}]_vg1x4", "vm4di", "d", 
MergeNone, "aarch64_sme_fmls_lane_vg1x4", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_1>]>;
 }
 
+let TargetGuard = "sme2p1,sme-f16f16" in {
+  def SVMLA_MULTI_VG1x2_F16 : Inst<"svmla_za16[_f16]_vg1x2", "vm22", "h", 
MergeNone, "aarch64_sme_fmla_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLA_MULTI_VG1x4_F16 : Inst<"svmla_za16[_f16]_vg1x4", "vm44", "h", 
MergeNone, "aarch64_sme_fmla_vg1x4", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_MULTI_VG1x2_F16 : Inst<"svmls_za16[_f16]_vg1x2", "vm22", "h", 
MergeNone, "aarch64_sme_fmls_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_MULTI_VG1x4_F16 : Inst<"svmls_za16[_f16]_vg1x4", "vm44", "h", 
MergeNone, "aarch64_sme_fmls_vg1x4", [IsStreaming, IsInOutZA], []>;
+
+  def SVMLA_SINGLE_VG1x2_F16 : Inst<"svmla[_single]_za16[_f16]_vg1x2", "vm2d", 
"h", MergeNone, "aarch64_sme_fmla_single_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLA_SINGLE_VG1x4_F16 : Inst<"svmla[_single]_za16[_f16]_vg1x4", "vm4d", 
"h", MergeNone, "aarch64_sme_fmla_single_vg1x4", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_SINGLE_VG1x2_F16 : Inst<"svmls[_single]_za16[_f16]_vg1x2", "vm2d", 
"h", MergeNone, "aarch64_sme_fmls_single_vg1x2", [IsStreaming, IsInOutZA], []>;
+  def SVMLS_SINGLE_VG1x4_F16 : Inst<"svmls[_single]_za16[_f16]_vg1x4", "vm4d", 
"h", MergeNone, "aarch64_sme_fmls_single_vg1x4", [IsStreaming, IsInOutZA], []>;
+
+  def SVMLA_LANE_VG1x2_F16 : Inst<"svmla_lane_za16[_f16]_vg1x2", "vm2di", "h", 
MergeNone, "aarch64_sme_fmla_lane_vg1x2", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+  def SVMLA_LANE_VG1x4_F16 : Inst<"svmla_lane_za16[_f16]_vg1x4", "vm4di", "h", 
MergeNone, "aarch64_sme_fmla_lane_vg1x4", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+  def SVMLS_LANE_VG1x2_F16 : Inst<"svmls_lane_za16[_f16]_vg1x2", "vm2di", "h", 
MergeNone, "aarch64_sme_fmls_lane_vg1x2", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+  def SVMLS_LANE_VG1x4_F16 : Inst<"svmls_lane_za16[_f16]_vg1x4", "vm4di", "h", 
MergeNone, "aarch64_sme_fmls_lane_vg1x4", [IsStreaming, IsInOutZA], 
[ImmCheck<3, ImmCheck0_7>]>;
+}
+
+let TargetGuard = "sme2,b16b16" in {

momchil-velikov wrote:

Arm ARM, version K.a (March 2024) 
(https://developer.arm.com/documentation/ddi0487/ka ), page A2-173
> If FEAT_SVE_B16B16 is implemented, then FEAT_SME2 or FEAT_SVE2 is implemented.

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


[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)

2024-04-23 Thread via cfe-commits

ealcdan wrote:

Sure, I just updated my settings, thanks for the suggestion.

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


[clang] [Clang][AArch64] Extend diagnostics when warning non/streaming about … (PR #88380)

2024-04-23 Thread Dinar Temirbulatov via cfe-commits

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


[clang] [clang-repl] Test explicit emission of dtors in runtime interface builder (NFC) (PR #89734)

2024-04-23 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail created 
https://github.com/llvm/llvm-project/pull/89734

This patch adds test coverage for an edge case that is supported already.

From 085a93919d8f65419cc856fe5584c83d3eceb142 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Tue, 23 Apr 2024 12:23:11 +0200
Subject: [PATCH] [clang-repl] Add test for explicit emission of dtors in the
 runtime interface builder

---
 clang/test/Interpreter/force-codegen-dtor.cpp | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 clang/test/Interpreter/force-codegen-dtor.cpp

diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp 
b/clang/test/Interpreter/force-codegen-dtor.cpp
new file mode 100644
index 00..a299ea46d5eac0
--- /dev/null
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -0,0 +1,13 @@
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl | FileCheck %s
+int *x = new int();
+template  struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); 
};
+template  GuardX::~GuardX() { delete x; x = nullptr; }
+
+// clang would normally defer codegen for ~GuardX()
+// Make sure that RuntimeInterfaceBuilder requests it explicitly
+(GuardX(x))
+
+// CHECK-NOT: Symbols not found
+// CHECK-NOT: _ZN6GuardXIiED2Ev

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


[clang] [clang-repl] Test explicit emission of dtors in runtime interface builder (NFC) (PR #89734)

2024-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Stefan Gränitz (weliveindetail)


Changes

This patch adds test coverage for an edge case that is supported already.

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


1 Files Affected:

- (added) clang/test/Interpreter/force-codegen-dtor.cpp (+13) 


``diff
diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp 
b/clang/test/Interpreter/force-codegen-dtor.cpp
new file mode 100644
index 00..a299ea46d5eac0
--- /dev/null
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -0,0 +1,13 @@
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl | FileCheck %s
+int *x = new int();
+template  struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); 
};
+template  GuardX::~GuardX() { delete x; x = nullptr; }
+
+// clang would normally defer codegen for ~GuardX()
+// Make sure that RuntimeInterfaceBuilder requests it explicitly
+(GuardX(x))
+
+// CHECK-NOT: Symbols not found
+// CHECK-NOT: _ZN6GuardXIiED2Ev

``




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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread via cfe-commits

cor3ntin wrote:

I'm not strongly opposed to merge that, however, i did confirm locally that  
removing the call to `MaybeDestroyTemplateIds` in `ParseStatementOrDeclaration` 
fixes the bug.

We  currently destroy annotations
 - At the end of a top level decl (and extern decl)
 - At the end of a member specification
 - At the end of statements

Removing the last case would only impact long functions using lots of 
templates.  so the added complexity feels a bit brittle and unnecessary to to 
me but I'll let Aron have the last word :)




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


[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)

2024-04-23 Thread Jannik Silvanus via cfe-commits

https://github.com/jasilvanus updated 
https://github.com/llvm/llvm-project/pull/89228

>From 5d4a3b0f922b0c28960f610c695c92da7d3538c1 Mon Sep 17 00:00:00 2001
From: Jannik Silvanus 
Date: Thu, 18 Apr 2024 14:56:47 +0200
Subject: [PATCH 1/2] [clang-format] Remove YAML hack to emit a BasedOnStyle
 comment

When serializing a formatting style to YAML, we were emitting a
comment `# BasedOnStyle: 

[clang] [clang-repl] Test explicit emission of dtors in runtime interface builder (NFC) (PR #89734)

2024-04-23 Thread Stefan Gränitz via cfe-commits


@@ -0,0 +1,13 @@
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl | FileCheck %s
+int *x = new int();
+template  struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); 
};
+template  GuardX::~GuardX() { delete x; x = nullptr; }
+
+// clang would normally defer codegen for ~GuardX()
+// Make sure that RuntimeInterfaceBuilder requests it explicitly
+(GuardX(x))
+
+// CHECK-NOT: Symbols not found
+// CHECK-NOT: _ZN6GuardXIiED2Ev

weliveindetail wrote:

I'd prefer a check like below that is more explicit, but we recognize 
expressions for value printing (the thing we parse as "semi-missing") only in 
trailing statements. If we added the code below, then `(GuardX(x))` is not 
considered trailing anymore, because we pipe he whole file into clang-repl.

```
#include 
auto x_addr = static_cast(reinterpret_cast(x));

extern "C" int printf(const char *, ...);
printf("0x%016" PRIx64 "\n", x_addr);

// CHECK: 0x0
```

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


[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)

2024-04-23 Thread Jannik Silvanus via cfe-commits


@@ -807,12 +807,18 @@ template <> struct MappingTraits {
 FormatStyle PredefinedStyle;
 if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) &&
 Style == PredefinedStyle) {
-  IO.mapOptional("# BasedOnStyle", StyleName);
+  // For convenience, emit the info which style this matches. However,
+  // setting BasedOnStyle will override all other keys when importing,
+  // so we set a helper key that is ignored when importing.
+  // Ideally, we'd want a YAML comment here, but that's not supported.
+  IO.mapOptional("OrigBasedOnStyle", StyleName);
   BasedOnStyle = StyleName;
   break;
 }
   }
 } else {
+  StringRef OrigBasedOnStyle; // ignored
+  IO.mapOptional("OrigBasedOnStyle", OrigBasedOnStyle);

jasilvanus wrote:

This allows the key being present in the input, avoiding an unknown key error. 
But now with all of it removed, this is no longer relevant.

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


[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)

2024-04-23 Thread Jannik Silvanus via cfe-commits

jasilvanus wrote:

I've removed the dummy field and the comment now. This should prevent confusion.
I don't know whether anyone actually uses the emitted comment, there is no 
explanation,
and tests pass without it.

I suggest that if we later learn that there are valid uses that require the 
comment, we should add proper comment
support in the YAML writer, and add a test for it.

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


[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-04-23 Thread Stefan Gränitz via cfe-commits

weliveindetail wrote:

FYI: The run on the Windows bot failed even though tests worked as expected. In 
particular, all `ClangReplInterpreterTests` unittests passed as well as all 
`Interpreter` LIT tests. I could land this towards the end of the week.

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


[clang] fast math test overhaul (PR #89687)

2024-04-23 Thread Zahira Ammarguellat via cfe-commits

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

LGTM. Thanks.

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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

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

aheejin wrote:

This first tried to enable four features (reference-types, multivalue, 
bulk-memory, and nontrapping-fptoint), but I think now we can enable the two 
first: reference-types and multivalue. These two were actually the first 
motivation I started this (these are necessary for the new EH spec adopted in 
Oct 2023). I believe I ran all emscripten tests with these two enabled and I 
don't think more tests fail than the current status. (We have some tests 
failing even now in the modes that are not regularly checked by CI, but 
enabling these two doesn't change that.)

Usually, when we enable new features, we provide corresponding lowering pass in 
Binaryen to support legacy users. But I don't think that's necessary or even 
possible for these two. You can lower neither all multivalue-returning 
functions away (especially when they are imported or exported), nor reference 
types away. But I think it's fine, given that these two features are not really 
generated unless you opt into it, for example, by explicitly using `__funcref` 
or `__externref`. And after #88492, multivalue code is not gonna be generated 
unless you explicitly use a multivalue ABI like `-Xclang -target-abi -Xclang 
experimental-mv` or use the new EH instructions (`try_table` vaiants) in LLVM, 
which have not been implemented yet. So even if we enable these two features, 
the legacy users wouldn't be suddenly getting reference types or multivalue in 
their code.

I'll modify this PR to enable the two features (multivalue and reference-types) 
first. That way I think we can land this soon. WDYT?

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


[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)

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

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


[clang-tools-extra] c52b18d - [clang-tidy] Avoid overflow when dumping unsigned integer values (#85060)

2024-04-23 Thread via cfe-commits

Author: ealcdan
Date: 2024-04-23T13:03:09+02:00
New Revision: c52b18d1e41107067b7557d8af3a06e6fe0beb0f

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

LOG: [clang-tidy] Avoid overflow when dumping unsigned integer values (#85060)

Some options take the maximum unsigned integer value as default, but
they are being dumped to a string as integers. This makes -dump-config
write invalid '-1' values for these options. This change fixes this
issue by using utostr if the option is unsigned.

Fixes #60217

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy

Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 3e926236adb451..710b361e16c0a7 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -139,6 +139,12 @@ void 
ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options,
   store(Options, LocalName, llvm::itostr(Value));
 }
 
+void ClangTidyCheck::OptionsView::storeUnsigned(
+ClangTidyOptions::OptionMap &Options, StringRef LocalName,
+uint64_t Value) const {
+  store(Options, LocalName, llvm::utostr(Value));
+}
+
 template <>
 void ClangTidyCheck::OptionsView::store(
 ClangTidyOptions::OptionMap &Options, StringRef LocalName,

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 656a2f008f6e0e..7427aa9bf48f89 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -411,7 +411,10 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 std::enable_if_t>
 store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
   T Value) const {
-  storeInt(Options, LocalName, Value);
+  if constexpr (std::is_signed_v)
+storeInt(Options, LocalName, Value);
+  else
+storeUnsigned(Options, LocalName, Value);
 }
 
 /// Stores an option with the check-local name \p LocalName with
@@ -422,7 +425,7 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
   std::optional Value) const {
   if (Value)
-storeInt(Options, LocalName, *Value);
+store(Options, LocalName, *Value);
   else
 store(Options, LocalName, "none");
 }
@@ -470,6 +473,8 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
   int64_t Value) const;
 
+void storeUnsigned(ClangTidyOptions::OptionMap &Options,
+   StringRef LocalName, uint64_t Value) const;
 
 std::string NamePrefix;
 const ClangTidyOptions::OptionMap &CheckOptions;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f3f9a81f9a8e82..28840b9beae881 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
   to aid in clang-tidy and test development.
+- Fixed bug where big values for unsigned check options overflowed into 
negative values
+  when being printed with ``--dump-config``.
 
 - Fixed ``--verify-config`` option not properly parsing checks when using the 
   literal operator in the ``.clang-tidy`` config.

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy
new file mode 100644
index 00..e33f0f8bb33218
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/5/.clang-tidy
@@ -0,0 +1,4 @@
+InheritParentConfig: true
+Checks: 'misc-throw-by-value-catch-by-reference'
+CheckOptions:
+  misc-throw-by-value-catch-by-reference.MaxSize: '1152921504606846976'

diff  --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
index ab4f3becb7a9fc..cb0f0bc4d13308 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -64,3 +64,11 @@
 
 //

[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)

2024-04-23 Thread via cfe-commits

github-actions[bot] wrote:



@ealcdan Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> I'm not strongly opposed to merge that, however, i did confirm locally that 
> removing the call to `MaybeDestroyTemplateIds` in 
> `ParseStatementOrDeclaration` fixes the bug.
> 
> We currently destroy annotations
> 
> * At the end of a top level decl (and extern decl)
> * At the end of a member specification
> * At the end of statements
> 
> Removing the last case would only impact long functions using lots of 
> templates. so the added complexity feels a bit brittle and unnecessary to to 
> me but I'll let Aron have the last word :)

@AaronBallman Would you mind giving a final stamp on this? Or if you also feel 
the complexity is unnecessary (based on Corentin's opinion), I'd love to do it 
the other way around. :)

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


[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-04-23 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/84481

>From 8fdf6306085ed4cf0f77b7e718e374e9f65fedf9 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 8 Mar 2024 19:02:47 +0530
Subject: [PATCH 01/14] add clang-tidy check
 readability-math-missing-parentheses

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../MathMissingParenthesesCheck.cpp   | 167 ++
 .../readability/MathMissingParenthesesCheck.h |  31 
 .../readability/ReadabilityTidyModule.cpp |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../readability/math-missing-parentheses.rst  |  19 ++
 .../readability/math-missing-parentheses.cpp  |  42 +
 8 files changed, 270 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index a6c8cbd8eb448a..0d4fa095501dfb 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangTidyReadabilityModule
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
   MakeMemberFunctionConstCheck.cpp
+  MathMissingParenthesesCheck.cpp
   MisleadingIndentationCheck.cpp
   MisplacedArrayIndexCheck.cpp
   NamedParameterCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
new file mode 100644
index 00..d9574a9fb7a476
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -0,0 +1,167 @@
+//===--- MathMissingParenthesesCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MathMissingParenthesesCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
+hasDescendant(binaryOperator()))
+ .bind("binOp"),
+ this);
+}
+static int precedenceCheck(const char op) {
+  if (op == '/' || op == '*' || op == '%')
+return 5;
+
+  else if (op == '+' || op == '-')
+return 4;
+
+  else if (op == '&')
+return 3;
+  else if (op == '^')
+return 2;
+
+  else if (op == '|')
+return 1;
+
+  else
+return 0;
+}
+static bool isOperand(const char c) {
+  if (c >= 'a' && c <= 'z')
+return true;
+  else if (c >= 'A' && c <= 'Z')
+return true;
+  else if (c >= '0' && c <= '9')
+return true;
+  else if (c == '$')
+return true;
+  else
+return false;
+}
+static bool conditionForNegative(const std::string s, int i,
+ const std::string CurStr) {
+  if (CurStr[0] == '-') {
+if (i == 0) {
+  return true;
+} else {
+  while (s[i - 1] == ' ') {
+i--;
+  }
+  if (!isOperand(s[i - 1])) {
+return true;
+  } else {
+return false;
+  }
+}
+  } else {
+return false;
+  }
+}
+static std::string getOperationOrder(std::string s, std::set &Operators) 
{
+  std::stack StackOne;
+  std::string TempStr = "";
+  for (int i = 0; i < s.length(); i++) {
+std::string CurStr = "";
+CurStr += s[i];
+if (CurStr == " ")
+  continue;
+else {
+  if (isOperand(CurStr[0]) || conditionForNegative(s, i, CurStr)) {
+while (i < s.length() && (isOperand(s[i]) || s[i] == '-')) {
+  if (s[i] == '-') {
+TempStr += "$";
+  } else {
+TempStr += CurStr;
+  }
+  i++;
+  CurStr = s[i];
+}
+TempStr += " ";
+  } else if (CurStr == "(") {
+StackOne.push("(");
+  } else if (CurStr == ")") {
+while (StackOne.top() != "(") {
+  TempStr += StackOne.top();
+  StackOne.pop();
+}
+StackOne.pop();
+  } else {
+while (!StackOne.empty() && precedenceCh

[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-04-23 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

hello @5chmidti I am sorry for my delayed response quite busy with my academic 
work last week, I have added this change
```
if (EndLoc.isInvalid())
  return;
 ```
 this works fine for those macros.
 Thank you

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


[clang] [clang-repl] Test explicit emission of dtors in runtime interface builder (NFC) (PR #89734)

2024-04-23 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,13 @@
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl | FileCheck %s
+int *x = new int();
+template  struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); 
};
+template  GuardX::~GuardX() { delete x; x = nullptr; }
+
+// clang would normally defer codegen for ~GuardX()
+// Make sure that RuntimeInterfaceBuilder requests it explicitly
+(GuardX(x))
+
+// CHECK-NOT: Symbols not found
+// CHECK-NOT: _ZN6GuardXIiED2Ev

vgvassilev wrote:

How about a printf in the dtor?

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


[clang] Push immediate function context while transforming lambdas in templates. (PR #89702)

2024-04-23 Thread Daniel M. Katz via cfe-commits

katzdm wrote:

> LGTM, thanks! Will you need me to merge the change for you?

@cor3ntin That would be great, thanks!

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-23 Thread via cfe-commits

edunad wrote:

@nicovank You're right ^^, it's better to just use negative regex, i'll close 
this PR then

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-23 Thread via cfe-commits

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


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

2024-04-23 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,194 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +fullbf16 
-S -emit-llvm %s -o - | FileCheck %s
+// CHECK-LABEL: define dso_local half @test_convert_from_bf16_to_fp16(
+// CHECK-SAME: bfloat noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca bfloat, align 2
+// CHECK-NEXT:store bfloat [[A]], ptr [[A_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load bfloat, ptr [[A_ADDR]], align 2
+// CHECK-NEXT:[[CONV:%.*]] = fpext bfloat [[TMP0]] to float
+// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to half
+// CHECK-NEXT:ret half [[CONV1]]
+//
+_Float16 test_convert_from_bf16_to_fp16(__bf16 a) {
+return (_Float16)a;
+}
+
+// CHECK-LABEL: define dso_local bfloat @test_convert_from_fp16_to_bf16(
+// CHECK-SAME: half noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store half [[A]], ptr [[A_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load half, ptr [[A_ADDR]], align 2
+// CHECK-NEXT:[[CONV:%.*]] = fpext half [[TMP0]] to float
+// CHECK-NEXT:[[CONV1:%.*]] = fptrunc float [[CONV]] to bfloat
+// CHECK-NEXT:ret bfloat [[CONV1]]
+//
+__bf16 test_convert_from_fp16_to_bf16(_Float16 a) {
+return (__bf16)a;
+}
+
+typedef _Float16 half2 __attribute__((ext_vector_type(2)));
+typedef _Float16 half4 __attribute__((ext_vector_type(4)));
+
+typedef __bf16 bfloat2 __attribute__((ext_vector_type(2)));
+typedef __bf16 bfloat4 __attribute__((ext_vector_type(4)));
+
+// CHECK-LABEL: define dso_local i32 @test_cast_from_fp162_to_bf162(
+// CHECK-SAME: i32 noundef [[IN_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x bfloat>, align 4
+// CHECK-NEXT:[[IN:%.*]] = alloca <2 x half>, align 4
+// CHECK-NEXT:[[IN_ADDR:%.*]] = alloca <2 x half>, align 4
+// CHECK-NEXT:store i32 [[IN_COERCE]], ptr [[IN]], align 4
+// CHECK-NEXT:[[IN1:%.*]] = load <2 x half>, ptr [[IN]], align 4
+// CHECK-NEXT:store <2 x half> [[IN1]], ptr [[IN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load <2 x half>, ptr [[IN_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x half> [[TMP0]] to <2 x bfloat>

arsenm wrote:

Does GCC have the same behavior for the bfloat x half case? 

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


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

2024-04-23 Thread Matt Arsenault via cfe-commits

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


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

2024-04-23 Thread Matt Arsenault via cfe-commits

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

LGTM. Would be good to verify the vector case is "correct" in as far as it's 
what GCC does 

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


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

2024-04-23 Thread Matt Arsenault via cfe-commits


@@ -1431,9 +1431,13 @@ Value *ScalarExprEmitter::EmitScalarCast(Value *Src, 
QualType SrcType,
 return Builder.CreateFPToUI(Src, DstTy, "conv");
   }
 
-  if (DstElementTy->getTypeID() < SrcElementTy->getTypeID())
+  if ((DstElementTy->is16bitFPTy() && SrcElementTy->is16bitFPTy())) {
+Value *FloatVal = Builder.CreateFPExt(Src, Builder.getFloatTy(), "conv");
+return Builder.CreateFPTrunc(FloatVal, DstTy, "conv");
+  } else if (DstElementTy->getTypeID() < SrcElementTy->getTypeID())

arsenm wrote:

No else after return (although it's already violated in the existing code) 

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-23 Thread via cfe-commits

cor3ntin wrote:

> > > This approach is doable technically, but it feels hacky and fragile. What 
> > > if we emit an error (or warning) diagnostic and reject the code when we 
> > > parse the __is_deducible type trait?
> > 
> > 
> > Why do you think it is fragile? I think a comment around `BTT_IsDeducible` 
> > would take care of that
> 
> This is not a single-place change, we have to duplicate the `BTT_IsDeducible` 
> manual change for at least 4 places:
> 
> * 
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/TypeTraits.h#L28
> * 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/TypeTraits.cpp#L21
> * 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/TypeTraits.cpp#L30
> * 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/TypeTraits.cpp#L61

Something like that seem to be fine

```cpp
// IsDeducible is only used internally by clang and is not exposed to source 
code
TYPE_TRAIT_2(/**/, IsDeducible, KEYCXX)
```

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


[clang] [clang-repl] Test explicit emission of dtors in runtime interface builder (NFC) (PR #89734)

2024-04-23 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/89734

From 085a93919d8f65419cc856fe5584c83d3eceb142 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Tue, 23 Apr 2024 12:23:11 +0200
Subject: [PATCH 1/2] [clang-repl] Add test for explicit emission of dtors in
 the runtime interface builder

---
 clang/test/Interpreter/force-codegen-dtor.cpp | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 clang/test/Interpreter/force-codegen-dtor.cpp

diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp 
b/clang/test/Interpreter/force-codegen-dtor.cpp
new file mode 100644
index 00..a299ea46d5eac0
--- /dev/null
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -0,0 +1,13 @@
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl | FileCheck %s
+int *x = new int();
+template  struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); 
};
+template  GuardX::~GuardX() { delete x; x = nullptr; }
+
+// clang would normally defer codegen for ~GuardX()
+// Make sure that RuntimeInterfaceBuilder requests it explicitly
+(GuardX(x))
+
+// CHECK-NOT: Symbols not found
+// CHECK-NOT: _ZN6GuardXIiED2Ev

From 6fab67a6cf689c33a93748c66414050dfdf43d21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Tue, 23 Apr 2024 14:06:57 +0200
Subject: [PATCH 2/2] Add printf in dtor

---
 clang/test/Interpreter/force-codegen-dtor.cpp | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp 
b/clang/test/Interpreter/force-codegen-dtor.cpp
index a299ea46d5eac0..07758bb3fa0991 100644
--- a/clang/test/Interpreter/force-codegen-dtor.cpp
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -1,13 +1,17 @@
+// REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 
 // RUN: cat %s | clang-repl | FileCheck %s
 int *x = new int();
 template  struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); 
};
-template  GuardX::~GuardX() { delete x; x = nullptr; }
 
-// clang would normally defer codegen for ~GuardX()
-// Make sure that RuntimeInterfaceBuilder requests it explicitly
+// clang normally defers codegen for this out-of-line ~GuardX(), which would
+// cause the JIT to report Symbols not found: [ _ZN6GuardXIiED2Ev ]
+extern "C" int printf(const char *, ...);
+template  GuardX::~GuardX() { delete x; printf("Running dtor\n"); }
+
+// Let's make sure that the RuntimeInterfaceBuilder requests it explicitly:
 (GuardX(x))
 
 // CHECK-NOT: Symbols not found
-// CHECK-NOT: _ZN6GuardXIiED2Ev
+// CHECK: Running dtor

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


[clang] clang/win: Add a flag to disable default-linking of compiler-rt libraries (PR #89642)

2024-04-23 Thread via cfe-commits

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

lgtm

Both changes mentioned in the description are old-ish. Maybe expand it to cover 
what was the recent change triggering the need for a flag?

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


[clang] [Driver] Improve error when a compiler-rt library is not found (PR #81037)

2024-04-23 Thread Nico Weber via cfe-commits


@@ -656,19 +656,29 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, 
StringRef Component,
   // Check for runtime files in the new layout without the architecture first.
   std::string CRTBasename =
   buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  SmallString<128> Path;
   for (const auto &LibPath : getLibraryPaths()) {
 SmallString<128> P(LibPath);
 llvm::sys::path::append(P, CRTBasename);
 if (getVFS().exists(P))
   return std::string(P);
+if (Path.empty())
+  Path = P;
   }
+  if (getTriple().isOSAIX())
+Path.clear();
 
-  // Fall back to the old expected compiler-rt name if the new one does not
-  // exist.
+  // Check the filename for the old layout if the new one does not exist.
   CRTBasename =
   buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
-  SmallString<128> Path(getCompilerRTPath());
-  llvm::sys::path::append(Path, CRTBasename);
+  SmallString<128> OldPath(getCompilerRTPath());
+  llvm::sys::path::append(OldPath, CRTBasename);
+  if (Path.empty() || getVFS().exists(OldPath))
+return std::string(OldPath);
+
+  // If none is found, use a file name from the new layout, which may get
+  // printed in an error message, aiding users in knowing what Clang is
+  // looking for.

nico wrote:

Oh sorry, that comment was for #87866, which I think does change behavior 
outside of warning messages, combined with this change. 
https://crbug.com/335997052 has details. I'll move the comment to that other PR.

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


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-23 Thread Nico Weber via cfe-commits

nico wrote:

This is a behavior change: In distributed build environments, neither lib file 
exists at compile time. Previously, this would result in the "old" style, now 
(together with #81037) it results in the "new" style (which we disable 
everywhere since it causes all kinds of issues – from what I can tell, we're 
not alone in this).

Is there some way we can tell clang that we always want the old style here, 
independent of what's on disk?

[ttps://crbug.com/335997052](https://crbug.com/335997052) has details.

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


[clang] clang/win: Add a flag to disable default-linking of compiler-rt libraries (PR #89642)

2024-04-23 Thread Nico Weber via cfe-commits

https://github.com/nico updated https://github.com/llvm/llvm-project/pull/89642

>From 39bd2d2ece1f55c3c77e1f376913846fb604be27 Mon Sep 17 00:00:00 2001
From: Nico Weber 
Date: Mon, 22 Apr 2024 14:05:04 -0400
Subject: [PATCH] clang/win: Add a flag to disable default-linking of
 compiler-rt libraries

For ASan, users already manually have to pass in the path to the lib,
and for other libraries they have to pass in the path to the libpath.

With LLVM's unreliable name of the lib (due to
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR confusion and whatnot), it's useful
to be able to opt in to just explicitly passing the paths to the libs
everywhere.

Follow-up of sorts to https://reviews.llvm.org/D65543, and to #87866.
---
 clang/docs/UsersManual.rst|  3 +++
 clang/include/clang/Driver/Options.td |  8 
 clang/lib/Driver/SanitizerArgs.cpp|  8 ++--
 clang/lib/Driver/ToolChains/Clang.cpp |  8 ++--
 clang/test/Driver/cl-options.c|  4 
 clang/test/Driver/sanitizer-ld.c  | 14 ++
 6 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c464bc3a69adc5..8df40566fcba3d 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -4921,6 +4921,9 @@ directory. Using the example installation above, this 
would mean passing
 If the user links the program with the ``clang`` or ``clang-cl`` drivers, the
 driver will pass this flag for them.
 
+The auto-linking can be disabled with -fno-rtlib-defaultlib. If that flag is
+used, pass the complete flag to required libraries as described for ASan below.
+
 If the linker cannot find the appropriate library, it will emit an error like
 this::
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9f86808145d9ab..902eb450a7e042 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5502,6 +5502,14 @@ def fno_rtlib_add_rpath: Flag<["-"], 
"fno-rtlib-add-rpath">,
   Visibility<[ClangOption, FlangOption]>,
   HelpText<"Do not add -rpath with architecture-specific resource directory to 
the linker flags. "
   "When --hip-link is specified, do not add -rpath with HIP runtime library 
directory to the linker flags">;
+def frtlib_defaultlib : Flag<["-"], "frtlib-defaultlib">,
+  Visibility<[ClangOption, CLOption]>,
+  Group,
+  HelpText<"On Windows, emit /defaultlib: directives to 
link compiler-rt libraries (default)">;
+def fno_rtlib_defaultlib : Flag<["-"], "fno-rtlib-defaultlib">,
+  Visibility<[ClangOption, CLOption]>,
+  Group,
+  HelpText<"On Windows, do not emit /defaultlib: 
directives to link compiler-rt libraries">;
 def offload_add_rpath: Flag<["--"], "offload-add-rpath">,
   Flags<[NoArgumentUnused]>,
   Alias;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 8bfe9f02a091d1..6a4f2548c0bffa 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1192,7 +1192,9 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const 
llvm::opt::ArgList &Args,
   BinaryMetadataIgnorelistFiles);
   }
 
-  if (TC.getTriple().isOSWindows() && needsUbsanRt()) {
+  if (TC.getTriple().isOSWindows() && needsUbsanRt() &&
+  Args.hasFlag(options::OPT_frtlib_defaultlib,
+   options::OPT_fno_rtlib_defaultlib, true)) {
 // Instruct the code generator to embed linker directives in the object 
file
 // that cause the required runtime libraries to be linked.
 CmdArgs.push_back(
@@ -1203,7 +1205,9 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const 
llvm::opt::ArgList &Args,
   "--dependent-lib=" +
   TC.getCompilerRTBasename(Args, "ubsan_standalone_cxx")));
   }
-  if (TC.getTriple().isOSWindows() && needsStatsRt()) {
+  if (TC.getTriple().isOSWindows() && needsStatsRt() &&
+  Args.hasFlag(options::OPT_frtlib_defaultlib,
+   options::OPT_fno_rtlib_defaultlib, true)) {
 CmdArgs.push_back(Args.MakeArgString(
 "--dependent-lib=" + TC.getCompilerRTBasename(Args, "stats_client")));
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f8a81ee8ab56bc..3d31ac3cd0e34c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -637,7 +637,9 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
ProfileGenerateArg->getValue()));
 // The default is to use Clang Instrumentation.
 CmdArgs.push_back("-fprofile-instrument=clang");
-if (TC.getTriple().isWindowsMSVCEnvironment()) {
+if (TC.getTriple().isWindowsMSVCEnvironment() &&
+Args.hasFlag(options::OPT_frtlib_defaultlib,
+ options::OPT_fno_rtlib_defaultlib, 

[clang] clang/win: Add a flag to disable default-linking of compiler-rt libraries (PR #89642)

2024-04-23 Thread Nico Weber via cfe-commits

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


[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread Aaron Ballman via cfe-commits

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


[clang] clang/win: Add a flag to disable default-linking of compiler-rt libraries (PR #89642)

2024-04-23 Thread Nico Weber via cfe-commits

nico wrote:

Good call-out, thanks. I meant #87866, which is new.

I also forgot that llvm-project likes to do squash commits and put the new 
commit message in the old commit and `git push -f`'d. But the only thing that 
changed in the new commit is the commit message text.

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


[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for the fix! You should also add a release note to 
clang/docs/ReleaseNotes.rst so that users know about the improvement.

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


[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

2024-04-23 Thread Aaron Ballman via cfe-commits


@@ -14644,6 +14644,17 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
 return QualType();
   }
 
+  // C++11 [expr.unary.op] p4:
+  // A pointer to member is only formed when an explicit & is used and
+  // its operand is a qualified-id not enclosed in parentheses.
+  if (isa(OrigOp.get())) {
+// `op->getEndLoc()` is the last part of the qualified-id.
+// For example, "baz" in "foo::bar::baz".
+Diag(op->getEndLoc(), diag::err_invalid_non_static_member_use)
+<< dcl->getDeclName() << op->getSourceRange();

AaronBallman wrote:

We should also add a fix-it to remove the parentheses as a kindness to the user.

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


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-23 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> This is a behavior change: In distributed build environments, neither lib 
> file exists at compile time. Previously, this would result in the "old" 
> style, now (together with #81037) it results in the "new" style (which we 
> disable everywhere since it causes all kinds of issues – from what I can 
> tell, we're not alone in this).

Hmm, in which cases does this PR change anything of what happens at compile 
time? The only functional behaviour difference I'm aware of, is that `clang 
--print-runtime-dir` now always prints the new style path, even if the old 
style path exists and was expected to be used.

There have been talks about embedding directives for autolinking compiler-rt 
builtins for msvc mode builds, and switching between old and new path style 
depending on what files exist on disk (which would be a problem for the kind of 
distributed build environment you have, admittedly!), but that's not 
implemented yet. Or is this already the case for embedded directives for asan? 
And based on your linked issue, apparently also for profiling?

Can you distill out a minimal standalone command that showcases compiling, and 
shows the embedded directive that gets changed by this PR?

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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libclc] [libcxx] [libcxxabi] [libunwind] [lld] [lldb] [llvm] [mlir] [openmp] [polly] [pstl] Update IDE Folders (PR #89153)

2024-04-23 Thread Michael Kruse via cfe-commits

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


[clang] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)

2024-04-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Precommit CI is currently failing on libc++ tests that are impacted by this 
change; should I solve those as part of this patch or are you okay with fixing 
those after this patch lands? (Or would you like to push a fix to this branch?)

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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Oops, I misunderstood what @cor3ntin was saying. One moment while I re-think 
now that I have understood his point better.

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


[clang] 8ab3caf - [Clang][Parser] Don't always destroy template annotations at the end of a declaration (#89494)

2024-04-23 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-04-23T20:34:22+08:00
New Revision: 8ab3caf4d3acef29f373e09bc6a0ac459918930e

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

LOG: [Clang][Parser] Don't always destroy template annotations at the end of a 
declaration (#89494)

Since
[6163aa9](https://github.com/llvm/llvm-project/commit/6163aa96799cbad7f2f58e02c5bebee9647056a5#diff-3a7ef0bff7d2b73b4100de636f09ea68b72eda191b39c8091a6a1765d917c1a2),
we have introduced an optimization that almost always destroys
TemplateIdAnnotations at the end of a function declaration. This doesn't
always work properly: a lambda within a default template argument could
also result in such deallocation and hence a use-after-free bug while
building a type constraint on the template parameter.

This patch adds another flag to the parser to tell apart cases when we
shouldn't do such cleanups eagerly. A bit complicated as it is, this retains
the optimization on a highly templated function with lots of generic lambdas.

Note the test doesn't always trigger a conspicuous bug/crash even with a
debug build. But a sanitizer build can detect them, I believe.

Fixes https://github.com/llvm/llvm-project/issues/67235
Fixes https://github.com/llvm/llvm-project/issues/89127

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseTemplate.cpp
clang/test/Parser/cxx2a-constrained-template-param.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f339fab6e8428f..3db558a1c11a3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -560,6 +560,7 @@ Bug Fixes to C++ Support
 - Fix the Itanium mangling of lambdas defined in a member of a local class 
(#GH88906)
 - Fixed a crash when trying to evaluate a user-defined ``static_assert`` 
message whose ``size()``
   function returns a large or negative value. Fixes (#GH89407).
+- Fixed a use-after-free bug in parsing of type constraints with default 
arguments that involve lambdas. (#GH67235)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 00a2f35d7f7041..fb117bf04087ee 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -313,7 +313,15 @@ class Parser : public CodeCompletionHandler {
   /// top-level declaration is finished.
   SmallVector TemplateIds;
 
+  /// Don't destroy template annotations in MaybeDestroyTemplateIds even if
+  /// we're at the end of a declaration. Instead, we defer the destruction 
until
+  /// after a top-level declaration.
+  /// Use DelayTemplateIdDestructionRAII rather than setting it directly.
+  bool DelayTemplateIdDestruction = false;
+
   void MaybeDestroyTemplateIds() {
+if (DelayTemplateIdDestruction)
+  return;
 if (!TemplateIds.empty() &&
 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
   DestroyTemplateIds();
@@ -329,6 +337,22 @@ class Parser : public CodeCompletionHandler {
 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
   };
 
+  struct DelayTemplateIdDestructionRAII {
+Parser &Self;
+bool PrevDelayTemplateIdDestruction;
+
+DelayTemplateIdDestructionRAII(Parser &Self,
+   bool DelayTemplateIdDestruction) noexcept
+: Self(Self),
+  PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
+  Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
+}
+
+~DelayTemplateIdDestructionRAII() noexcept {
+  Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
+}
+  };
+
   /// Identifiers which have been declared within a tentative parse.
   SmallVector TentativelyDeclaredIdentifiers;
 

diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index b07ce451e878eb..665253a6674d27 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -733,7 +733,12 @@ NamedDecl *Parser::ParseTypeParameter(unsigned Depth, 
unsigned Position) {
   // we introduce the type parameter into the local scope.
   SourceLocation EqualLoc;
   ParsedType DefaultArg;
+  std::optional DontDestructTemplateIds;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
+// The default argument might contain a lambda declaration; avoid 
destroying
+// parsed template ids at the end of that declaration because they can be
+// used in a type constraint later.
+DontDestructTemplateIds.emplace(*this, 
/*DelayTemplateIdDestruction=*/true);
 // The default argument may declare template parameters, notably
 // if it contains a generic lambda, so we need to increase
 // the templat

[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Oops. I thought there was some latency between clicking the merge button and 
your latest comment. Should I revert?

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


[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Oops. I thought there was some latency between clicking the merge button and 
> your latest comment. Should I revert?

No worries, I should have hit `Request Changes` instead of `Comment`. :-) No 
need to revert yet.

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


[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)

2024-04-23 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88735

>From 5be7a57838b8fe7042e0719911670f6f369db2e8 Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Thu, 28 Mar 2024 09:30:32 -0400
Subject: [PATCH] [clang-tidy] Refactor how NamedDecl are renamed

The handling of renaming failures and multiple usages related to those
failures is currently spread over several functions. Identifying the
failure NamedDecl for a given usage is also duplicated, once when
creating failures and again when identify usages. There are currently
two ways to a failed NamedDecl from a usage: use the canonical decl or
use the overridden method. With new methods about to be added, a cleanup
was in order.

The data flow is simplified as follows:
* The visitor always forwards NamedDecls to addUsage(NamedDecl).
* addUsage(NamedDecl) determines the failed NamedDecl and determines
  potential new names based on that failure. Usages are registered using
  addUsage(NamingCheckId).
* addUsage(NamingCheckId) is now protected and its single responsibility
  is maintaining the integrity of the failure/usage map.
---
 .../utils/RenamerClangTidyCheck.cpp   | 196 ++
 .../clang-tidy/utils/RenamerClangTidyCheck.h  |  14 +-
 2 files changed, 113 insertions(+), 97 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 962a243ce94d48..f5ed617365403a 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -61,6 +61,7 @@ struct 
DenseMapInfo {
 namespace clang::tidy {
 
 namespace {
+
 class NameLookup {
   llvm::PointerIntPair Data;
 
@@ -78,6 +79,7 @@ class NameLookup {
   operator bool() const { return !hasMultipleResolutions(); }
   const NamedDecl *operator*() const { return getDecl(); }
 };
+
 } // namespace
 
 static const NamedDecl *findDecl(const RecordDecl &RecDecl,
@@ -91,6 +93,44 @@ static const NamedDecl *findDecl(const RecordDecl &RecDecl,
   return nullptr;
 }
 
+/// Returns the function that \p Method is overridding. If There are none or
+/// multiple overrides it returns nullptr. If the overridden function itself is
+/// overridding then it will recurse up to find the first decl of the function.
+static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
+  if (Method->size_overridden_methods() != 1)
+return nullptr;
+
+  while (true) {
+Method = *Method->begin_overridden_methods();
+assert(Method && "Overridden method shouldn't be null");
+unsigned NumOverrides = Method->size_overridden_methods();
+if (NumOverrides == 0)
+  return Method;
+if (NumOverrides > 1)
+  return nullptr;
+  }
+}
+
+static bool hasNoName(const NamedDecl *Decl) {
+  return !Decl->getIdentifier() || Decl->getName().empty();
+}
+
+static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) {
+  const auto *Canonical = cast(ND->getCanonicalDecl());
+  if (Canonical != ND)
+return Canonical;
+
+  if (const auto *Method = dyn_cast(ND)) {
+if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
+  Canonical = cast(Overridden->getCanonicalDecl());
+
+if (Canonical != ND)
+  return Canonical;
+  }
+
+  return ND;
+}
+
 /// Returns a decl matching the \p DeclName in \p Parent or one of its base
 /// classes. If \p AggressiveTemplateLookup is `true` then it will check
 /// template dependent base classes as well.
@@ -132,24 +172,6 @@ static NameLookup findDeclInBases(const CXXRecordDecl 
&Parent,
   return NameLookup(Found); // If nullptr, decl wasn't found.
 }
 
-/// Returns the function that \p Method is overridding. If There are none or
-/// multiple overrides it returns nullptr. If the overridden function itself is
-/// overridding then it will recurse up to find the first decl of the function.
-static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
-  if (Method->size_overridden_methods() != 1)
-return nullptr;
-
-  while (true) {
-Method = *Method->begin_overridden_methods();
-assert(Method && "Overridden method shouldn't be null");
-unsigned NumOverrides = Method->size_overridden_methods();
-if (NumOverrides == 0)
-  return Method;
-if (NumOverrides > 1)
-  return nullptr;
-  }
-}
-
 namespace {
 
 /// Callback supplies macros to RenamerClangTidyCheck::checkMacro
@@ -192,10 +214,6 @@ class RenamerClangTidyVisitor
   : Check(Check), SM(SM),
 AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
 
-  static bool hasNoName(const NamedDecl *Decl) {
-return !Decl->getIdentifier() || Decl->getName().empty();
-  }
-
   bool shouldVisitTemplateInstantiations() const { return true; }
 
   bool shouldVisitImplicitCode() const { return false; }
@@ -246,29 +264,10 @@ class RenamerClangTidyVisitor
   }
 
   bool VisitNamedDecl(NamedDecl *Decl) {
-if (hasNoName(Decl))
- 

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

2024-04-23 Thread via cfe-commits

https://github.com/zmodem created 
https://github.com/llvm/llvm-project/pull/89751

The C++ standard requires that symmetric transfer from one coroutine to another 
is performed via a tail call. Failure to do so is a miscompile and often breaks 
programs by quickly overflowing the stack.

Until now, the coro split pass tried to ensure this in the 
`addMustTailToCoroResumes()` function by searching for `llvm.coro.resume` calls 
to lower as tail calls if the conditions were right: the right function 
arguments, attributes, calling convention etc., and if a `ret void` was sure to 
be reached after traversal with some ad-hoc constant folding following the call.

This was brittle, as the kind of implicit variants required for a tail call to 
happen could easily be broken by other passes (e.g. if some instruction got in 
between the `resume` and `ret`), see for example 
9d1cb18d19862fc0627e4a56e1e491a498e84c71 and 
284da049f5feb62b40f5abc41dda7895e3d81d72.

Also the logic seemed backwards: instead of searching for possible tail call 
candidates and doing them if the circumstances are right, it seems better to 
start with the intention of making the tail calls we need, and forcing the 
circumstances to be right.

Now that we have the `llvm.coro.await.suspend.handle` intrinsic (since 
f78688134026686288a8d310b493d9327753a022) which corresponds exactly to 
symmetric transfer, change the lowering of that to also include the `resume` 
part, always lowered as a tail call.

>From 33b07efe6d68cb4d17e96349b552ef5e5901d8c6 Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 26 Mar 2024 15:04:35 +0100
Subject: [PATCH] stuff

---
 clang/lib/CodeGen/CGCoroutine.cpp |   5 +-
 clang/test/CodeGenCoroutines/coro-await.cpp   |   3 +-
 .../coro-symmetric-transfer-01.cpp|   4 +-
 .../coro-symmetric-transfer-02.cpp|   6 +-
 llvm/docs/Coroutines.rst  |  19 +-
 llvm/docs/LangRef.rst |   2 +-
 llvm/include/llvm/IR/Intrinsics.td|   2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|   4 +-
 llvm/lib/Transforms/Coroutines/CoroInternal.h |   3 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  | 234 +-
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |   2 +-
 .../Coro/coro-split-musttail.ll   |  63 -
 .../Coro/coro-split-musttail1.ll  |  97 
 .../Coro/coro-split-musttail10.ll |  55 
 .../Coro/coro-split-musttail11.ll |  55 
 .../Coro/coro-split-musttail12.ll |  85 ---
 .../Coro/coro-split-musttail13.ll |  76 --
 .../Coro/coro-split-musttail2.ll  |  68 -
 .../Coro/coro-split-musttail3.ll  |  91 ---
 .../Coro/coro-split-musttail4.ll  |  66 -
 .../Coro/coro-split-musttail5.ll  |  63 -
 .../Coro/coro-split-musttail6.ll  | 112 -
 .../Coro/coro-split-musttail7.ll  | 115 -
 .../coro-await-suspend-lower-invoke.ll|   5 +-
 .../Coroutines/coro-await-suspend-lower.ll|   5 +-
 .../Coroutines/coro-preserve-final.ll | 131 --
 ...-split-musttail-chain-pgo-counter-promo.ll |   9 +-
 .../Coroutines/coro-split-musttail.ll |  17 +-
 .../Coroutines/coro-split-musttail1.ll|  32 ++-
 .../Coroutines/coro-split-musttail10.ll   |  13 +-
 .../Coroutines/coro-split-musttail11.ll   |  55 
 .../Coroutines/coro-split-musttail2.ll|  12 +-
 .../Coroutines/coro-split-musttail3.ll|  33 ++-
 .../Coroutines/coro-split-musttail4.ll|   5 +-
 .../Coroutines/coro-split-musttail5.ll|   5 +-
 .../Coroutines/coro-split-musttail6.ll|   9 +-
 .../Coroutines/coro-split-musttail7.ll|  15 +-
 37 files changed, 157 insertions(+), 1419 deletions(-)
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail1.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail10.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail11.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail12.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail13.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail2.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail3.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail4.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail5.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail6.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail7.ll
 delete mode 100644 llvm/test/Transforms/Coroutines/

[clang] [Clang][Parser] Don't always destroy template annotations at the end of a declaration (PR #89494)

2024-04-23 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> > Oops. I thought there was some latency between clicking the merge button 
> > and your latest comment. Should I revert?
> 
> No worries, I should have hit `Request Changes` instead of `Comment`. :-) No 
> need to revert yet.

OK, so if you feel that approach is better, I think I'd better to revert this 
commit, and I'm happy to re-apply it with that.

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


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

2024-04-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-coroutines

Author: Hans (zmodem)


Changes

The C++ standard requires that symmetric transfer from one coroutine to another 
is performed via a tail call. Failure to do so is a miscompile and often breaks 
programs by quickly overflowing the stack.

Until now, the coro split pass tried to ensure this in the 
`addMustTailToCoroResumes()` function by searching for `llvm.coro.resume` calls 
to lower as tail calls if the conditions were right: the right function 
arguments, attributes, calling convention etc., and if a `ret void` was sure to 
be reached after traversal with some ad-hoc constant folding following the call.

This was brittle, as the kind of implicit variants required for a tail call to 
happen could easily be broken by other passes (e.g. if some instruction got in 
between the `resume` and `ret`), see for example 
9d1cb18d19862fc0627e4a56e1e491a498e84c71 and 
284da049f5feb62b40f5abc41dda7895e3d81d72.

Also the logic seemed backwards: instead of searching for possible tail call 
candidates and doing them if the circumstances are right, it seems better to 
start with the intention of making the tail calls we need, and forcing the 
circumstances to be right.

Now that we have the `llvm.coro.await.suspend.handle` intrinsic (since 
f78688134026686288a8d310b493d9327753a022) which corresponds exactly to 
symmetric transfer, change the lowering of that to also include the `resume` 
part, always lowered as a tail call.

---

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


37 Files Affected:

- (modified) clang/lib/CodeGen/CGCoroutine.cpp (+1-4) 
- (modified) clang/test/CodeGenCoroutines/coro-await.cpp (+1-2) 
- (modified) clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp (+2-2) 
- (modified) clang/test/CodeGenCoroutines/coro-symmetric-transfer-02.cpp (+2-4) 
- (modified) llvm/docs/Coroutines.rst (+10-9) 
- (modified) llvm/docs/LangRef.rst (+1-1) 
- (modified) llvm/include/llvm/IR/Intrinsics.td (+1-1) 
- (modified) llvm/lib/Transforms/Coroutines/CoroInstr.h (+2-2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroInternal.h (+2-1) 
- (modified) llvm/lib/Transforms/Coroutines/CoroSplit.cpp (+59-175) 
- (modified) llvm/lib/Transforms/Coroutines/Coroutines.cpp (+1-1) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail.ll (-63) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail1.ll (-97) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail10.ll (-55) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail11.ll (-55) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail12.ll (-85) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail13.ll (-76) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail2.ll (-68) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail3.ll (-91) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail4.ll (-66) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail5.ll (-63) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail6.ll (-112) 
- (removed) 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail7.ll (-115) 
- (modified) llvm/test/Transforms/Coroutines/coro-await-suspend-lower-invoke.ll 
(+2-3) 
- (modified) llvm/test/Transforms/Coroutines/coro-await-suspend-lower.ll (+2-3) 
- (removed) llvm/test/Transforms/Coroutines/coro-preserve-final.ll (-131) 
- (modified) 
llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll 
(+2-7) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail.ll (+7-10) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail1.ll (+15-17) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail10.ll (+7-6) 
- (removed) llvm/test/Transforms/Coroutines/coro-split-musttail11.ll (-55) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail2.ll (+5-7) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail3.ll (+15-18) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail4.ll (+3-2) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail5.ll (+3-2) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (+5-4) 
- (modified) llvm/test/Transforms/Coroutines/coro-split-musttail7.ll (+9-6) 


``diff
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..e976734898b9b8 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -307,10 +307,7 @@ static LValueOrRValue 
emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
 break;
   }
   case CoroutineSuspendExpr::SuspendReturnType::SuspendHandle: {
-assert(SuspendRet->getType()->isPointerTy());
-
-

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

2024-04-23 Thread via cfe-commits

zmodem wrote:

What do you think?

(The test updates are a bit hacky for now, but I wanted to get feedback before 
spending more time on them. Also I think many of the tests become uninteresting 
after this patch and could probably be deleted.)

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


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

2024-04-23 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 c52b18d1e41107067b7557d8af3a06e6fe0beb0f 
33b07efe6d68cb4d17e96349b552ef5e5901d8c6 -- clang/lib/CodeGen/CGCoroutine.cpp 
clang/test/CodeGenCoroutines/coro-await.cpp 
clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp 
clang/test/CodeGenCoroutines/coro-symmetric-transfer-02.cpp 
llvm/lib/Transforms/Coroutines/CoroInstr.h 
llvm/lib/Transforms/Coroutines/CoroInternal.h 
llvm/lib/Transforms/Coroutines/CoroSplit.cpp 
llvm/lib/Transforms/Coroutines/Coroutines.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp 
b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 01eb75617e..ff037518cb 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -212,7 +212,8 @@ static void lowerAwaitSuspend(IRBuilder<> &Builder, 
CoroAwaitSuspendInst *CB,
 
   if (CB->getCalledFunction()->getIntrinsicID() ==
   Intrinsic::coro_await_suspend_handle) {
-// Follow the await_suspend by a lowered resume call to the returned 
coroutine.
+// Follow the await_suspend by a lowered resume call to the returned
+// coroutine.
 if (auto *Invoke = dyn_cast(CB))
   Builder.SetInsertPoint(Invoke->getNormalDest()->getFirstInsertionPt());
 
@@ -220,7 +221,7 @@ static void lowerAwaitSuspend(IRBuilder<> &Builder, 
CoroAwaitSuspendInst *CB,
 auto *ResumeAddr = LB.makeSubFnCall(NewCall, CoroSubFnInst::ResumeIndex,
 &*Builder.GetInsertPoint());
 
-LLVMContext& Ctx = Builder.getContext();
+LLVMContext &Ctx = Builder.getContext();
 FunctionType *ResumeTy = FunctionType::get(
 Type::getVoidTy(Ctx), PointerType::getUnqual(Ctx), false);
 auto *ResumeCall = Builder.CreateCall(ResumeTy, ResumeAddr, {NewCall});
diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp 
b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
index d891173156..1a92bc1636 100644
--- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -48,7 +48,7 @@ coro::LowererBase::LowererBase(Module &M)
 //call ptr @llvm.coro.subfn.addr(ptr %Arg, i8 %index)
 
 CallInst *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
-Instruction *InsertPt) {
+   Instruction *InsertPt) {
   auto *IndexVal = ConstantInt::get(Type::getInt8Ty(Context), Index);
   auto *Fn = Intrinsic::getDeclaration(&TheModule, Intrinsic::coro_subfn_addr);
 

``




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


[clang] [llvm] [mlir] Fix mismatches between function parameter definitions and declarations (PR #89512)

2024-04-23 Thread Troy Butler via cfe-commits

Troy-Butler wrote:

I do not have the ability to merge, so if everything looks good with my pull 
request, can the last reviewer please merge this? Thank you!

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


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

2024-04-23 Thread via cfe-commits

https://github.com/zmodem updated 
https://github.com/llvm/llvm-project/pull/89751

>From 33b07efe6d68cb4d17e96349b552ef5e5901d8c6 Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 26 Mar 2024 15:04:35 +0100
Subject: [PATCH 1/2] stuff

---
 clang/lib/CodeGen/CGCoroutine.cpp |   5 +-
 clang/test/CodeGenCoroutines/coro-await.cpp   |   3 +-
 .../coro-symmetric-transfer-01.cpp|   4 +-
 .../coro-symmetric-transfer-02.cpp|   6 +-
 llvm/docs/Coroutines.rst  |  19 +-
 llvm/docs/LangRef.rst |   2 +-
 llvm/include/llvm/IR/Intrinsics.td|   2 +-
 llvm/lib/Transforms/Coroutines/CoroInstr.h|   4 +-
 llvm/lib/Transforms/Coroutines/CoroInternal.h |   3 +-
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  | 234 +-
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |   2 +-
 .../Coro/coro-split-musttail.ll   |  63 -
 .../Coro/coro-split-musttail1.ll  |  97 
 .../Coro/coro-split-musttail10.ll |  55 
 .../Coro/coro-split-musttail11.ll |  55 
 .../Coro/coro-split-musttail12.ll |  85 ---
 .../Coro/coro-split-musttail13.ll |  76 --
 .../Coro/coro-split-musttail2.ll  |  68 -
 .../Coro/coro-split-musttail3.ll  |  91 ---
 .../Coro/coro-split-musttail4.ll  |  66 -
 .../Coro/coro-split-musttail5.ll  |  63 -
 .../Coro/coro-split-musttail6.ll  | 112 -
 .../Coro/coro-split-musttail7.ll  | 115 -
 .../coro-await-suspend-lower-invoke.ll|   5 +-
 .../Coroutines/coro-await-suspend-lower.ll|   5 +-
 .../Coroutines/coro-preserve-final.ll | 131 --
 ...-split-musttail-chain-pgo-counter-promo.ll |   9 +-
 .../Coroutines/coro-split-musttail.ll |  17 +-
 .../Coroutines/coro-split-musttail1.ll|  32 ++-
 .../Coroutines/coro-split-musttail10.ll   |  13 +-
 .../Coroutines/coro-split-musttail11.ll   |  55 
 .../Coroutines/coro-split-musttail2.ll|  12 +-
 .../Coroutines/coro-split-musttail3.ll|  33 ++-
 .../Coroutines/coro-split-musttail4.ll|   5 +-
 .../Coroutines/coro-split-musttail5.ll|   5 +-
 .../Coroutines/coro-split-musttail6.ll|   9 +-
 .../Coroutines/coro-split-musttail7.ll|  15 +-
 37 files changed, 157 insertions(+), 1419 deletions(-)
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail1.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail10.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail11.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail12.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail13.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail2.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail3.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail4.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail5.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail6.ll
 delete mode 100644 
llvm/test/Instrumentation/InstrProfiling/Coro/coro-split-musttail7.ll
 delete mode 100644 llvm/test/Transforms/Coroutines/coro-preserve-final.ll
 delete mode 100644 llvm/test/Transforms/Coroutines/coro-split-musttail11.ll

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..e976734898b9b8 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -307,10 +307,7 @@ static LValueOrRValue 
emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
 break;
   }
   case CoroutineSuspendExpr::SuspendReturnType::SuspendHandle: {
-assert(SuspendRet->getType()->isPointerTy());
-
-auto ResumeIntrinsic = CGF.CGM.getIntrinsic(llvm::Intrinsic::coro_resume);
-Builder.CreateCall(ResumeIntrinsic, SuspendRet);
+assert(SuspendRet->getType()->isVoidTy());
 break;
   }
   }
diff --git a/clang/test/CodeGenCoroutines/coro-await.cpp 
b/clang/test/CodeGenCoroutines/coro-await.cpp
index 75851d8805bb6e..7caaa6351844b2 100644
--- a/clang/test/CodeGenCoroutines/coro-await.cpp
+++ b/clang/test/CodeGenCoroutines/coro-await.cpp
@@ -370,8 +370,7 @@ extern "C" void TestTailcall() {
   // ---
   // Call coro.await.suspend
   // ---
-  // CHECK-NEXT: %[[RESUMED:.+]] = call ptr 
@llvm.coro.await.suspend.handle(ptr %[[AWAITABLE]], ptr %[[FRAME]], ptr 
@__await_suspend_wrapper_TestTailcall_await)
-  // CHECK-NEXT: call void @llvm.coro.resume(ptr %[[RESUMED]])
+  // CHECK-NEXT: c

[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/89756

We've recently seen the libclc llvm-link invocations become so long that they 
exceed the character limits on certain platforms.

Using a 'response file' should solve this by offloading the list of inputs into 
a separate file, and using special syntax to pass it to llvm-link. Note that 
neither the response file nor syntax aren't specific to Windows but we restrict 
it to that platform regardless. We have the option of expanding it to other 
platforms in the future.

>From 640b18bdf3ccd706a509b534d1b8a01b499eddd7 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 23 Apr 2024 13:50:54 +0100
Subject: [PATCH] [libclc] Use a response file when building on Windows

We've recently seen the libclc llvm-link invocations become so long that
they exceed the character limits on certain platforms.

Using a 'response file' should solve this by offloading the list of
inputs into a separate file, and using special syntax to pass it to
llvm-link. Note that neither the response file nor syntax aren't
specific to Windows but we restrict it to that platform regardless. We
have the option of expanding it to other platforms in the future.
---
 libclc/cmake/modules/AddLibclc.cmake | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index bbedc244a72899..7f4620fa6a21df 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -88,10 +88,25 @@ function(link_bc)
 ${ARGN}
   )
 
+  set( LINK_INPUT_ARG ${ARG_INPUTS} )
+  if( WIN32 OR CYGWIN )
+# Create a response file in case the number of inputs exceeds command-line
+# character limits on certain platforms.
+file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
+# Turn it into a space-separate list of input files
+list( JOIN ARG_INPUTS " " RSP_INPUT )
+file( WRITE ${RSP_FILE} ${RSP_INPUT} )
+# Ensure that if this file is removed, we re-run CMake
+set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  ${RSP_FILE}
+)
+set( LINK_INPUT_ARG "@${RSP_FILE}" )
+  endif()
+
   add_custom_command(
 OUTPUT ${ARG_TARGET}.bc
-COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${ARG_INPUTS}
-DEPENDS libclc::llvm-link ${ARG_INPUTS}
+COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
+DEPENDS libclc::llvm-link ${ARG_INPUTS} ${RSP_FILE}
   )
 
   add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )

___
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   >